diff options
Diffstat (limited to 'crypto/kerberosIV/appl/bsd/su.c')
| -rw-r--r-- | crypto/kerberosIV/appl/bsd/su.c | 42 |
1 files changed, 28 insertions, 14 deletions
diff --git a/crypto/kerberosIV/appl/bsd/su.c b/crypto/kerberosIV/appl/bsd/su.c index 8c610e1d3036..d0da21d95a0d 100644 --- a/crypto/kerberosIV/appl/bsd/su.c +++ b/crypto/kerberosIV/appl/bsd/su.c @@ -33,7 +33,7 @@ #include "bsd_locl.h" -RCSID ("$Id: su.c,v 1.59 1997/05/26 17:45:54 bg Exp $"); +RCSID ("$Id: su.c,v 1.66 1999/03/11 13:57:58 joda Exp $"); #ifdef SYSV_SHADOW #include "sysv_shadow.h" @@ -112,7 +112,7 @@ main (int argc, char **argv) if (errno) prio = 0; setpriority (PRIO_PROCESS, 0, -2); - openlog ("su", LOG_CONS, 0); + openlog ("su", LOG_CONS, LOG_AUTH); /* get current login name and shell */ ruid = getuid (); @@ -123,13 +123,17 @@ main (int argc, char **argv) if (pwd == NULL) errx (1, "who are you?"); username = strdup (pwd->pw_name); - if (asme) - if (pwd->pw_shell && *pwd->pw_shell) - shell = strcpy (shellbuf, pwd->pw_shell); - else { + if (username == NULL) + errx (1, "strdup: out of memory"); + if (asme) { + if (pwd->pw_shell && *pwd->pw_shell) { + strcpy_truncate (shellbuf, pwd->pw_shell, sizeof(shellbuf)); + shell = shellbuf; + } else { shell = _PATH_BSHELL; iscsh = NO; } + } /* get target login information, default to root */ user = *argv ? *argv : "root"; @@ -229,6 +233,8 @@ main (int argc, char **argv) char *t = getenv ("TERM"); environ = malloc (10 * sizeof (char *)); + if (environ == NULL) + err (1, "malloc"); environ[0] = NULL; setenv ("PATH", _PATH_DEFPATH, 1); if (t) @@ -250,13 +256,13 @@ main (int argc, char **argv) *np-- = "-m"; } if (asthem) { - avshellbuf[0] = '-'; - strcpy (avshellbuf + 1, avshell); + snprintf (avshellbuf, sizeof(avshellbuf), + "-%s", avshell); avshell = avshellbuf; } else if (iscsh == YES) { /* csh strips the first character... */ - avshellbuf[0] = '_'; - strcpy (avshellbuf + 1, avshell); + snprintf (avshellbuf, sizeof(avshellbuf), + "_%s", avshell); avshell = avshellbuf; } *np = avshell; @@ -272,7 +278,7 @@ main (int argc, char **argv) if (k_setpag () != 0) warn ("setpag"); - code = k_afsklog (0, 0); + code = krb_afslog (0, 0); if (code != KSUCCESS && code != KDC_PR_UNKNOWN) warnx ("afsklog: %s", krb_get_err_text (code)); } @@ -334,6 +340,15 @@ kerberos (char *username, char *user, int uid) setenv ("KRBTKFILE", krbtkfile, 1); krb_set_tkt_string (krbtkfile); /* + * Set real as well as effective ID to 0 for the moment, + * to make the kerberos library do the right thing. + */ + if (setuid(0) < 0) { + warn("setuid"); + return (1); + } + + /* * Little trick here -- if we are su'ing to root, we need to get a ticket * for "xxx.root", where xxx represents the name of the person su'ing. * Otherwise (non-root case), we need to get a ticket for "yyy.", where @@ -388,13 +403,12 @@ kerberos (char *username, char *user, int uid) } setpriority (PRIO_PROCESS, 0, -2); - if (k_gethostname (hostname, sizeof (hostname)) == -1) { + if (gethostname (hostname, sizeof (hostname)) == -1) { warn ("gethostname"); dest_tkt (); return (1); } - strncpy (savehost, krb_get_phost (hostname), sizeof (savehost)); - savehost[sizeof (savehost) - 1] = '\0'; + strcpy_truncate (savehost, krb_get_phost (hostname), sizeof (savehost)); kerno = krb_mk_req (&ticket, "rcmd", savehost, lrealm, 33); |
