]> andersk Git - moira.git/blobdiff - afssync/sync.qc
Used /bin/sh format instead of /bin/csh format, by accident.
[moira.git] / afssync / sync.qc
index 093f294fbc0ab716b642735f80a5a4737d3a0a1f..3910eb8cdf00d129c5dbb6f61cfe084546d75e59 100644 (file)
@@ -25,9 +25,23 @@ char *whoami = "sync";
 char *malloc(), *strsave();
 int dbase_fd;
 
+int ucount = 0;
+int gcount = 0;
+int mcount = 0;
+
 struct hash *users;
 struct hash *groups;
-struct hash *idpos;
+
+struct member {
+    struct entry *user;
+    struct entry *group;
+    struct member *unext;
+    struct member *gnext;
+};
+struct entry {
+    long id;
+    struct member *members;
+};
 
 main(argc, argv)
 int argc;
@@ -37,6 +51,9 @@ char **argv;
     
     int status;
     int ingerr();
+    long t;
+
+    strcpy(db, "sms");
 
     if (!strcmp(argv[1], "-db")) {
        strncpy(db, argv[2], sizeof(db)-1);
@@ -59,7 +76,6 @@ char **argv;
     initialize_pt_error_table();
     Initdb();                                  /* Initialize prdb */
     
-    idpos = create_hash(20000);
     users = create_hash(10000);
     groups = create_hash(15000);
     
@@ -70,6 +86,10 @@ char **argv;
     do_passwd();
     do_groups();
 
+    t = time(0);
+    fprintf(stderr, "Done (%d users, %d groups, %d members): %s",
+           ucount, gcount, mcount, ctime(&t));
+
 ##  end transaction
 ##  exit
 
@@ -81,8 +101,9 @@ do_passwd()
 ##{
 ##  char login[9];
 ##  int uid, id, status;
-    int t;
+    long t;
     struct prentry tentry;
+    struct entry *u;
 
     t = time(0);
     fprintf(stderr, "Doing users: %s", ctime(&t));
@@ -100,8 +121,13 @@ do_passwd()
            if (status)
                fprintf(stderr, "Error adding user %s uid %d: %s\n",
                        login, uid, error_message(status));
-           else
-               hash_store(users, id, uid);
+           else {
+               u = (struct entry *)malloc(sizeof(struct entry));
+               u->id = uid;
+               u->members = 0;
+               hash_store(users, id, u);
+               ucount++;
+           }
 ##  }
 ##}
 
@@ -109,10 +135,13 @@ do_passwd()
 
 do_groups()
 ##{
-    long u, g, status, gpos, upos;
+    long status, pos;
     struct prentry gentry, uentry;
-    char namebuf[41];
-    int aid, t;
+    struct entry *u, *g;
+    struct member *m;
+    struct bucket **p, *b;
+    char namebuf[40];
+    long aid, t;
 ##  char name[33];
 ##  int gid, id, lid, hide;
 
@@ -139,21 +168,29 @@ do_groups()
            if (status)
                fprintf(stderr, "Error adding group %s id %d: %s\n",
                        namebuf, aid, error_message(status));
-           else
-               hash_store(groups, lid, aid);
-
-           /* If this list is hidden, set the pts entry to be s---- */
-           if (hide && (status==0 || status==PRIDEXIST)) {
-               gpos = get_id(aid);
-               status = pr_ReadEntry(0, 0, gpos, &gentry);
-               if (!status) {
-                   gentry.flags = PRGRP|PRACCESS|PRP_STATUS_ANY;
-                   status = pr_WriteEntry(0, 0, gpos, &gentry);
+
+           if ((status==0 || status==PRIDEXIST) &&
+               (aid!=ANYUSERID && aid!=AUTHUSERID)) {
+
+               g = (struct entry *)malloc(sizeof(struct entry));
+               g->id = aid;
+               g->members = 0;
+               hash_store(groups, lid, g);
+               gcount++;
+
+               /* Set modes on hidden lists (S----) */
+               if (hide) {
+                   pos = FindByID(0, aid);
+                   status = pr_Read(0, 0, pos, &gentry, sizeof(gentry));
+                   if (!status) {
+                       gentry.flags = htonl(PRGRP|PRACCESS|PRP_STATUS_ANY);
+                       status = pr_Write(0, 0, pos, &gentry, sizeof(gentry));
+                   }
+                   if (status)
+                       fprintf(stderr,
+                               "Error setting flags on group %s: %s\n",
+                               namebuf, error_message(status));
                }
-               if (status)
-                   fprintf(stderr,
-                           "Error setting flags on group %s: %s\n",
-                           namebuf, error_message(status));
            }
 ##  }
 
@@ -162,42 +199,96 @@ do_groups()
 
 ##  retrieve (lid = m.list_id, id = m.member_id)
 ##     where m.member_type = "USER" {
-      if ((u = (long) hash_lookup(users, id)) &&
-         (g = (long) hash_lookup(groups, lid))) {
-         if (g==ANYUSERID || g==AUTHUSERID || u==ANONYMOUSID) {
-             status = PRPERM;
-         } else if ((gpos = get_id(g)) && (upos = get_id(u))) {
-             status = pr_ReadEntry(0,0,upos,&uentry);
-             if (!status) status = pr_ReadEntry(0,0,gpos,&gentry);
-             if (!status) status = AddToEntry (0, &gentry, gpos, u);
-             if (!status) status = AddToEntry (0, &uentry, upos, g);
-         } else {
-             status = PRNOENT;
-         }
-         if (status)
-             fprintf(stderr, "Error adding uid %d to group %d: %s\n",
-                     u, -g, error_message(status));
+      if ((u = (struct entry *)hash_lookup(users, id)) &&
+         (g = (struct entry *)hash_lookup(groups, lid))) {
+             m = (struct member *)malloc(sizeof(struct member));
+             m->user = u;
+             m->group = g;
+             m->unext = u->members;
+             m->gnext = g->members;
+             u->members = g->members = m;
+             mcount++;
       }
 ##  }
 
-    t = time(0);
-    fprintf(stderr, "Done: %s", ctime(&t));
-
+    /* Do the bulk of the membership quickly.
+     * Add PRSIZE members into the user/group record.  After that, we
+     * require the use of continuation records, but we assume this is
+     * few enough that we do this the slow way (AddToEntry).
+     */
+    for (p = &(users->data[users->size - 1]); p >= users->data; p--) {
+       for (b = *p; b; b = b->next) {
+           if ((u = (struct entry *)b->data)->members == 0)
+               continue;
+           pos = FindByID(0, u->id);
+           pr_Read(0, 0, pos, &uentry, sizeof(uentry));
+           for (t=0, m=u->members; m && t<PRSIZE; m=m->unext, t++)
+               uentry.entries[t] = htonl(m->group->id);
+           uentry.count = htonl(t);
+           pr_Write(0, 0, pos, &uentry, sizeof(uentry));
+           if (m) {
+               pr_ReadEntry(0, 0, pos, &uentry);
+               while (m) {
+                   AddToEntry(0, &uentry, pos, m->group->id);
+                   m = m->unext;
+               }
+           }
+       }
+    }
+    for (p = &(groups->data[groups->size - 1]); p >= groups->data; p--) {
+       for (b = *p; b; b = b->next) {
+           if ((g = (struct entry *)b->data)->members == 0)
+               continue;
+           pos = FindByID(0, g->id);
+           pr_Read(0, 0, pos, &gentry, sizeof(gentry));
+           for (t=0, m=g->members; m && t<PRSIZE; m=m->gnext, t++)
+               gentry.entries[t] = htonl(m->user->id);
+           gentry.count = htonl(t);
+           pr_Write(0, 0, pos, &gentry, sizeof(gentry));
+           if (m) {
+               pr_ReadEntry(0, 0, pos, &gentry);
+               while (m) {
+                   AddToEntry(0, &gentry, pos, m->user->id);
+                   m = m->gnext;
+               }
+           }
+       }
+    }
 ##}
 
+#if 0
+do_kerberos()
+##{
+    long status, pos;
+    struct prentry gentry, uentry;
+    struct entry *u, *g;
+    struct member *m;
+    struct bucket **p, *b;
+    char namebuf[40];
+    int aid, t;
+##  char name[129];
+##  int gid, id, lid, hide;
 
-get_id(id)
-{
-    long i;
-
-    if (i=(long)hash_lookup(idpos, id))
-        return i;
-    hash_store(idpos, id, i=FindByID(0, id));
-    return i;
-}
+    t = time(0);
+    fprintf(stderr, "Doing kerberos members: %s", ctime(&t));
 
+##  range of s is strings
+##  range of m is imembers
+    /* get lock records */
+##  retrieve (name = list.modtime) where list.list_id = 0
+##  retrieve (name = s.modtime) where s.string_id = 0
 
+##  retrieve (lid = m.list_id, id = m.member_id)
+##     where m.member_type = "KERBEROS" {
+       xxx;
+       {
+       }
+##  }
 
+##}
+#endif
+    
+    
 /*
  * ingerr: (supposedly) called when Ingres indicates an error.
  * I have not yet been able to get this to work to intercept a
This page took 0.058821 seconds and 4 git commands to generate.