]> andersk Git - moira.git/blob - update/ticket.c
Implement AUTH_002, which isn't vulnerable to replay attacks. Remove
[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()
34 {
35     static int initialized = 0;
36
37     if (!initialized) {
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
47 get_mr_update_ticket(host, ticket)
48      char *host;
49      KTEXT ticket;
50 {
51      register int code;
52      register int pass;
53      char phost[BUFSIZ];
54      CREDENTIALS cr;
55
56      pass = 1;
57      init();
58      strcpy(phost, (char*)krb_get_phost(host));
59  try_it:
60      code = krb_mk_req(ticket, service, phost, realm, (long)0);
61      if (code) {
62          if (pass == 1) {
63              /* maybe we're taking too long? */
64              if ((code = get_mr_tgt()) != 0) {
65                  com_err(whoami, code, " can't get Kerberos TGT");
66                  return(code);
67              }
68              pass++;
69              goto try_it;
70          }
71          com_err(whoami, code, "in krb_mk_req");
72      } else {
73          code = krb_get_cred(service, phost, realm, &cr);
74          memcpy(session, cr.session, sizeof(session));
75      }
76      return(code);
77 }
78
79 int
80 get_mr_tgt()
81 {
82     register int code;
83     char linst[INST_SZ], kinst[INST_SZ];
84
85     init();
86     linst[0] = '\0';
87     strcpy(kinst, "krbtgt");
88     code = krb_get_svc_in_tkt(master, linst, realm, kinst, realm,
89                               DEFAULT_TKT_LIFE, srvtab);
90     if (!code)
91         return(0);
92     else
93         return(code + ERROR_TABLE_BASE_krb);
94 }
This page took 0.037135 seconds and 5 git commands to generate.