]> andersk Git - moira.git/blob - update/ticket.c
77e2b1c1ef4ddc2d7b720410f0909ef51efa8e3e
[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   krb5_error_code 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   code = krb5_cc_default(context, &ccache);
45   if (code)
46     goto out;
47
48   code = krb5_mk_req(context, &auth_con, 0, "host", host, NULL, ccache,
49                      &auth);
50
51  out:
52   if (ccache)
53     krb5_cc_close(context, ccache);
54   if (auth_con)
55     krb5_auth_con_free(context, auth_con);
56   return code;
57 }
58
59 int get_mr_update_ticket(char *host, KTEXT ticket)
60 {
61   int code, pass;
62   char phost[BUFSIZ];
63   CREDENTIALS cr;
64
65   pass = 1;
66   if (krb_get_lrealm(realm, 1))
67     strcpy(realm, KRB_REALM);
68   strcpy(phost, (char *)krb_get_phost(host));
69
70 try_it:
71   code = krb_mk_req(ticket, service, phost, realm, (long)0);
72   if (code)
73     {
74       if (pass == 1)
75         {
76           /* maybe we're taking too long? */
77           if ((code = get_mr_tgt()))
78             {
79               com_err(whoami, code, "can't get Kerberos TGT");
80               return code;
81             }
82           pass++;
83           goto try_it;
84         }
85       code += ERROR_TABLE_BASE_krb;
86       com_err(whoami, code, "in krb_mk_req");
87     }
88   else
89     {
90       code = krb_get_cred(service, phost, realm, &cr);
91       if (code)
92         code += ERROR_TABLE_BASE_krb;
93       memcpy(session, cr.session, sizeof(session));
94     }
95   return code;
96 }
97
98 static int get_mr_tgt(void)
99 {
100   int code;
101   char linst[INST_SZ], kinst[INST_SZ];
102
103   linst[0] = '\0';
104   strcpy(kinst, "krbtgt");
105   code = krb_get_svc_in_tkt(master, linst, realm, kinst, realm,
106                             DEFAULT_TKT_LIFE, KEYFILE);
107   if (!code)
108     return 0;
109   else
110     return code + ERROR_TABLE_BASE_krb;
111 }
This page took 0.03051 seconds and 3 git commands to generate.