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>
18 #include <WINNT/afsevent.h>
19 #include <WINNT/afsreg.h>
22 #include <afs/cellconfig.h>
23 #include <afs/afsutil.h>
24 #include <afs/com_err.h>
32 #include "ptprototypes.h"
41 extern struct ubik_client *pruclient;
44 struct sourcestack *s_next;
51 char cell[MAXCELLCHARS];
54 static int CleanUp(struct cmd_syndesc *as, void *arock);
57 pts_Interactive(struct cmd_syndesc *as, void *arock)
65 pts_Quit(struct cmd_syndesc *as, void *arock)
72 pts_Source(struct cmd_syndesc *as, void *arock)
75 struct sourcestack *sp;
78 if (!as->parms[0].items) {
79 /* can this happen? */
82 fd = fopen(as->parms[0].items->data, "r");
84 perror(as->parms[0].items->data);
87 sp = (struct sourcestack *)malloc(sizeof *sp);
89 return errno ? errno : ENOMEM;
100 pts_Sleep(struct cmd_syndesc *as, void *arock)
103 if (!as->parms[0].items) {
104 /* can this happen? */
107 delay = atoi(as->parms[0].items->data);
108 #ifdef AFS_PTHREAD_ENV
119 struct sourcestack *sp;
133 /* OK, this REALLY sucks bigtime, but I can't tell who is calling
134 * afsconf_CheckAuth easily, and only *SERVERS* should be calling osi_audit
135 * anyway. It's gonna give somebody fits to debug, I know, I know.
142 win32_enableCrypt(void)
149 /* Look up configuration parameters in Registry */
150 code = RegOpenKeyEx(HKEY_LOCAL_MACHINE, AFSREG_CLT_SVC_PARAM_SUBKEY,
151 0, (IsWow64()?KEY_WOW64_64KEY:0)|KEY_QUERY_VALUE, &parmKey);
152 if (code != ERROR_SUCCESS) {
153 dummyLen = sizeof(cryptall);
154 RegQueryValueEx(parmKey, "SecurityLevel", NULL, NULL,
155 (BYTE *) &cryptall, &dummyLen);
157 RegCloseKey (parmKey);
161 #endif /* AFS_NT40_ENV */
164 GetGlobals(struct cmd_syndesc *as, void *arock)
166 struct authstate *state = (struct authstate *) arock;
175 if (!strcmp(as->name, "help"))
183 if (state->confdir == NULL) {
187 if (as->parms[16].items) {
189 cell = as->parms[16].items->data;
191 if (as->parms[17].items) { /* -noauth */
195 if (as->parms[20].items) { /* -localauth */
199 if (as->parms[21].items) { /* -auth */
203 if (as->parms[22].items /* -encrypt */
205 || win32_enableCrypt()
206 #endif /* AFS_NT40_ENV */
211 if (as->parms[18].items || as->parms[20].items) { /* -test, -localauth */
213 confdir = AFSDIR_SERVER_ETC_DIRPATH;
216 confdir = AFSDIR_SERVER_ETC_DIRPATH;
218 confdir = AFSDIR_CLIENT_ETC_DIRPATH;
221 if (as->parms[23].items) { /* -config */
223 confdir = as->parms[23].items->data;
228 code = pr_Initialize(sec, confdir, cell);
233 afs_com_err(whoami, code, "while initializing");
237 state->confdir = confdir;
238 if (cell && cell != state->cell)
239 strncpy(state->cell, cell, MAXCELLCHARS-1);
242 if (as->parms[19].items)
249 CleanUp(struct cmd_syndesc *as, void *arock)
251 if (as && !strcmp(as->name, "help"))
254 /* Need to shutdown the ubik_client & other connections */
262 CreateGroup(struct cmd_syndesc *as, void *arock)
267 struct cmd_item *namei;
268 struct cmd_item *idi;
270 namei = as->parms[0].items;
271 idi = as->parms[2].items;
272 if (as->parms[1].items)
273 owner = as->parms[1].items->data;
279 code = util_GetInt32(idi->data, &id);
281 afs_com_err(whoami, code, "because group id was: '%s'",
286 printf("0 isn't a valid group id; aborting\n");
291 afs_com_err(whoami, code, "because group id %d was not negative",
300 code = pr_CreateGroup(namei->data, owner, &id);
303 afs_com_err(whoami, code,
304 "; unable to create group %s with id %d%s%s%s%s",
305 namei->data, id, owner ? " owned by '" : "",
306 owner ? owner : "", owner ? "'" : "",
307 (force ? " (ignored)" : ""));
309 afs_com_err(whoami, code, "; unable to create group %s %s",
310 namei->data, (force ? "(ignored)" : ""));
314 printf("group %s has id %d\n", namei->data, id);
321 CreateUser(struct cmd_syndesc *as, void *arock)
325 struct cmd_item *namei;
326 struct cmd_item *idi;
328 namei = as->parms[0].items;
329 idi = as->parms[1].items;
333 code = util_GetInt32(idi->data, &id);
335 afs_com_err(whoami, code, "because id was: '%s'", idi->data);
339 printf("0 isn't a valid user id; aborting\n");
344 afs_com_err(whoami, code, "because user id %d was not positive",
352 code = pr_CreateUser(namei->data, &id);
355 afs_com_err(whoami, code,
356 "; unable to create user %s with id %d %s",
357 namei->data, id, (force ? "(ignored)" : ""));
359 afs_com_err(whoami, code, "; unable to create user %s %s",
360 namei->data, (force ? "(ignored)" : ""));
364 printf("User %s has id %d\n", namei->data, id);
373 GetNameOrId(struct cmd_syndesc *as, struct idlist *lids, struct namelist *lnames)
380 if (!(as->parms[0].items || as->parms[1].items)) {
381 afs_com_err(whoami, 0, "must specify either a name or an id.");
384 if (as->parms[0].items && as->parms[1].items) {
385 afs_com_err(whoami, 0, "can't specify both a name and id.");
390 lids->idlist_len = 0;
391 lids->idlist_val = 0;
393 if (as->parms[0].items) { /* name */
394 struct namelist names; /* local copy, if not ret. names */
397 names.namelist_val = 0; /* so it gets freed later if needed */
403 n = 0; /* count names */
404 for (i = as->parms[0].items; i; i = i->next)
406 nl->namelist_val = (prname *) malloc(n * PR_MAXNAMELEN);
407 nl->namelist_len = n;
409 for (i = as->parms[0].items; i; i = i->next)
410 strncpy(nl->namelist_val[n++], i->data, PR_MAXNAMELEN);
412 code = pr_NameToId(nl, lids);
414 afs_com_err(whoami, code, "so couldn't look up names");
416 for (n = 0; n < lids->idlist_len; n++) {
417 if ((lids->idlist_val[n] == ANONYMOUSID)) {
418 afs_com_err(whoami, PRNOENT, "so couldn't look up id for %s",
419 nl->namelist_val[n]);
423 /* treat things as working if any of the lookups worked */
428 if (names.namelist_val)
429 free(names.namelist_val);
430 } else if (as->parms[1].items) { /* id */
432 for (i = as->parms[1].items; i; i = i->next)
434 lids->idlist_val = (afs_int32 *) malloc(n * sizeof(afs_int32));
435 lids->idlist_len = n;
437 for (i = as->parms[1].items; i; i = i->next) {
438 code = util_GetInt32(i->data, &lids->idlist_val[n]);
440 afs_com_err(whoami, code =
441 PRNOENT, "because a bogus id '%s' was specified",
445 if (!code && lnames) {
446 lnames->namelist_val = 0;
447 lnames->namelist_len = 0;
448 code = pr_IdToName(lids, lnames);
450 afs_com_err(whoami, code, "translating ids");
454 if (lids->idlist_val)
455 free(lids->idlist_val);
464 GetNameOrId(struct cmd_syndesc *as, struct idlist *lids,
465 struct namelist *lnames)
468 int n = 0, nd = 0, nm = 0, id, x;
470 struct namelist names, tnames; /* local copy, if not ret. names */
471 struct idlist ids, tids; /* local copy, if not ret. ids */
474 /* Initialise our outputs */
475 memset(lids, 0, sizeof(struct idlist));
477 memset(lnames, 0, sizeof(struct namelist));
479 for (i = as->parms[0].items; i; i = i->next)
482 /* Nothing to do, so bail */
486 lids->idlist_val = malloc(n * sizeof(afs_int32));
487 lids->idlist_len = n;
488 ids.idlist_val = malloc(n * sizeof(afs_int32));
490 names.namelist_val = malloc(n * PR_MAXNAMELEN);
491 names.namelist_len = n;
493 lnames->namelist_val = malloc(n * PR_MAXNAMELEN);
494 lnames->namelist_len = 0;
496 for (i = as->parms[0].items; i; i = i->next) {
497 tnames.namelist_val = (prname *) malloc(PR_MAXNAMELEN);
498 strncpy(tnames.namelist_val[0], i->data, PR_MAXNAMELEN);
499 tnames.namelist_len = 1;
502 code = pr_NameToId(&tnames, &tids);
503 if ((!code && (tids.idlist_val[0] != 32766))
504 || (code = util_GetInt32(i->data, &id))) {
505 /* Assume it's a name instead */
506 strncpy(names.namelist_val[nm++], i->data, PR_MAXNAMELEN);
508 ids.idlist_val[nd++] = id;
510 free(tnames.namelist_val);
512 names.namelist_len = nm;
514 tids.idlist_len = nd = nm = 0;
516 code = pr_NameToId(&names, &tids);
518 afs_com_err(whoami, code, "so couldn't look up names");
520 for (n = 0; n < tids.idlist_len; n++) {
521 if (tids.idlist_val[n] == ANONYMOUSID) {
522 afs_com_err(whoami, PRNOENT, "so couldn't look up id for %s",
523 names.namelist_val[n]);
526 lids->idlist_val[nd] = tids.idlist_val[n];
528 strcpy(lnames->namelist_val[nd], names.namelist_val[n]);
532 for (x = 0; x < ids.idlist_len; x++) {
533 lids->idlist_val[nd + x] = ids.idlist_val[x];
535 lids->idlist_len = nd + x;
536 if (!code && lnames) {
537 tnames.namelist_val = 0;
538 tnames.namelist_len = 0;
539 code = pr_IdToName(&ids, &tnames);
541 afs_com_err(whoami, code, "translating ids");
545 for (x = 0; x < ids.idlist_len; x++)
546 strcpy(lnames->namelist_val[nd + x], tnames.namelist_val[x]);
547 lnames->namelist_len = nd + x;
550 /* treat things as working if any of the lookups worked */
554 if (lids->idlist_val)
555 free(lids->idlist_val);
563 AddToGroup(struct cmd_syndesc *as, void *arock)
566 struct cmd_item *u, *g;
568 for (u = as->parms[0].items; u; u = u->next) {
569 for (g = as->parms[1].items; g; g = g->next) {
570 code = pr_AddToGroup(u->data, g->data);
572 afs_com_err(whoami, code,
573 "; unable to add user %s to group %s %s", u->data,
574 g->data, (force ? "(ignored)" : ""));
584 RemoveFromGroup(struct cmd_syndesc *as, void *arock)
587 struct cmd_item *u, *g;
589 for (u = as->parms[0].items; u; u = u->next) {
590 for (g = as->parms[1].items; g; g = g->next) {
591 code = pr_RemoveUserFromGroup(u->data, g->data);
593 afs_com_err(whoami, code,
594 "; unable to remove user %s from group %s %s",
595 u->data, g->data, (force ? "(ignored)" : ""));
605 ListMembership(struct cmd_syndesc *as, void *arock)
614 if (GetNameOrId(as, &ids, &names))
617 for (i = 0; i < ids.idlist_len; i++) {
618 afs_int32 id = ids.idlist_val[i];
619 char *name = names.namelist_val[i];
621 if (id == ANONYMOUSID)
622 continue; /* bad entry */
624 list.namelist_val = 0;
625 list.namelist_len = 0;
626 if (as->parms[2].items) { /* -expandgroups */
627 code = pr_IDListExpandedMembers(id, &list);
631 code = pr_IDListMembers(id, &list);
634 afs_com_err(whoami, code, "; unable to get membership of %s (id: %d)",
639 printf("Members of %s (id: %d) are:\n", name, id);
641 printf("Groups %s (id: %d) is a member of:\n", name, id);
643 for (j = 0; j < list.namelist_len; j++)
644 printf(" %s\n", list.namelist_val[j]);
645 if (list.namelist_val)
646 free(list.namelist_val);
647 if (as->parms[1].items && id < 0) { /* -supergroups */
648 list.namelist_val = 0;
649 list.namelist_len = 0;
650 code = pr_ListSuperGroups(ids.idlist_val[i], &list);
651 if (code == RXGEN_OPCODE) {
652 continue; /* server does not support supergroups */
653 } else if (code != 0) {
654 afs_com_err(whoami, code,
655 "; unable to get supergroups of %s (id: %d)",
659 printf("Groups %s (id: %d) is a member of:\n", name, id);
660 for (j = 0; j < list.namelist_len; j++)
661 printf(" %s\n", list.namelist_val[j]);
662 if (list.namelist_val)
663 free(list.namelist_val);
667 free(ids.idlist_val);
668 if (names.namelist_val)
669 free(names.namelist_val);
674 Delete(struct cmd_syndesc *as, void *arock)
681 if (GetNameOrId(as, &ids, &names))
684 for (i = 0; i < ids.idlist_len; i++) {
685 afs_int32 id = ids.idlist_val[i];
686 char *name = names.namelist_val[i];
688 if (id == ANONYMOUSID)
691 code = pr_DeleteByID(id);
693 afs_com_err(whoami, code, "deleting %s (id: %d) %s", name, id,
694 (force ? "(ignored)" : ""));
700 free(ids.idlist_val);
701 if (names.namelist_val)
702 free(names.namelist_val);
706 /* access bit translation info */
708 char *flags_upcase = "SOMA "; /* legal all access values */
709 char *flags_dncase = "s mar"; /* legal member acces values */
710 int flags_shift[5] = { 2, 1, 2, 2, 1 }; /* bits for each */
713 CheckEntry(struct cmd_syndesc *as, void *arock)
717 int i, flag = 0, admin = 0;
718 namelist lnames, names;
721 struct prcheckentry aentry;
723 if (GetNameOrId(as, &ids, &names))
727 lids.idlist_val = (afs_int32 *) malloc(sizeof(afs_int32) * 2);
728 lnames.namelist_len = 0;
729 lnames.namelist_val = 0;
731 for (i = 0; i < ids.idlist_len; i++) {
732 afs_int32 id = ids.idlist_val[i];
734 if (id == ANONYMOUSID)
738 code = pr_ListEntry(id, &aentry);
741 afs_com_err(whoami, code, "; unable to find entry for (id: %d)", id);
745 lids.idlist_val[0] = aentry.owner;
746 lids.idlist_val[1] = aentry.creator;
747 code = pr_IdToName(&lids, &lnames);
750 afs_com_err(whoami, code,
751 "translating owner (%d) and creator (%d) ids",
752 aentry.owner, aentry.creator);
755 printf("Name: %s, id: %d, owner: %s, creator: %s,\n", aentry.name,
756 aentry.id, lnames.namelist_val[0], lnames.namelist_val[1]);
757 printf(" membership: %d", aentry.count);
760 afs_int32 flags = aentry.flags;
763 access[5] = 0; /* null-terminate the string */
764 for (j = 4; j >= 0; j--) {
783 printf(", flags: %s", access);
785 if (aentry.id == SYSADMINID)
787 else if (!pr_IsAMemberOf(aentry.name, "system:administrators", &flag)) {
792 printf(", group quota: unlimited");
794 printf(", group quota: %d", aentry.ngroups);
796 printf(", foreign user quota=%d", aentry.nusers);
801 if (lnames.namelist_val)
802 free(lnames.namelist_val);
804 free(lids.idlist_val);
806 free(ids.idlist_val);
812 ListEntries(struct cmd_syndesc *as, void *arock)
815 afs_int32 flag, startindex, nentries, nextstartindex;
816 struct prlistentries *entriesp = 0, *e;
820 if (as->parms[1].items)
822 if (as->parms[0].items)
825 printf("Name ID Owner Creator\n");
826 for (startindex = 0; startindex != -1; startindex = nextstartindex) {
828 pr_ListEntries(flag, startindex, &nentries, &entriesp,
831 afs_com_err(whoami, code, "; unable to list entries");
837 /* Now display each of the entries we read */
838 for (i = 0, e = entriesp; i < nentries; i++, e++) {
839 printf("%-25s %6d %6d %7d \n", e->name, e->id, e->owner,
849 ChownGroup(struct cmd_syndesc *as, void *arock)
855 name = as->parms[0].items->data;
856 owner = as->parms[1].items->data;
857 code = pr_ChangeEntry(name, "", 0, owner);
859 afs_com_err(whoami, code, "; unable to change owner of %s to %s", name,
865 ChangeName(struct cmd_syndesc *as, void *arock)
871 oldname = as->parms[0].items->data;
872 newname = as->parms[1].items->data;
873 code = pr_ChangeEntry(oldname, newname, 0, "");
875 afs_com_err(whoami, code, "; unable to change name of %s to %s", oldname,
881 ListMax(struct cmd_syndesc *as, void *arock)
884 afs_int32 maxUser, maxGroup;
886 code = pr_ListMaxUserId(&maxUser);
888 afs_com_err(whoami, code, "getting maximum user id");
890 code = pr_ListMaxGroupId(&maxGroup);
892 afs_com_err(whoami, code, "getting maximum group id");
894 printf("Max user id is %d and max group id is %d.\n", maxUser,
902 SetMaxCommand(struct cmd_syndesc *as, void *arock)
908 if (as->parms[1].items) {
910 code = util_GetInt32(as->parms[1].items->data, &maxid);
912 afs_com_err(whoami, code, "because id was: '%s'",
913 as->parms[1].items->data);
915 code = pr_SetMaxUserId(maxid);
917 afs_com_err(whoami, code, "so couldn't set Max User Id to %d",
921 if (as->parms[0].items) {
923 code = util_GetInt32(as->parms[0].items->data, &maxid);
925 afs_com_err(whoami, code, "because id was: '%s'",
926 as->parms[0].items->data);
928 code = pr_SetMaxGroupId(maxid);
930 afs_com_err(whoami, code, "so couldn't set Max Group Id to %d",
934 if (!as->parms[0].items && !as->parms[1].items) {
936 printf("Must specify at least one of group or user.\n");
942 SetFields(struct cmd_syndesc *as, void *arock)
948 afs_int32 mask, flags=0, ngroups, nusers;
950 if (GetNameOrId(as, &ids, &names))
957 if (as->parms[1].items) { /* privacy bits */
958 char *access = as->parms[1].items->data;
961 if (strpbrk(access, "76543210") != 0) { /* all octal digits */
962 sscanf(access, "%lo", (long unsigned int *) &flags);
963 } else { /* interpret flag bit names */
964 if (strlen(access) != 5) {
966 printf("Access bits must be of the form 'somar', not %s\n",
970 if (strpbrk(access, "somar-") == 0)
973 for (i = 0; i < 5; i++) {
974 if (access[i] == flags_upcase[i])
976 else if (access[i] == flags_dncase[i])
978 else if (access[i] == '-')
982 ("Access bits out of order or illegal:\n must be a combination of letters from '%s' or '%s' or hyphen, not %s\n",
983 flags_upcase, flags_dncase, access);
986 flags <<= flags_shift[i];
987 if (flags_shift[i] == 1) {
994 mask |= PR_SF_ALLBITS;
996 if (as->parms[2].items) { /* limitgroups */
997 code = util_GetInt32(as->parms[2].items->data, &ngroups);
999 afs_com_err(whoami, code, "because ngroups was: '%s'",
1000 as->parms[2].items->data);
1003 mask |= PR_SF_NGROUPS;
1006 if (as->parms[3].items) { /* limitgroups */
1007 code = util_GetInt32(as->parms[3].items->data, &nusers);
1009 afs_com_err(whoami, code, "because nusers was: '%s'",
1010 as->parms[3].items->data);
1013 mask |= PR_SF_NUSERS;
1017 for (i = 0; i < ids.idlist_len; i++) {
1018 afs_int32 id = ids.idlist_val[i];
1019 char *name = names.namelist_val[i];
1020 if (id == ANONYMOUSID)
1022 code = pr_SetFieldsEntry(id, mask, flags, ngroups, nusers);
1024 afs_com_err(whoami, code, "; unable to set fields for %s (id: %d)",
1030 free(ids.idlist_val);
1031 if (names.namelist_val)
1032 free(names.namelist_val);
1037 ListOwned(struct cmd_syndesc *as, void *arock)
1046 if (GetNameOrId(as, &ids, &names))
1049 for (i = 0; i < ids.idlist_len; i++) {
1050 afs_int32 oid = ids.idlist_val[i];
1051 char *name = names.namelist_val[i];
1053 if (oid == ANONYMOUSID)
1057 printf("Groups owned by %s (id: %d) are:\n", name, oid);
1059 printf("Orphaned groups are:\n");
1062 list.namelist_val = 0;
1063 list.namelist_len = 0;
1064 code = pr_ListOwned(oid, &list, &more);
1066 afs_com_err(whoami, code,
1067 "; unable to get owner list for %s (id: %d)", name,
1072 for (j = 0; j < list.namelist_len; j++)
1073 printf(" %s\n", list.namelist_val[j]);
1074 if (list.namelist_val)
1075 free(list.namelist_val);
1080 free(ids.idlist_val);
1081 if (names.namelist_val)
1082 free(names.namelist_val);
1087 add_std_args(struct cmd_syndesc *ts)
1089 char test_help[AFSDIR_PATH_MAX];
1091 sprintf(test_help, "use config file in %s", AFSDIR_SERVER_ETC_DIRPATH);
1094 cmd_AddParm(ts, "-cell", CMD_SINGLE, CMD_OPTIONAL, "cell name");
1095 cmd_AddParm(ts, "-noauth", CMD_FLAG, CMD_OPTIONAL, "run unauthenticated");
1096 cmd_AddParm(ts, "-test", CMD_FLAG, CMD_OPTIONAL | CMD_HIDE, test_help);
1097 cmd_AddParm(ts, "-force", CMD_FLAG, CMD_OPTIONAL,
1098 "Continue oper despite reasonable errors");
1099 cmd_AddParm(ts, "-localauth", CMD_FLAG, CMD_OPTIONAL,
1100 "use local authentication");
1101 cmd_AddParm(ts, "-auth", CMD_FLAG, CMD_OPTIONAL,
1102 "use user's authentication (default)");
1103 cmd_AddParm(ts, "-encrypt", CMD_FLAG, CMD_OPTIONAL,
1104 "encrypt commands");
1105 cmd_AddParm(ts, "-config", CMD_SINGLE, CMD_OPTIONAL, "config location");
1109 static void add_NameOrId_args (ts)
1110 struct cmd_syndesc *ts;
1112 cmd_AddParm(ts,"-name",CMD_LIST,CMD_OPTIONAL,"user or group name");
1113 cmd_AddParm(ts,"-id",CMD_LIST,CMD_OPTIONAL,"user or group id");
1117 #include "AFS_component_version_number.c"
1120 main(int argc, char **argv)
1123 struct cmd_syndesc *ts;
1128 char *parsev[CMD_MAXPARMS];
1130 struct authstate state;
1137 WSAStartup(0x0101, &WSAjunk);
1140 #ifdef AFS_AIX32_ENV
1142 * The following signal action for AIX is necessary so that in case of a
1143 * crash (i.e. core is generated) we can include the user's data section
1144 * in the core dump. Unfortunately, by default, only a partial core is
1145 * generated which, in many cases, isn't too useful.
1147 struct sigaction nsa;
1149 sigemptyset(&nsa.sa_mask);
1150 nsa.sa_handler = SIG_DFL;
1151 nsa.sa_flags = SA_FULLDUMP;
1152 sigaction(SIGSEGV, &nsa, NULL);
1155 memset(&state, 0, sizeof(state));
1156 state.sec = 1; /* default is auth */
1158 ts = cmd_CreateSyntax("creategroup", CreateGroup, NULL,
1159 "create a new group");
1160 cmd_AddParm(ts, "-name", CMD_LIST, 0, "group name");
1161 cmd_AddParm(ts, "-owner", CMD_SINGLE, CMD_OPTIONAL, "owner of the group");
1162 cmd_AddParm(ts, "-id", CMD_LIST, CMD_OPTIONAL,
1163 "id (negated) for the group");
1165 cmd_CreateAlias(ts, "cg");
1167 ts = cmd_CreateSyntax("createuser", CreateUser, NULL, "create a new user");
1168 cmd_AddParm(ts, "-name", CMD_LIST, 0, "user name");
1169 cmd_AddParm(ts, "-id", CMD_LIST, CMD_OPTIONAL, "user id");
1171 cmd_CreateAlias(ts, "cu");
1173 ts = cmd_CreateSyntax("adduser", AddToGroup, NULL, "add a user to a group");
1174 cmd_AddParm(ts, "-user", CMD_LIST, 0, "user name");
1175 cmd_AddParm(ts, "-group", CMD_LIST, 0, "group name");
1178 ts = cmd_CreateSyntax("removeuser", RemoveFromGroup, NULL,
1179 "remove a user from a group");
1180 cmd_AddParm(ts, "-user", CMD_LIST, 0, "user name");
1181 cmd_AddParm(ts, "-group", CMD_LIST, 0, "group name");
1184 ts = cmd_CreateSyntax("membership", ListMembership, NULL,
1185 "list membership of a user or group");
1186 cmd_AddParm(ts, "-nameorid", CMD_LIST, 0, "user or group name or id");
1187 cmd_AddParm(ts, "-supergroups", CMD_FLAG, CMD_OPTIONAL, "show supergroups");
1188 cmd_AddParm(ts, "-expandgroups", CMD_FLAG, CMD_OPTIONAL, "expand super and sub group membership");
1190 cmd_CreateAlias(ts, "groups");
1192 ts = cmd_CreateSyntax("delete", Delete, NULL,
1193 "delete a user or group from database");
1194 cmd_AddParm(ts, "-nameorid", CMD_LIST, 0, "user or group name or id");
1197 ts = cmd_CreateSyntax("examine", CheckEntry, NULL, "examine an entry");
1198 cmd_AddParm(ts, "-nameorid", CMD_LIST, 0, "user or group name or id");
1200 cmd_CreateAlias(ts, "check");
1202 ts = cmd_CreateSyntax("chown", ChownGroup, NULL,
1203 "change ownership of a group");
1204 cmd_AddParm(ts, "-name", CMD_SINGLE, 0, "group name");
1205 cmd_AddParm(ts, "-owner", CMD_SINGLE, 0, "new owner");
1208 ts = cmd_CreateSyntax("rename", ChangeName, NULL, "rename user or group");
1209 cmd_AddParm(ts, "-oldname", CMD_SINGLE, 0, "old name");
1210 cmd_AddParm(ts, "-newname", CMD_SINGLE, 0, "new name");
1212 cmd_CreateAlias(ts, "chname");
1214 ts = cmd_CreateSyntax("listmax", ListMax, NULL, "list max id");
1217 ts = cmd_CreateSyntax("setmax", SetMaxCommand, NULL, "set max id");
1218 cmd_AddParm(ts, "-group", CMD_SINGLE, CMD_OPTIONAL, "group max");
1219 cmd_AddParm(ts, "-user", CMD_SINGLE, CMD_OPTIONAL, "user max");
1222 ts = cmd_CreateSyntax("setfields", SetFields, NULL,
1223 "set fields for an entry");
1224 cmd_AddParm(ts, "-nameorid", CMD_LIST, 0, "user or group name or id");
1225 cmd_AddParm(ts, "-access", CMD_SINGLE, CMD_OPTIONAL, "set privacy flags");
1226 cmd_AddParm(ts, "-groupquota", CMD_SINGLE, CMD_OPTIONAL,
1227 "set limit on group creation");
1229 cmd_AddParm(ts, "-userquota", CMD_SINGLE, CMD_OPTIONAL,
1230 "set limit on foreign user creation");
1234 ts = cmd_CreateSyntax("listowned", ListOwned, NULL,
1235 "list groups owned by an entry or zero id gets orphaned groups");
1236 cmd_AddParm(ts, "-nameorid", CMD_LIST, 0, "user or group name or id");
1239 ts = cmd_CreateSyntax("listentries", ListEntries, NULL,
1240 "list users/groups in the protection database");
1241 cmd_AddParm(ts, "-users", CMD_FLAG, CMD_OPTIONAL, "list user entries");
1242 cmd_AddParm(ts, "-groups", CMD_FLAG, CMD_OPTIONAL, "list group entries");
1245 ts = cmd_CreateSyntax("interactive", pts_Interactive, NULL,
1246 "enter interactive mode");
1248 cmd_CreateAlias(ts, "in");
1250 ts = cmd_CreateSyntax("quit", pts_Quit, NULL, "exit program");
1253 ts = cmd_CreateSyntax("source", pts_Source, NULL, "read commands from file");
1254 cmd_AddParm(ts, "-file", CMD_SINGLE, 0, "filename");
1257 ts = cmd_CreateSyntax("sleep", pts_Sleep, NULL, "pause for a bit");
1258 cmd_AddParm(ts, "-delay", CMD_SINGLE, 0, "seconds");
1261 cmd_SetBeforeProc(GetGlobals, &state);
1265 if ((code = cmd_Dispatch(argc, argv))) {
1266 CleanUp(NULL, NULL);
1269 while (source && !finished) {
1270 if (isatty(fileno(source)))
1271 fprintf(stderr, "pts> ");
1272 if (!fgets(line, sizeof line, source)) {
1278 for (cp = line; *cp; ++cp)
1288 cmd_ParseLine(line, parsev, &parsec,
1289 sizeof(parsev) / sizeof(*parsev));
1291 afs_com_err(whoami, code, "parsing line: <%s>", line);
1295 parsev[0] = argv[0];
1296 code = cmd_Dispatch(parsec, parsev);
1298 cmd_FreeArgv(parsev);
1300 CleanUp(NULL, NULL);