History log of /freebsd-10.1-release/usr.bin/su/su.c
Revision Date Author Comments
(<<< Hide modified files)
(Show modified files >>>)
# 272461 02-Oct-2014 gjb

Copy stable/10@r272459 to releng/10.1 as part of
the 10.1-RELEASE process.

Approved by: re (implicit)
Sponsored by: The FreeBSD Foundation

# 256281 10-Oct-2013 gjb

Copy head (r256279) to stable/10 as part of the 10.0-RELEASE cycle.

Approved by: re (implicit)
Sponsored by: The FreeBSD Foundation


# 254259 12-Aug-2013 trasz

Make check for unknown login class actually work. Previously, using the "-c" option
with login class not defined in login.conf(5) would silently fail, resulting in using
the default login class.


# 220055 27-Mar-2011 ume

getpwnam(3) may return NULL.

Requested by: nork
Reviewed by: Takeharu KATO <takeharu1219__at__ybb.ne.jp>, nork
MFC after: 1 week


# 216370 11-Dec-2010 joel

Remove the advertising clause from UCB copyrighted files in usr.bin. This
is in accordance with the information provided at
ftp://ftp.cs.berkeley.edu/pub/4bsd/README.Impt.License.Change

Also add $FreeBSD$ to a few files to keep svn happy.

Discussed with: imp, rwatson


# 200462 13-Dec-2009 delphij

Revert most part of 200420 as requested, as more review and polish is
needed.


# 200420 11-Dec-2009 delphij

Remove unneeded header includes from usr.bin/ except contributed code.

Tested with: make universe


# 190700 04-Apr-2009 csjp

Fixup the parameters to audit_submit(3) the order is errno then return
value. This bug went un-noticed for so long because EPERM == 1

MFC after: 1 week
Spotted by: sson, rwatson


# 179547 04-Jun-2008 dwmalone

Fix a strict aliasing warning - I think it is really telling us
that the way char * and void * pointers may not be stored in the
same way.


# 172749 18-Oct-2007 davidxu

The upper while loop has already recycled child process, so the if
statement has never executed as expected, fix it.

MFC after: 3 days


# 171195 03-Jul-2007 scf

Significantly reduce the memory leak as noted in BUGS section for
setenv(3) by tracking the size of the memory allocated instead of using
strlen() on the current value.

Convert all calls to POSIX from historic BSD API:
- unsetenv returns an int.
- putenv takes a char * instead of const char *.
- putenv no longer makes a copy of the input string.
- errno is set appropriately for POSIX. Exceptions involve bad environ
variable and internal initialization code. These both set errno to
EFAULT.

Several patches to base utilities to handle the POSIX changes from
Andrey Chernov's previous commit. A few I re-wrote to use setenv()
instead of putenv().

New regression module for tools/regression/environ to test these
functions. It also can be used to test the performance.

Bump __FreeBSD_version to 700050 due to API change.

PR: kern/99826
Approved by: wes
Approved by: re (kensmith)


# 169177 01-May-2007 ache

Back out all POSIXified *env() changes.

Not because I admit they are technically wrong and not because of bug
reports (I receive nothing). But because I surprisingly meets so
strong opposition and resistance so lost any desire to continue that.

Anyone who interested in POSIX can dig out what changes and how
through cvs diffs.


# 169125 30-Apr-2007 ache

Prepare for upcoming POSIXed putenv() rewrite:
don't free memory after putenv()


# 163665 24-Oct-2006 sobomax

Backout previous change (SIGSYS related). The fix has been applied to the
proper place.

Pointed out by: rwatson


# 163641 24-Oct-2006 sobomax

Ignore SIGSYS when BSM is compiled in. Otherwise, attempt to invoke su on
system that don't have audit framefork compiled into kernel or ia32 binary
on amd64 system will result in SIGSYS. There is one place in su.c itself
where it tries to check for errno != ENOSYS, but it has been a nop since su
does not catch SIGSYS anyway. There are few other places in libbsm,
where attempt to invoke audit syscal would result in SIGSYS if no audit
support is present in the kernel, so that the only reliable method for
now is to disable SIGSYS completely in the case when BSM is compiled in.

In the long run, both direct invocation of audit-related syscalls and
libbsm should be made more intellegent to handle the case when BSM is not
compiled into the kernel gracefully.

