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
10 #include <afsconfig.h>
11 #include <afs/param.h>
17 #include <sys/types.h>
20 #include <WINNT/afsevent.h>
22 #include <sys/socket.h>
24 #include <netinet/in.h>
28 #include <afs/rxgen_consts.h>
31 #include <afs/cellconfig.h>
34 #include <afs/afsutil.h>
36 extern char *ucstring();
37 extern char *lcstring();
39 static char *whoami = "testpr";
40 static struct afsconf_dir *conf; /* cell info, set by MyBeforeProc */
41 static char conf_dir[100];
42 static char lcell[MAXCELLCHARS];
44 ListUsedIds (as, arock)
45 struct cmd_syndesc *as;
51 int group = 0; /* check groups */
52 int unused = 0; /* print unused */
53 int number = 100; /* check 100 ids */
54 afs_int32 startId = 1;
58 if (as->parms[0].items) startId = atoi (as->parms[0].items->data);
59 if (as->parms[1].items) number = atoi (as->parms[1].items->data);
60 if (as->parms[2].items) unused = 1;
62 code = pr_Initialize(1, conf_dir,(char *)0);
64 com_err (whoami, code, "initializing pruser");
69 code = pr_ListMaxGroupId (&maxId);
72 com_err (whoami, code, "getting maximum id");
75 if (startId < maxId) {
76 fprintf (stderr, "Max group id is only %d.\n", maxId);
80 code = pr_ListMaxUserId (&maxId);
81 if (code) goto bad_max;
82 if (startId > maxId) {
83 fprintf (stderr, "Max user id is only %d.\n", maxId);
87 range = abs(startId - maxId);
88 if (range < 0) range = -range;
89 range++; /* number that can be printed */
91 fprintf (stderr, "Only %d ids to be checked.\n", range);
95 printf ("Checking for %d %sused ids starting at %d.\n",
96 number, (unused ? "un" : ""), startId);
98 lids.idlist_val = (afs_int32 *)malloc(sizeof(afs_int32)*NUM);
99 lnames.namelist_len = 0;
100 lnames.namelist_val = 0;
102 if (number < NUM) i = number; else i = NUM;
103 for (j=0; j<i; j++) {
104 lids.idlist_val[j] = startId;
105 if (group) startId--; else startId++;
108 code = pr_IdToName (&lids, &lnames);
110 com_err (whoami, code, "converting id to name");
113 for (j=0;j<lnames.namelist_len;j++) {
114 if (lids.idlist_val[j] == atoi(lnames.namelist_val[j])) {
115 if (unused) printf ("%s is free\n", lnames.namelist_val[j]);
117 if (!unused) printf ("%s is id %d\n", lnames.namelist_val[j],
123 if (lids.idlist_val) free (lids.idlist_val);
124 if (lnames.namelist_val) free (lnames.namelist_val);
128 /* TestManyMembers - called with a number N. Try creating N users and N groups
129 * and put all the users on one of the groups and one of the users on all the
130 * groups. Also put many users on many groups.
132 * To keep track of this create an NxN matrix of membership and fill it in with
133 * a function that looks like a quarter of a circle. That makes the first
134 * group contain every user and the first user be a member of every group. */
137 char callerName[PR_MAXNAMELEN];
139 afs_int32 lastGroup; /* id of last group created */
140 afs_int32 ownerUser; /* first created user */
141 char ownerUserName[PR_MAXNAMELEN]; /* " " " name */
142 int steepDropOff; /* precentage decreate in GroupLimit */
143 char *createPrefix; /* prefix for naming users&groups */
144 extern struct ubik_client *pruclient; /* initialized by pr_Initialize */
146 /* These variables form the state if this test */
147 int number; /* max number of members */
148 char *population; /* matrix of memberships */
149 afs_int32 *users; /* ids of users */
150 afs_int32 *groups; /* ids of groups */
151 afs_int32 *groupOwners; /* ids of owners of groups */
154 int nUsers, nGroups, nAdds, nRems, nUDels, nGDels;
160 if (*a > *b) return 1;
161 if (*a == *b) return 0;
162 if (*a < *b) return -1;
171 static int GetGroupLimit (N, x)
178 if ((x >= N) || (x < 0)) {
179 printf ("GetGroupLimit: input value out of range %d (%d)\n", x, N);
182 if (steepDropOff) { /* Use exponential decrease */
185 for (i=0; i<x; i++) {
186 y = (y*steepDropOff)/100; /* parameter is a percentage */
188 y = 1; /* with a floor of 1 */
193 else { /* Use a circle's third quadrant */
194 y = sqr(N-1) - sqr(N-1-x);
195 y = (int) (sqrt ((double)y) + 0.5); /* round off */
198 if ((y > N) || (y < 1)) {
199 printf ("filling value out of range: %d (%d) => %d\n", x, N, y);
212 sprintf (name, "%s%d", createPrefix, u);
214 code = pr_CreateUser (name, &id);
216 if (code == PREXIST) {
217 code = pr_Delete (name);
220 code = pr_CreateUser (name, &id);
222 if (verbose) printf ("RE-");
227 com_err (whoami, code, "couldn't create %s", name);
231 if (verbose) printf ("Creating user %s (%di)\n", name, id);
235 if (ownerUser == 0) {
237 strcpy (ownerUserName, name);
248 afs_int32 flags = PRGRP;
251 int ownerType; /* type of ownership */
252 static char *lastGroupPrefix; /* prefix used for type==2 */
254 /* At least 50 groups should be owned by another group to test long owner
255 * chains during deletion. Also let's create some long owners of owners
257 ownerType = random() % 3;
259 if (!ownerUser) ownerType = 0;
260 if (!lastGroup) ownerType = 0;
264 ownerName = callerName;
268 ownerName = ownerUserName;
272 ownerName = lastGroupPrefix;
276 sprintf (name, "%s:%s%d", ownerName, createPrefix, g);
277 code = ubik_Call (PR_NewEntry, pruclient, 0, name, PRGRP, owner, &id);
279 if (code == PREXIST) {
280 code = pr_Delete (name);
284 (PR_NewEntry, pruclient, 0, name, PRGRP, owner, &id);
286 if (verbose) printf ("RE-");
291 com_err (whoami, code, "couldn't create %s w/ owner=%d", name, owner);
295 if (verbose) printf ("Creating group %s (%di)\n", name, id);
297 groupOwners[g] = owner;
299 if (!lastGroup || (ownerType == 2)) {
301 lastGroupPrefix = ownerName;
306 int DeleteRandomId (list)
314 k = random(); /* random starting point */
315 for (j=0; j<number; j++) { /* find an undeleted id */
318 code = ubik_Call (PR_Delete, pruclient, 0, id);
320 com_err (whoami, code, "Couldn't delete %di", id);
324 if (list == users) nUDels++;
329 return -1; /* none left */
338 if (users[u] == 0) /* create if necessary */
340 if (groups[g] == 0) /* create group if necessary */
344 code = ubik_Call(PR_AddToGroup, pruclient, 0, ui, gi);
346 com_err (whoami, code, "couldn't add %d to %d", ui, gi);
349 if (verbose) printf ("Adding user (%di) to group (%di)\n", ui, gi);
350 population[u*number+g]++;
363 code = ubik_Call(PR_RemoveFromGroup, pruclient, 0, ui, gi);
365 com_err (whoami, code, "couldn't remove %d from %d", ui, gi);
368 if (verbose) printf ("Removing user (%di) from group (%di)\n", ui, gi);
369 population[u*number+g]--;
374 TestManyMembers (as, arock)
375 struct cmd_syndesc *as;
378 char *filled; /* users filled up */
379 char *cleaned; /* users cleaned up */
381 int nFilled, nCleaned;
383 int seed; /* random number generator seed */
385 afs_int32 *glist; /* membership list */
389 code = pr_Initialize(1, conf_dir,(char *)0);
391 com_err (whoami, code, "initializing pruser");
394 /* get name of person running command */
395 { struct ktc_principal afs, user;
396 struct ktc_token token;
398 strcpy (afs.name, "afs");
399 strcpy (afs.instance, "");
400 code = afsconf_GetLocalCell (conf, afs.cell, sizeof(afs.cell));
402 code = ktc_GetToken (&afs, &token, sizeof(token), &user);
404 com_err (whoami, code, "getting afs tokens");
407 if (strlen(user.instance) > 0) {
408 fprintf (stderr, "can't handle non-null instance %s.%s\n", user.name, user.cell);
411 if (strncmp (user.name, "AFS ID ", 7) == 0) {
412 callerId = atoi (user.name+7);
413 code = pr_SIdToName (callerId, callerName);
415 com_err (whoami, code, "call get name for id %d", callerId);
419 strcpy (callerName, user.name);
420 code = pr_SNameToId (callerName, &callerId);
421 if ((code == 0) && (callerId == ANONYMOUSID)) code = PRNOENT;
423 #if 0 /* don't create user */
424 if (code == PRNOENT) {
426 code = pr_CreateUser (callerName, &callerId);
428 com_err (whoami, code, "can't create caller %s", callerName);
431 printf ("Creating caller %s (%di)\n", callerName, callerId);
436 com_err (whoami, code, "can't find caller %s", callerName);
439 else printf ("Assuming caller is %s (%di)\n", callerName, callerId);
442 /* Parse arguments */
443 if (as->parms[0].items) number = atoi (as->parms[0].items->data);
444 if (as->parms[1].items) {
445 steepDropOff = atoi (as->parms[1].items->data);
446 if ((steepDropOff < 0) || (steepDropOff > 100)) {
447 fprintf (stderr, "Illegal value for dropoff: %d, must be between 0 and 100, inclusive.\n", steepDropOff);
450 } else steepDropOff = 0; /* use quadratic dropoff */
451 if (as->parms[2].items) createPrefix = as->parms[2].items->data;
452 else createPrefix = "u";
453 if (as->parms[3].items) verbose = 1;
455 if (as->parms[4].items) seed = atoi(as->parms[4].items->data);
460 users = (afs_int32 *) malloc (number*sizeof(afs_int32));
461 groups = (afs_int32 *) malloc (number*sizeof(afs_int32));
462 filled = (char *) malloc (number*sizeof(char));
463 cleaned = (char *) malloc (number*sizeof(char));
464 population = (char *)malloc (sqr(number)*sizeof(char));
467 memset(filled, 0, number);
469 memset(cleaned, 0, number);
470 memset(population, 0, sqr(number));
471 memset(users, 0, number*sizeof(afs_int32));
472 memset(groups, 0, number*sizeof(afs_int32));
474 ownerUser = lastGroup = 0;
475 groupOwners = (afs_int32 *) malloc (number*sizeof(afs_int32));
476 nUsers = nGroups = nAdds = nRems = nUDels = nGDels = 0;
478 while ((nFilled < number) || (nCleaned < number)) {
479 /* pick a user at random, using */
480 u = random() % number;
482 n = GetGroupLimit (number, u); /* get group limit for that user */
483 g = random() % (n+1); /* pick a random group */
484 if (g == n) { /* in a few cases create any user */
485 n = number; /* in the whole range */
488 for (i=0; i<n; i++) { /* rotate until unused one found */
490 if (!population[u*number+j]) {
491 /* add this user/group membership */
502 if (filled[u]) { /* only clean above GroupLimit */
503 base = GetGroupLimit (number, u);
505 if (n == 0) goto iscleaned;
510 n = number; /* pick a group from the whole range */
511 g = random() % 2*n; /* at random for removal */
512 if (g >= n) goto remed; /* but half the time do nothing */
514 for (i=0; i<n; i++) { /* rotate until used one found */
515 j = (g+i) % n + base;
516 if (population[u*number+j]) {
517 /* remove this user/group membership */
522 if (filled[u]) { /* track finished ones */
531 /* check the membership list of all users for correctness */
532 printf ("Starting check of memberships\n");
533 glist = (afs_int32 *)malloc (number*sizeof(afs_int32));
534 for (u=0; u<number; u++) {
535 afs_int32 ui = users[u];
538 int ng; /* number groups */
539 int (*proc)(); /* membership listing procedure */
543 alist.prlist_len = 0;
544 alist.prlist_val = 0;
545 if (random() & 4) proc = PR_ListElements;
546 else proc = PR_GetCPS;
547 code = ubik_Call (proc, pruclient, 0, ui, &alist, &over);
549 com_err (whoami, code,
550 "getting membership list of (%di) using %s", ui,
551 ((proc == PR_GetCPS) ? "GetCPR" : "ListElements"));
556 "membership list for id %di too long\n", ui);
559 for (i=0; i<number; i++)
560 if (population[u*number+i])
561 glist[ng++] = groups[i];
562 qsort (glist, ng, sizeof(afs_int32), IdCmp);
563 if (ng != (alist.prlist_len - ((proc == PR_GetCPS) ? 3 : 0))) {
564 fprintf (stderr, "Membership list for %di of unexpected length: was %d but expected %d\n", ui, alist.prlist_len, ng);
567 /* all the extra entries for the CPS should be at the end. */
570 if (alist.prlist_val[i] != glist[i]) {
571 fprintf (stderr, "membership for %di not correct: was %di but expected %di\n", ui, alist.prlist_val[i], glist[i]);
575 if (proc == PR_GetCPS) {
576 if ((alist.prlist_val[i /* =ng */] != AUTHUSERID) ||
577 (alist.prlist_val[++i] != ANYUSERID) ||
578 (alist.prlist_val[++i] != ui)) {
579 fprintf (stderr, "CPS doesn't have extra entries\n");
583 if (alist.prlist_val) free(alist.prlist_val);
585 /* User 0 is a member of all groups all of which should also be on
586 * the owner list of the caller or the ownerUser, although there
587 * may also be others. Check this. */
591 prlist lastGroupList;
595 fprintf (stderr, "User 0 not a member of all groups\n");
599 #define GETOWNED(xlist,xid) \
600 (xlist).prlist_val = 0; (xlist).prlist_len = 0; \
601 code = ubik_Call (PR_ListOwned, pruclient, 0, (xid), &(xlist), &over); \
603 com_err (whoami, code, "getting owner list of (%di)", (xid)); \
606 { fprintf (stderr, "membership of id %di too long\n", (xid)); }
608 GETOWNED (callerList, callerId);
609 GETOWNED (ownerList, ownerUser);
611 /* look for every entry in glist, in all the owner lists */
612 for (i=j=k=l=0; i<number; i++) {
613 while ((j < callerList.prlist_len) &&
614 (callerList.prlist_val[j] < glist[i])) j++;
615 while ((k < ownerList.prlist_len) &&
616 (ownerList.prlist_val[k] < glist[i])) k++;
617 #define PRLISTCMP(l,i) \
618 (((l).prlist_len == 0) || (glist[i] != (l).prlist_val[(i)]))
619 if (PRLISTCMP(callerList,j) &&
620 PRLISTCMP(ownerList,k)) {
621 for (l=0; l<number; l++) {
622 if (groups[l] == glist[i]) {
623 if ((groupOwners[l] != callerId) &&
624 (groupOwners[l] != ownerUser)) {
625 GETOWNED (lastGroupList, groupOwners[l]);
626 if ((lastGroupList.prlist_len != 1) ||
627 (lastGroupList.prlist_val[0] != glist[i])) {
628 fprintf (stderr, "Group (%di) not on any owner list\n", glist[i]);
635 fprintf (stderr, "unexpected group %di\n", glist[i]);
639 if (callerList.prlist_val) free(callerList.prlist_val);
640 if (ownerList.prlist_val) free(ownerList.prlist_val);
641 if (lastGroupList.prlist_val) free(lastGroupList.prlist_val);
646 /* cleanup by deleting all the users and groups */
647 printf ("Starting deletion of users and groups\n");
648 for (i=0; i<number; i++) {
649 DeleteRandomId (users);
650 DeleteRandomId (groups);
653 printf ("Created/deleted %d/%d users and %d/%d groups; added %d and removed %d.\n",
654 nUsers, nUDels, nGroups, nGDels, nAdds, nRems);
658 /* from ka_ConvertBytes included here to avoid circularity */
659 /* Converts a byte string to ascii. Return the number of unconverted bytes. */
661 static int ka_ConvertBytes (ascii, alen, bs, bl)
662 char *ascii; /* output buffer */
663 int alen; /* buffer length */
664 char bs[]; /* byte string */
665 int bl; /* number of bytes */
669 alen--; /* make room for termination */
670 for (i=0; i < bl; i++) {
672 if (alen <= 0) return bl-i;
673 if (isalnum(c) || ispunct(c)) (*ascii++ = c), alen--;
675 if (alen <= 3) return bl-i;
677 *ascii++ = (c>>6) + '0';
678 *ascii++ = (c>>3 & 7) + '0';
679 *ascii++ = (c&7) + '0';
683 *ascii = 0; /* terminate string */
686 /* This runs various tests on the server. It creates, then deletes, a bunch of
687 * users and groups, so it would be safest to run it on a test database.
689 * These are the things I check for:
690 * User names longer than PR_MAXNAMELEN - strlen(cellname).
691 * Group names longer than PR_MAXNAMELEN.
692 * User names containing all legal 8-bit ascii characters. This excludes
693 * only ':', '@', and '\n'.
694 * Group names as above, but at least one colon is required, and the owner
698 TestPrServ (as, arock)
699 struct cmd_syndesc *as;
703 char name[PR_MAXNAMELEN+1];
704 char creator[PR_MAXNAMELEN]; /* our name */
705 struct prcheckentry ent;
708 int maxLen = PR_MAXNAMELEN-1 - strlen(lcell) - 1;
710 code = pr_Initialize(1, conf_dir,(char *)0);
712 com_err (whoami, code, "initializing pruser");
716 for (i=0; i<maxLen; i++) name[i] = 'a';
717 name[i]='a'; /* too long a name... */
720 code = pr_CreateUser (name, &id);
721 if ((code != RXGEN_CC_MARSHAL) && (code != PRBADNAM)) {
722 com_err (whoami, code, "succeeded creating %s", name);
727 code = pr_CreateUser (name, &id);
728 if (code == PREXIST) {
729 fprintf (stderr, "group already exists, skipping\n");
730 pr_SNameToId (name, &id);
732 com_err (whoami, code, "failed creating %s", name);
735 if ((code = pr_ListEntry (id, &ent)) ||
736 (code = pr_SIdToName (ent.creator, creator))) {
737 com_err (whoami, code, "getting creator's name");
740 code = pr_DeleteByID (id);
742 com_err (whoami, code, "deleting %s", name);
745 /* now make sure the illegal chars are detected */
746 { char *illegalChars;
747 for (illegalChars = "@:\n"; *illegalChars; illegalChars++) {
748 name[10] = *illegalChars;
750 code = pr_CreateUser (name, &id);
751 if (code != PRBADNAM) {
752 com_err (whoami, code, "succeeded creating %s", name);
758 for (i=1; i <= 255;) { /* for all 8-bit ascii... */
759 j=0; /* build a new name */
760 while ((j<maxLen) && (i<=255)) {
761 if (!((i == ':') || (i == '@') || (i == '\n')))
765 name[j]=0; /* terminate string */
767 code = pr_CreateUser (name, &id);
768 if (code == PREXIST) {
769 fprintf (stderr, "user already exists, skipping\n");
770 pr_SNameToId (name, &id);
773 ka_ConvertBytes (ascii, sizeof(ascii), name, strlen(name));
774 com_err (whoami, code, "failed creating %s", ascii);
777 code = pr_DeleteByID (id);
779 com_err (whoami, code, "deleting %s", name);
784 /* now check group names */
785 strcpy (name, creator);
786 strcat (name, ":abcdefghijklmnopqrstuvwxyz");
787 name[0] = 1; /* bash the owner name */
789 code = pr_CreateGroup (name, &id);
790 if (code != PRNOENT) { /* owner doesn't exist */
791 com_err (whoami, code, "succeeded creating %s", name);
794 name[0] = creator[0]; /* fix owner */
795 /* Make sure the illegal chars are detected */
796 { char *illegalChars;
797 for (illegalChars = ":@\n"; *illegalChars; illegalChars++) {
798 name[strlen(creator)+10] = *illegalChars;
800 code = pr_CreateGroup (name, creator, &id);
801 if (code != PRBADNAM) {
802 com_err (whoami, code, "succeeded creating %s", name);
807 for (i=1; i <= 255;) { /* for all 8-bit ascii... */
808 j=strlen(creator)+1; /* build a new name */
809 while ((j<PR_MAXNAMELEN-1) && (i<=255)) {
810 if (!((i == ':') || (i == '@') || (i == '\n')))
814 name[j]=0; /* terminate string */
816 code = pr_CreateGroup (name, creator, &id);
817 if (code == PREXIST) {
818 fprintf (stderr, "group already exists, skipping\n");
819 pr_SNameToId (name, &id);
822 ka_ConvertBytes (ascii, sizeof(ascii), name, strlen(name));
823 com_err (whoami, code, "failed creating %s", ascii);
826 code = pr_DeleteByID (id);
828 com_err (whoami, code, "deleting %s", name);
837 static char tmp_conf_dir[128] = "";
838 static char tmp_conf_file[128] = "";
839 static char tmp_cell_file[128] = "";
840 static char tmp_noauth_file[128] = "";
842 static int MyAfterProc (as, arock)
843 struct cmd_syndesc *as;
846 if (strlen (tmp_conf_file)) unlink (tmp_conf_file);
847 if (strlen (tmp_cell_file)) unlink (tmp_cell_file);
848 if (strlen (tmp_noauth_file)) unlink (tmp_noauth_file);
849 if (strlen (tmp_conf_dir)) rmdir (tmp_conf_dir);
853 static int MyBeforeProc (as, arock)
854 struct cmd_syndesc *as;
860 struct cmd_item *serverList = 0;
861 struct afsconf_dir *local_conf = 0; /* so we can default stuff nicely */
862 struct afsconf_cell cellinfo;
864 if (as->parms[12].items) { /* if conf dir specified */
865 cdir = as->parms[12].items->data;
866 if (as->parms[13].items || as->parms[14].items || as->parms[15].items) {
867 printf ("Can't specify conf dir and other cell parameters\n");
868 return AFSCONF_SYNTAX;
872 /* if we need to default cell name or cell servers, get local conf info */
874 if (!(local_conf = afsconf_Open (AFSDIR_CLIENT_ETC_DIRPATH)) &&
875 !(local_conf = afsconf_Open (AFSDIR_SERVER_ETC_DIRPATH))){
876 printf("** Can't local configuration!\n");
877 return AFSCONF_NOCELL;
880 if (as->parms[13].items) { /* if cell name specified */
881 lcstring (lcell, as->parms[13].items->data, sizeof(lcell));
882 code = afsconf_GetCellInfo (local_conf, lcell, 0, &cellinfo);
883 if (code == 0) strncpy (lcell, cellinfo.name, sizeof(lcell));
885 code = afsconf_GetLocalCell (local_conf, lcell, sizeof(lcell));
886 if (code) return code;
889 if (as->parms[14].items) { /* noauth flag */
893 if (as->parms[15].items) { /* servers list */
894 serverList = as->parms[15].items;
895 for (i=0; serverList; i++, serverList = serverList->next) {
897 if (i >= MAXHOSTSPERCELL) return AFSCONF_FULL;
898 strncpy (cellinfo.hostName[i], serverList->data, MAXHOSTCHARS);
899 th = gethostbyname(cellinfo.hostName[i]);
900 if (!th) return UBADHOST;
901 memcpy(&cellinfo.hostAddr[i].sin_addr, th->h_addr, sizeof(afs_int32));
902 cellinfo.hostAddr[i].sin_family = AF_INET;
903 cellinfo.hostAddr[i].sin_port = 0;
905 cellinfo.numServers = i;
906 strcpy (cellinfo.name, lcell);
908 code = afsconf_GetCellInfo (local_conf, lcell, 0, &cellinfo);
909 if (code) return code;
912 if (local_conf) afsconf_Close (local_conf);
917 sprintf (tmp_conf_dir, "%s/afsconf.%lu", gettmpdir(), (unsigned long) getpid());
918 code = mkdir (tmp_conf_dir, 0777);
919 if ((code < 0) && (errno != EEXIST)) {
920 com_err (whoami, errno, "can't create temporary afsconf dir: %s", cdir);
924 strcompose(tmp_conf_file, 128, tmp_conf_dir, "/", AFSDIR_CELLSERVDB_FILE, NULL);
925 f = fopen (tmp_conf_file, "w");
928 com_err (whoami, errno, "can't create conf file %s", tmp_conf_file);
931 fprintf (f, ">%s\n", lcell);
932 for (i=0; i<cellinfo.numServers; i++) {
933 register unsigned char *tp = (unsigned char *)&cellinfo.hostAddr[i].sin_addr;
934 fprintf (f, "%d.%d.%d.%d\t#%s\n",
935 tp[0], tp[1], tp[2], tp[3], cellinfo.hostName[i]);
937 if (fclose (f) == EOF) {
939 com_err (whoami, errno, "can't write to conf file %s", tmp_conf_file);
943 strcompose(tmp_cell_file, 128, tmp_conf_dir, "/", AFSDIR_THISCELL_FILE, NULL);
944 f = fopen (tmp_cell_file, "w");
945 if (f == 0) goto cantcreate;
946 fprintf (f, "%s", lcell);
947 if (fclose(f) == EOF) goto cantclose;
949 strcompose(tmp_noauth_file, 128, tmp_conf_dir, "/", AFSDIR_NOAUTH_FILE, NULL);
951 code = creat (tmp_noauth_file, 0777);
952 if (code && (errno != EEXIST)) return errno;
953 } else { /* make sure file doesn't exist */
954 code = unlink (tmp_noauth_file);
955 if (code && (errno != ENOENT)) return errno;
959 strncpy (conf_dir, tmp_conf_dir, sizeof(conf_dir));
960 conf = afsconf_Open (conf_dir);
961 if (conf == 0) return AFSCONF_NOTFOUND;
965 static void add_std_args (ts)
966 register struct cmd_syndesc *ts;
969 cmd_AddParm(ts, "-confdir", CMD_SINGLE, CMD_OPTIONAL, "AFS Conf dir pathname");
970 cmd_AddParm(ts, "-cell", CMD_SINGLE, CMD_OPTIONAL, "Cell name");
971 cmd_AddParm(ts, "-noauth", CMD_FLAG, CMD_OPTIONAL, "Don't authenticate");
972 cmd_AddParm(ts, "-servers", CMD_LIST, CMD_OPTIONAL, "Server config");
977 /* OK, this REALLY sucks bigtime, but I can't tell who is calling
978 * afsconf_CheckAuth easily, and only *SERVERS* should be calling osi_audit
979 * anyway. It's gonna give somebody fits to debug, I know, I know.
984 #include "AFS_component_version_number.c"
990 struct cmd_syndesc *ts; /* ptr to parsed command line syntax */
993 initialize_CMD_error_table();
994 initialize_ACFG_error_table();
995 initialize_KTC_error_table();
996 initialize_U_error_table();
997 initialize_PT_error_table();
998 initialize_RXK_error_table();
1001 /* initialize winsock */
1002 if (afs_winsockInit()<0) {
1003 fprintf(stderr, "%s: couldn't initialize winsock. \n", whoami);
1008 cmd_SetBeforeProc(MyBeforeProc, (char *)0);
1009 cmd_SetAfterProc(MyAfterProc, (char *)0);
1011 ts = cmd_CreateSyntax("usedIds", ListUsedIds, 0, "Find used (or unused) user (or group) ids");
1012 cmd_AddParm (ts, "-startId", CMD_SINGLE, CMD_OPTIONAL, "id to start checking");
1013 cmd_AddParm (ts, "-number", CMD_SINGLE, CMD_OPTIONAL, "number of ids to check");
1014 cmd_AddParm (ts, "-unused", CMD_FLAG, CMD_OPTIONAL, "print unused ids");
1017 ts = cmd_CreateSyntax("initcmd", TestPrServ, 0, "test the prserver");
1020 ts = cmd_CreateSyntax("testmanymembers", TestManyMembers, 0, "test creating users and groups w/ many members");
1021 cmd_AddParm (ts, "-number", CMD_SINGLE, 0, "number of users/groups to create");
1022 cmd_AddParm (ts, "-dropoff", CMD_SINGLE, CMD_OPTIONAL, "precentage for exponential dropoff");
1023 cmd_AddParm (ts, "-prefix", CMD_SINGLE, CMD_OPTIONAL, "naming prefix");
1024 cmd_AddParm (ts, "-long", CMD_FLAG, CMD_OPTIONAL, "show progress");
1025 cmd_AddParm (ts, "-seed", CMD_SINGLE, CMD_OPTIONAL, "random number seed");
1027 cmd_CreateAlias(ts,"mm");
1030 code = cmd_Dispatch(argc, argv);
1031 if (code) com_err (whoami, code, "calling cmd_Dispatch");