]> andersk Git - moira.git/blobdiff - afssync/sync.fast.qc
Now rcp'ing with encryption, and actually checking that backup succeeded.
[moira.git] / afssync / sync.fast.qc
index 8c38de604f3789576099e4cf460902a56a09fa83..e7518b6a1ce304268339f05c7cf194de7add775d 100644 (file)
@@ -31,7 +31,19 @@ long groupcount;     /* cheader.groupcount */
 
 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;
+    long pos;
+    struct member *members;
+};
 
 main(argc, argv)
 int argc;
@@ -42,6 +54,8 @@ char **argv;
     int status;
     int ingerr();
 
+    strcpy(db, "sms");
+
     if (!strcmp(argv[1], "-db")) {
        strncpy(db, argv[2], sizeof(db)-1);
        argc -= 2;
@@ -63,7 +77,6 @@ char **argv;
     initialize_pt_error_table();
     Initdb();                                  /* Initialize prdb */
     
-    idpos = create_hash(20000);
     users = create_hash(10000);
     groups = create_hash(15000);
     
@@ -88,9 +101,10 @@ char **argv;
 do_passwd()
 ##{
 ##  char login[9];
-##  int uid, id, status;
-    int t, i;
+##  int uid, id;
+    int t, i, status;
     struct prentry tentry;
+    struct entry *u;
 
     t = time(0);
     fprintf(stderr, "Doing users: %s", ctime(&t));
@@ -104,26 +118,31 @@ do_passwd()
                status = PRIDEXIST;
            else {
                bzero(&tentry, sizeof(tentry));
-               hash_store(idpos, pos);
                strcpy(tentry.name, login);
-               tentry.id = uid;
-               tentry.owner = SYSADMINID;
-               tentry.creator = SYSADMINID;
-               tentry.flags = PRQUOTA;
-               tentry.ngroups = tentry.nusers = 20;
-               if (tentry.id > ntohl(cheader.maxID))
-                   cheader.maxID = htonl(tentry.id);
+               tentry.id = htonl(uid);
+               tentry.owner = htonl(SYSADMINID);
+               tentry.creator = htonl(SYSADMINID);
+               tentry.flags = htonl(PRQUOTA);
+               tentry.ngroups = tentry.nusers = htonl(20);
+               if (uid > ntohl(cheader.maxID))
+                   cheader.maxID = tentry.id;
                usercount++;
 
-               i = IDHash(tentry.id);
-               tentry.nextID = ntohl(cheader.idHash[i]);
+               i = IDHash(uid);
+               tentry.nextID = cheader.idHash[i];
                cheader.idHash[i] = htonl(pos);
 
                i = NameHash(tentry.name);
-               tentry.nextName = ntohl(cheader.nameHash[i]);
+               tentry.nextName = cheader.nameHash[i];
                cheader.nameHash[i] = htonl(pos);
                
-               pr_WriteEntry(0, 0, pos, &tentry);
+               pr_Write(0, 0, pos, &tentry, sizeof(tentry));
+
+               u = (struct entry *)malloc(sizeof(struct entry));
+               u->id = uid;
+               u->pos = pos;
+               u->members = 0;
+               
                pos += ENTRYSIZE;
                status = 0;
            }
@@ -132,7 +151,7 @@ do_passwd()
                fprintf(stderr, "Error adding user %s uid %d: %s\n",
                        login, uid, error_message(status));
            else
-               hash_store(users, id, uid);
+               hash_store(users, id, u);
 ##  }
 ##}
 
@@ -140,8 +159,11 @@ do_passwd()
 
 do_groups()
 ##{
-    long u, g, status, gpos, upos;
+    long status;
     struct prentry gentry, uentry;
+    struct entry *u, *g;
+    struct bucket **p, *b;
+    struct member *m;
     char namebuf[41];
     int aid, t, i;
 ##  char name[33];
@@ -162,41 +184,46 @@ do_groups()
            sprintf(namebuf, "system:%s", name);
            aid = -gid;
 
-           if (aid==ANYUSERID || aid==AUTHUSERID)
+           if (aid==ANYUSERID || aid==AUTHUSERID || aid==SYSADMINID)
                status = PRIDEXIST;
            else {
                bzero(&gentry, sizeof(gentry));
-               hash_store(idpos, pos);
                strcpy(gentry.name, namebuf);
-               gentry.id = aid;
-               gentry.owner = SYSADMINID;
-               gentry.creator = SYSADMINID;
+               gentry.id = htonl(aid);
+               gentry.owner = htonl(SYSADMINID);
+               gentry.creator = htonl(SYSADMINID);
                if (hide)
-                   gentry.flags = PRGRP|PRACCESS|PRP_STATUS_ANY;
+                   gentry.flags = htonl(PRGRP|PRACCESS|PRP_STATUS_ANY);
                else
-                   gentry.flags = PRGRP;
-               if (gentry.id < ntohl(cheader.maxGroup))
-                   cheader.maxGroup = htonl(gentry.id);
+                   gentry.flags = htonl(PRGRP);
+               if (aid < ntohl(cheader.maxGroup))
+                   cheader.maxGroup = gentry.id;
                groupcount++;
 
-               i = IDHash(gentry.id);
-               gentry.nextID = ntohl(cheader.idHash[i]);
+               i = IDHash(aid);
+               gentry.nextID = cheader.idHash[i];
                cheader.idHash[i] = htonl(pos);
 
                i = NameHash(gentry.name);
-               gentry.nextName = ntohl(cheader.nameHash[i]);
+               gentry.nextName = cheader.nameHash[i];
                cheader.nameHash[i] = htonl(pos);
 
-               pr_WriteEntry(0, 0, pos, &gentry);
-               AddToOwnerChain(0,gentry.id,gentry.owner);
+               pr_Write(0, 0, pos, &gentry, sizeof(gentry));
+               AddToOwnerChain(0, aid, SYSADMINID);
+
+               g = (struct entry *)malloc(sizeof(struct entry));
+               g->id = aid;
+               g->pos = pos;
+               g->members = 0;
+               
                pos += ENTRYSIZE;
                status = 0;
            }
            if (status)
                fprintf(stderr, "Error adding group %s id %d: %s\n",
                        namebuf, aid, error_message(status));
-           else
-               hash_store(groups, lid, aid);
+           if (status==0 || (status==PRIDEXIST && aid==SYSADMINID))
+               hash_store(groups, lid, g);
 
 ##  }
 
@@ -210,41 +237,60 @@ 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 ((gpos = get_id(g)) && (upos = get_id(u))) {
-             pr_ReadEntry(0,0,upos,&uentry);
-             pr_ReadEntry(0,0,gpos,&gentry);
-             AddToEntry (0, &gentry, gpos, u);
-             AddToEntry (0, &uentry, upos, g);
-             status = 0;
-         } 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;
       }
 ##  }
 
