]> andersk Git - moira.git/blobdiff - afssync/pt_util.c
Fix usage message.
[moira.git] / afssync / pt_util.c
index 99d8519c64d034a3f3e1da9c46303a2d89a9c1a3..1ad31c5bb4337e2f508bd38471584f38231e6458 100644 (file)
@@ -13,7 +13,7 @@
 #include <sys/time.h>
 #include <stdio.h>
 #include <ctype.h>
-#include <strings.h>
+#include <string.h>
 #include <sys/file.h>
 
 #include <afs/param.h>
@@ -28,8 +28,8 @@
 #include "pterror.h"
 
 #define IDHash(x) (abs(x) % HASHSIZE)
-#define print_id(x) ( ((flags&DO_SYS)==0 && (abs(x)>32767)) || \
-                     ((flags&DO_OTR)==0 && (abs(x)<32768)))
+#define print_id(x) ( ((flags&DO_SYS)==0 && (x<-32767 || x>97536)) || \
+                     ((flags&DO_OTR)==0 && (x>-32768 && x<97537)))
 
 extern char *optarg;
 extern int optind;
@@ -132,7 +132,7 @@ char **argv;
            break;
        default:
            fprintf(stderr,
-                   "Usage: ptdump [options] [-d data] [-p prdb]\n");
+                   "Usage: pt_util [options] [-d data] [-p prdb]\n");
            fputs("  Options:\n", stderr);
            fputs("    -w  Update prdb with contents of data file\n", stderr);
            fputs("    -u  Display users\n", stderr);
@@ -168,7 +168,17 @@ char **argv;
     if (ntohl(uh->magic) != UBIK_MAGIC)
        fprintf(stderr, "ptdump: %s: Bad UBIK_MAGIC. Is %x should be %x\n",
                pfile, ntohl(uh->magic), UBIK_MAGIC);
-    bcopy(&uh->version, &uv, sizeof(struct ubik_version));
+    memcpy(&uv, &uh->version, sizeof(struct ubik_version));
+    if (wflag && uv.epoch==0 && uv.counter==0) {
+       uv.epoch=2; /* a ubik version of 0 or 1 has special meaning */
+       memcpy(&uh->version, &uv, sizeof(struct ubik_version));
+       lseek(dbase_fd, 0, SEEK_SET);
+       if (write(dbase_fd, buffer, HDRSIZE) < 0) {
+           fprintf(stderr, "ptdump: error writing ubik version to %s: %s\n",
+                   pfile, sys_errlist[errno]);
+           exit (1);
+       }
+    }
     fprintf(stderr, "Ubik Version is: %d.%d\n",
            uv.epoch, uv.counter);
     if (read(dbase_fd, &prh, sizeof(struct prheader)) < 0) {
@@ -189,8 +199,7 @@ char **argv;
 
            if (isspace(*buffer)) {
                sscanf(buffer, "%s %d", mem, &uid);
-#if 0
-               /* CROSS-CELL SUPPORT - NYI */
+
                for (u=usr_head; u; u=u->next)
                    if (u->uid && u->uid==uid) break;
                if (u) {
@@ -198,15 +207,23 @@ char **argv;
                    u->uid = 0;
                    if (FindByID(0, uid))
                        code = PRIDEXIST;
-                   else
+                   else {
+                       if (!code && (flags&(PRGRP|PRQUOTA))==(PRGRP|PRQUOTA)){
+                           gentry.ngroups++;
+                           code = pr_WriteEntry(0,0,gpos,&gentry);
+                           if (code)
+                               fprintf(stderr, "Error setting group count on %s: %s\n",
+                                       name, error_message(code));
+                       }
                        code = CreateEntry
                            (0, u->name, &uid, 1/*idflag*/, 1/*gflag*/,
                             SYSADMINID/*oid*/, SYSADMINID/*cid*/);
+                   }
                    if (code)
                        fprintf(stderr, "Error while creating %s: %s\n",
                                u->name, error_message(code));
+                   continue;
                }
-#endif
                /* Add user to group */
                if (id==ANYUSERID || id==AUTHUSERID || uid==ANONYMOUSID) {
                    code = PRPERM;
@@ -230,7 +247,6 @@ char **argv;
                else
                    code = CreateEntry(0, name, &id, 1/*idflag*/,
                                       flags&PRGRP, oid, cid);
-#if 0
                if (code == PRBADNAM) {
                    u = (struct usr_list *)malloc(sizeof(struct usr_list));
                    u->next = usr_head;
@@ -238,7 +254,6 @@ char **argv;
                    strcpy(u->name, name);
                    usr_head = u;
                } else
-#endif
                if (code) {
                    fprintf(stderr, "Error while creating %s: %s\n",
                            name, error_message(code));
@@ -248,8 +263,7 @@ char **argv;
                    code = pr_ReadEntry(0,0,gpos,&gentry);
                    if (!code) {
                        gentry.flags = flags;
-                       if ((flags&(PRGRP|PRQUOTA))==(PRGRP|PRQUOTA))
-                           gentry.ngroups = quota + gentry.count;
+                       gentry.ngroups = quota;
                        code = pr_WriteEntry(0,0,gpos,&gentry);
                    }
                    if (code)
@@ -258,12 +272,10 @@ char **argv;
                }
            }
        }
-#if 0
        for (u=usr_head; u; u=u->next)
            if (u->uid)
                fprintf(stderr, "Error while creating %s: %s\n",
                        u->name, error_message(PRBADNAM));
-#endif
     } else {
        for (i = 0; i < HASHSIZE; i++) {
            upos = nflag ? ntohl(prh.nameHash[i]) : ntohl(prh.idHash[i]);
This page took 0.046889 seconds and 4 git commands to generate.