]> andersk Git - moira.git/blob - update/ticket.c
Initialize a few more things to NULL.
[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 <krb5.h>
18 #include <update.h>
19
20 RCSID("$Header$");
21
22 static char realm[REALM_SZ];
23 static char master[INST_SZ] = "sms";
24 static char service[ANAME_SZ] = "rcmd";
25 des_cblock session;
26 krb5_context context = NULL;
27
28 static int get_mr_tgt(void);
29
30 int get_mr_krb5_update_ticket(char *host, krb5_data auth)
31 {
32   krb5_auth_context auth_con = NULL;
33   krb5_ccache ccache = NULL;
34   int code;
35
36   code = krb5_init_context(&context);
37   if (code)
38     goto out;
39
40   code = krb5_auth_con_init(context, &auth_con);
41   if (code)
42     goto out;
43
44   krb5_init_ets(context);
45
46   code = krb5_cc_default(context, &ccache);
47   if (code)
48     goto out;
49
50   code = krb5_mk_req(context, &auth_con, NULL, "host", host, NULL, ccache,
51                      &auth);
52
53  out:
54   if (ccache)
55     krb5_cc_close(context, ccache);
56   if (auth_con)
57     krb5_auth_con_free(context, auth_con);
58   return code;
59 }
60
61 int get_mr_update_ticket(char *host, KTEXT ticket)
62 {
63   int code, pass;
64   char phost[BUFSIZ];
65   CREDENTIALS cr;
66
67   pass = 1;
68   if (krb_get_lrealm(realm, 1))
69     strcpy(realm, KRB_REALM);
70   strcpy(phost, (char *)krb_get_phost(host));
71
72 try_it:
73   code = krb_mk_req(ticket, service, phost, realm, (long)0);
74   if (code)
75     {
76       if (pass == 1)
77         {
78           /* maybe we're taking too long? */
79           if ((code = get_mr_tgt()))
80             {
81               com_err(whoami, code, "can't get Kerberos TGT");
82               return code;
83             }
84           pass++;
85           goto try_it;
86         }
87       code += ERROR_TABLE_BASE_krb;
88       com_err(whoami, code, "in krb_mk_req");
89     }
90   else
91     {
92       code = krb_get_cred(service, phost, realm, &cr);
93       if (code)
94         code += ERROR_TABLE_BASE_krb;
95       memcpy(session, cr.session, sizeof(session));
96     }
97   return code;
98 }
99
100 static int get_mr_tgt(void)
101 {
102   int code;
103   char linst[INST_SZ], kinst[INST_SZ];
104
105   linst[0] = '\0';
106   strcpy(kinst, "krbtgt");
107   code = krb_get_svc_in_tkt(master, linst, realm, kinst, realm,
108                             DEFAULT_TKT_LIFE, KEYFILE);
109   if (!code)
110     return 0;
111   else
112     return code + ERROR_TABLE_BASE_krb;
113 }
This page took 0.052198 seconds and 5 git commands to generate.