]>
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 | |
33 | static init() | |
34 | { | |
35 | static int initialized = 0; | |
36 | ||
37 | if (!initialized) { | |
f4f2cbe9 | 38 | if (krb_get_lrealm(realm, 1)) |
39 | strcpy(realm, KRB_REALM); | |
851fd300 | 40 | initialize_krb_error_table(); |
5c87ce34 | 41 | initialized=1; |
42 | } | |
43 | } | |
de56407f | 44 | |
de56407f | 45 | |
46 | int | |
2ad0a777 | 47 | get_mr_update_ticket(host, ticket) |
de56407f | 48 | char *host; |
49 | KTEXT ticket; | |
50 | { | |
51 | register int code; | |
52 | register int pass; | |
53 | char phost[BUFSIZ]; | |
49b589d4 | 54 | CREDENTIALS cr; |
de56407f | 55 | |
56 | pass = 1; | |
57 | init(); | |
7da203a3 | 58 | strcpy(phost, (char*)krb_get_phost(host)); |
de56407f | 59 | try_it: |
5c87ce34 | 60 | code = krb_mk_req(ticket, service, phost, realm, (long)0); |
b95ec814 | 61 | if (code) { |
64ac4338 | 62 | if (pass == 1) { |
63 | /* maybe we're taking too long? */ | |
64 | if ((code = get_mr_tgt()) != 0) { | |
af30a831 | 65 | com_err(whoami, code, "can't get Kerberos TGT"); |
64ac4338 | 66 | return(code); |
67 | } | |
68 | pass++; | |
69 | goto try_it; | |
70 | } | |
585b298c | 71 | code += ERROR_TABLE_BASE_krb; |
b95ec814 | 72 | com_err(whoami, code, "in krb_mk_req"); |
49b589d4 | 73 | } else { |
74 | code = krb_get_cred(service, phost, realm, &cr); | |
585b298c | 75 | if (code) code += ERROR_TABLE_BASE_krb; |
a6e20de8 | 76 | memcpy(session, cr.session, sizeof(session)); |
b95ec814 | 77 | } |
5c87ce34 | 78 | return(code); |
de56407f | 79 | } |
80 | ||
81 | int | |
2ad0a777 | 82 | get_mr_tgt() |
de56407f | 83 | { |
84 | register int code; | |
b95ec814 | 85 | char linst[INST_SZ], kinst[INST_SZ]; |
86 | ||
de56407f | 87 | init(); |
b95ec814 | 88 | linst[0] = '\0'; |
89 | strcpy(kinst, "krbtgt"); | |
ec14a982 | 90 | code = krb_get_svc_in_tkt(master, linst, realm, kinst, realm, |
91 | DEFAULT_TKT_LIFE, srvtab); | |
de56407f | 92 | if (!code) |
93 | return(0); | |
94 | else | |
851fd300 | 95 | return(code + ERROR_TABLE_BASE_krb); |
de56407f | 96 | } |