summaryrefslogtreecommitdiffstats
path: root/src/clients/kinit/kinit.c
blob: b9fb6d475545ad1eacc24514af5496c35c36204b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
/*
 * $Source$
 * $Author$
 *
 * Copyright 1990 by the Massachusetts Institute of Technology.
 *
 * For copying and distribution information, please see the file
 * <krb5/mit-copyright.h>.
 *
 * Initialize a credentials cache.
 */

#if !defined(lint) && !defined(SABER)
static char rcsid_kinit_c [] =
"$Id$";
#endif	/* !lint & !SABER */

#include <stdio.h>

#include <krb5/copyright.h>
#include <krb5/krb5.h>

#define KRB5_DEFAULT_FLAGS 0
#define KRB5_DEFAULT_LIFE 60*60*8 /* 8 hours */

extern int optind;
extern char *optarg;

krb5_parse_lifetime (time, len)
    char *time;
    long *len;
{
    *len = atoi (time) * 60 * 60; /* XXX stub version */
}
    

main(argc, argv)
    int argc;
    char **argv;
{
    krb5_ccache cache = NULL;
    char *cache_name = NULL;		/* -f option */
    long lifetime = KRB5_DEFAULT_LIFE;	/* -l option */
    int flags = KRB5_DEFAULT_FLAGS;
    int option;
    int errflg = 0;
    krb5_address **my_addresses;
    int code;
    krb5_principal me;
    
    /*
     * XXX init error tables here
     */
    while ((option = getopt(argc, argv, "rpl:c:")) != EOF) {
	switch (option) {
	case 'r':
	    flags |= KDC_OPT_RENEWABLE;
	    break;
	case 'p':
	    flags |= KDC_OPT_PROXIABLE;
	    break;
	case 'l':
	    code = krb5_parse_lifetime(optarg, &lifetime);
	    if (code != 0) {
		fprintf(stderr, "Bad lifetime value %s\n", optarg);
		errflg++;
	    }
	    break;
	case 'c':
	    if (cache == NULL) {
		cache_name = optarg;
		
		code = krb5_cc_resolve (cache_name, &cache);
		if (code != 0) {
		    com_err (argv[0], code, "resolving %s", cache_name);
		    errflg++;
		}
	    } else {
		fprintf(stderr, "Only one -c option allowed\n");
		errflg++;
	    }
	    break;
	case '?':
	default:
	    errflg++;
	    break;
	}
    }
    if (optind != argc-1)
	errflg++;
    
    if (errflg) {
	fprintf(stderr, "Usage: %s [ -rp ] [ -l lifetime ] [ -c cachename ] principal", argv[0]);
	exit(2);
    }
    if (cache == NULL)
	cache = krb5_cc_default();

    krb5_parse_name (argv[optind], &me);

    code = krb5_cc_initialize (cache, me);
    if (code != 0) {
	com_err (argv[0], code, "when initializing cache %s",
		 cache_name?cache_name:"");
	exit(1);
    }

    code = krb5_os_localaddr(&my_addresses);
    if (code != 0) {
	com_err (argv[0], code, "when getting my address");
	exit(1);
    }	
#ifdef notyet
    code = krb5_get_in_tkt_with_password
	(flags, my_addresses, <<<enctype>>>,
	 <<<keytype>>>,
	 <<<char *>>>,
	 ccache,
	 my_creds,
	 <<<int>>>);
    if (code != 0) {
	com_err (argv[0], code, "getting initial credentials");
	exit(1);
    }
#endif
    exit(0);
}