Bug 14078
| Summary: | Document -l (or bring su in line with D****n) | ||
|---|---|---|---|
| Product: | Sisyphus | Reporter: | Andrey Rahmatullin <wrar> |
| Component: | su | Assignee: | placeholder <placeholder> |
| Status: | NEW --- | QA Contact: | qa-sisyphus |
| Severity: | major | ||
| Priority: | P2 | CC: | dottedmag, glebfm, kharpost, ldv, led, mike, placeholder, vvk |
| Version: | unstable | ||
| Hardware: | all | ||
| OS: | Linux | ||
| Bug Depends on: | 23700 | ||
| Bug Blocks: | 77 | ||
Yes, ALT Linux su(1) and Debian su(1) differ. So, what do you suggest? Документировать, что происходит с окружением с - и без него. Т.е. толпы румяных линуксоидов не понимают что такое "login shell" и чем он отличается от обычного интерактивного? И при чём тут вообще su в таком случае? (In reply to comment #3) > Т.е. толпы румяных линуксоидов не понимают что такое "login shell" и чем он > отличается от обычного интерактивного? Да. Я, например. (In reply to comment #4) > Да. Я, например. man `basename $SHELL`, раздел INVOCATION или что-то в этом роде. Что при этом будет происходить с окружением зависит от шелла и его стартовых скриптов, а не от su... (In reply to comment #3) > Т.е. толпы румяных линуксоидов не понимают что такое "login shell" и чем он > отличается от обычного интерактивного? И при чём тут вообще su в таком случае? При том, что всю документацию не перечитаешь и возможность полагаться на привычки помогает примерно как кэш L1. Ну или хоть Url: починить, нынешний 404... подсказывают про http://www.linux-pam.org/pre/applications/ Актуально: в su(1) из SimplePAMApps 0.60-alt37 по-прежнему нет ни слова о том, что происходит с окружением, — только «-, -l, --login: Invoke the shell as a login shell».
Что происходит на самом деле (проверено на su 0.60-alt37):
- без «-»: окружение вызывающего передаётся целиком, включая PATH и HOME (то есть HOME остаётся домашним каталогом того, кто вызвал su), рабочий каталог не меняется;
- с «-»: переносятся только TERM, LANG, LC_*, TZ, DISPLAY (pamapps/lib/make_env.c, posix_env[]), а HOME, LOGNAME и PATH выставляются для целевого пользователя (pamapps/lib/setcred.c: /bin:/usr/bin:/usr/local/bin для обычного пользователя и /sbin:/usr/sbin:/usr/local/sbin:/bin:/usr/bin:/usr/local/bin для root; login-шелл затем обычно переопределяет PATH из /etc/profile), рабочий каталог меняется на домашний каталог целевого пользователя.
Патч ниже добавляет в su.1 раздел ENVIRONMENT с этим описанием и упоминанием отличия от su(1) из shadow (Debian и прочие), который сбрасывает PATH по /etc/login.defs и без «-». Рендеринг groff проверен.
--- a/pamapps/su/su.1
+++ b/pamapps/su/su.1
@@ -129,6 +129,46 @@
.BR su
configurations similar.
+.SH ENVIRONMENT
+Unless the
+.BR - " (" -l ", " --login )
+flag is given,
+.BR su
+passes the whole environment of the invoking user to the new shell
+unchanged. In particular
+.BR PATH " and " HOME
+keep the values they had before, so the assumed user's shell runs with
+the invoking user's search path and home directory, and the current
+working directory is not changed either.
+.sp
+With
+.BR - ", "
+only
+.BR TERM ", " LANG ", " LC_* ", " TZ " and " DISPLAY
+are carried over from the invoking user; the rest of the environment is
+built for the assumed user:
+.BR HOME " and " LOGNAME
+are taken from the password database and
+.BR PATH
+is set to
+.I /bin:/usr/bin:/usr/local/bin
+for an ordinary user and to
+.I /sbin:/usr/sbin:/usr/local/sbin:/bin:/usr/bin:/usr/local/bin
+for the superuser (a login shell usually overrides
+.BR PATH
+again from
+.IR /etc/profile ).
+The working directory is changed to the assumed user's home directory.
+.sp
+Note that this differs from
+.BR su (1)
+of the shadow suite (Debian and others), which resets
+.BR PATH
+from
+.I /etc/login.defs
+even without
+.BR - "."
+
.SH "EXIT CODE"
On successful completion of its task,
|

Description
Andrey Rahmatullin 2008-01-18 15:35:15 MSKALT Linux su(1) keeps running user's $PATH (maybe other variables) when invoked without -l. This behavior is different from e.g. Debian and is confusing. Moreover, this behavior (neither default nor with -l) is not documented in any way: By default the user's shell is invoked directly, however, giving the argument flag -, su is instructed to invoke the shell as a login shell. This means that the current working directory will be changed to the home of the new user and the shell's first argument will be prefixed with a -. [...] -, -l, --login Invoke the shell as a login shell. Compare with Debian su(1): The optional argument - may be used to provide an environment similar to what the user would expect had the user logged in directly. [...] The current environment is passed to the new shell. The value of $PATH is reset to /bin:/usr/bin for normal users, or /sbin:/bin:/usr/sbin:/usr/bin for the superuser. This may be changed with the ENV_PATH and ENV_SUPATH definitions in /etc/login.defs. [...] -, -l, --login Provide an environment similar to what the user would expect had the user logged in directly.