userenv-fromenv 1 user commands nosh
userenv-fromenv set the "user" environment variables from a given UID
`userenv-fromenv` --no-set-user --no-set-shell --default-locale --default-path --default-term --default-timezone --default-tools --set-xdg --set-dbus --set-other --toolkit-pager next-prog

## Description

`userenv-fromenv` is a chain-loading utility that sets environment variables and then chain loads to next-prog with the execvp 3 function.

next-prog may contain its own command line options, which `userenv-fromenv` will ignore.

`userenv-fromenv` takes the value given in the `UID` environment variable as a user ID to look up in the system account database. That variable can be set by commands such as getuidgid 1, envuidgid 1. or login-envuidgid 1. It first looks up the account record whose name matches the value given in the `LOGNAME` environment variable, if that variable is set. If that account record's user ID field has the desired ID, it uses that record; otherwise, it looks up the account record by user ID.

This lookup by name falling back to lookup by ID allows for systems where multiple user names map to the same user ID in the system account database. It ensures that the right account record, with the desired name, home directory, and shell fields, is found and used.

From the contents of the account database record, it sets these environment variables.

### User account database variables

The following environment variables are set unless the --no-set-user command-line option is used:

`HOME`

  Set to the pathname of the user's home directory, as given in the system account database, falling back if the field is blank to unset.

`USER`
`LOGNAME`

  Set to the user's name, as given in the system account database, falling back if the field is blank to unset.

The following environment variables are set unless the --no-set-shell command-line option is used:

`SHELL`

  Set to the pathname of the user's shell program, as given in the system account database, falling back if the field is blank to the system's default "B" shell name that is hardwired into the C library. (This fallback is in line with the behaviour of login 1.)

### Path variables

The following environment variables are set from the login.conf 5 database if the --default-path command-line option is used and they are not already set:

`PATH`

  Set to the value of the `path` capability, defaulting if there is no capability to the system's default path that is hardwired into the C library.

`MANPATH`

  Set to the value of the `manpath` capability, defaulting to unset if there is no capability.

`TERMPATH`

  Set to the value of the `termpath` capability, defaulting if there is no capability to `/usr/local/etc/termcap`:`/etc/termcap`:`/usr/pkg/etc/termcap`:`/usr/share/misc/termcap`.

`TERMINFO_DIRS`

  Set to the value of the `terminfopath` capability, defaulting if there is no capability to `/usr/local/etc/terminfo`:`/etc/terminfo`:`/usr/pkg/etc/terminfo`:`/usr/share/misc/terminfo`.

### Tools variables

The following environment variables are set from the login.conf 5 database if the --default-tools command-line option is used and they are not already set:

`EDITOR`

  Set to the value of the `editor` capability, defaulting if there is no capability to `ex`. (POSIX gives two choices of universally available line editor. This is the one that is not ed 1.)

`VISUAL`

  Set to the value of the `visual` capability, defaulting if there is no capability to `vi`. (POSIX gives one choice of universally available full-screen editor.)

`PAGER`

  Set to the value of the `pager` capability, defaulting if there is no capability to `more`. (The Single Unix Specification dropped `pg` in 2017. `less` is not universal, and where it is available it is usually also available as `more` anyway. `most` is likewise not universal.) If the --toolkit-pager command-line option is used that default changes from the standard more 1 to the console-tty37-viewer 1 that comes in the same toolkit as `userenv-fromenv`.

### Terminal variables

The following environment variables are set from the login.conf 5 database if the --default-term command-line option is used and they are not already set:

`TERM` 7

  Set to the value of the `term` capability, defaulting if there is no capability to `ansi`. The `TERM` variable will have been set for a login session by the TTY login system, and this default will thus not be required.

### Locale variables

The following environment variables are set from the login.conf 5 database if the --default-locale command-line option is used and they are not already set:

`LANG`

  Set to the value of the `lang` capability, defaulting to `POSIX` if there is no capability.

`MM_CHARSET`

  Set to the value of the `charset` capability, defaulting to `UTF-8` if there is no capability.

