]>
Commit | Line | Data |
---|---|---|
de56407f | 1 | /* |
2 | * $Source$ | |
3 | * $Header$ | |
4 | */ | |
546bc43b | 5 | /* (c) Copyright 1988 by the Massachusetts Institute of Technology. */ |
6 | /* For copying and distribution information, please see the file */ | |
7 | /* <mit-copyright.h>. */ | |
de56407f | 8 | |
9 | #ifndef lint | |
10 | static char *rcsid_ticket_c = "$Header$"; | |
7da203a3 | 11 | #endif |
de56407f | 12 | |
546bc43b | 13 | #include <mit-copyright.h> |
de56407f | 14 | #include <stdio.h> |
15 | #include <krb.h> | |
16 | #include <sys/types.h> | |
17 | #include <sys/stat.h> | |
a6e20de8 | 18 | #include <string.h> |
5c87ce34 | 19 | #include <update.h> |
20 | #include <com_err.h> | |
851fd300 | 21 | #include <krb_et.h> |
de56407f | 22 | |
7da203a3 | 23 | extern char *whoami; |
24 | ||
de56407f | 25 | /* too bad we can't set the pathname easily */ |
5c87ce34 | 26 | static char *srvtab = KEYFILE; /* default == /etc/srvtab */ |
de56407f | 27 | static char realm[REALM_SZ]; |
b95ec814 | 28 | static char master[INST_SZ] = "sms"; |
29 | static char service[ANAME_SZ] = "rcmd"; | |
49b589d4 | 30 | C_Block session; |
851fd300 | 31 | |
5c87ce34 | 32 | |
5eaef520 | 33 | static init(void) |
5c87ce34 | 34 | { |
5eaef520 | 35 | static int initialized = 0; |
5c87ce34 | 36 | |
5eaef520 | 37 | if (!initialized) |
38 | { | |
39 | if (krb_get_lrealm(realm, 1)) | |
40 | strcpy(realm, KRB_REALM); | |
41 | initialize_krb_error_table(); | |
42 | initialized = 1; | |
5c87ce34 | 43 | } |
44 | } | |
de56407f | 45 | |
de56407f | 46 | |
5eaef520 | 47 | int get_mr_update_ticket(char *host, KTEXT ticket) |
de56407f | 48 | { |
5eaef520 | 49 | register int code; |
50 | register int pass; | |
51 | char phost[BUFSIZ]; | |
52 | CREDENTIALS cr; | |
de56407f | 53 | |
5eaef520 | 54 | pass = 1; |
55 | init(); | |
56 | strcpy(phost, (char *)krb_get_phost(host)); | |
57 | try_it: | |
58 | code = krb_mk_req(ticket, service, phost, realm, (long)0); | |
59 | if (code) | |
60 | { | |
61 | if (pass == 1) | |
62 | { | |
63 | /* maybe we're taking too long? */ | |
64 | if ((code = get_mr_tgt())) | |
65 | { | |
66 | com_err(whoami, code, "can't get Kerberos TGT"); | |
67 | return code; | |
68 | } | |
69 | pass++; | |
70 | goto try_it; | |
71 | } | |
72 | code += ERROR_TABLE_BASE_krb; | |
73 | com_err(whoami, code, "in krb_mk_req"); | |
74 | } | |
75 | else | |
76 | { | |
77 | code = krb_get_cred(service, phost, realm, &cr); | |
78 | if (code) | |
79 | code += ERROR_TABLE_BASE_krb; | |
80 | memcpy(session, cr.session, sizeof(session)); | |
81 | } | |
82 | return code; | |
de56407f | 83 | } |
84 | ||
5eaef520 | 85 | int get_mr_tgt(void) |
de56407f | 86 | { |
5eaef520 | 87 | register int code; |
88 | char linst[INST_SZ], kinst[INST_SZ]; | |
b95ec814 | 89 | |
5eaef520 | 90 | init(); |
91 | linst[0] = '\0'; | |
92 | strcpy(kinst, "krbtgt"); | |
93 | code = krb_get_svc_in_tkt(master, linst, realm, kinst, realm, | |
94 | DEFAULT_TKT_LIFE, srvtab); | |
95 | if (!code) | |
96 | return 0; | |
97 | else | |
98 | return code + ERROR_TABLE_BASE_krb; | |
de56407f | 99 | } |