prdb_check: check for continuation entries in owner chains
[openafs.git] / src / ptserver / db_verify.c
index 6a04ab1..4803076 100644 (file)
@@ -529,17 +529,13 @@ WalkNextChain(char map[],         /* one byte per db entry */
            if (id == PRBADID)
                continue;
            else if (id) {
-               int eid_s, id_s;
+               int id_s;
                sgcount++;
                /* in case the ids are large, convert to pure sign. */
                if (id > 0)
                    id_s = 1;
                else
                    id_s = -1;
-               if (eid > 0)
-                   eid_s = 1;
-               else
-                   eid_s = -1;
                if (id_s > 0) {
                    fprintf(stderr,
                            "User can't be member of supergroup list\n");
@@ -702,7 +698,7 @@ WalkOwnedChain(char map[],          /* one byte per db entry */
 {
     afs_int32 head;
     afs_int32 code;
-    struct prentry c;          /* continuation entry */
+    struct prentry te;         /* next entry in owner chain */
     afs_int32 na;              /* next thread */
     int ni;
     afs_int32 eid = 0;
@@ -715,7 +711,7 @@ WalkOwnedChain(char map[],          /* one byte per db entry */
        head = ntohl(cheader.orphan);
 
     length = 0;
-    for (na = head; na; na = ntohl(c.nextOwned)) {
+    for (na = head; na; na = ntohl(te.nextOwned)) {
        code = ConvertDiskAddress(na, &ni);
        if (code) {
            fprintf(stderr, "Bad owned list ptr %d", na);
@@ -725,23 +721,33 @@ WalkOwnedChain(char map[],                /* one byte per db entry */
                return PRDBBAD;
            if (na != head) {
                fprintf(stderr, "last block: \n");
-               if (PrintEntryError(misc, na, &c, 4))
+               if (PrintEntryError(misc, na, &te, 4))
                    return PRDBBAD;
            }
            return 0;
        }
-       code = pr_Read(na, (char *)&c, sizeof(c));
+       code = pr_Read(na, (char *)&te, sizeof(te));
        if (code)
            return code;
        length++;
 
+       if ((ntohl(te.flags) & PRTYPE) == PRCONT) {
+           fprintf(stderr, "Continuation entry found on owner chain\n");
+           if (e == 0)
+               fprintf(stderr, "walking orphan list");
+           else if (PrintEntryError(misc, ea, e, 2))
+               return PRDBBAD;
+           if (PrintEntryError(misc, na, &te, 4))
+               return PRDBBAD;
+           break;
+       }
        if (map[ni] & MAP_OWNED) {
            fprintf(stderr, "Entry on multiple owner chains\n");
            if (e == 0)
                fprintf(stderr, "walking orphan list");
            else if (PrintEntryError(misc, ea, e, 2))
                return PRDBBAD;
-           if (PrintEntryError(misc, na, &c, 4))
+           if (PrintEntryError(misc, na, &te, 4))
                return PRDBBAD;
            break;
        }
@@ -753,16 +759,16 @@ WalkOwnedChain(char map[],                /* one byte per db entry */
                fprintf(stderr, "walking orphan list");
            else if (PrintEntryError(misc, ea, e, 2))
                return PRDBBAD;
-           if (PrintEntryError(misc, na, &c, 4))
+           if (PrintEntryError(misc, na, &te, 4))
                return PRDBBAD;
            continue;
        }
        if (e) {
-           if (ntohl(c.owner) != eid) {
+           if (ntohl(te.owner) != eid) {
                fprintf(stderr, "Owner id mismatch\n");
                goto abort;
            }
-       } else /* orphan */ if (c.owner) {
+       } else /* orphan */ if (te.owner) {
            fprintf(stderr, "Orphan group owner not zero\n");
            goto abort;
        }
@@ -962,7 +968,8 @@ QuoteName(char *s)
 {
     char *qs;
     if (strpbrk(s, " \t")) {
-       asprintf(&qs, "\"%s\"", s);
+       if (asprintf(&qs, "\"%s\"", s) < 0)
+           qs = "<<-OUT-OF-MEMORY->>";
     } else
        qs = s;
     return qs;
@@ -1253,8 +1260,7 @@ CheckPrDatabase(struct misc_data *misc)   /* info & statistics */
     }
     if (misc->verbose)
        printf("Database has %d entries\n", n);
-    map = (char *)malloc(n);
-    memset(map, 0, n);
+    map = calloc(1, n);
     misc->nEntries = n;
 
     if (misc->verbose) {
@@ -1282,14 +1288,13 @@ CheckPrDatabase(struct misc_data *misc) /* info & statistics */
 #else
     n = ((misc->maxId > misc->maxForId) ? misc->maxId : misc->maxForId);
     misc->idRange = n - misc->minId + 1;
-    misc->idmap = (afs_int32 *) malloc(misc->idRange * sizeof(afs_int32));
+    misc->idmap = calloc(misc->idRange, sizeof(afs_int32));
     if (!misc->idmap) {
        afs_com_err(whoami, 0, "Unable to malloc space for max ids of %d",
                misc->idRange);
        code = -1;
        goto abort;
     }
-    memset(misc->idmap, 0, misc->idRange * sizeof(misc->idmap[0]));
 #endif /* SUPERGROUPS */
 
     if (misc->verbose) {
@@ -1437,7 +1442,7 @@ main(int argc, char *argv[])
 
     setlinebuf(stdout);
 
-    ts = cmd_CreateSyntax(NULL, WorkerBee, NULL, "PRDB check");
+    ts = cmd_CreateSyntax(NULL, WorkerBee, NULL, 0, "PRDB check");
     cmd_AddParm(ts, "-database", CMD_SINGLE, CMD_REQUIRED, "ptdb_file");
     cmd_AddParm(ts, "-uheader", CMD_FLAG, CMD_OPTIONAL,
                "Display UBIK header");
@@ -1480,12 +1485,11 @@ inccount(struct idused **idmapp, int id)
        idmapp = &idmap->idnext;
     }
     if (!idmap) {
-       idmap = (struct idused *)malloc(sizeof *idmap);
+       idmap = calloc(1, sizeof *idmap);
        if (!idmap) {
            perror("idmap");
            exit(1);
        }
-       memset(idmap, 0, sizeof idmap);
        idmap->idstart = id & ~(IDCOUNT - 1);
        idmap->idnext = *idmapp;
        *idmapp = idmap;