]> andersk Git - moira.git/blob - update/ticket.c
print an error message in fail()
[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 static char realm[REALM_SZ];
22 static char master[INST_SZ] = "sms";
23 static char service[ANAME_SZ] = "rcmd";
24 des_cblock session;
25
26 static int get_mr_tgt(void);
27
28 int get_mr_update_ticket(char *host, KTEXT ticket)
29 {
30   int code, pass;
31   char phost[BUFSIZ];
32   CREDENTIALS cr;
33
34   pass = 1;
35   if (krb_get_lrealm(realm, 1))
36     strcpy(realm, KRB_REALM);
37   strcpy(phost, (char *)krb_get_phost(host));
38
39 try_it:
40   code = krb_mk_req(ticket, service, phost, realm, (long)0);
41   if (code)
42     {
43       if (pass == 1)
44         {
45           /* maybe we're taking too long? */
46           if ((code = get_mr_tgt()))
47             {
48               com_err(whoami, code, "can't get Kerberos TGT");
49               return code;
50             }
51           pass++;
52           goto try_it;
53         }
54       code += ERROR_TABLE_BASE_krb;
55       com_err(whoami, code, "in krb_mk_req");
56     }
57   else
58     {
59       code = krb_get_cred(service, phost, realm, &cr);
60       if (code)
61         code += ERROR_TABLE_BASE_krb;
62       memcpy(session, cr.session, sizeof(session));
63     }
64   return code;
65 }
66
67 static int get_mr_tgt(void)
68 {
69   int code;
70   char linst[INST_SZ], kinst[INST_SZ];
71
72   linst[0] = '\0';
73   strcpy(kinst, "krbtgt");
74   code = krb_get_svc_in_tkt(master, linst, realm, kinst, realm,
75                             DEFAULT_TKT_LIFE, KEYFILE);
76   if (!code)
77     return 0;
78   else
79     return code + ERROR_TABLE_BASE_krb;
80 }
This page took 1.448931 seconds and 5 git commands to generate.