Annotation of 43BSDReno/kerberosIV/kinit/kinit.c, revision 1.1.1.1

1.1       root        1: /*
                      2:  * $Source: /usr/src/kerberosIV/kinit/RCS/kinit.c,v $
                      3:  * $Author: kfall $ 
                      4:  *
                      5:  * Copyright 1987, 1988 by the Massachusetts Institute of Technology. 
                      6:  *
                      7:  * For copying and distribution information, please see the file
                      8:  * <mit-copyright.h>. 
                      9:  *
                     10:  * Routine to initialize user to Kerberos.  Prompts optionally for
                     11:  * user, instance and realm.  Authenticates user and gets a ticket
                     12:  * for the Kerberos ticket-granting service for future use. 
                     13:  *
                     14:  * Options are: 
                     15:  *
                     16:  *   -i[instance]
                     17:  *   -r[realm]
                     18:  *   -v[erbose]
                     19:  *   -l[ifetime]
                     20:  */
                     21: 
                     22: #ifndef        lint
                     23: static char rcsid_kinit_c[] =
                     24: "$Header: /usr/src/kerberosIV/kinit/RCS/kinit.c,v 4.15 90/06/25 21:01:06 kfall Exp $";
                     25: #endif lint
                     26: 
                     27: #include <sys/types.h>
                     28: #include <sys/param.h>
                     29: #include <mit-copyright.h>
                     30: #include <string.h>
                     31: #include <stdio.h>
                     32: #include <des.h>
                     33: #include <krb.h>
                     34: #include <pwd.h>
                     35: #include <paths.h>
                     36: 
                     37: #define        LEN             MAXHOSTNAMELEN
                     38: #define        LIFE            DEFAULT_TKT_LIFE /* in 5-minute units */
                     39: #define        INITIAL_TICKET  "krbtgt"
                     40: 
                     41: char   *progname;
                     42: 
                     43: char    aname[ANAME_SZ];
                     44: char    inst[INST_SZ];
                     45: char    realm[REALM_SZ];
                     46: 
                     47: main(argc, argv)
                     48:     char   *argv[];
                     49: {
                     50:     char    buf[LEN];
                     51:     char   *username = NULL;
                     52:     int     iflag, rflag, vflag, lflag, lifetime, k_errno;
                     53:     register char *cp;
                     54:     register i;
                     55: 
                     56:     *inst = *realm = '\0';
                     57:     iflag = rflag = vflag = lflag = 0;
                     58:     lifetime = LIFE;
                     59:     progname = (cp = rindex(*argv, '/')) ? cp + 1 : *argv;
                     60: 
                     61:     while (--argc) {
                     62:        if ((*++argv)[0] != '-') {
                     63:            if (username)
                     64:                usage();
                     65:            username = *argv;
                     66:            continue;
                     67:        }
                     68:        for (i = 1; (*argv)[i] != '\0'; i++)
                     69:            switch ((*argv)[i]) {
                     70:            case 'i':           /* Instance */
                     71:                ++iflag;
                     72:                continue;
                     73:            case 'r':           /* Realm */
                     74:                ++rflag;
                     75:                continue;
                     76:            case 'v':           /* Verbose */
                     77:                ++vflag;
                     78:                continue;
                     79:            case 'l':
                     80:                ++lflag;
                     81:                continue;
                     82:            default:
                     83:                usage();
                     84:                exit(1);
                     85:            }
                     86:     }
                     87:     if (username && (k_errno = kname_parse(aname, inst, realm, username)) !=
                     88:        KSUCCESS) {
                     89:        fprintf(stderr, "%s: %s\n", progname, krb_err_txt[k_errno]);
                     90:        iflag = rflag = 1;
                     91:        username = NULL;
                     92:     }
                     93:     if (k_gethostname(buf, LEN)) {
                     94:        fprintf(stderr, "%s: k_gethostname failed\n", progname);
                     95:        exit(1);
                     96:     }
                     97:     if (vflag)
                     98:        printf("4.4 BSD/MIT Project Athena (%s)\n", buf);
                     99: 
                    100:     if (username) {
                    101:        printf("Kerberos Initialization for \"%s", aname);
                    102:        if (*inst)
                    103:            printf(".%s", inst);
                    104:        if (*realm)
                    105:            printf("@%s", realm);
                    106:        printf("\"\n");
                    107:     } else {
                    108:        if (iflag) {
                    109:                printf("Kerberos Initialization\n");
                    110:                printf("Kerberos name: ");
                    111:                gets(aname);
                    112:        } else {
                    113:                /* default to current user name */
                    114:                struct passwd   *pwd = getpwuid(geteuid());
                    115: 
                    116:                if (pwd == (struct passwd *) NULL) {
                    117:                        fprintf(stderr, "Unknown Kerberos name for your uid\n");
                    118:                        printf("Kerberos name: ");
                    119:                        gets(aname);
                    120:                } else
                    121:                        strncpy(aname, pwd->pw_name, sizeof(aname));
                    122:        }
                    123:                
                    124:        if (!*aname)
                    125:            exit(0);
                    126:        if (!k_isname(aname)) {
                    127:            fprintf(stderr, "%s: bad Kerberos name format\n",
                    128:                    progname);
                    129:            exit(1);
                    130:        }
                    131:     }
                    132:     /* optional instance */
                    133:     if (iflag) {
                    134:        printf("Kerberos instance: ");
                    135:        gets(inst);
                    136:        if (!k_isinst(inst)) {
                    137:            fprintf(stderr, "%s: bad Kerberos instance format\n",
                    138:                    progname);
                    139:            exit(1);
                    140:        }
                    141:     }
                    142:     if (rflag) {
                    143:        printf("Kerberos realm: ");
                    144:        gets(realm);
                    145:        if (!k_isrealm(realm)) {
                    146:            fprintf(stderr, "%s: bad Kerberos realm format\n",
                    147:                    progname);
                    148:            exit(1);
                    149:        }
                    150:     }
                    151:     if (lflag) {
                    152:         printf("Kerberos ticket lifetime (minutes): ");
                    153:         gets(buf);
                    154:         lifetime = atoi(buf);
                    155:         if (lifetime < 5)
                    156:              lifetime = 1;
                    157:         else
                    158:              lifetime /= 5;
                    159:         /* This should be changed if the maximum ticket lifetime */
                    160:         /* changes */
                    161:         if (lifetime > 255)
                    162:              lifetime = 255;
                    163:     }
                    164:     if (!*realm && krb_get_lrealm(realm, 1)) {
                    165:        fprintf(stderr, "%s: krb_get_lrealm failed\n", progname);
                    166:        exit(1);
                    167:     }
                    168: 
                    169:     k_errno = krb_get_pw_in_tkt(aname, inst, realm, INITIAL_TICKET,
                    170:                realm, lifetime, 0);
                    171: 
                    172:     if (vflag) {
                    173:        printf("Kerberos realm %s:\n", realm);
                    174:        printf("%s\n", krb_err_txt[k_errno]);
                    175:     } else if (k_errno) {
                    176:        fprintf(stderr, "%s: %s\n", progname, krb_err_txt[k_errno]);
                    177:        exit(1);
                    178:     }
                    179: }
                    180: 
                    181: usage()
                    182: {
                    183:     fprintf(stderr, "Usage: %s [-irvl] [name]\n", progname);
                    184:     exit(1);
                    185: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.