MFC after: 3 days
(provided re@ approval)


# 162761 29-Sep-2006 luoqi

Do not chdir(2) until after setuid(2), otherwise "su - username" would fail
when root doesn't have the permission to enter target user's home directory.
If set, PAM environment variable HOME will be used in chdir(2) instead of
pwd->pw_dir, this allows pam_chroot module to continue to function.


# 161815 01-Sep-2006 csjp

Integrate audit_submit(3) bits into su. This means that records for
successful and failed su attempts will be recorded using the AUE_su
event type (login or lo class) if auditing is present in the system.
Currently, the records will have a header, subject, text (with the
actual diagnostics), a return and trailer token.

See audit_submit(3) for more information.

Reviewed by: rwatson
Obtained from: TrustedBSD Project


# 153985 03-Jan-2006 brian

Fix the other su bug reintroduced two commits ago, namely

$ su
% kill -STOP $$

where su is executing (t)csh. csh's job handling is a little more
special than that of (a)sh, bash and even zsh and blows up a little
more spectacularly. This modification restores the original mucking
about with the tty pgrp, but is careful to only do it when su (or
su's child) is the foreground process.

While I'm here, fix a STDERR_FILENO spelling as suggested by bde.


# 153966 02-Jan-2006 brian

Handle the case (that I just broke) where the following hangs:

$ su
# kill -STOP $$

Pointed out by: David Xu <davidxu@freebsd.org>


# 153964 02-Jan-2006 brian

Remove broken code that mucks about with tcsetpgrp() -- even if
su isn't the foreground process. Hopefully this won't break PAM,
but I couldn't find any useful information about ache's theory
that it will.

Specifically, this change fixes the following:

# sh
# echo $$
# su - root -c id &
# echo $$

The PID output changes as su seems to be kill -STOP'ing itself
and catching the parent shell in the process. This is especially
bad if you add a ``su - user -c command &'' to an rc script!

Sponsored by: Sophos/Activestate
Not objected to by: des


# 140392 17-Jan-2005 rwatson

If su(1) is run without an effective uid of 0, generate an error to
the user indicating that su is not running setuid, which may help
suggest to the user that it should be setuid, or should not be
running from a file system mounted nosuid.

Suggsted by: Ivan Voras <ivoras at fer dot hr>
MFC after: 2 weeks


# 130541 15-Jun-2004 markm

Oops. My last commit included a bug that would make "su -m" always
use /bin/sh. Fix this.


# 130409 13-Jun-2004 markm

Paranoia, WARNS fixes and lint.


# 127848 04-Apr-2004 charnier

Add FBSDID. Do not dot terminate errx(3) string.


# 124166 06-Jan-2004 des

When root tries to su to a non-existent user, pam_authenticate() will
normally succeed (because root can su to anyone), but pam_acct_mgmt()
will most likely fail, causing su to log a confusing "pam_acct_mgmt:
error in service module" message. To avoid this, call getpwnam()
before pam_acct_mgmt().

Sponsored by: registrar.no


# 122061 04-Nov-2003 davidxu

Be sure to restore foreground group to parent su before parent su
exits, otherwise shell will be confused and does not set foreground
group correctly for next su command. This sounds like a bug in sh.


# 122013 03-Nov-2003 davidxu

It seems when su executes in a shell scripts, there is a timing race,
sometimes, su will receive a SIGTTOU when parent su tries to set child
su's process group as foreground group, and su will be stopped unexpectly,
ignoring SIGTTOU fixes the problem.

Noticed by: fjoe


# 121236 19-Oct-2003 cognet

Fix broken su -m behaviour :
chshell must return 0 if the shell is not a standard shell, or else it is
possible to use an account without a valid shell.

Reviewed by: des


# 113262 08-Apr-2003 des

PAM-related improvements:

- if operating "as them" (su -l), use pam_{open,close}_session()
- allow PAM to override $HOME (pam_chroot needs this)
- chdir early, because later on we may be chrooted and chdir will fail

Also use pid_t instead of int where applicable.


# 112695 26-Mar-2003 davidxu

Put child process in a different process group, ensure that the broadcast
signal never affects su directly, some shells changes its pgrp at running
or suspended time, so a broadcast SIGTSTP from child will mess up su's job
control.

Discussed with: bde


# 112087 11-Mar-2003 des

Fix style bugs in the previous commit (which weren't in bde's patch)


# 112085 11-Mar-2003 davidxu

Reset SIGTSTP handler to default both for parent and child process.

Submitted by: bde


# 112072 10-Mar-2003 davidxu

Fix long standing job control bug. SIGTSTP shouldn't be ignored.
Special instructions tested:
suspend
stop $$


# 110456 06-Feb-2003 des

Pass the correct, verified username to PAM instead of getlogin().


# 105758 23-Oct-2002 rwatson

Add a new '-s' option to su(1): if the flag is present, attempt to
also set the user's MAC label as part of the user credential setup
by setting setusercontext(3)'s SETMAC flag. By default, change only
traditional process properties.

Approved by: re
Obtained from: TrustedBSD Project
Sponsored by: DARPA, Network Associates Laboratories


# 105386 18-Oct-2002 markm

When a user gets refused because the password is wrong, use the
older "BAD SU" syslog message that folks prefer. There is quite
a bit more tweaking that can be done with other similar messages.

Asked for by: tjr


# 105362 17-Oct-2002 tjr

Style: use sa_handler instead of __sigaction_u.__sa_handler.


# 105080 14-Oct-2002 phk

Remove an unused variable.


# 101749 12-Aug-2002 ache

Fix typing error in prev. commit


# 101748 12-Aug-2002 ache

Fix style bug in prev. commit


# 101722 12-Aug-2002 ache

Fix su job control (recently introduced for PAM cleanup purposes) to not
kill login shell on either "suspend/fg" or "stop $$/fg" for tcsh. Since
this bug occurse on -stable too, it is not kernel threads bug.

Submitted by: David Xu <bsddiy@yahoo.com>


# 101446 07-Aug-2002 ache

Back out workaround of fixing "suspend/fg" by price of breaking "stop $$/fg".

This is real kernel bug (threads) and don't attempt to mask it by
workarounds to increase chances to fix it in the kernel.


# 99685 09-Jul-2002 ache

Remove tcsetpgrp() stuff across suspend/continue because it cause upper level
tcsh killed on resume (fg). It is because tcsh is interactive itself and
do its own things with terminal group.


# 98837 25-Jun-2002 dillon

This is Alexander Kabaev's patch to solve the signal problem with su
(see 'zsh exits upon ^C' thread). This may be temporary be he's been
running it for a year without incident so we should be golden with it.

Approved by: des


# 98836 25-Jun-2002 dillon

Backout 1.51 on DES's request.

Approved by: des


# 97438 29-May-2002 des

Make our child the leader of its own process group to avoid receiving
signals in its stead. This fixes the dread "zsh exits upon ^C" bug.


# 97377 28-May-2002 des

Drive-by whitespace cleanup & add NAI copyright


# 91745 06-Mar-2002 des

Belatedly OpenPAMify. I forgot this patch in last night's megacommit.

Sponsored by: DARPA, NAI Labs


# 89746 24-Jan-2002 des

Don't set PAM_RHOST, this is a local login.

Sponsored by: DARPA, NAI Labs


# 83373 12-Sep-2001 markm

Reinstate complete (and now correctly functioning) WARNS=2.


# 83209 07-Sep-2001 markm

Back out (with prejudice) the last WARNS=2 fix. I cannot understand
its failure mode, and will revisit it later.


# 82979 04-Sep-2001 markm

WARNS=2 fixes.

The remaining problem of converting highly incompatible pointer types
is done by "laundering" the value through a union.

This solves the problem (in my own mind) of how a "const char *" _ever_
actually gets a value in a WARNS=2 world.


# 81971 20-Aug-2001 markm

Very minor stylistic nit.

Discussed with: ru


# 81703 15-Aug-2001 ru

Substitute ARGSTR in-place.
Forgot trailing newline in usage().


# 81702 15-Aug-2001 ru

Fixed the usage() string.

This also reverts change in rev. 1.36 to the documented
style of writing usage().

PR: bin/29730
Submitted by: Joseph Mallett <jmallett@xMach.org>


# 81529 11-Aug-2001 markm

Set the RUSER for PAM so that (eg) kerberos can set up tickets properly.


# 81528 11-Aug-2001 markm

WARNS=2 type cleanup.

WARNS=2 cannot be enable because of an unresolvable conflict in arg 2
of execv(). Document this in the Makefile.

Reviewed by: bde (su.c only)


# 77220 26-May-2001 markm

Deconvolute the authentication mess, and hand total responsiblity
for authentication to PAM. This meens that WHEELSU-type logic can
now be effected in the pam.conf "su" configuration stack. While here,
clean up the mess that the code had assumed over years of hacking by
folks using different styles. ANSIfy.

There is more policy in here that can be handed over to PAM. This will
be revisited.


# 76427 10-May-2001 obrien

Tell the user what group they must be in to su to root.

Submitted by: Seth Kingsley <sethk@osd.bsdi.com>


# 76103 28-Apr-2001 markm

Dike out the Kerberos(IV) support on the grounds that better kerberos
support can be already obtained via PAM.


# 74874 27-Mar-2001 markm

Add full PAM support for account management and sessions.

The PAM_FAIL_CHECK and PAM_END macros in su.c came from the util-linux
package's PAM patches to the BSD login.c

Submitted by: "David J. MacKenzie" <djm@web.us.uu.net>


# 69427 30-Nov-2000 rwatson

o Make comment match reality, synch code with comment.
o In practice: the comment indicates that all but umask and
environmental variables of the users login class are applied when su
occurs, unless -m is used to specify a class. This was incorrect;
in practice, the uid, gids, resources, and priority were set, and
then resources and priority were selectively removed. This meant
that some aspects of the user context were not set, including handling
of login events (wtmp, utmp), as well as the path specified in
login.conf.
o I changed it so that the behavior is the same, but instead,
LOGIN_SETALL is used, and appropriate flags are removed, including
the LOGIN_SETLOGIN and LOGIN_SETPATH entries that were implicitly
not present before. I also updated the comment to reflect
reality, selecting reality as the "correct" behavior.
o This has the practical benefit that as new LOGIN_SET* flags are
introduced, they are supported by su unless specifically disabled.
For example, of a LOGIN_SETLABEL flag is introduced to support
MAC labels determined by the user's login class, then su no longer
has to be modified.
o It might be desirable to have su use LOGIN_SETPATH depending on
its command line parameters, as it might or might not be
considered part of the "environment".

Obtained from: TrustedBSD Project


# 57450 24-Feb-2000 markm

Use libcrypto in place of libdes.


# 50477 27-Aug-1999 peter

$Id$ -> $FreeBSD$


# 49696 13-Aug-1999 sheldonh

Axe LOGIN_CAP_AUTH.

PR: 10115
Reported by: Gene Skonicki <gene@cif.rochester.edu>
Requested by: jdp


# 48458 02-Jul-1999 bde

Actually fixed ambiguous else. The previous revision had no effect.


# 48403 01-Jul-1999 billf

Fix ambigious else.

Reviewed By: eivind


# 40128 09-Oct-1998 markm

Add JKH's auth.conf parser to turn on/off Kerberos in userland


# 39538 21-Sep-1998 roberto

Fix bad option processing.

PR: bin/7986
Submitted by: Dan Nelson <dnelson@emsphone.com>


# 36391 26-May-1998 danny

PR: 1904
Abort if given uname is > MAXLOGNAME-1


# 36348 25-May-1998 steve

Allow a user in group 0 to su(1) to root if their primary
group is 0 in /etc/passwd even if they aren't listed
as a member in /etc/group. This is more inline with
what the group manpage says.

PR: 6696
Submitted by: Max Euston <meuston@jmrodgers.com>


# 30820 28-Oct-1997 guido

I wonder how I managed to get the krb.h include wrong. Anyway: correct it.


# 30793 27-Oct-1997 guido

Add -c option that allows root to specify a login_class.


# 29923 28-Sep-1997 markm

Changes for KTH KerberosIV.
Quieten -Wall a bit.

From Joe Traister:
The previous patch did not propogate the KRBTKFILE environment variable
into the new environment when -l is given to su, making it impossible
for kdestroy to find the ticket file. This patch corrects that problem
as well as the original segfault problem.
(Fixes PR 3903)


# 28612 23-Aug-1997 joerg

Prevent a NULL dereferencation when given a garbage command line.

PR: bin/3206
Submitted by: blank@fox.uni-trier.de


# 28099 12-Aug-1997 charnier

Add usage().


# 25674 10-May-1997 davidn

login_getclass() -> login_getpwclass().


# 24360 29-Mar-1997 imp

compare return value from getopt against -1 rather than EOF, per the final
posix standard on the topic.


# 23085 24-Feb-1997 guido

When group wheel is empty, allow everyone to su to root. This has normally
no conseqeunces as we ship with a non-empty wheel.

Closes PR/1882
Submitted by: Arne Henrik Juul <arnej@frida.imf.unit.no>


# 21677 14-Jan-1997 davidn

Fix problem with mask passwd to setusercontext() which
prevented uid/group change with non-root target.


# 21673 14-Jan-1997 jkh

Make the long-awaited change from $Id$ to $FreeBSD$

This will make a number of things easier in the future, as well as (finally!)
avoiding the Id-smashing problem which has plagued developers for so long.

Boy, I'm glad we're not using sup anymore. This update would have been
insane otherwise.


# 21646 13-Jan-1997 davidn

Make su login_cap savvy.
As with login(1), LOGIN_CAP_AUTH is not yet enabled since we don't
yet have authorisation modules.


# 18789 07-Oct-1996 joerg

Export $TERM only if it has been set in our environment.

Detected by: Amancio Hasty


# 14572 11-Mar-1996 markm

Make su a little less fascist about using Kerberos if it is not
configured or available.

Also fix a _nasty_ bug that would let one in if su -K was used.
Any old password would work :-( :-(.


# 14440 09-Mar-1996 markm

Better integrate kerberos into su so that if an incorrect Kerberos
password is entered, the user is not prompted for a password a second
time.

This closes pr-bin/1006.


# 14024 11-Feb-1996 markm

#include <kerberosIV/des.h> -> #include <des.h>


# 11233 05-Oct-1995 gibbs

Kerberos can now deal with multi-homed clients.

Kerberos obtains a network address for the local host from the routing
tables and uses it consistently for all Kerberos transactions. This ensures
that packets only leave the *authenticated* interface. Clients who open
and use their own sockets for encrypted or authenticated correspondance
to kerberos services should bind their sockets to the same address as that
used by kerberos. krb_get_local_addr() and krb_bind_local_addr() allow
clients to obtain the local address or bind a socket to the local address
used by Kerberos respectively.

Reviewed by: Mark Murray <markm>, Garrett Wollman <wollman>
Obtained from: concept by Dieter Dworkin Muller <dworkin@village.org>


# 10586 06-Sep-1995 joerg

Bring Barry Morris' changes from FreeBSD 1.1.5.1 back: pass arguments
to the target login's shell. This allows for "su -c".

Do it right this time and also explain this behaviour in the man
page. :)

Obtained from: bsm's work in FreeBSD 1.1.5.1


# 10401 28-Aug-1995 mpp

Check for expired passwords before allowing access to the system.


# 9502 12-Jul-1995 wollman

Added support for an LCS-style `wheel su' which allows users in group wheel
to su to root by authenticating as themselves (using a password or S/Key)
rather than by using the root password. This is useful in contexts like
ours, where a large group of people need root access to a set of machines.
(However, the security implications are such that this should not be
enabled by default.)

The code is conditionalized on WHEELSU.


# 8874 30-May-1995 rgrimes

Remove trailing whitespace.


# 7641 06-Apr-1995 jkh

It has always bugged me that ps and w did not display su with tcsh
properly. I know, tcsh is not a "Real Shell".

jc p2 :0.0 Tue04PM - -u (tcsh)
^^^
7173 p2 S+ 0:01.33 -u (tcsh)
^^^

Submitted by: John Capo <jc@irbs.com>


# 4563 17-Nov-1994 ats

Fixed the PATH and cleanenv setting in su. This was totally broken in the
4.4BSD Lite source.


# 3702 18-Oct-1994 pst

Include most of the logdaemon v4.4 S/key changes


# 3208 29-Sep-1994 pst

Add support for s/keys


# 1591 27-May-1994 rgrimes

This commit was generated by cvs2svn to compensate for changes in r1590,
which included commits to RCS files with non-trunk default branches.


# 1590 27-May-1994 rgrimes

BSD 4.4 Lite Usr.bin Sources