### Timezone variables

The following environment variables are set from the login.conf 5 database if the --default-timezone command-line option is used and they are not already set:

`TZ`

  Set to the value of the `timezone` capability, defaulting to `UTC` if there is no capability.

### XDG variables

The following environment variables are set if the --set-xdg command-line option is used:

`XDG_RUNTIME_DIR`

  Set to `/run/user/username/`.

`XDG_CONFIG_DIRS`

  Set to `/usr/local/etc/xdg:/etc/xdg:/usr/pkg/etc/xdg`.

The addition of `/usr/local/etc` comes from the BSDs. `/usr/pkg/etc` is the conventional `$LOCALBASE/etc` from NetBSD pkgsrc.
`XDG_CONFIG_HOME`

  Unset, so that applications use the default of `$HOME/.config`.

`XDG_DATA_DIRS`

  Set to `/usr/local/share`:`/usr/pkg/share`:`/usr/share`:`/share`. The addition of `/share` comes from TrueOS Desktop. `/usr/pkg/share` is the conventional `$LOCALBASE/share` from NetBSD pkgsrc.

  TrueOS Desktop ordered the directories the other way around, giving operating system data files priority over "site local" ones. This ordering, on the other hand, is the ordering that is used in the XDG Desktop Specification.
`XDG_DATA_HOME`

  Unset, so that applications use the default of `$HOME/.local/share`.

`XDG_STATE_HOME`

  Unset, so that applications use the default of `$HOME/.local/state`.

`XDG_CACHE_HOME`

  Unset, so that applications use the default of `$HOME/.cache`.

`PATH`

  The value `$HOME/.local/bin` is prepended, after any login.conf 5 processing has been done.

`MANPATH`

  The value `$HOME/.local/share/man` is prepended, after any login.conf 5 processing has been done.

`TERMPATH`

  The value `$HOME/.config/termcap` is prepended, after any login.conf 5 processing has been done.

### Desktop Bus variables

The following environment variables are set if the --set-dbus command-line option is used:

`DBUS_SESSION_BUS_ADDRESS`

  Set to `unix:path=/run/user/username/bus`. (In practice, `unix:runtime=yes` is not actually supported yet by most operating systems.)

### Other variables

If the --set-other command-line option is used, all environment variables are set from the `setenv` capability in the login.conf 5 database. Both the system and user databases are processed. In line with the behaviour of login 1, any conflicting environment variables set here will be overridden by the variables taken from other capabilities and from the user account database, with the exceptions of the tools, XDG, and Desktop Bus variables, which will conversely be overriden by any settings here. This ordering is because the tools, XDG, and Desktop Bus variables are an extension, setting variables for which people will have been using `setenv`.

## bugs and compatibility

As of version 1.34 this program no longer employs the GNU C library nor the BSD C library for environment variable handling. The previously documented workaround for those libraries' have memory leaks in their setenv 3 and clearenv 3 functions, is therefore no longer necessary.

The FreeBSD login_getpath 3 library function has a bug that makes it impossible to specify paths containing space characters. This command implements the OpenBSD mechanism of allowing space characters, in the `path` and `manpath` capabilities, to be escaped with a backslash.

The FreeBSD login_getcaplist 3 library function has several bugs, one of which makes it impossible to specify paths containing comma characters. This command implements the OpenBSD mechanism of allowing comma characters, in the `setenv` capability, to be escaped with a backslash.

In both cases, the backslash must be itself escaped again in the actual capability file text, as this is two levels of escaping. First the comma/space is escaped to make an escape sequence in the unencoded capability string, then the capability string is encoded with a second level of escaping in order to store it as text in the capability file.

Unlike the OpenBSD behaviour, this command does not restrict the expansion of `~` and `$` to certain places in the aforementioned environment list and path strings. To include literal tildes and dollar characters anywhere in environment lists and paths, those characters too must always be (double) escaped with a backslash.

## See also

- userenv 1

- machineenv 1

- setenv 1

- envuidgid 1

- clearenv 1

## Author

Jonathan de Boyne Pollard