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";
32 krb5_context context = NULL;
34 static int get_mr_krb5_tgt(krb5_context context, krb5_ccache ccache);
36 static int get_mr_tgt(void);
39 int get_mr_krb5_update_ticket(char *host, krb5_data *auth)
41 krb5_auth_context auth_con = NULL;
42 krb5_ccache ccache = NULL;
46 code = krb5_init_context(&context);
50 code = krb5_auth_con_init(context, &auth_con);
54 code = krb5_cc_default(context, &ccache);
59 code = krb5_mk_req(context, &auth_con, 0, "host", host, NULL, ccache,
65 if ((code = get_mr_krb5_tgt(context, ccache)))
67 com_err(whoami, code, "can't get Kerberos v5 TGT");
73 com_err(whoami, code, "in krb5_mk_req");
78 krb5_cc_close(context, ccache);
80 krb5_auth_con_free(context, auth_con);
84 int get_mr_krb5_tgt(krb5_context context, krb5_ccache ccache)
87 krb5_principal me = NULL;
90 memset(&my_creds, 0, sizeof(my_creds));
92 code = krb5_parse_name(context, master, &me);
96 code = krb5_get_init_creds_keytab(context, &my_creds, me, NULL, NULL, NULL, NULL);
100 code = krb5_cc_initialize(context, ccache, me);
104 code = krb5_cc_store_cred(context, ccache, &my_creds);
110 krb5_free_principal(context, me);
111 krb5_free_cred_contents(context, &my_creds);
116 int get_mr_update_ticket(char *host, KTEXT ticket)
124 if (krb_get_lrealm(realm, 1))
125 strcpy(realm, KRB_REALM);
126 strcpy(phost, (char *)krb_get_phost(host));
129 code = krb_mk_req(ticket, service, phost, realm, (long)0);
134 /* maybe we're taking too long? */
135 if ((code = get_mr_tgt()))
137 com_err(whoami, code, "can't get Kerberos TGT");
143 code += ERROR_TABLE_BASE_krb;
144 com_err(whoami, code, "in krb_mk_req");
148 code = krb_get_cred(service, phost, realm, &cr);
150 code += ERROR_TABLE_BASE_krb;
151 memcpy(session, cr.session, sizeof(session));
160 static int get_mr_tgt(void)
163 char linst[INST_SZ], kinst[INST_SZ];
166 strcpy(kinst, "krbtgt");
167 code = krb_get_svc_in_tkt(master, linst, realm, kinst, realm,
168 DEFAULT_TKT_LIFE, KEYFILE);
172 return code + ERROR_TABLE_BASE_krb;