diff options
author | markm <markm@FreeBSD.org> | 1998-02-16 12:36:49 +0000 |
---|---|---|
committer | markm <markm@FreeBSD.org> | 1998-02-16 12:36:49 +0000 |
commit | 765f216743abff981070746df6c44b18ad0a1b14 (patch) | |
tree | ced37129b76a0179f17dec72d0d38517f5d09741 /crypto/kerberosIV/kuser/kinit.c | |
parent | e713b973b9898de357baf427c2c26c18bd20049d (diff) | |
download | FreeBSD-src-765f216743abff981070746df6c44b18ad0a1b14.zip FreeBSD-src-765f216743abff981070746df6c44b18ad0a1b14.tar.gz |
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
<uid>.root if we are already su'ed).
Requested By: Garrett Wollman
Diffstat (limited to 'crypto/kerberosIV/kuser/kinit.c')
-rw-r--r-- | crypto/kerberosIV/kuser/kinit.c | 42 |
1 files 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) { |