From 879e5f26e8308040354276f04d02c2de75378add Mon Sep 17 00:00:00 2001 From: Mark Murray Date: Mon, 16 Feb 1998 12:36:49 +0000 Subject: [PATCH] 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 b7dd19d1aedf..482739ad2335 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) {