]> andersk Git - moira.git/blame - update/ticket.c
- Don't ifdef out auth_002; it breaks backward compatability.
[moira.git] / update / ticket.c
CommitLineData
7ac48069 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>.
de56407f 6 */
de56407f 7
546bc43b 8#include <mit-copyright.h>
7ac48069 9#include <moira.h>
10
de56407f 11#include <sys/stat.h>
7ac48069 12
13#include <stdio.h>
a6e20de8 14#include <string.h>
7ac48069 15
cb974713 16#ifdef HAVE_KRB4
7ac48069 17#include <krb.h>
cb974713 18#else
19#define KTEXT void*
20#endif
991417e4 21#include <krb5.h>
5c87ce34 22#include <update.h>
7ac48069 23
24RCSID("$Header$");
de56407f 25
cb974713 26#ifdef HAVE_KRB4
de56407f 27static char realm[REALM_SZ];
b95ec814 28static char master[INST_SZ] = "sms";
29static char service[ANAME_SZ] = "rcmd";
85330553 30des_cblock session;
cb974713 31#endif
991417e4 32krb5_context context = NULL;
de56407f 33
cb974713 34#ifdef HAVE_KRB4
85330553 35static int get_mr_tgt(void);
cb974713 36#endif
de56407f 37
e51080f9 38int get_mr_krb5_update_ticket(char *host, krb5_data *auth)
991417e4 39{
40 krb5_auth_context auth_con = NULL;
41 krb5_ccache ccache = NULL;
42 krb5_error_code code;
43
44 code = krb5_init_context(&context);
45 if (code)
46 goto out;
47
48 code = krb5_auth_con_init(context, &auth_con);
49 if (code)
50 goto out;
51
52 code = krb5_cc_default(context, &ccache);
53 if (code)
54 goto out;
55
548fc1f0 56 code = krb5_mk_req(context, &auth_con, 0, "host", host, NULL, ccache,
e51080f9 57 auth);
991417e4 58
59 out:
60 if (ccache)
61 krb5_cc_close(context, ccache);
62 if (auth_con)
63 krb5_auth_con_free(context, auth_con);
64 return code;
65}
66
5eaef520 67int get_mr_update_ticket(char *host, KTEXT ticket)
de56407f 68{
cb974713 69#ifdef HAVE_KRB4
85330553 70 int code, pass;
5eaef520 71 char phost[BUFSIZ];
72 CREDENTIALS cr;
de56407f 73
5eaef520 74 pass = 1;
85330553 75 if (krb_get_lrealm(realm, 1))
76 strcpy(realm, KRB_REALM);
5eaef520 77 strcpy(phost, (char *)krb_get_phost(host));
85330553 78
5eaef520 79try_it:
80 code = krb_mk_req(ticket, service, phost, realm, (long)0);
81 if (code)
82 {
83 if (pass == 1)
84 {
85 /* maybe we're taking too long? */
86 if ((code = get_mr_tgt()))
87 {
88 com_err(whoami, code, "can't get Kerberos TGT");
89 return code;
90 }
91 pass++;
92 goto try_it;
93 }
94 code += ERROR_TABLE_BASE_krb;
95 com_err(whoami, code, "in krb_mk_req");
96 }
97 else
98 {
99 code = krb_get_cred(service, phost, realm, &cr);
100 if (code)
101 code += ERROR_TABLE_BASE_krb;
102 memcpy(session, cr.session, sizeof(session));
103 }
104 return code;
cb974713 105#else
106 return MR_NO_KRB4;
107#endif
de56407f 108}
109
cb974713 110#ifdef HAVE_KRB4
85330553 111static int get_mr_tgt(void)
de56407f 112{
44d12d58 113 int code;
5eaef520 114 char linst[INST_SZ], kinst[INST_SZ];
b95ec814 115
5eaef520 116 linst[0] = '\0';
117 strcpy(kinst, "krbtgt");
118 code = krb_get_svc_in_tkt(master, linst, realm, kinst, realm,
91519120 119 DEFAULT_TKT_LIFE, KEYFILE);
5eaef520 120 if (!code)
121 return 0;
122 else
123 return code + ERROR_TABLE_BASE_krb;
de56407f 124}
cb974713 125#endif
This page took 0.129302 seconds and 5 git commands to generate.