]> andersk Git - moira.git/blobdiff - update/ticket.c
Build without krb4 if it's unavailable.
[moira.git] / update / ticket.c
index 155fa9de4ad257b2c5d01863f6d9fd387dbfb547..9eb47c7e5916a72e7792286a15c0f08cc4f7699f 100644 (file)
 #include <stdio.h>
 #include <string.h>
 
+#ifdef HAVE_KRB4
 #include <krb.h>
+#else
+#define KTEXT void*
+#endif
+#include <krb5.h>
 #include <update.h>
 
 RCSID("$Header$");
 
-extern char *whoami;
-
-/* too bad we can't set the pathname easily */
-static char *srvtab = KEYFILE; /* default == /etc/srvtab */
+#ifdef HAVE_KRB4
 static char realm[REALM_SZ];
 static char master[INST_SZ] = "sms";
 static char service[ANAME_SZ] = "rcmd";
-C_Block session;
+des_cblock session;
+#endif
+krb5_context context = NULL;
 
-int get_mr_tgt(void);
+#ifdef HAVE_KRB4
+static int get_mr_tgt(void);
+#endif
 
-static void init(void)
+int get_mr_krb5_update_ticket(char *host, krb5_data auth)
 {
-  static int initialized = 0;
+  krb5_auth_context auth_con = NULL;
+  krb5_ccache ccache = NULL;
+  krb5_error_code code;
 
-  if (!initialized)
-    {
-      if (krb_get_lrealm(realm, 1))
-       strcpy(realm, KRB_REALM);
-      initialize_krb_error_table();
-      initialized = 1;
-    }
-}
+  code = krb5_init_context(&context);
+  if (code)
+    goto out;
+
+  code = krb5_auth_con_init(context, &auth_con);
+  if (code)
+    goto out;
 
+  code = krb5_cc_default(context, &ccache);
+  if (code)
+    goto out;
+
+  code = krb5_mk_req(context, &auth_con, 0, "host", host, NULL, ccache,
+                    &auth);
+
+ out:
+  if (ccache)
+    krb5_cc_close(context, ccache);
+  if (auth_con)
+    krb5_auth_con_free(context, auth_con);
+  return code;
+}
 
 int get_mr_update_ticket(char *host, KTEXT ticket)
 {
-  int code;
-  int pass;
+#ifdef HAVE_KRB4
+  int code, pass;
   char phost[BUFSIZ];
   CREDENTIALS cr;
 
   pass = 1;
-  init();
+  if (krb_get_lrealm(realm, 1))
+    strcpy(realm, KRB_REALM);
   strcpy(phost, (char *)krb_get_phost(host));
+
 try_it:
   code = krb_mk_req(ticket, service, phost, realm, (long)0);
   if (code)
@@ -79,20 +102,24 @@ try_it:
       memcpy(session, cr.session, sizeof(session));
     }
   return code;
+#else
+  return MR_NO_KRB4;
+#endif
 }
 
-int get_mr_tgt(void)
+#ifdef HAVE_KRB4
+static int get_mr_tgt(void)
 {
   int code;
   char linst[INST_SZ], kinst[INST_SZ];
 
-  init();
   linst[0] = '\0';
   strcpy(kinst, "krbtgt");
   code = krb_get_svc_in_tkt(master, linst, realm, kinst, realm,
-                           DEFAULT_TKT_LIFE, srvtab);
+                           DEFAULT_TKT_LIFE, KEYFILE);
   if (!code)
     return 0;
   else
     return code + ERROR_TABLE_BASE_krb;
 }
+#endif
This page took 0.034935 seconds and 4 git commands to generate.