3 * Copyright (C) 1988-1998 by the Massachusetts Institute of Technology.
4 * For copying and distribution information, please see the file
8 #include <mit-copyright.h>
27 static char realm[REALM_SZ];
28 static char master[INST_SZ] = "sms";
29 static char service[ANAME_SZ] = "rcmd";
33 krb5_context context = NULL;
35 static int get_mr_krb5_tgt(krb5_context context, krb5_ccache ccache);
37 static int get_mr_tgt(void);
40 int get_mr_krb5_update_ticket(char *host, krb5_data *auth)
42 krb5_auth_context auth_con = NULL;
43 krb5_ccache ccache = NULL;
47 code = krb5_init_context(&context);
51 code = krb5_auth_con_init(context, &auth_con);
55 code = krb5_cc_default(context, &ccache);
60 code = krb5_mk_req(context, &auth_con, 0, "host", host, NULL, ccache,
66 if ((code = get_mr_krb5_tgt(context, ccache)))
68 com_err(whoami, code, "can't get Kerberos v5 TGT");
74 com_err(whoami, code, "in krb5_mk_req");
79 krb5_cc_close(context, ccache);
81 krb5_auth_con_free(context, auth_con);
85 int get_mr_krb5_tgt(krb5_context context, krb5_ccache ccache)
88 krb5_principal me = NULL;
91 memset(&my_creds, 0, sizeof(my_creds));
93 code = krb5_parse_name(context, master, &me);
97 code = krb5_get_init_creds_keytab(context, &my_creds, me, NULL, NULL, NULL, NULL);
101 code = krb5_cc_initialize(context, ccache, me);
105 code = krb5_cc_store_cred(context, ccache, &my_creds);
111 krb5_free_principal(context, me);
112 krb5_free_cred_contents(context, &my_creds);
117 int get_mr_update_ticket(char *host, KTEXT ticket)
125 if (krb_get_lrealm(realm, 1))
126 strcpy(realm, KRB_REALM);
127 strcpy(phost, (char *)krb_get_phost(host));
130 code = krb_mk_req(ticket, service, phost, realm, (long)0);
135 /* maybe we're taking too long? */
136 if ((code = get_mr_tgt()))
138 com_err(whoami, code, "can't get Kerberos TGT");
144 code += ERROR_TABLE_BASE_krb;
145 com_err(whoami, code, "in krb_mk_req");
149 code = krb_get_cred(service, phost, realm, &cr);
151 code += ERROR_TABLE_BASE_krb;
152 memcpy(session, cr.session, sizeof(session));
161 static int get_mr_tgt(void)
164 char linst[INST_SZ], kinst[INST_SZ];
167 strcpy(kinst, "krbtgt");
168 code = krb_get_svc_in_tkt(master, linst, realm, kinst, realm,
169 DEFAULT_TKT_LIFE, KEYFILE);
173 return code + ERROR_TABLE_BASE_krb;