From 765f216743abff981070746df6c44b18ad0a1b14 Mon Sep 17 00:00:00 2001 From: markm Date: Mon, 16 Feb 1998 12:36:49 +0000 Subject: Bring back the old behaviour of kinit; if no username is mentioned on the command line, attempt to get a ticket for the current uid (or .root if we are already su'ed). Requested By: Garrett Wollman --- crypto/kerberosIV/kuser/kinit.c | 42 ++++++++++++++++++++++++++++++++++------- 1 file changed, 35 insertions(+), 7 deletions(-) diff --git a/crypto/kerberosIV/kuser/kinit.c b/crypto/kerberosIV/kuser/kinit.c index b7dd19d..482739a 100644 --- a/crypto/kerberosIV/kuser/kinit.c +++ b/crypto/kerberosIV/kuser/kinit.c @@ -108,13 +108,41 @@ main(int argc, char **argv) printf("@%s", realm); printf("\"\n"); } else { - printf("Kerberos Initialization\n"); - printf("Kerberos name: "); - get_input(name, sizeof(name), stdin); - if (!*name) - return 0; - if ((k_errno = kname_parse(aname, inst, realm, name)) != KSUCCESS ) - errx(1, "%s", krb_get_err_text(k_errno)); + if (iflag) { + printf("Kerberos Initialization\n"); + printf("Kerberos name: "); + get_input(name, sizeof(name), stdin); + if (!*name) + return 0; + if ((k_errno = kname_parse(aname, inst, realm, name)) + != KSUCCESS ) + errx(1, "%s", krb_get_err_text(k_errno)); + } else { + int uid = getuid(); + char *getenv(); + struct passwd *pwd; + + /* default to current user name unless running as root */ + if (uid == 0 && (username = getenv("USER")) && + strcmp(username, "root") != 0) { + strncpy(aname, username, sizeof(aname)); + strncpy(inst, "root", sizeof(inst)); + } else { + pwd = getpwuid(uid); + + if (pwd == (struct passwd *) NULL) { + fprintf(stderr, "Unknown name for your uid\n"); + printf("Kerberos name: "); + get_input(aname, sizeof(aname), stdin); + } else + strncpy(aname, pwd->pw_name, sizeof(aname)); + } + if (!*name) + return 0; + if (!k_isname(aname)) { + errx(1, "%s", "bad Kerberos name format"); + } + } } /* optional instance */ if (iflag) { -- cgit v1.1