]> andersk Git - moira.git/commitdiff
Get a krb5 TGT if we don't have one.
authorzacheiss <zacheiss>
Tue, 8 Sep 2009 21:59:26 +0000 (21:59 +0000)
committerzacheiss <zacheiss>
Tue, 8 Sep 2009 21:59:26 +0000 (21:59 +0000)
update/ticket.c

index 438e248c4db4f5b327a5d6c411403b3821d4d47c..91348fd9fb1961a08b92e83db805e95f6c02ea74 100644 (file)
@@ -31,6 +31,7 @@ des_cblock session;
 #endif
 krb5_context context = NULL;
 
+static int get_mr_krb5_tgt(krb5_context context, krb5_ccache ccache);
 #ifdef HAVE_KRB4
 static int get_mr_tgt(void);
 #endif
@@ -40,6 +41,7 @@ int get_mr_krb5_update_ticket(char *host, krb5_data *auth)
   krb5_auth_context auth_con = NULL;
   krb5_ccache ccache = NULL;
   krb5_error_code code;
+  int pass = 1;
 
   code = krb5_init_context(&context);
   if (code)
@@ -53,8 +55,23 @@ int get_mr_krb5_update_ticket(char *host, krb5_data *auth)
   if (code)
     goto out;
 
+ try_it:
   code = krb5_mk_req(context, &auth_con, 0, "host", host, NULL, ccache,
                     auth);
+  if (code)
+    {
+      if (pass == 1)
+       {
+         if ((code = get_mr_krb5_tgt(context, ccache)))
+           {
+             com_err(whoami, code, "can't get Kerberos v5 TGT");
+             return code;
+           }
+         pass++;
+         goto try_it;
+       }
+      com_err(whoami, code, "in krb5_mk_req");
+    }
 
  out:
   if (ccache)
@@ -64,6 +81,38 @@ int get_mr_krb5_update_ticket(char *host, krb5_data *auth)
   return code;
 }
 
+int get_mr_krb5_tgt(krb5_context context, krb5_ccache ccache)
+{
+  krb5_creds my_creds;
+  krb5_principal me = NULL;
+  krb5_error_code code;
+
+  memset(&my_creds, 0, sizeof(my_creds));
+
+  code = krb5_parse_name(context, master, &me);
+  if (code)
+    goto out;
+  
+  code = krb5_get_init_creds_keytab(context, &my_creds, me, NULL, NULL, NULL, NULL);
+  if (code)
+    goto out;
+  
+  code = krb5_cc_initialize(context, ccache, me);
+  if (code)
+    goto out;
+
+  code = krb5_cc_store_cred(context, ccache, &my_creds);
+  if (code)
+    goto out;
+
+ out:
+  if (me)
+    krb5_free_principal(context, me);
+  krb5_free_cred_contents(context, &my_creds);
+
+  return code;
+}
+
 int get_mr_update_ticket(char *host, KTEXT ticket)
 {
 #ifdef HAVE_KRB4
This page took 0.053062 seconds and 5 git commands to generate.