ptserver/testpt.c: remove dead code in ListUsedIds
[openafs.git] / src / ptserver / testpt.c
index ab9f408..8ddf429 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * Copyright 2000, International Business Machines Corporation and others.
  * All Rights Reserved.
- * 
+ *
  * This software has been released under the terms of the IBM Public
  * License.  For details, see the LICENSE file in the top-level source
  * directory or online at http://www.openafs.org/dl/license10.html
 #include <afsconfig.h>
 #include <afs/param.h>
 
-RCSID
-    ("$Header$");
+#include <roken.h>
+#include <afs/opr.h>
 
 #include <ctype.h>
-#include <errno.h>
-#include <sys/types.h>
+#include <math.h>
+
 #ifdef AFS_NT40_ENV
-#include <winsock2.h>
 #include <WINNT/afsevent.h>
-#else
-#include <sys/socket.h>
-#include <netdb.h>
-#include <netinet/in.h>
-#endif
-#include <string.h>
-#ifdef HAVE_FCNTL_H
-#include <fcntl.h>
-#endif
-#ifdef HAVE_SYS_STAT_H
-#include <sys/stat.h>
-#endif
-#ifdef HAVE_SYS_TYPES_H
-#include <sys/types.h>
 #endif
+
 #include <rx/rx.h>
 #include <rx/xdr.h>
 #include <afs/rxgen_consts.h>
 #include <afs/cmd.h>
 #include <afs/auth.h>
 #include <afs/cellconfig.h>
-#include "ptclient.h"
-#include "pterror.h"
 #include <afs/afsutil.h>
 #include <afs/com_err.h>
 
+#include "ptclient.h"
+#include "pterror.h"
+#include "ptuser.h"
+#include "ptprototypes.h"
+
 static char *whoami = "testpr";
 static struct afsconf_dir *conf;       /* cell info, set by MyBeforeProc */
 static char conf_dir[100];
 static char lcell[MAXCELLCHARS];
 
 int
-ListUsedIds(struct cmd_syndesc *as, char *arock)
+ListUsedIds(struct cmd_syndesc *as, void *arock)
 {
     afs_int32 code;
     namelist lnames;
@@ -98,8 +87,6 @@ ListUsedIds(struct cmd_syndesc *as, char *arock)
        }
     }
     range = abs(startId - maxId);
