]> andersk Git - moira.git/blobdiff - incremental/afs/afs.c
Build shared libmoira via libtool.
[moira.git] / incremental / afs / afs.c
index 78e7475619e31b7de41f1ea2fe47f5950d5c1a6b..7c1b35a3479dba6290a33386ba928411c107f968 100644 (file)
 #include <unistd.h>
 
 #include <com_err.h>
+#ifdef HAVE_KRB4
 #include <krb.h>
+#endif
+#include <krb5.h>
 
 #include <afs/param.h>
 #include <afs/cellconfig.h>
 #include <afs/ptclient.h>
 #include <afs/pterror.h>
 
+/* Cheesy test for determining AFS more recent than 3.4a */
+#ifndef AFSCONF_CLIENTNAME
+#include <afs/dirpath.h>
+#define AFSCONF_CLIENTNAME AFSDIR_CLIENT_ETC_DIRPATH
+#endif
+
 #define STOP_FILE "/moira/afs/noafs"
 #define file_exists(file) (access((file), F_OK) == 0)
 
@@ -167,7 +176,7 @@ void do_user(char **before, int beforec, char **after, int afterc)
       code = pr_try(pr_ChangeEntry, before[U_NAME], after[U_NAME], auid, "");
       if (code)
        {
-         critical_alert("incremental",
+         critical_alert(whoami, "incremental",
                         "Couldn't change user %s (id %d) to %s (id %d): %s",
                         before[U_NAME], buid, after[U_NAME], auid,
                         error_message(code));
@@ -182,7 +191,7 @@ void do_user(char **before, int beforec, char **after, int afterc)
       code = pr_try(pr_DeleteByID, buid);
       if (code && code != PRNOENT)
        {
-         critical_alert("incremental", "Couldn't delete user %s (id %d): %s",
+         critical_alert(whoami, "incremental", "Couldn't delete user %s (id %d): %s",
                         before[U_NAME], buid, error_message(code));
        }
       return;
@@ -207,7 +216,7 @@ void do_user(char **before, int beforec, char **after, int afterc)
        }
       if (code)
        {
-         critical_alert("incremental", "Couldn't create user %s (id %d): %s",
+         critical_alert(whoami, "incremental", "Couldn't create user %s (id %d): %s",
                         after[U_NAME], auid, error_message(code));
          return;
        }
@@ -218,7 +227,7 @@ void do_user(char **before, int beforec, char **after, int afterc)
          code = moira_connect();
          if (code)
            {
-             critical_alert("incremental", "Error contacting Moira server "
+             critical_alert(whoami, "incremental", "Error contacting Moira server "
                             "to retrieve grouplist of user %s: %s",
                             after[U_NAME], error_message(code));
              return;
@@ -229,7 +238,7 @@ void do_user(char **before, int beforec, char **after, int afterc)
                          after[U_NAME]);
          if (code && code != MR_NO_MATCH)
            {
-             critical_alert("incremental",
+             critical_alert(whoami, "incremental",
                             "Couldn't retrieve membership of user %s: %s",
                             after[U_NAME], error_message(code));
            }
@@ -279,7 +288,7 @@ void do_list(char **before, int beforec, char **after, int afterc)
          code = pr_try(pr_ChangeEntry, g1, g2, -agid, "");
          if (code)
            {
-             critical_alert("incremental", "Couldn't change group %s (id %d) "
+             critical_alert(whoami, "incremental", "Couldn't change group %s (id %d) "
                             "to %s (id %d): %s", before[L_NAME], -bgid,
                             after[L_NAME], -agid, error_message(code));
            }
@@ -293,7 +302,7 @@ void do_list(char **before, int beforec, char **after, int afterc)
                        PRIVATE_SHIFT, 0 /*ngroups*/, 0 /*nusers*/);
          if (code)
            {
-             critical_alert("incremental",
+             critical_alert(whoami, "incremental",
                             "Couldn't set flags of group %s: %s",
                             after[L_NAME], error_message(code));
            }
@@ -306,7 +315,7 @@ void do_list(char **before, int beforec, char **after, int afterc)
       code = pr_try(pr_DeleteByID, -bgid);
       if (code && code != PRNOENT)
        {
-         critical_alert("incremental",
+         critical_alert(whoami, "incremental",
                         "Couldn't delete group %s (id %d): %s",
                         before[L_NAME], -bgid, error_message(code));
        }
@@ -330,7 +339,7 @@ void do_list(char **before, int beforec, char **after, int afterc)
        }
       if (code)
        {
-         critical_alert("incremental", "Couldn't create group %s (id %d): %s",
+         critical_alert(whoami, "incremental", "Couldn't create group %s (id %d): %s",
                         after[L_NAME], id, error_message(code));
          return;
        }
@@ -341,7 +350,7 @@ void do_list(char **before, int beforec, char **after, int afterc)
                        PRIVATE_SHIFT, 0 /*ngroups*/, 0 /*nusers*/);
          if (code)
            {
-             critical_alert("incremental",
+             critical_alert(whoami, "incremental",
                             "Couldn't set flags of group %s: %s",
                             after[L_NAME], error_message(code));
            }
@@ -354,7 +363,7 @@ void do_list(char **before, int beforec, char **after, int afterc)
       code = moira_connect();
       if (code)
        {
-         critical_alert("incremental",
+         critical_alert(whoami, "incremental",
                         "Error contacting Moira server to resolve %s: %s",
                         after[L_NAME], error_message(code));
          return;
@@ -364,7 +373,7 @@ void do_list(char **before, int beforec, char **after, int afterc)
                      add_list_members, after[L_NAME]);
       if (code)
        {
-         critical_alert("incremental",
+         critical_alert(whoami, "incremental",
                         "Couldn't retrieve full membership of list %s: %s",
                         after[L_NAME], error_message(code));
        }
@@ -443,7 +452,7 @@ void do_filesys(char **before, int beforec, char **after, int afterc)
   if (afterc < FS_CREATE)
     {
       if (btype && bcreate)
-       critical_alert("incremental", "Cannot delete AFS filesystem %s: "
+       critical_alert(whoami, "incremental", "Cannot delete AFS filesystem %s: "
                       "Operation not supported", before[FS_NAME]);
       return;
     }
@@ -469,7 +478,7 @@ void do_filesys(char **before, int beforec, char **after, int afterc)
   if (strcmp(before[FS_OWNER], after[FS_OWNER]) ||
       strcmp(before[FS_OWNERS], after[FS_OWNERS]))
     {
-      critical_alert("incremental",
+      critical_alert(whoami, "incremental",
                     "Cannot change ownership of filesystem %s: Operation not yet supported",
                     after[FS_NAME]);
     }
@@ -516,7 +525,7 @@ void run_cmd(char *cmd)
        success++;
     }
   if (!success)
-    critical_alert("incremental", "failed command: %s", cmd);
+    critical_alert(whoami, "incremental", "failed command: %s", cmd);
 }
 
 
@@ -546,14 +555,24 @@ void edit_group(int op, char *group, char *type, char *member)
   char *p = 0;
   char buf[PR_MAXNAMELEN];
   int code, ustate;
-  static char local_realm[REALM_SZ+1] = "";
+  static char *local_realm = NULL;
   struct member *m;
+  krb5_context context = NULL;
 
   /* The following KERBEROS code allows for the use of entities
    * user@foreign_cell.
    */
-  if (!local_realm[0])
-    krb_get_lrealm(local_realm, 1);
+  if (!local_realm)
+    {
+      code = krb5_init_context(&context);
+      if (code)
+       goto out;
+
+      code = krb5_get_default_realm(context, &local_realm);
+      if (code)
+       goto out;
+    }
+
   if (!strcmp(type, "KERBEROS"))
     {
       p = strchr(member, '@');
@@ -572,7 +591,7 @@ void edit_group(int op, char *group, char *type, char *member)
       m = malloc(sizeof(struct member));
       if (!m)
        {
-         critical_alert("incremental", "Out of memory");
+         critical_alert(whoami, "incremental", "Out of memory");
          exit(1);
        }
       m->op = op;
@@ -610,7 +629,7 @@ void edit_group(int op, char *group, char *type, char *member)
            }
          if (code)
            {
-             critical_alert("incremental", "Error contacting Moira server "
+             critical_alert(whoami, "incremental", "Error contacting Moira server "
                             "to lookup user %s: %s", member,
                             error_message(code));
            }
@@ -626,7 +645,13 @@ void edit_group(int op, char *group, char *type, char *member)
          code = PRNOENT;
        }
 
-      critical_alert("incremental", "Couldn't %s %s %s %s: %s",
+    out:
+      if (context)
+       krb5_free_context(context);
+      if (local_realm)
+       free(local_realm);
+
+      critical_alert(whoami, "incremental", "Couldn't %s %s %s %s: %s",
                     op ? "add" : "remove", member,
                     op ? "to" : "from", buf,
                     error_message(code));
@@ -654,7 +679,7 @@ long pr_try(long (*fn)(), char *a1, char *a2, char *a3, char *a4, char *a5,
     code = pr_Initialize(1, AFSCONF_CLIENTNAME, 0);
   if (code)
     {
-      critical_alert("incremental", "Couldn't initialize libprot: %s",
+      critical_alert(whoami, "incremental", "Couldn't initialize libprot: %s",
                     error_message(code));
       return code;
     }
@@ -679,7 +704,7 @@ long pr_try(long (*fn)(), char *a1, char *a2, char *a3, char *a4, char *a5,
        code = pr_Initialize(1, AFSCONF_CLIENTNAME, 0);
       if (code)
        {
-         critical_alert("incremental", "Couldn't re-initialize libprot: %s",
+         critical_alert(whoami, "incremental", "Couldn't re-initialize libprot: %s",
                         error_message(code));
          initd = 0;                            /* we lost */
          break;
@@ -697,7 +722,7 @@ void check_afs(void)
     {
       if (i > 30)
        {
-         critical_alert("incremental",
+         critical_alert(whoami, "incremental",
                         "AFS incremental failed (%s exists): %s",
                         STOP_FILE, tbl_buf);
          exit(1);
@@ -717,7 +742,7 @@ int moira_connect(void)
       uname(&uts);
       code = mr_connect(uts.nodename);
       if (!code)
-       code = mr_auth("afs.incr");
+       code = mr_krb5_auth("afs.incr");
       return code;
     }
   return 0;
This page took 0.045585 seconds and 4 git commands to generate.