+    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;
+           pr_Read(0, 0, u->pos, &uentry, sizeof(uentry));
+           for (i=0, m=u->members; m && i<PRSIZE; m=m->unext, i++)
+               uentry.entries[i] = htonl(m->group->id);
+           uentry.count = htonl(i);
+           pr_Write(0, 0, u->pos, &uentry, sizeof(uentry));
+           if (m) {
+               pr_ReadEntry(0, 0, u->pos, &uentry);
+               while (m) {
+                   AddToEntry(0, &uentry, u->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;
+           pr_Read(0, 0, g->pos, &gentry, sizeof(gentry));
+           for (i=0, m=g->members; m && i<PRSIZE; m=m->gnext, i++)
+               gentry.entries[i] = htonl(m->user->id);
+           gentry.count = htonl(i);
+           pr_Write(0, 0, g->pos, &gentry, sizeof(gentry));
+           if (m) {
+               pr_ReadEntry(0, 0, g->pos, &gentry);
+               while (m) {
+                   AddToEntry(0, &gentry, g->pos, m->user->id);
+                   m = m->gnext;
+               }
+           }
+       }
+    }
+
     t = time(0);
     fprintf(stderr, "Done: %s", ctime(&t));
 
 ##}
 
 
-get_id(id)
-{
-    long i;
-
-    if (i=(long)hash_lookup(idpos, id))
-        return i;
-    hash_store(idpos, id, i=FindByID(0, id));
-    return i;
-}
-
-
-
 /*
  * 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.042846 seconds and 4 git commands to generate.