-    if (range < 0)
-       range = -range;
     range++;                   /* number that can be printed */
     if (range < number) {
        fprintf(stderr, "Only %d ids to be checked.\n", range);
@@ -109,7 +96,7 @@ ListUsedIds(struct cmd_syndesc *as, char *arock)
     printf("Checking for %d %sused ids starting at %d.\n", number,
           (unused ? "un" : ""), startId);
 #define NUM 100
-    lids.idlist_val = (afs_int32 *) malloc(sizeof(afs_int32) * NUM);
+    lids.idlist_val = malloc(sizeof(afs_int32) * NUM);
     lnames.namelist_len = 0;
     lnames.namelist_val = 0;
     while (number) {
@@ -178,11 +165,11 @@ afs_int32 *groupOwners;           /* ids of owners of groups */
 int nUsers, nGroups, nAdds, nRems, nUDels, nGDels;
 
 int
-IdCmp(afs_int32 *a, afs_int32 *b)
+IdCmp(const void *a, const void *b)
 {
-    if (*a > *b) {
+    if (*(afs_int32 *)a > *(afs_int32 *)b) {
        return 1;
-    } else if (*a == *b) {
+    } else if (*(afs_int32 *)a == *(afs_int32 *)b) {
        return 0;
     } else /* (*a < *b) */ {
        return -1;
@@ -199,7 +186,6 @@ static int
 GetGroupLimit(int N, int x)
 {
     int y;
-    double sqrt();
 
     if ((x >= N) || (x < 0)) {
        printf("GetGroupLimit: input value out of range %d (%d)\n", x, N);
@@ -271,9 +257,8 @@ CreateGroup(int g)
     afs_int32 code;
     char name[16];
     afs_int32 id = 0;
-    afs_int32 flags = PRGRP;
-    afs_int32 owner;
-    char *ownerName;
+    afs_int32 owner = 0;
+    char *ownerName = NULL;
     int ownerType;             /* type of ownership */
     static char *lastGroupPrefix;      /* prefix used for type==2 */
 
@@ -344,7 +329,7 @@ DeleteRandomId(afs_int32 *list)
     k = random();              /* random starting point */
     for (j = 0; j < number; j++) {     /* find an undeleted id */
        m = (k + j) % number;
-       if (id = list[m]) {
+       if ((id = list[m])) {
            code = ubik_PR_Delete(pruclient, 0, id);
            if (code) {
                afs_com_err(whoami, code, "Couldn't delete %di", id);
@@ -404,7 +389,7 @@ RemUser(int u, int g)
 }
 
 int
-TestManyMembers(struct cmd_syndesc *as, char *arock)
+TestManyMembers(struct cmd_syndesc *as, void *arock)
 {
     char *filled;              /* users filled up */
     char *cleaned;             /* users cleaned up */
@@ -502,22 +487,17 @@ TestManyMembers(struct cmd_syndesc *as, char *arock)
 
     srandom(seed);
 
-    users = (afs_int32 *) malloc(number * sizeof(afs_int32));
-    groups = (afs_int32 *) malloc(number * sizeof(afs_int32));
-    filled = (char *)malloc(number * sizeof(char));
-    cleaned = (char *)malloc(number * sizeof(char));
-    population = (char *)malloc(sqr(number) * sizeof(char));
+    users = calloc(number, sizeof(afs_int32));
+    groups = calloc(number, sizeof(afs_int32));
+    filled = calloc(number, sizeof(char));
+    cleaned = calloc(number, sizeof(char));
+    population = calloc(sqr(number), sizeof(char));
 
     nFilled = 0;
-    memset(filled, 0, number);
     nCleaned = 0;
-    memset(cleaned, 0, number);
-    memset(population, 0, sqr(number));
-    memset(users, 0, number * sizeof(afs_int32));
-    memset(groups, 0, number * sizeof(afs_int32));
 
     ownerUser = lastGroup = 0;
-    groupOwners = (afs_int32 *) malloc(number * sizeof(afs_int32));
+    groupOwners = malloc(number * sizeof(afs_int32));
     nUsers = nGroups = nAdds = nRems = nUDels = nGDels = 0;
 
     while ((nFilled < number) || (nCleaned < number)) {
@@ -576,27 +556,29 @@ TestManyMembers(struct cmd_syndesc *as, char *arock)
 
     /* check the membership list of all users for correctness */
     printf("Starting check of memberships\n");
-    glist = (afs_int32 *) malloc(number * sizeof(afs_int32));
+    glist = malloc(number * sizeof(afs_int32));
     for (u = 0; u < number; u++) {
        afs_int32 ui = users[u];
        if (ui) {
            int i;
            int ng;             /* number groups */
-           int (*proc) ();     /* membership listing procedure */
            int over;
+           int (*proc)(struct ubik_client *, afs_int32, afs_int32, prlist *,
+                       afs_int32 *);
            prlist alist;
 
            alist.prlist_len = 0;
            alist.prlist_val = 0;
-           if (random() & 4)
-               proc = PR_ListElements;
-           else
-               proc = PR_GetCPS;
-           code = ubik_Call(proc, pruclient, 0, ui, &alist, &over);
+           if (random() & 4) {
+               proc = ubik_PR_ListElements;
+           } else {
+               proc = ubik_PR_GetCPS;
+           }
+           code = (*proc)(pruclient, 0, ui, &alist, &over);
            if (code) {
                afs_com_err(whoami, code,
                        "getting membership list of (%di) using %s", ui,
-                       ((proc == PR_GetCPS) ? "GetCPR" : "ListElements"));
+                       (proc == ubik_PR_ListElements?"ListElements":"GetCPS"));
                exit(24);
            }
            if (over) {
@@ -607,7 +589,7 @@ TestManyMembers(struct cmd_syndesc *as, char *arock)
                if (population[u * number + i])
                    glist[ng++] = groups[i];
            qsort(glist, ng, sizeof(afs_int32), IdCmp);
-           if (ng != (alist.prlist_len - ((proc == PR_GetCPS) ? 3 : 0))) {
+           if (ng != (alist.prlist_len - ((proc == ubik_PR_GetCPS) ? 3 : 0))) {
                fprintf(stderr,
                        "Membership list for %di of unexpected length: was %d but expected %d\n",
                        ui, alist.prlist_len, ng);
@@ -624,7 +606,7 @@ TestManyMembers(struct cmd_syndesc *as, char *arock)
                }
            if (code)
                exit(21);
-           if (proc == PR_GetCPS) {
+           if (proc == ubik_PR_GetCPS) {
                if ((alist.prlist_val[i /* =ng */ ] != AUTHUSERID) ||
                    (alist.prlist_val[++i] != ANYUSERID)
                    || (alist.prlist_val[++i] != ui)) {
@@ -761,7 +743,7 @@ ka_ConvertBytes(char *ascii,                /* output buffer */
  */
 
 int
-TestPrServ(struct cmd_syndesc *as, char *arock)
+TestPrServ(struct cmd_syndesc *as, void *arock)
 {
     afs_int32 id;
     char name[PR_MAXNAMELEN + 1];
@@ -852,7 +834,7 @@ TestPrServ(struct cmd_syndesc *as, char *arock)
     strcat(name, ":abcdefghijklmnopqrstuvwxyz");
     name[0] = 1;               /* bash the owner name */
     id = 0;
-    code = pr_CreateGroup(name, &id);
+    code = pr_CreateGroup(name, creator, &id);
     if (code != PRNOENT) {     /* owner doesn't exist */
        afs_com_err(whoami, code, "succeeded creating %s", name);
        exit(9);
@@ -907,7 +889,7 @@ static char tmp_cell_file[128] = "";
 static char tmp_noauth_file[128] = "";
 
 static int
-MyAfterProc(struct cmd_syndesc *as, char *arock)
+MyAfterProc(struct cmd_syndesc *as, void *arock)
 {
     if (strlen(tmp_conf_file))
        unlink(tmp_conf_file);
@@ -921,7 +903,7 @@ MyAfterProc(struct cmd_syndesc *as, char *arock)
 }
 
 static int
-MyBeforeProc(struct cmd_syndesc *as, char *arock)
+MyBeforeProc(struct cmd_syndesc *as, void *arock)
 {
     afs_int32 code;
     int i;
@@ -1004,7 +986,7 @@ MyBeforeProc(struct cmd_syndesc *as, char *arock)
        }
 
        strcompose(tmp_conf_file, 128, tmp_conf_dir, "/",
-                  AFSDIR_CELLSERVDB_FILE, NULL);
+                  AFSDIR_CELLSERVDB_FILE, (char *)NULL);
        f = fopen(tmp_conf_file, "w");
        if (f == 0) {
          cantcreate:
@@ -1014,7 +996,7 @@ MyBeforeProc(struct cmd_syndesc *as, char *arock)
        }
        fprintf(f, ">%s\n", lcell);
        for (i = 0; i < cellinfo.numServers; i++) {
-           register unsigned char *tp =
+           unsigned char *tp =
                (unsigned char *)&cellinfo.hostAddr[i].sin_addr;
            fprintf(f, "%d.%d.%d.%d\t#%s\n", tp[0], tp[1], tp[2], tp[3],
                    cellinfo.hostName[i]);
@@ -1027,7 +1009,7 @@ MyBeforeProc(struct cmd_syndesc *as, char *arock)
        }
 
        strcompose(tmp_cell_file, 128, tmp_conf_dir, "/",
-                  AFSDIR_THISCELL_FILE, NULL);
+                  AFSDIR_THISCELL_FILE, (char *)NULL);
        f = fopen(tmp_cell_file, "w");
        if (f == 0)
            goto cantcreate;
@@ -1036,7 +1018,7 @@ MyBeforeProc(struct cmd_syndesc *as, char *arock)
            goto cantclose;
 
        strcompose(tmp_noauth_file, 128, tmp_conf_dir, "/",
-                  AFSDIR_NOAUTH_FILE, NULL);
+                  AFSDIR_NOAUTH_FILE, (char *)NULL);
        if (noAuth) {
            code = creat(tmp_noauth_file, 0777);
            if (code && (errno != EEXIST))
@@ -1056,7 +1038,7 @@ MyBeforeProc(struct cmd_syndesc *as, char *arock)
 }
 
 static void
-add_std_args(register struct cmd_syndesc *ts)
+add_std_args(struct cmd_syndesc *ts)
 {
     cmd_Seek(ts, 12);
     cmd_AddParm(ts, "-confdir", CMD_SINGLE, CMD_OPTIONAL,
@@ -1067,7 +1049,7 @@ add_std_args(register struct cmd_syndesc *ts)
 }
 
 int
-osi_audit()
+osi_audit(void)
 {
 /* OK, this REALLY sucks bigtime, but I can't tell who is calling
  * afsconf_CheckAuth easily, and only *SERVERS* should be calling osi_audit
@@ -1078,7 +1060,7 @@ osi_audit()
 
 #include "AFS_component_version_number.c"
 
-int 
+int
 main(int argc, char *argv[])
 {
     afs_int32 code;
@@ -1103,7 +1085,7 @@ main(int argc, char *argv[])
     cmd_SetBeforeProc(MyBeforeProc, NULL);
     cmd_SetAfterProc(MyAfterProc, NULL);
 
-    ts = cmd_CreateSyntax("usedIds", ListUsedIds, 0,
+    ts = cmd_CreateSyntax("usedIds", ListUsedIds, NULL,
                          "Find used (or unused) user (or group) ids");
     cmd_AddParm(ts, "-startId", CMD_SINGLE, CMD_OPTIONAL,
                "id to start checking");
@@ -1112,10 +1094,10 @@ main(int argc, char *argv[])
     cmd_AddParm(ts, "-unused", CMD_FLAG, CMD_OPTIONAL, "print unused ids");
     add_std_args(ts);
 
-    ts = cmd_CreateSyntax("initcmd", TestPrServ, 0, "test the prserver");
+    ts = cmd_CreateSyntax("initcmd", TestPrServ, NULL, "test the prserver");
     add_std_args(ts);
 
-    ts = cmd_CreateSyntax("testmanymembers", TestManyMembers, 0,
+    ts = cmd_CreateSyntax("testmanymembers", TestManyMembers, NULL,
                          "test creating users and groups w/ many members");
     cmd_AddParm(ts, "-number", CMD_SINGLE, 0,
                "number of users/groups to create");