2 * Copyright 2000, International Business Machines Corporation and others.
5 * This software has been released under the terms of the IBM Public
6 * License. For details, see the LICENSE file in the top-level source
7 * directory or online at http://www.openafs.org/dl/license10.html
12 #include <afs/param.h>
15 #include <sys/types.h>
18 #include <WINNT/afsevent.h>
20 #include <sys/socket.h>
22 #include <netinet/in.h>
26 #include <afs/rxgen_consts.h>
29 #include <afs/cellconfig.h>
32 #include <afs/afsutil.h>
34 extern char *ucstring();
35 extern char *lcstring();
37 static char *whoami = "testpr";
38 static struct afsconf_dir *conf; /* cell info, set by MyBeforeProc */
39 static char conf_dir[100];
40 static char lcell[MAXCELLCHARS];
42 ListUsedIds (as, arock)
43 struct cmd_syndesc *as;
49 int group = 0; /* check groups */
50 int unused = 0; /* print unused */
51 int number = 100; /* check 100 ids */
52 afs_int32 startId = 1;
56 if (as->parms[0].items) startId = atoi (as->parms[0].items->data);
57 if (as->parms[1].items) number = atoi (as->parms[1].items->data);
58 if (as->parms[2].items) unused = 1;
60 code = pr_Initialize(1, conf_dir,(char *)0);
62 com_err (whoami, code, "initializing pruser");
67 code = pr_ListMaxGroupId (&maxId);
70 com_err (whoami, code, "getting maximum id");
73 if (startId < maxId) {
74 fprintf (stderr, "Max group id is only %d.\n", maxId);
78 code = pr_ListMaxUserId (&maxId);
79 if (code) goto bad_max;
80 if (startId > maxId) {
81 fprintf (stderr, "Max user id is only %d.\n", maxId);
85 range = abs(startId - maxId);
86 if (range < 0) range = -range;
87 range++; /* number that can be printed */
89 fprintf (stderr, "Only %d ids to be checked.\n", range);
93 printf ("Checking for %d %sused ids starting at %d.\n",
94 number, (unused ? "un" : ""), startId);
96 lids.idlist_val = (afs_int32 *)malloc(sizeof(afs_int32)*NUM);
97 lnames.namelist_len = 0;
98 lnames.namelist_val = 0;
100 if (number < NUM) i = number; else i = NUM;
101 for (j=0; j<i; j++) {
102 lids.idlist_val[j] = startId;
103 if (group) startId--; else startId++;
106 code = pr_IdToName (&lids, &lnames);
108 com_err (whoami, code, "converting id to name");
111 for (j=0;j<lnames.namelist_len;j++) {
112 if (lids.idlist_val[j] == atoi(lnames.namelist_val[j])) {
113 if (unused) printf ("%s is free\n", lnames.namelist_val[j]);
115 if (!unused) printf ("%s is id %d\n", lnames.namelist_val[j],
121 if (lids.idlist_val) free (lids.idlist_val);
122 if (lnames.namelist_val) free (lnames.namelist_val);
126 /* TestManyMembers - called with a number N. Try creating N users and N groups
127 * and put all the users on one of the groups and one of the users on all the
128 * groups. Also put many users on many groups.
130 * To keep track of this create an NxN matrix of membership and fill it in with
131 * a function that looks like a quarter of a circle. That makes the first
132 * group contain every user and the first user be a member of every group. */
135 char callerName[PR_MAXNAMELEN];
137 afs_int32 lastGroup; /* id of last group created */
138 afs_int32 ownerUser; /* first created user */
139 char ownerUserName[PR_MAXNAMELEN]; /* " " " name */
140 int steepDropOff; /* precentage decreate in GroupLimit */
141 char *createPrefix; /* prefix for naming users&groups */
142 extern struct ubik_client *pruclient; /* initialized by pr_Initialize */
144 /* These variables form the state if this test */
145 int number; /* max number of members */
146 char *population; /* matrix of memberships */
147 afs_int32 *users; /* ids of users */
148 afs_int32 *groups; /* ids of groups */
149 afs_int32 *groupOwners; /* ids of owners of groups */
152 int nUsers, nGroups, nAdds, nRems, nUDels, nGDels;
158 if (*a > *b) return 1;
159 if (*a == *b) return 0;
160 if (*a < *b) return -1;
169 static int GetGroupLimit (N, x)
176 if ((x >= N) || (x < 0)) {
177 printf ("GetGroupLimit: input value out of range %d (%d)\n", x, N);
180 if (steepDropOff) { /* Use exponential decrease */
183 for (i=0; i<x; i++) {
184 y = (y*steepDropOff)/100; /* parameter is a percentage */
186 y = 1; /* with a floor of 1 */
191 else { /* Use a circle's third quadrant */
192 y = sqr(N-1) - sqr(N-1-x);
193 y = (int) (sqrt ((double)y) + 0.5); /* round off */
196 if ((y > N) || (y < 1)) {
197 printf ("filling value out of range: %d (%d) => %d\n", x, N, y);
210 sprintf (name, "%s%d", createPrefix, u);
212 code = pr_CreateUser (name, &id);
214 if (code == PREXIST) {
215 code = pr_Delete (name);
218 code = pr_CreateUser (name, &id);
220 if (verbose) printf ("RE-");
225 com_err (whoami, code, "couldn't create %s", name);
229 if (verbose) printf ("Creating user %s (%di)\n", name, id);
233 if (ownerUser == 0) {
235 strcpy (ownerUserName, name);
246 afs_int32 flags = PRGRP;
249 int ownerType; /* type of ownership */
250 static char *lastGroupPrefix; /* prefix used for type==2 */
252 /* At least 50 groups should be owned by another group to test long owner
253 * chains during deletion. Also let's create some long owners of owners
255 ownerType = random() % 3;
257 if (!ownerUser) ownerType = 0;
258 if (!lastGroup) ownerType = 0;
262 ownerName = callerName;
266 ownerName = ownerUserName;
270 ownerName = lastGroupPrefix;
274 sprintf (name, "%s:%s%d", ownerName, createPrefix, g);
275 code = ubik_Call (PR_NewEntry, pruclient, 0, name, PRGRP, owner, &id);
277 if (code == PREXIST) {
278 code = pr_Delete (name);
282 (PR_NewEntry, pruclient, 0, name, PRGRP, owner, &id);
284 if (verbose) printf ("RE-");
289 com_err (whoami, code, "couldn't create %s w/ owner=%d", name, owner);
293 if (verbose) printf ("Creating group %s (%di)\n", name, id);
295 groupOwners[g] = owner;
297 if (!lastGroup || (ownerType == 2)) {
299 lastGroupPrefix = ownerName;
304 int DeleteRandomId (list)
312 k = random(); /* random starting point */
313 for (j=0; j<number; j++) { /* find an undeleted id */
316 code = ubik_Call (PR_Delete, pruclient, 0, id);
318 com_err (whoami, code, "Couldn't delete %di", id);
322 if (list == users) nUDels++;
327 return -1; /* none left */
336 if (users[u] == 0) /* create if necessary */
338 if (groups[g] == 0) /* create group if necessary */
342 code = ubik_Call(PR_AddToGroup, pruclient, 0, ui, gi);
344 com_err (whoami, code, "couldn't add %d to %d", ui, gi);
347 if (verbose) printf ("Adding user (%di) to group (%di)\n", ui, gi);
348 population[u*number+g]++;
361 code = ubik_Call(PR_RemoveFromGroup, pruclient, 0, ui, gi);
363 com_err (whoami, code, "couldn't remove %d from %d", ui, gi);
366 if (verbose) printf ("Removing user (%di) from group (%di)\n", ui, gi);
367 population[u*number+g]--;
372 TestManyMembers (as, arock)
373 struct cmd_syndesc *as;
376 char *filled; /* users filled up */
377 char *cleaned; /* users cleaned up */
379 int nFilled, nCleaned;
381 int seed; /* random number generator seed */
383 afs_int32 *glist; /* membership list */
387 code = pr_Initialize(1, conf_dir,(char *)0);
389 com_err (whoami, code, "initializing pruser");
392 /* get name of person running command */
393 { struct ktc_principal afs, user;
394 struct ktc_token token;
396 strcpy (afs.name, "afs");
397 strcpy (afs.instance, "");
398 code = afsconf_GetLocalCell (conf, afs.cell, sizeof(afs.cell));
400 code = ktc_GetToken (&afs, &token, sizeof(token), &user);
402 com_err (whoami, code, "getting afs tokens");
405 if (strlen(user.instance) > 0) {
406 fprintf (stderr, "can't handle non-null instance %s.%s\n", user.name, user.cell);
409 if (strncmp (user.name, "AFS ID ", 7) == 0) {
410 callerId = atoi (user.name+7);
411 code = pr_SIdToName (callerId, callerName);
413 com_err (whoami, code, "call get name for id %d", callerId);
417 strcpy (callerName, user.name);
418 code = pr_SNameToId (callerName, &callerId);
419 if ((code == 0) && (callerId == ANONYMOUSID)) code = PRNOENT;
421 #if 0 /* don't create user */
422 if (code == PRNOENT) {
424 code = pr_CreateUser (callerName, &callerId);
426 com_err (whoami, code, "can't create caller %s", callerName);
429 printf ("Creating caller %s (%di)\n", callerName, callerId);
434 com_err (whoami, code, "can't find caller %s", callerName);
437 else printf ("Assuming caller is %s (%di)\n", callerName, callerId);
440 /* Parse arguments */
441 if (as->parms[0].items) number = atoi (as->parms[0].items->data);
442 if (as->parms[1].items) {
443 steepDropOff = atoi (as->parms[1].items->data);
444 if ((steepDropOff < 0) || (steepDropOff > 100)) {
445 fprintf (stderr, "Illegal value for dropoff: %d, must be between 0 and 100, inclusive.\n", steepDropOff);
448 } else steepDropOff = 0; /* use quadratic dropoff */
449 if (as->parms[2].items) createPrefix = as->parms[2].items->data;
450 else createPrefix = "u";
451 if (as->parms[3].items) verbose = 1;
453 if (as->parms[4].items) seed = atoi(as->parms[4].items->data);
458 users = (afs_int32 *) malloc (number*sizeof(afs_int32));
459 groups = (afs_int32 *) malloc (number*sizeof(afs_int32));
460 filled = (char *) malloc (number*sizeof(char));
461 cleaned = (char *) malloc (number*sizeof(char));
462 population = (char *)malloc (sqr(number)*sizeof(char));
465 bzero (filled, number);
467 bzero (cleaned, number);
468 bzero (population, sqr(number));
469 bzero (users, number*sizeof(afs_int32));
470 bzero (groups, number*sizeof(afs_int32));
472 ownerUser = lastGroup = 0;
473 groupOwners = (afs_int32 *) malloc (number*sizeof(afs_int32));
474 nUsers = nGroups = nAdds = nRems = nUDels = nGDels = 0;
476 while ((nFilled < number) || (nCleaned < number)) {
477 /* pick a user at random, using */
478 u = random() % number;
480 n = GetGroupLimit (number, u); /* get group limit for that user */
481 g = random() % (n+1); /* pick a random group */
482 if (g == n) { /* in a few cases create any user */
483 n = number; /* in the whole range */
486 for (i=0; i<n; i++) { /* rotate until unused one found */
488 if (!population[u*number+j]) {
489 /* add this user/group membership */
500 if (filled[u]) { /* only clean above GroupLimit */
501 base = GetGroupLimit (number, u);
503 if (n == 0) goto iscleaned;
508 n = number; /* pick a group from the whole range */
509 g = random() % 2*n; /* at random for removal */
510 if (g >= n) goto remed; /* but half the time do nothing */
512 for (i=0; i<n; i++) { /* rotate until used one found */
513 j = (g+i) % n + base;
514 if (population[u*number+j]) {
515 /* remove this user/group membership */
520 if (filled[u]) { /* track finished ones */
529 /* check the membership list of all users for correctness */
530 printf ("Starting check of memberships\n");
531 glist = (afs_int32 *)malloc (number*sizeof(afs_int32));
532 for (u=0; u<number; u++) {
533 afs_int32 ui = users[u];
536 int ng; /* number groups */
537 int (*proc)(); /* membership listing procedure */
541 alist.prlist_len = 0;
542 alist.prlist_val = 0;
543 if (random() & 4) proc = PR_ListElements;
544 else proc = PR_GetCPS;
545 code = ubik_Call (proc, pruclient, 0, ui, &alist, &over);
547 com_err (whoami, code,
548 "getting membership list of (%di) using %s", ui,
549 ((proc == PR_GetCPS) ? "GetCPR" : "ListElements"));
554 "membership list for id %di too long\n", ui);
557 for (i=0; i<number; i++)
558 if (population[u*number+i])
559 glist[ng++] = groups[i];
560 qsort (glist, ng, sizeof(afs_int32), IdCmp);
561 if (ng != (alist.prlist_len - ((proc == PR_GetCPS) ? 3 : 0))) {
562 fprintf (stderr, "Membership list for %di of unexpected length: was %d but expected %d\n", ui, alist.prlist_len, ng);
565 /* all the extra entries for the CPS should be at the end. */
568 if (alist.prlist_val[i] != glist[i]) {
569 fprintf (stderr, "membership for %di not correct: was %di but expected %di\n", ui, alist.prlist_val[i], glist[i]);
573 if (proc == PR_GetCPS) {
574 if ((alist.prlist_val[i /* =ng */] != AUTHUSERID) ||
575 (alist.prlist_val[++i] != ANYUSERID) ||
576 (alist.prlist_val[++i] != ui)) {
577 fprintf (stderr, "CPS doesn't have extra entries\n");
581 if (alist.prlist_val) free(alist.prlist_val);
583 /* User 0 is a member of all groups all of which should also be on
584 * the owner list of the caller or the ownerUser, although there
585 * may also be others. Check this. */
589 prlist lastGroupList;
593 fprintf (stderr, "User 0 not a member of all groups\n");
597 #define GETOWNED(xlist,xid) \
598 (xlist).prlist_val = 0; (xlist).prlist_len = 0; \
599 code = ubik_Call (PR_ListOwned, pruclient, 0, (xid), &(xlist), &over); \
601 com_err (whoami, code, "getting owner list of (%di)", (xid)); \
604 { fprintf (stderr, "membership of id %di too long\n", (xid)); }
606 GETOWNED (callerList, callerId);
607 GETOWNED (ownerList, ownerUser);
609 /* look for every entry in glist, in all the owner lists */
610 for (i=j=k=l=0; i<number; i++) {
611 while ((j < callerList.prlist_len) &&
612 (callerList.prlist_val[j] < glist[i])) j++;
613 while ((k < ownerList.prlist_len) &&
614 (ownerList.prlist_val[k] < glist[i])) k++;
615 #define PRLISTCMP(l,i) \
616 (((l).prlist_len == 0) || (glist[i] != (l).prlist_val[(i)]))
617 if (PRLISTCMP(callerList,j) &&
618 PRLISTCMP(ownerList,k)) {
619 for (l=0; l<number; l++) {
620 if (groups[l] == glist[i]) {
621 if ((groupOwners[l] != callerId) &&
622 (groupOwners[l] != ownerUser)) {
623 GETOWNED (lastGroupList, groupOwners[l]);
624 if ((lastGroupList.prlist_len != 1) ||
625 (lastGroupList.prlist_val[0] != glist[i])) {
626 fprintf (stderr, "Group (%di) not on any owner list\n", glist[i]);
633 fprintf (stderr, "unexpected group %di\n", glist[i]);
637 if (callerList.prlist_val) free(callerList.prlist_val);
638 if (ownerList.prlist_val) free(ownerList.prlist_val);
639 if (lastGroupList.prlist_val) free(lastGroupList.prlist_val);
644 /* cleanup by deleting all the users and groups */
645 printf ("Starting deletion of users and groups\n");
646 for (i=0; i<number; i++) {
647 DeleteRandomId (users);
648 DeleteRandomId (groups);
651 printf ("Created/deleted %d/%d users and %d/%d groups; added %d and removed %d.\n",
652 nUsers, nUDels, nGroups, nGDels, nAdds, nRems);
656 /* from ka_ConvertBytes included here to avoid circularity */
657 /* Converts a byte string to ascii. Return the number of unconverted bytes. */
659 static int ka_ConvertBytes (ascii, alen, bs, bl)
660 char *ascii; /* output buffer */
661 int alen; /* buffer length */
662 char bs[]; /* byte string */
663 int bl; /* number of bytes */
667 alen--; /* make room for termination */
668 for (i=0; i < bl; i++) {
670 if (alen <= 0) return bl-i;
671 if (isalnum(c) || ispunct(c)) (*ascii++ = c), alen--;
673 if (alen <= 3) return bl-i;
675 *ascii++ = (c>>6) + '0';
676 *ascii++ = (c>>3 & 7) + '0';
677 *ascii++ = (c&7) + '0';
681 *ascii = 0; /* terminate string */
684 /* This runs various tests on the server. It creates, then deletes, a bunch of
685 * users and groups, so it would be safest to run it on a test database.
687 * These are the things I check for:
688 * User names longer than PR_MAXNAMELEN - strlen(cellname).
689 * Group names longer than PR_MAXNAMELEN.
690 * User names containing all legal 8-bit ascii characters. This excludes
691 * only ':', '@', and '\n'.
692 * Group names as above, but at least one colon is required, and the owner
696 TestPrServ (as, arock)
697 struct cmd_syndesc *as;
701 char name[PR_MAXNAMELEN+1];
702 char creator[PR_MAXNAMELEN]; /* our name */
703 struct prcheckentry ent;
706 int maxLen = PR_MAXNAMELEN-1 - strlen(lcell) - 1;
708 code = pr_Initialize(1, conf_dir,(char *)0);
710 com_err (whoami, code, "initializing pruser");
714 for (i=0; i<maxLen; i++) name[i] = 'a';
715 name[i]='a'; /* too long a name... */
718 code = pr_CreateUser (name, &id);
719 if ((code != RXGEN_CC_MARSHAL) && (code != PRBADNAM)) {
720 com_err (whoami, code, "succeeded creating %s", name);
725 code = pr_CreateUser (name, &id);
726 if (code == PREXIST) {
727 fprintf (stderr, "group already exists, skipping\n");
728 pr_SNameToId (name, &id);
730 com_err (whoami, code, "failed creating %s", name);
733 if ((code = pr_ListEntry (id, &ent)) ||
734 (code = pr_SIdToName (ent.creator, creator))) {
735 com_err (whoami, code, "getting creator's name");
738 code = pr_DeleteByID (id);
740 com_err (whoami, code, "deleting %s", name);
743 /* now make sure the illegal chars are detected */
744 { char *illegalChars;
745 for (illegalChars = "@:\n"; *illegalChars; illegalChars++) {
746 name[10] = *illegalChars;
748 code = pr_CreateUser (name, &id);
749 if (code != PRBADNAM) {
750 com_err (whoami, code, "succeeded creating %s", name);
756 for (i=1; i <= 255;) { /* for all 8-bit ascii... */
757 j=0; /* build a new name */
758 while ((j<maxLen) && (i<=255)) {
759 if (!((i == ':') || (i == '@') || (i == '\n')))
763 name[j]=0; /* terminate string */
765 code = pr_CreateUser (name, &id);
766 if (code == PREXIST) {
767 fprintf (stderr, "user already exists, skipping\n");
768 pr_SNameToId (name, &id);
771 ka_ConvertBytes (ascii, sizeof(ascii), name, strlen(name));
772 com_err (whoami, code, "failed creating %s", ascii);
775 code = pr_DeleteByID (id);
777 com_err (whoami, code, "deleting %s", name);
782 /* now check group names */
783 strcpy (name, creator);
784 strcat (name, ":abcdefghijklmnopqrstuvwxyz");
785 name[0] = 1; /* bash the owner name */
787 code = pr_CreateGroup (name, &id);
788 if (code != PRNOENT) { /* owner doesn't exist */
789 com_err (whoami, code, "succeeded creating %s", name);
792 name[0] = creator[0]; /* fix owner */
793 /* Make sure the illegal chars are detected */
794 { char *illegalChars;
795 for (illegalChars = ":@\n"; *illegalChars; illegalChars++) {
796 name[strlen(creator)+10] = *illegalChars;
798 code = pr_CreateGroup (name, creator, &id);
799 if (code != PRBADNAM) {
800 com_err (whoami, code, "succeeded creating %s", name);
805 for (i=1; i <= 255;) { /* for all 8-bit ascii... */
806 j=strlen(creator)+1; /* build a new name */
807 while ((j<PR_MAXNAMELEN-1) && (i<=255)) {
808 if (!((i == ':') || (i == '@') || (i == '\n')))
812 name[j]=0; /* terminate string */
814 code = pr_CreateGroup (name, creator, &id);
815 if (code == PREXIST) {
816 fprintf (stderr, "group already exists, skipping\n");
817 pr_SNameToId (name, &id);
820 ka_ConvertBytes (ascii, sizeof(ascii), name, strlen(name));
821 com_err (whoami, code, "failed creating %s", ascii);
824 code = pr_DeleteByID (id);
826 com_err (whoami, code, "deleting %s", name);
835 static char tmp_conf_dir[128] = "";
836 static char tmp_conf_file[128] = "";
837 static char tmp_cell_file[128] = "";
838 static char tmp_noauth_file[128] = "";
840 static afs_int32 MyAfterProc (as, arock)
841 struct cmd_syndesc *as;
844 if (strlen (tmp_conf_file)) unlink (tmp_conf_file);
845 if (strlen (tmp_cell_file)) unlink (tmp_cell_file);
846 if (strlen (tmp_noauth_file)) unlink (tmp_noauth_file);
847 if (strlen (tmp_conf_dir)) rmdir (tmp_conf_dir);
851 static afs_int32 MyBeforeProc (as, arock)
852 struct cmd_syndesc *as;
858 struct cmd_item *serverList = 0;
859 struct afsconf_dir *local_conf = 0; /* so we can default stuff nicely */
860 struct afsconf_cell cellinfo;
862 if (as->parms[12].items) { /* if conf dir specified */
863 cdir = as->parms[12].items->data;
864 if (as->parms[13].items || as->parms[14].items || as->parms[15].items) {
865 printf ("Can't specify conf dir and other cell parameters\n");
866 return AFSCONF_SYNTAX;
870 /* if we need to default cell name or cell servers, get local conf info */
872 if (!(local_conf = afsconf_Open (AFSDIR_CLIENT_ETC_DIRPATH)) &&
873 !(local_conf = afsconf_Open (AFSDIR_SERVER_ETC_DIRPATH))){
874 printf("** Can't local configuration!\n");
875 return AFSCONF_NOCELL;
878 if (as->parms[13].items) { /* if cell name specified */
879 lcstring (lcell, as->parms[13].items->data, sizeof(lcell));
880 code = afsconf_GetCellInfo (local_conf, lcell, 0, &cellinfo);
881 if (code == 0) strncpy (lcell, cellinfo.name, sizeof(lcell));
883 code = afsconf_GetLocalCell (local_conf, lcell, sizeof(lcell));
884 if (code) return code;
887 if (as->parms[14].items) { /* noauth flag */
891 if (as->parms[15].items) { /* servers list */
892 serverList = as->parms[15].items;
893 for (i=0; serverList; i++, serverList = serverList->next) {
895 if (i >= MAXHOSTSPERCELL) return AFSCONF_FULL;
896 strncpy (cellinfo.hostName[i], serverList->data, MAXHOSTCHARS);
897 th = gethostbyname(cellinfo.hostName[i]);
898 if (!th) return UBADHOST;
899 bcopy(th->h_addr, &cellinfo.hostAddr[i].sin_addr, sizeof(afs_int32));
900 cellinfo.hostAddr[i].sin_family = AF_INET;
901 cellinfo.hostAddr[i].sin_port = 0;
903 cellinfo.numServers = i;
904 strcpy (cellinfo.name, lcell);
906 code = afsconf_GetCellInfo (local_conf, lcell, 0, &cellinfo);
907 if (code) return code;
910 if (local_conf) afsconf_Close (local_conf);
915 sprintf (tmp_conf_dir, "%s/afsconf.%lu", gettmpdir(), (unsigned long) getpid());
916 code = mkdir (tmp_conf_dir, 0777);
917 if ((code < 0) && (errno != EEXIST)) {
918 com_err (whoami, errno, "can't create temporary afsconf dir: %s", cdir);
922 strcompose(tmp_conf_file, 128, tmp_conf_dir, "/", AFSDIR_CELLSERVDB_FILE, NULL);
923 f = fopen (tmp_conf_file, "w");
926 com_err (whoami, errno, "can't create conf file %s", tmp_conf_file);
929 fprintf (f, ">%s\n", lcell);
930 for (i=0; i<cellinfo.numServers; i++) {
931 register unsigned char *tp = (unsigned char *)&cellinfo.hostAddr[i].sin_addr;
932 fprintf (f, "%d.%d.%d.%d\t#%s\n",
933 tp[0], tp[1], tp[2], tp[3], cellinfo.hostName[i]);
935 if (fclose (f) == EOF) {
937 com_err (whoami, errno, "can't write to conf file %s", tmp_conf_file);
941 strcompose(tmp_cell_file, 128, tmp_conf_dir, "/", AFSDIR_THISCELL_FILE, NULL);
942 f = fopen (tmp_cell_file, "w");
943 if (f == 0) goto cantcreate;
944 fprintf (f, "%s", lcell);
945 if (fclose(f) == EOF) goto cantclose;
947 strcompose(tmp_noauth_file, 128, tmp_conf_dir, "/", AFSDIR_NOAUTH_FILE, NULL);
949 code = creat (tmp_noauth_file, 0777);
950 if (code && (errno != EEXIST)) return errno;
951 } else { /* make sure file doesn't exist */
952 code = unlink (tmp_noauth_file);
953 if (code && (errno != ENOENT)) return errno;
957 strncpy (conf_dir, tmp_conf_dir, sizeof(conf_dir));
958 conf = afsconf_Open (conf_dir);
959 if (conf == 0) return AFSCONF_NOTFOUND;
963 static void add_std_args (ts)
964 register struct cmd_syndesc *ts;
967 cmd_AddParm(ts, "-confdir", CMD_SINGLE, CMD_OPTIONAL, "AFS Conf dir pathname");
968 cmd_AddParm(ts, "-cell", CMD_SINGLE, CMD_OPTIONAL, "Cell name");
969 cmd_AddParm(ts, "-noauth", CMD_FLAG, CMD_OPTIONAL, "Don't authenticate");
970 cmd_AddParm(ts, "-servers", CMD_LIST, CMD_OPTIONAL, "Server config");
975 /* OK, this REALLY sucks bigtime, but I can't tell who is calling
976 * afsconf_CheckAuth easily, and only *SERVERS* should be calling osi_audit
977 * anyway. It's gonna give somebody fits to debug, I know, I know.
982 #include "AFS_component_version_number.c"
988 struct cmd_syndesc *ts; /* ptr to parsed command line syntax */
991 initialize_cmd_error_table();
992 initialize_acfg_error_table();
993 initialize_ktc_error_table();
994 initialize_u_error_table();
995 initialize_pt_error_table();
996 initialize_rxk_error_table();
999 /* initialize winsock */
1000 if (afs_winsockInit()<0) {
1001 fprintf(stderr, "%s: couldn't initialize winsock. \n", whoami);
1006 cmd_SetBeforeProc(MyBeforeProc, (char *)0);
1007 cmd_SetAfterProc(MyAfterProc, (char *)0);
1009 ts = cmd_CreateSyntax("usedIds", ListUsedIds, 0, "Find used (or unused) user (or group) ids");
1010 cmd_AddParm (ts, "-startId", CMD_SINGLE, CMD_OPTIONAL, "id to start checking");
1011 cmd_AddParm (ts, "-number", CMD_SINGLE, CMD_OPTIONAL, "number of ids to check");
1012 cmd_AddParm (ts, "-unused", CMD_FLAG, CMD_OPTIONAL, "print unused ids");
1015 ts = cmd_CreateSyntax("initcmd", TestPrServ, 0, "test the prserver");
1018 ts = cmd_CreateSyntax("testmanymembers", TestManyMembers, 0, "test creating users and groups w/ many members");
1019 cmd_AddParm (ts, "-number", CMD_SINGLE, 0, "number of users/groups to create");
1020 cmd_AddParm (ts, "-dropoff", CMD_SINGLE, CMD_OPTIONAL, "precentage for exponential dropoff");
1021 cmd_AddParm (ts, "-prefix", CMD_SINGLE, CMD_OPTIONAL, "naming prefix");
1022 cmd_AddParm (ts, "-long", CMD_FLAG, CMD_OPTIONAL, "show progress");
1023 cmd_AddParm (ts, "-seed", CMD_SINGLE, CMD_OPTIONAL, "random number seed");
1025 cmd_CreateAlias(ts,"mm");
1028 code = cmd_Dispatch(argc, argv);
1029 if (code) com_err (whoami, code, "calling cmd_Dispatch");