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