]> andersk Git - moira.git/blob - update/ticket.c
36aee35159d0d9c6fb89e016f42370e655ce0d61
[moira.git] / update / ticket.c
1 /*
2  *      $Source$
3  *      $Header$
4  */
5 /*  (c) Copyright 1988 by the Massachusetts Institute of Technology. */
6 /*  For copying and distribution information, please see the file */
7 /*  <mit-copyright.h>. */
8
9 #ifndef lint
10 static char *rcsid_ticket_c = "$Header$";
11 #endif
12
13 #include <mit-copyright.h>
14 #include <stdio.h>
15 #include <krb.h>
16 #include <sys/types.h>
17 #include <sys/stat.h>
18 #include <string.h>
19 #include <update.h>
20 #include <com_err.h>
21 #include <krb_et.h>
22
23 extern char *whoami;
24
25 /* too bad we can't set the pathname easily */
26 static char *srvtab = KEYFILE; /* default == /etc/srvtab */
27 static char realm[REALM_SZ];
28 static char master[INST_SZ] = "sms";
29 static char service[ANAME_SZ] = "rcmd";
30 C_Block session;
31
32
33 static init(void)
34 {
35   static int initialized = 0;
36
37   if (!initialized)
38     {
39       if (krb_get_lrealm(realm, 1))
40         strcpy(realm, KRB_REALM);
41       initialize_krb_error_table();
42       initialized = 1;
43     }
44 }
45
46
47 int get_mr_update_ticket(char *host, KTEXT ticket)
48 {
49   register int code;
50   register int pass;
51   char phost[BUFSIZ];
52   CREDENTIALS cr;
53
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;
83 }
84
85 int get_mr_tgt(void)
86 {
87   register int code;
88   char linst[INST_SZ], kinst[INST_SZ];
89
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;
99 }
This page took 0.175174 seconds and 3 git commands to generate.