From c7b7a71f79cef9dbb230f353d9bbf3d6ef3a5aed Mon Sep 17 00:00:00 2001 From: Artur Grabowski Date: Fri, 28 Nov 1997 12:49:35 +0000 Subject: The first big step towards a complete upgrade to kth-krb4-0.9.7 --- kerberosIV/kinit/kinit.c | 106 +++++++++++++++++++++-------------------------- 1 file changed, 47 insertions(+), 59 deletions(-) (limited to 'kerberosIV/kinit') diff --git a/kerberosIV/kinit/kinit.c b/kerberosIV/kinit/kinit.c index bd7ca653887..d3aa92b8661 100644 --- a/kerberosIV/kinit/kinit.c +++ b/kerberosIV/kinit/kinit.c @@ -1,4 +1,7 @@ -/* $Id: kinit.c,v 1.1 1995/12/14 06:52:51 tholo Exp $ */ +/* $Id: kinit.c,v 1.2 1997/11/28 12:48:47 art Exp $ */ +/* $KTH: kinit.c,v 1.15 1997/03/30 18:58:46 assar Exp $ */ + + /*- * Copyright 1987, 1988 by the Student Information Processing Board @@ -28,55 +31,50 @@ * -r[realm] * -v[erbose] * -l[ifetime] + * -p */ #include #include #define LIFE DEFAULT_TKT_LIFE /* lifetime of ticket in 5-minute units */ +#define CHPASSLIFE 2 -char *progname; +char progname[] = "kinit"; static void -get_input(s, size, stream) -char *s; -int size; -FILE *stream; +get_input(char *s, int size, FILE *stream) { - char *p; + char *p; - if (fgets(s, size, stream) == NULL) - exit(1); - if ( (p = strchr(s, '\n')) != NULL) - *p = '\0'; + if (fgets(s, size, stream) == NULL) + exit(1); + if ( (p = strchr(s, '\n')) != NULL) + *p = '\0'; } - static void -usage() +usage(void) { - fprintf(stderr, "Usage: %s [-irvl] [name]\n", progname); + fprintf(stderr, "Usage: %s [-irvlp] [name]\n", progname); exit(1); } int -main(argc, argv) - int argc; - char *argv[]; +main(int argc, char **argv) { char aname[ANAME_SZ]; char inst[INST_SZ]; char realm[REALM_SZ]; char buf[MAXHOSTNAMELEN]; + char name[MAX_K_NAME_SZ]; char *username = NULL; - int iflag, rflag, vflag, lflag, lifetime, k_errno; - register char *cp; - register i; + int iflag, rflag, vflag, lflag, pflag, lifetime, k_errno; + int i; *inst = *realm = '\0'; - iflag = rflag = vflag = lflag = 0; + iflag = rflag = vflag = lflag = pflag = 0; lifetime = LIFE; - progname = (cp = strrchr(*argv, '/')) ? cp + 1 : *argv; while (--argc) { if ((*++argv)[0] != '-') { @@ -99,22 +97,22 @@ main(argc, argv) case 'l': ++lflag; continue; + case 'p': + ++pflag; /* chpass-tickets */ + lifetime = CHPASSLIFE; + break; default: usage(); - exit(1); } } if (username && - (k_errno = kname_parse(aname, inst, realm, username)) - != KSUCCESS) { - fprintf(stderr, "%s: %s\n", progname, krb_err_txt[k_errno]); + (k_errno = kname_parse(aname, inst, realm, username)) != KSUCCESS) { + warnx("%s", krb_get_err_text(k_errno)); iflag = rflag = 1; username = NULL; } - if (gethostname(buf, MAXHOSTNAMELEN)) { - fprintf(stderr, "%s: gethostname failed\n", progname); - exit(1); - } + if (k_gethostname(buf, MAXHOSTNAMELEN)) + errx(1, "k_gethostname failed"); printf("%s (%s)\n", ORGANIZATION, buf); if (username) { printf("Kerberos Initialization for \"%s", aname); @@ -126,33 +124,24 @@ main(argc, argv) } else { printf("Kerberos Initialization\n"); printf("Kerberos name: "); - get_input(aname, sizeof(aname), stdin); - if (!*aname) - exit(0); - if (!k_isname(aname)) { - fprintf(stderr, "%s: bad Kerberos name format\n", - progname); - exit(1); - } + 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)); } /* optional instance */ if (iflag) { printf("Kerberos instance: "); get_input(inst, sizeof(inst), stdin); - if (!k_isinst(inst)) { - fprintf(stderr, "%s: bad Kerberos instance format\n", - progname); - exit(1); - } + if (!k_isinst(inst)) + errx(1, "bad Kerberos instance format"); } if (rflag) { printf("Kerberos realm: "); get_input(realm, sizeof(realm), stdin); - if (!k_isrealm(realm)) { - fprintf(stderr, "%s: bad Kerberos realm format\n", - progname); - exit(1); - } + if (!k_isrealm(realm)) + errx(1, "bad Kerberos realm format"); } if (lflag) { printf("Kerberos ticket lifetime (minutes): "); @@ -161,24 +150,23 @@ main(argc, argv) if (lifetime < 5) lifetime = 1; else - lifetime /= krb_time_to_life(0, lifetime*60); + lifetime = krb_time_to_life(0, lifetime*60); /* This should be changed if the maximum ticket lifetime */ /* changes */ if (lifetime > 255) lifetime = 255; } - if (!*realm && krb_get_lrealm(realm, 1)) { - fprintf(stderr, "%s: krb_get_lrealm failed\n", progname); - exit(1); - } - k_errno = krb_get_pw_in_tkt(aname, inst, realm, "krbtgt", realm, + if (!*realm && krb_get_lrealm(realm, 1)) + errx(1, "krb_get_lrealm failed"); + k_errno = krb_get_pw_in_tkt(aname, inst, realm, + pflag ? PWSERV_NAME : + KRB_TICKET_GRANTING_TICKET, + pflag ? KADM_SINST : realm, lifetime, 0); if (vflag) { printf("Kerberos realm %s:\n", realm); - printf("%s\n", krb_err_txt[k_errno]); - } else if (k_errno) { - fprintf(stderr, "%s: %s\n", progname, krb_err_txt[k_errno]); - exit(1); - } + printf("%s\n", krb_get_err_text(k_errno)); + } else if (k_errno) + errx(1, "%s", krb_get_err_text(k_errno)); exit(0); } -- cgit v1.2.3