Home | History | Annotate | Line # | Download | only in su
su.c revision 1.16
      1  1.16  explorer /*	$NetBSD: su.c,v 1.16 1997/03/04 00:21:13 explorer Exp $	*/
      2  1.12  christos 
      3   1.1       cgd /*
      4   1.1       cgd  * Copyright (c) 1988 The Regents of the University of California.
      5   1.1       cgd  * All rights reserved.
      6   1.1       cgd  *
      7   1.1       cgd  * Redistribution and use in source and binary forms, with or without
      8   1.1       cgd  * modification, are permitted provided that the following conditions
      9   1.1       cgd  * are met:
     10   1.1       cgd  * 1. Redistributions of source code must retain the above copyright
     11   1.1       cgd  *    notice, this list of conditions and the following disclaimer.
     12   1.1       cgd  * 2. Redistributions in binary form must reproduce the above copyright
     13   1.1       cgd  *    notice, this list of conditions and the following disclaimer in the
     14   1.1       cgd  *    documentation and/or other materials provided with the distribution.
     15   1.1       cgd  * 3. All advertising materials mentioning features or use of this software
     16   1.1       cgd  *    must display the following acknowledgement:
     17   1.1       cgd  *	This product includes software developed by the University of
     18   1.1       cgd  *	California, Berkeley and its contributors.
     19   1.1       cgd  * 4. Neither the name of the University nor the names of its contributors
     20   1.1       cgd  *    may be used to endorse or promote products derived from this software
     21   1.1       cgd  *    without specific prior written permission.
     22   1.1       cgd  *
     23   1.1       cgd  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     24   1.1       cgd  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     25   1.1       cgd  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     26   1.1       cgd  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     27   1.1       cgd  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     28   1.1       cgd  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     29   1.1       cgd  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     30   1.1       cgd  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     31   1.1       cgd  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     32   1.1       cgd  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     33   1.1       cgd  * SUCH DAMAGE.
     34   1.1       cgd  */
     35   1.1       cgd 
     36   1.1       cgd #ifndef lint
     37   1.1       cgd char copyright[] =
     38   1.1       cgd "@(#) Copyright (c) 1988 The Regents of the University of California.\n\
     39   1.1       cgd  All rights reserved.\n";
     40   1.1       cgd #endif /* not lint */
     41   1.1       cgd 
     42   1.1       cgd #ifndef lint
     43  1.12  christos #if 0
     44  1.13       tls static char sccsid[] = "@(#)su.c	8.3 (Berkeley) 4/2/94";*/
     45  1.12  christos #else
     46  1.16  explorer static char rcsid[] = "$NetBSD: su.c,v 1.16 1997/03/04 00:21:13 explorer Exp $";
     47  1.12  christos #endif
     48   1.1       cgd #endif /* not lint */
     49   1.1       cgd 
     50   1.1       cgd #include <sys/param.h>
     51   1.1       cgd #include <sys/time.h>
     52   1.1       cgd #include <sys/resource.h>
     53   1.1       cgd #include <syslog.h>
     54   1.1       cgd #include <stdio.h>
     55  1.13       tls #include <err.h>
     56  1.11  christos #include <errno.h>
     57   1.7       jtc #include <stdlib.h>
     58   1.1       cgd #include <pwd.h>
     59   1.1       cgd #include <grp.h>
     60   1.1       cgd #include <string.h>
     61   1.1       cgd #include <unistd.h>
     62   1.1       cgd #include <paths.h>
     63   1.1       cgd 
     64   1.1       cgd #ifdef KERBEROS
     65   1.1       cgd #include <kerberosIV/des.h>
     66   1.1       cgd #include <kerberosIV/krb.h>
     67   1.1       cgd #include <netdb.h>
     68   1.1       cgd 
     69   1.1       cgd #define	ARGSTR	"-Kflm"
     70   1.1       cgd 
     71   1.1       cgd int use_kerberos = 1;
     72  1.11  christos 
     73  1.11  christos static int kerberos __P((char *, char *, int));
     74  1.11  christos static int koktologin __P((char *, char *, char *));
     75  1.11  christos 
     76   1.1       cgd #else
     77   1.1       cgd #define	ARGSTR	"-flm"
     78   1.1       cgd #endif
     79   1.1       cgd 
     80  1.11  christos 
     81  1.11  christos int main __P((int, char **));
     82  1.11  christos 
     83  1.11  christos static int chshell __P((char *));
     84  1.11  christos static char *ontty __P((void));
     85  1.11  christos 
     86   1.2       sef 
     87   1.7       jtc int
     88   1.1       cgd main(argc, argv)
     89   1.1       cgd 	int argc;
     90   1.1       cgd 	char **argv;
     91   1.1       cgd {
     92  1.11  christos 	extern char *__progname;
     93   1.1       cgd 	extern char **environ;
     94  1.13       tls 	struct passwd *pwd;
     95  1.13       tls 	char *p, **g;
     96   1.1       cgd 	struct group *gr;
     97  1.11  christos 	uid_t ruid;
     98   1.1       cgd 	int asme, ch, asthem, fastlogin, prio;
     99   1.1       cgd 	enum { UNSET, YES, NO } iscsh = UNSET;
    100   1.8   mycroft 	char *user, *shell, *avshell, *username, *cleanenv[10], **np;
    101   1.8   mycroft 	char shellbuf[MAXPATHLEN], avshellbuf[MAXPATHLEN];
    102   1.1       cgd 
    103   1.1       cgd 	asme = asthem = fastlogin = 0;
    104   1.1       cgd 	while ((ch = getopt(argc, argv, ARGSTR)) != EOF)
    105   1.1       cgd 		switch((char)ch) {
    106   1.1       cgd #ifdef KERBEROS
    107   1.1       cgd 		case 'K':
    108   1.1       cgd 			use_kerberos = 0;
    109   1.1       cgd 			break;
    110   1.1       cgd #endif
    111   1.1       cgd 		case 'f':
    112   1.1       cgd 			fastlogin = 1;
    113   1.1       cgd 			break;
    114   1.1       cgd 		case '-':
    115   1.1       cgd 		case 'l':
    116   1.1       cgd 			asme = 0;
    117   1.1       cgd 			asthem = 1;
    118   1.1       cgd 			break;
    119   1.1       cgd 		case 'm':
    120   1.1       cgd 			asme = 1;
    121   1.1       cgd 			asthem = 0;
    122   1.1       cgd 			break;
    123   1.1       cgd 		case '?':
    124   1.1       cgd 		default:
    125  1.11  christos 			(void)fprintf(stderr,
    126  1.11  christos 			    "Usage: %s [%s] [login [shell arguments]]\n",
    127  1.11  christos 			    __progname, ARGSTR);
    128   1.1       cgd 			exit(1);
    129   1.1       cgd 		}
    130   1.1       cgd 	argv += optind;
    131   1.1       cgd 
    132   1.1       cgd 	errno = 0;
    133   1.1       cgd 	prio = getpriority(PRIO_PROCESS, 0);
    134   1.1       cgd 	if (errno)
    135   1.1       cgd 		prio = 0;
    136   1.1       cgd 	(void)setpriority(PRIO_PROCESS, 0, -2);
    137   1.1       cgd 	openlog("su", LOG_CONS, 0);
    138   1.1       cgd 
    139   1.1       cgd 	/* get current login name and shell */
    140   1.1       cgd 	ruid = getuid();
    141   1.1       cgd 	username = getlogin();
    142   1.1       cgd 	if (username == NULL || (pwd = getpwnam(username)) == NULL ||
    143   1.1       cgd 	    pwd->pw_uid != ruid)
    144   1.1       cgd 		pwd = getpwuid(ruid);
    145   1.1       cgd 	if (pwd == NULL) {
    146  1.13       tls 		errx(1, "who are you?");
    147   1.1       cgd 	}
    148   1.1       cgd 	username = strdup(pwd->pw_name);
    149   1.1       cgd 	if (asme)
    150   1.1       cgd 		if (pwd->pw_shell && *pwd->pw_shell)
    151  1.15       mrg 			shell = strncpy(shellbuf, pwd->pw_shell,
    152  1.15       mrg 			    sizeof(shellbuf) + 1);
    153   1.1       cgd 		else {
    154   1.1       cgd 			shell = _PATH_BSHELL;
    155   1.1       cgd 			iscsh = NO;
    156   1.1       cgd 		}
    157   1.1       cgd 
    158   1.1       cgd 	/* get target login information, default to root */
    159   1.1       cgd 	user = *argv ? *argv : "root";
    160   1.2       sef 	np = *argv ? argv : argv-1;
    161   1.2       sef 
    162   1.1       cgd 	if ((pwd = getpwnam(user)) == NULL) {
    163  1.13       tls 		errx(1, "unknown login %s", user);
    164   1.1       cgd 	}
    165   1.1       cgd 
    166   1.1       cgd 	if (ruid) {
    167   1.1       cgd #ifdef KERBEROS
    168   1.1       cgd 	    if (!use_kerberos || kerberos(username, user, pwd->pw_uid))
    169   1.1       cgd #endif
    170   1.1       cgd 	    {
    171  1.14   ghudson 		/* only allow those in group zero to su to root, if group
    172  1.14   ghudson 		 * zero has any members. */
    173  1.14   ghudson 		if (pwd->pw_uid == 0 && (gr = getgrgid((gid_t)0)) &&
    174  1.14   ghudson 		    *gr->gr_mem) {
    175   1.1       cgd 			for (g = gr->gr_mem;; ++g) {
    176  1.13       tls 				if (!*g)
    177  1.13       tls 					errx(1,
    178  1.13       tls 			    "you are not in the correct group to su %s.",
    179   1.1       cgd 					    user);
    180   1.1       cgd 				if (!strcmp(username, *g))
    181   1.1       cgd 					break;
    182  1.14   ghudson 			}
    183   1.1       cgd 		}
    184   1.1       cgd 		/* if target requires a password, verify it */
    185   1.1       cgd 		if (*pwd->pw_passwd) {
    186   1.1       cgd 			p = getpass("Password:");
    187  1.10   deraadt #ifdef SKEY
    188  1.10   deraadt 			if (strcasecmp(p, "s/key") == 0) {
    189  1.13       tls 				if (skey_haskey(user))
    190  1.13       tls 					errx(1, "Sorry, you have no s/key.");
    191  1.13       tls 				else {
    192  1.10   deraadt 					if (skey_authenticate(user)) {
    193  1.10   deraadt 						goto badlogin;
    194  1.10   deraadt 					}
    195  1.10   deraadt 				}
    196  1.10   deraadt 
    197  1.10   deraadt 			} else
    198  1.10   deraadt #endif
    199   1.1       cgd 			if (strcmp(pwd->pw_passwd, crypt(p, pwd->pw_passwd))) {
    200  1.10   deraadt badlogin:
    201   1.1       cgd 				fprintf(stderr, "Sorry\n");
    202   1.1       cgd 				syslog(LOG_AUTH|LOG_WARNING,
    203   1.1       cgd 					"BAD SU %s to %s%s", username,
    204   1.1       cgd 					user, ontty());
    205   1.1       cgd 				exit(1);
    206   1.1       cgd 			}
    207   1.1       cgd 		}
    208   1.1       cgd 	    }
    209   1.1       cgd 	}
    210   1.1       cgd 
    211   1.1       cgd 	if (asme) {
    212   1.1       cgd 		/* if asme and non-standard target shell, must be root */
    213  1.13       tls 		if (!chshell(pwd->pw_shell) && ruid)
    214  1.13       tls 			errx(1,"permission denied (shell).");
    215   1.1       cgd 	} else if (pwd->pw_shell && *pwd->pw_shell) {
    216   1.1       cgd 		shell = pwd->pw_shell;
    217   1.1       cgd 		iscsh = UNSET;
    218   1.1       cgd 	} else {
    219   1.1       cgd 		shell = _PATH_BSHELL;
    220   1.1       cgd 		iscsh = NO;
    221   1.1       cgd 	}
    222   1.1       cgd 
    223  1.13       tls 	if (p = strrchr(shell, '/'))
    224   1.9       cgd 		avshell = p+1;
    225   1.9       cgd 	else
    226   1.9       cgd 		avshell = shell;
    227   1.9       cgd 
    228   1.1       cgd 	/* if we're forking a csh, we want to slightly muck the args */
    229   1.9       cgd 	if (iscsh == UNSET)
    230  1.11  christos 		iscsh = strstr(avshell, "csh") ? YES : NO;
    231   1.1       cgd 
    232   1.1       cgd 	/* set permissions */
    233  1.13       tls 	if (setgid(pwd->pw_gid) < 0)
    234  1.13       tls 		err(1, "setgid");
    235  1.13       tls 	if (initgroups(user, pwd->pw_gid))
    236  1.13       tls 		errx(1, "initgroups failed");
    237  1.13       tls 	if (setuid(pwd->pw_uid) < 0)
    238  1.13       tls 		err(1, "setuid");
    239   1.1       cgd 
    240   1.1       cgd 	if (!asme) {
    241   1.1       cgd 		if (asthem) {
    242   1.1       cgd 			p = getenv("TERM");
    243   1.8   mycroft 			cleanenv[0] = NULL;
    244   1.1       cgd 			environ = cleanenv;
    245   1.8   mycroft 			(void)setenv("PATH", _PATH_DEFPATH, 1);
    246  1.11  christos 			if (p)
    247  1.11  christos 				(void)setenv("TERM", p, 1);
    248  1.13       tls 			if (chdir(pwd->pw_dir) < 0)
    249  1.13       tls 				errx(1, "no directory");
    250   1.1       cgd 		}
    251   1.5       jtc 		if (asthem || pwd->pw_uid)
    252   1.1       cgd 			(void)setenv("USER", pwd->pw_name, 1);
    253   1.1       cgd 		(void)setenv("HOME", pwd->pw_dir, 1);
    254   1.1       cgd 		(void)setenv("SHELL", shell, 1);
    255   1.1       cgd 	}
    256   1.1       cgd 
    257  1.12  christos 	if (iscsh == YES) {
    258  1.12  christos 		if (fastlogin)
    259  1.12  christos 			*np-- = "-f";
    260  1.12  christos 		if (asme)
    261  1.12  christos 			*np-- = "-m";
    262  1.12  christos 	}
    263   1.1       cgd 
    264   1.8   mycroft 	if (asthem) {
    265   1.8   mycroft 		avshellbuf[0] = '-';
    266  1.15       mrg 		(void)strncpy(avshellbuf+1, avshell, sizeof(avshellbuf) - 2);
    267   1.8   mycroft 		avshell = avshellbuf;
    268   1.8   mycroft 	} else if (iscsh == YES) {
    269   1.8   mycroft 		/* csh strips the first character... */
    270   1.8   mycroft 		avshellbuf[0] = '_';
    271  1.15       mrg 		(void)strncpy(avshellbuf+1, avshell, sizeof(avshellbuf) - 2);
    272   1.8   mycroft 		avshell = avshellbuf;
    273   1.8   mycroft 	}
    274  1.12  christos 	*np = avshell;
    275  1.11  christos 
    276   1.1       cgd 	if (ruid != 0)
    277   1.1       cgd 		syslog(LOG_NOTICE|LOG_AUTH, "%s to %s%s",
    278   1.1       cgd 		    username, user, ontty());
    279   1.1       cgd 
    280   1.1       cgd 	(void)setpriority(PRIO_PROCESS, 0, prio);
    281   1.1       cgd 
    282  1.12  christos 	execv(shell, np);
    283  1.13       tls 	err(1, "%s", shell);
    284   1.1       cgd }
    285  1.11  christos 
    286  1.11  christos static int
    287   1.1       cgd chshell(sh)
    288   1.1       cgd 	char *sh;
    289   1.1       cgd {
    290  1.13       tls 	char *cp;
    291   1.1       cgd 	char *getusershell();
    292   1.1       cgd 
    293   1.1       cgd 	while ((cp = getusershell()) != NULL)
    294   1.1       cgd 		if (!strcmp(cp, sh))
    295   1.1       cgd 			return (1);
    296   1.1       cgd 	return (0);
    297   1.1       cgd }
    298   1.1       cgd 
    299  1.11  christos static char *
    300   1.1       cgd ontty()
    301   1.1       cgd {
    302   1.1       cgd 	char *p, *ttyname();
    303   1.1       cgd 	static char buf[MAXPATHLEN + 4];
    304   1.1       cgd 
    305   1.1       cgd 	buf[0] = 0;
    306   1.1       cgd 	if (p = ttyname(STDERR_FILENO))
    307  1.15       mrg 		(void)snprintf(buf, sizeof buf, " on %s", p);
    308   1.1       cgd 	return (buf);
    309   1.1       cgd }
    310   1.1       cgd 
    311   1.1       cgd #ifdef KERBEROS
    312  1.11  christos static int
    313   1.1       cgd kerberos(username, user, uid)
    314   1.1       cgd 	char *username, *user;
    315   1.1       cgd 	int uid;
    316   1.1       cgd {
    317   1.1       cgd 	KTEXT_ST ticket;
    318   1.1       cgd 	AUTH_DAT authdata;
    319   1.1       cgd 	struct hostent *hp;
    320   1.1       cgd 	register char *p;
    321   1.1       cgd 	int kerno;
    322   1.1       cgd 	u_long faddr;
    323   1.1       cgd 	char lrealm[REALM_SZ], krbtkfile[MAXPATHLEN];
    324   1.1       cgd 	char hostname[MAXHOSTNAMELEN], savehost[MAXHOSTNAMELEN];
    325   1.1       cgd 	char *ontty(), *krb_get_phost();
    326   1.1       cgd 
    327   1.1       cgd 	if (krb_get_lrealm(lrealm, 1) != KSUCCESS)
    328   1.1       cgd 		return (1);
    329   1.1       cgd 	if (koktologin(username, lrealm, user) && !uid) {
    330  1.13       tls 		warnx("kerberos: not in %s's ACL.", user);
    331   1.1       cgd 		return (1);
    332   1.1       cgd 	}
    333  1.15       mrg 	(void)(void)snprintf(krbtkfile, sizeof krbtkfile, "%s_%s_%d", TKT_ROOT,
    334  1.15       mrg 	    user, getuid());
    335   1.1       cgd 
    336   1.1       cgd 	(void)setenv("KRBTKFILE", krbtkfile, 1);
    337   1.1       cgd 	(void)krb_set_tkt_string(krbtkfile);
    338   1.1       cgd 	/*
    339   1.1       cgd 	 * Set real as well as effective ID to 0 for the moment,
    340   1.1       cgd 	 * to make the kerberos library do the right thing.
    341   1.1       cgd 	 */
    342   1.1       cgd 	if (setuid(0) < 0) {
    343  1.13       tls 		warn("setuid");
    344   1.1       cgd 		return (1);
    345   1.1       cgd 	}
    346   1.1       cgd 
    347   1.1       cgd 	/*
    348   1.1       cgd 	 * Little trick here -- if we are su'ing to root,
    349   1.1       cgd 	 * we need to get a ticket for "xxx.root", where xxx represents
    350   1.1       cgd 	 * the name of the person su'ing.  Otherwise (non-root case),
    351   1.1       cgd 	 * we need to get a ticket for "yyy.", where yyy represents
    352   1.1       cgd 	 * the name of the person being su'd to, and the instance is null
    353   1.1       cgd 	 *
    354   1.1       cgd 	 * We should have a way to set the ticket lifetime,
    355   1.1       cgd 	 * with a system default for root.
    356   1.1       cgd 	 */
    357   1.1       cgd 	kerno = krb_get_pw_in_tkt((uid == 0 ? username : user),
    358   1.1       cgd 		(uid == 0 ? "root" : ""), lrealm,
    359   1.1       cgd 	    	"krbtgt", lrealm, DEFAULT_TKT_LIFE, 0);
    360   1.1       cgd 
    361   1.1       cgd 	if (kerno != KSUCCESS) {
    362   1.1       cgd 		if (kerno == KDC_PR_UNKNOWN) {
    363  1.13       tls 			warnx("kerberos: principal unknown: %s.%s@%s",
    364   1.1       cgd 				(uid == 0 ? username : user),
    365   1.1       cgd 				(uid == 0 ? "root" : ""), lrealm);
    366   1.1       cgd 			return (1);
    367   1.1       cgd 		}
    368  1.13       tls 		warnx("kerberos: unable to su: %s", krb_err_txt[kerno]);
    369   1.1       cgd 		syslog(LOG_NOTICE|LOG_AUTH,
    370   1.1       cgd 		    "BAD Kerberos SU: %s to %s%s: %s",
    371   1.1       cgd 		    username, user, ontty(), krb_err_txt[kerno]);
    372   1.1       cgd 		return (1);
    373   1.1       cgd 	}
    374   1.1       cgd 
    375   1.1       cgd 	if (chown(krbtkfile, uid, -1) < 0) {
    376  1.13       tls 		warn("chown");
    377   1.1       cgd 		(void)unlink(krbtkfile);
    378   1.1       cgd 		return (1);
    379   1.1       cgd 	}
    380   1.1       cgd 
    381   1.1       cgd 	(void)setpriority(PRIO_PROCESS, 0, -2);
    382   1.1       cgd 
    383   1.1       cgd 	if (gethostname(hostname, sizeof(hostname)) == -1) {
    384  1.13       tls 		warn("gethostname");
    385   1.1       cgd 		dest_tkt();
    386   1.1       cgd 		return (1);
    387   1.1       cgd 	}
    388   1.1       cgd 
    389   1.1       cgd 	(void)strncpy(savehost, krb_get_phost(hostname), sizeof(savehost));
    390   1.1       cgd 	savehost[sizeof(savehost) - 1] = '\0';
    391   1.1       cgd 
    392   1.1       cgd 	kerno = krb_mk_req(&ticket, "rcmd", savehost, lrealm, 33);
    393   1.1       cgd 
    394   1.1       cgd 	if (kerno == KDC_PR_UNKNOWN) {
    395  1.13       tls 		warnx("Warning: TGT not verified.");
    396   1.1       cgd 		syslog(LOG_NOTICE|LOG_AUTH,
    397   1.1       cgd 		    "%s to %s%s, TGT not verified (%s); %s.%s not registered?",
    398   1.1       cgd 		    username, user, ontty(), krb_err_txt[kerno],
    399   1.1       cgd 		    "rcmd", savehost);
    400   1.1       cgd 	} else if (kerno != KSUCCESS) {
    401  1.13       tls 		warnx("Unable to use TGT: %s", krb_err_txt[kerno]);
    402   1.1       cgd 		syslog(LOG_NOTICE|LOG_AUTH, "failed su: %s to %s%s: %s",
    403   1.1       cgd 		    username, user, ontty(), krb_err_txt[kerno]);
    404   1.1       cgd 		dest_tkt();
    405   1.1       cgd 		return (1);
    406   1.1       cgd 	} else {
    407   1.1       cgd 		if (!(hp = gethostbyname(hostname))) {
    408  1.13       tls 			warnx("can't get addr of %s", hostname);
    409   1.1       cgd 			dest_tkt();
    410   1.1       cgd 			return (1);
    411   1.1       cgd 		}
    412  1.13       tls 		memmove((char *)&faddr, (char *)hp->h_addr, sizeof(faddr));
    413   1.1       cgd 
    414   1.1       cgd 		if ((kerno = krb_rd_req(&ticket, "rcmd", savehost, faddr,
    415   1.1       cgd 		    &authdata, "")) != KSUCCESS) {
    416  1.13       tls 			warnx("kerberos: unable to verify rcmd ticket: %s\n",
    417   1.1       cgd 			    krb_err_txt[kerno]);
    418   1.1       cgd 			syslog(LOG_NOTICE|LOG_AUTH,
    419   1.1       cgd 			    "failed su: %s to %s%s: %s", username,
    420   1.1       cgd 			     user, ontty(), krb_err_txt[kerno]);
    421   1.1       cgd 			dest_tkt();
    422   1.1       cgd 			return (1);
    423   1.1       cgd 		}
    424   1.1       cgd 	}
    425   1.1       cgd 	return (0);
    426   1.1       cgd }
    427   1.1       cgd 
    428  1.11  christos static int
    429   1.1       cgd koktologin(name, realm, toname)
    430   1.1       cgd 	char *name, *realm, *toname;
    431   1.1       cgd {
    432   1.1       cgd 	register AUTH_DAT *kdata;
    433   1.1       cgd 	AUTH_DAT kdata_st;
    434   1.1       cgd 
    435   1.1       cgd 	kdata = &kdata_st;
    436  1.13       tls 	memset((char *)kdata, 0, sizeof(*kdata));
    437  1.15       mrg 	(void)strncpy(kdata->pname, name, sizeof(kdata->pname) - 1);
    438  1.16  explorer 	(void)strncpy(kdata->pinst,
    439  1.15       mrg 	    ((strcmp(toname, "root") == 0) ? "root" : ""), sizeof(kdata->pinst) - 1);
    440  1.16  explorer 	(void)strncpy(kdata->prealm, realm, sizeof(kdata->prealm) - 1);
    441   1.1       cgd 	return (kuserok(kdata, toname));
    442   1.1       cgd }
    443   1.1       cgd #endif
    444