]> andersk Git - moira.git/commitdiff
Make mrcl_krb_user() not broken.
authorzacheiss <zacheiss>
Wed, 23 Aug 2006 19:01:05 +0000 (19:01 +0000)
committerzacheiss <zacheiss>
Wed, 23 Aug 2006 19:01:05 +0000 (19:01 +0000)
Make mrcl_connect() fall backt to mr_auth RPC if the server doesn't
support the mr_krb5_auth RPC.

clients/lib/utils.c

index 540fee7a3fc67a13da77485a4c38ae8a0660a67e..7399c94dc6a281638d46274858c96d72bfe96d2e 100644 (file)
@@ -91,6 +91,11 @@ int mrcl_connect(char *server, char *client, int version, int auth)
   if (auth)
     {
       status = mr_krb5_auth(client);
+
+      /* New client talking to old server, try krb4. */
+      if (status == MR_UNKNOWN_PROC)
+       status = mr_auth(client);
+
       if (status)
        {
          com_err(whoami, status, "while authenticating to Moira.");
@@ -106,9 +111,9 @@ char *mrcl_krb_user(void)
 {
   int flags = 0;
   krb5_ccache cache = NULL;
-  krb5_principal princ;
+  krb5_principal princ = NULL;
   krb5_error_code status;
-  char *name;
+  char *username = NULL;
 
   if (!context)
     krb5_init_context(&context);
@@ -117,18 +122,31 @@ char *mrcl_krb_user(void)
   if (status)
     {
       com_err(whoami, status, "while reading Kerberos ticket file.");
-      return NULL;
+      goto out;
     }
 
   status = krb5_cc_get_principal(context, cache, &princ);
   if (status)
     {
       com_err(whoami, status, "while retrieving principal name.");
-      return NULL;
+      goto out;
     }
 
-  return (char *)krb5_princ_component(context, princ, 0);
+  username = malloc(krb5_princ_component(context, princ, 0)->length + 1);
+  if (!username)
+    goto out;
+
+  strncpy(username, krb5_princ_component(context, princ, 0)->data,
+         krb5_princ_component(context, princ, 0)->length);
+  username[krb5_princ_component(context, princ, 0)->length] = '\0';
+
+ out:
+  if (cache)
+    krb5_cc_close(context, cache);
+  if (princ)
+    krb5_free_principal(context, princ);
 
+  return username;
 }
 
 char *partial_canonicalize_hostname(char *s)
This page took 0.195357 seconds and 5 git commands to generate.