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"
39 extern struct ubik_client *pruclient;
42 struct sourcestack *s_next;
49 char cell[MAXCELLCHARS];
52 static int CleanUp(struct cmd_syndesc *as, void *arock);
55 pts_Interactive(struct cmd_syndesc *as, void *arock)
63 pts_Quit(struct cmd_syndesc *as, void *arock)
70 pts_Source(struct cmd_syndesc *as, void *arock)
73 struct sourcestack *sp;
76 if (!as->parms[0].items) {
77 /* can this happen? */
80 fd = fopen(as->parms[0].items->data, "r");
82 perror(as->parms[0].items->data);
85 sp = malloc(sizeof *sp);
87 return errno ? errno : ENOMEM;
98 pts_Sleep(struct cmd_syndesc *as, void *arock)
101 if (!as->parms[0].items) {
102 /* can this happen? */
105 delay = atoi(as->parms[0].items->data);
106 #ifdef AFS_PTHREAD_ENV
117 struct sourcestack *sp;
131 /* OK, this REALLY sucks bigtime, but I can't tell who is calling
132 * afsconf_CheckAuth easily, and only *SERVERS* should be calling osi_audit
133 * anyway. It's gonna give somebody fits to debug, I know, I know.
140 win32_enableCrypt(void)
147 /* Look up configuration parameters in Registry */
148 code = RegOpenKeyEx(HKEY_LOCAL_MACHINE, AFSREG_CLT_SVC_PARAM_SUBKEY,
149 0, (IsWow64()?KEY_WOW64_64KEY:0)|KEY_QUERY_VALUE, &parmKey);
150 if (code != ERROR_SUCCESS) {
151 dummyLen = sizeof(cryptall);
152 RegQueryValueEx(parmKey, "SecurityLevel", NULL, NULL,
153 (BYTE *) &cryptall, &dummyLen);
155 RegCloseKey (parmKey);
159 #endif /* AFS_NT40_ENV */
162 GetGlobals(struct cmd_syndesc *as, void *arock)
164 struct authstate *state = (struct authstate *) arock;
173 if (!strcmp(as->name, "help"))
181 if (state->confdir == NULL) {
185 if (as->parms[16].items) {
187 cell = as->parms[16].items->data;
189 if (as->parms[17].items) { /* -noauth */
193 if (as->parms[20].items) { /* -localauth */
197 if (as->parms[21].items) { /* -auth */
201 if (as->parms[22].items /* -encrypt */
203 || win32_enableCrypt()
204 #endif /* AFS_NT40_ENV */
209 if (as->parms[18].items || as->parms[20].items) { /* -test, -localauth */
211 confdir = AFSDIR_SERVER_ETC_DIRPATH;
214 confdir = AFSDIR_SERVER_ETC_DIRPATH;
216 confdir = AFSDIR_CLIENT_ETC_DIRPATH;
219 if (as->parms[23].items) { /* -config */
221 confdir = as->parms[23].items->data;
226 code = pr_Initialize(sec, confdir, cell);
231 afs_com_err(whoami, code, "while initializing");
235 state->confdir = confdir;
236 if (cell && cell != state->cell)
237 strncpy(state->cell, cell, MAXCELLCHARS-1);
240 if (as->parms[19].items)
247 CleanUp(struct cmd_syndesc *as, void *arock)
249 if (as && !strcmp(as->name, "help"))
252 /* Need to shutdown the ubik_client & other connections */
260 CreateGroup(struct cmd_syndesc *as, void *arock)
265 struct cmd_item *namei;
266 struct cmd_item *idi;
268 namei = as->parms[0].items;
269 idi = as->parms[2].items;
270 if (as->parms[1].items)
271 owner = as->parms[1].items->data;
277 code = util_GetInt32(idi->data, &id);
279 afs_com_err(whoami, code, "because group id was: '%s'",
284 fprintf(stderr, "0 isn't a valid group id; aborting\n");
289 afs_com_err(whoami, code, "because group id %d was not negative",
298 code = pr_CreateGroup(namei->data, owner, &id);
301 afs_com_err(whoami, code,
302 "; unable to create group %s with id %d%s%s%s%s",
303 namei->data, id, owner ? " owned by '" : "",
304 owner ? owner : "", owner ? "'" : "",
305 (force ? " (ignored)" : ""));
307 afs_com_err(whoami, code, "; unable to create group %s %s",
308 namei->data, (force ? "(ignored)" : ""));
312 printf("group %s has id %d\n", namei->data, id);
319 CreateUser(struct cmd_syndesc *as, void *arock)
323 struct cmd_item *namei;
324 struct cmd_item *idi;
326 namei = as->parms[0].items;
327 idi = as->parms[1].items;
331 code = util_GetInt32(idi->data, &id);
333 afs_com_err(whoami, code, "because id was: '%s'", idi->data);
337 fprintf(stderr, "0 isn't a valid user id; aborting\n");
342 afs_com_err(whoami, code, "because user id %d was not positive",
350 code = pr_CreateUser(namei->data, &id);
353 afs_com_err(whoami, code,
354 "; unable to create user %s with id %d %s",
355 namei->data, id, (force ? "(ignored)" : ""));
357 afs_com_err(whoami, code, "; unable to create user %s %s",
358 namei->data, (force ? "(ignored)" : ""));
362 printf("User %s has id %d\n", namei->data, id);
371 GetNameOrId(struct cmd_syndesc *as, struct idlist *lids, struct namelist *lnames)
378 if (!(as->parms[0].items || as->parms[1].items)) {
379 afs_com_err(whoami, 0, "must specify either a name or an id.");
382 if (as->parms[0].items && as->parms[1].items) {
383 afs_com_err(whoami, 0, "can't specify both a name and id.");
388 lids->idlist_len = 0;
389 lids->idlist_val = 0;
391 if (as->parms[0].items) { /* name */
392 struct namelist names; /* local copy, if not ret. names */
395 names.namelist_val = 0; /* so it gets freed later if needed */
401 n = 0; /* count names */
402 for (i = as->parms[0].items; i; i = i->next)
404 nl->namelist_val = malloc(n * PR_MAXNAMELEN);
405 nl->namelist_len = n;
407 for (i = as->parms[0].items; i; i = i->next)
408 strncpy(nl->namelist_val[n++], i->data, PR_MAXNAMELEN);
410 code = pr_NameToId(nl, lids);
412 afs_com_err(whoami, code, "so couldn't look up names");
414 for (n = 0; n < lids->idlist_len; n++) {
415 if ((lids->idlist_val[n] == ANONYMOUSID)) {
416 afs_com_err(whoami, PRNOENT, "so couldn't look up id for %s",
417 nl->namelist_val[n]);
421 /* treat things as working if any of the lookups worked */
426 if (names.namelist_val)
427 free(names.namelist_val);
428 } else if (as->parms[1].items) { /* id */
430 for (i = as->parms[1].items; i; i = i->next)
432 lids->idlist_val = malloc(n * sizeof(afs_int32));
433 lids->idlist_len = n;
435 for (i = as->parms[1].items; i; i = i->next) {
436 code = util_GetInt32(i->data, &lids->idlist_val[n]);
438 afs_com_err(whoami, code =
439 PRNOENT, "because a bogus id '%s' was specified",
443 if (!code && lnames) {
444 lnames->namelist_val = 0;
445 lnames->namelist_len = 0;
446 code = pr_IdToName(lids, lnames);
448 afs_com_err(whoami, code, "translating ids");
452 if (lids->idlist_val)
453 free(lids->idlist_val);
462 GetNameOrId(struct cmd_syndesc *as, struct idlist *lids,
463 struct namelist *lnames)
466 int n = 0, nd = 0, nm = 0, id, x;
468 struct namelist names, tnames; /* local copy, if not ret. names */
469 struct idlist ids, tids; /* local copy, if not ret. ids */
472 /* Initialise our outputs */
473 memset(lids, 0, sizeof(struct idlist));
475 memset(lnames, 0, sizeof(struct namelist));
477 for (i = as->parms[0].items; i; i = i->next)
480 /* Nothing to do, so bail */
484 lids->idlist_val = malloc(n * sizeof(afs_int32));
485 lids->idlist_len = n;
486 ids.idlist_val = malloc(n * sizeof(afs_int32));
488 names.namelist_val = malloc(n * PR_MAXNAMELEN);
489 names.namelist_len = n;
491 lnames->namelist_val = malloc(n * PR_MAXNAMELEN);
492 lnames->namelist_len = 0;
494 for (i = as->parms[0].items; i; i = i->next) {
495 tnames.namelist_val = malloc(PR_MAXNAMELEN);
496 strncpy(tnames.namelist_val[0], i->data, PR_MAXNAMELEN);
497 tnames.namelist_len = 1;
500 code = pr_NameToId(&tnames, &tids);
501 if ((!code && (tids.idlist_val[0] != 32766))
502 || (code = util_GetInt32(i->data, &id))) {
503 /* Assume it's a name instead */
504 strncpy(names.namelist_val[nm++], i->data, PR_MAXNAMELEN);
506 ids.idlist_val[nd++] = id;
508 free(tnames.namelist_val);
510 names.namelist_len = nm;
512 tids.idlist_len = nd = nm = 0;
514 code = pr_NameToId(&names, &tids);
516 afs_com_err(whoami, code, "so couldn't look up names");
518 for (n = 0; n < tids.idlist_len; n++) {
519 if (tids.idlist_val[n] == ANONYMOUSID) {
520 afs_com_err(whoami, PRNOENT, "so couldn't look up id for %s",
521 names.namelist_val[n]);
524 lids->idlist_val[nd] = tids.idlist_val[n];
526 strcpy(lnames->namelist_val[nd], names.namelist_val[n]);
530 for (x = 0; x < ids.idlist_len; x++) {
531 lids->idlist_val[nd + x] = ids.idlist_val[x];
533 lids->idlist_len = nd + x;
534 if (!code && lnames) {
535 tnames.namelist_val = 0;
536 tnames.namelist_len = 0;
537 code = pr_IdToName(&ids, &tnames);
539 afs_com_err(whoami, code, "translating ids");
543 for (x = 0; x < ids.idlist_len; x++)
544 strcpy(lnames->namelist_val[nd + x], tnames.namelist_val[x]);
545 lnames->namelist_len = nd + x;
549 /* treat things as working if any of the lookups worked */
553 if (lids->idlist_val)
554 free(lids->idlist_val);
562 AddToGroup(struct cmd_syndesc *as, void *arock)
565 struct cmd_item *u, *g;
567 for (u = as->parms[0].items; u; u = u->next) {
568 for (g = as->parms[1].items; g; g = g->next) {
569 code = pr_AddToGroup(u->data, g->data);
571 afs_com_err(whoami, code,
572 "; unable to add user %s to group %s %s", u->data,
573 g->data, (force ? "(ignored)" : ""));
583 RemoveFromGroup(struct cmd_syndesc *as, void *arock)
586 struct cmd_item *u, *g;
588 for (u = as->parms[0].items; u; u = u->next) {
589 for (g = as->parms[1].items; g; g = g->next) {
590 code = pr_RemoveUserFromGroup(u->data, g->data);
592 afs_com_err(whoami, code,
593 "; unable to remove user %s from group %s %s",
594 u->data, g->data, (force ? "(ignored)" : ""));
604 ListMembership(struct cmd_syndesc *as, void *arock)
613 if (GetNameOrId(as, &ids, &names))
616 for (i = 0; i < ids.idlist_len; i++) {
617 afs_int32 id = ids.idlist_val[i];
618 char *name = names.namelist_val[i];
620 if (id == ANONYMOUSID)
621 continue; /* bad entry */
623 list.namelist_val = 0;
624 list.namelist_len = 0;
625 if (as->parms[2].items) { /* -expandgroups */
626 code = pr_IDListExpandedMembers(id, &list);
630 code = pr_IDListMembers(id, &list);
633 afs_com_err(whoami, code, "; unable to get membership of %s (id: %d)",
638 printf("Members of %s (id: %d) are:\n", name, id);
640 printf("Groups %s (id: %d) is a member of:\n", name, id);
642 for (j = 0; j < list.namelist_len; j++)
643 printf(" %s\n", list.namelist_val[j]);
644 if (list.namelist_val)
645 free(list.namelist_val);
646 if (as->parms[1].items && id < 0) { /* -supergroups */
647 list.namelist_val = 0;
648 list.namelist_len = 0;
649 code = pr_ListSuperGroups(ids.idlist_val[i], &list);
650 if (code == RXGEN_OPCODE) {
651 continue; /* server does not support supergroups */
652 } else if (code != 0) {
653 afs_com_err(whoami, code,
654 "; unable to get supergroups of %s (id: %d)",
658 printf("Groups %s (id: %d) is a member of:\n", name, id);
659 for (j = 0; j < list.namelist_len; j++)
660 printf(" %s\n", list.namelist_val[j]);
661 if (list.namelist_val)
662 free(list.namelist_val);
666 free(ids.idlist_val);
667 if (names.namelist_val)
668 free(names.namelist_val);
673 Delete(struct cmd_syndesc *as, void *arock)
680 if (GetNameOrId(as, &ids, &names))
683 for (i = 0; i < ids.idlist_len; i++) {
684 afs_int32 id = ids.idlist_val[i];
685 char *name = names.namelist_val[i];
687 if (id == ANONYMOUSID)
690 code = pr_DeleteByID(id);
692 afs_com_err(whoami, code, "deleting %s (id: %d) %s", name, id,
693 (force ? "(ignored)" : ""));
699 free(ids.idlist_val);
700 if (names.namelist_val)
701 free(names.namelist_val);
705 /* access bit translation info */
707 char *flags_upcase = "SOMA "; /* legal all access values */
708 char *flags_dncase = "s mar"; /* legal member acces values */
709 int flags_shift[5] = { 2, 1, 2, 2, 1 }; /* bits for each */
712 CheckEntry(struct cmd_syndesc *as, void *arock)
716 int i, flag = 0, admin = 0;
717 namelist lnames, names;
720 struct prcheckentry aentry;
722 if (GetNameOrId(as, &ids, &names))
726 lids.idlist_val = malloc(sizeof(afs_int32) * 2);
727 lnames.namelist_len = 0;
728 lnames.namelist_val = 0;
730 for (i = 0; i < ids.idlist_len; i++) {
731 afs_int32 id = ids.idlist_val[i];
733 if (id == ANONYMOUSID)
737 code = pr_ListEntry(id, &aentry);
740 afs_com_err(whoami, code, "; unable to find entry for (id: %d)", id);
744 lids.idlist_val[0] = aentry.owner;
745 lids.idlist_val[1] = aentry.creator;
746 code = pr_IdToName(&lids, &lnames);
749 afs_com_err(whoami, code,
750 "translating owner (%d) and creator (%d) ids",
751 aentry.owner, aentry.creator);
754 printf("Name: %s, id: %d, owner: %s, creator: %s,\n", aentry.name,
755 aentry.id, lnames.namelist_val[0], lnames.namelist_val[1]);
756 printf(" membership: %d", aentry.count);
759 afs_int32 flags = aentry.flags;
762 access[5] = 0; /* null-terminate the string */
763 for (j = 4; j >= 0; j--) {
782 printf(", flags: %s", access);
784 if (aentry.id == SYSADMINID)
786 else if (!pr_IsAMemberOf(aentry.name, "system:administrators", &flag)) {
791 printf(", group quota: unlimited");
793 printf(", group quota: %d", aentry.ngroups);
797 if (lnames.namelist_val)
798 free(lnames.namelist_val);
800 free(lids.idlist_val);
802 free(ids.idlist_val);
808 ListEntries(struct cmd_syndesc *as, void *arock)
811 afs_int32 flag, startindex, nentries, nextstartindex;
812 struct prlistentries *entriesp = 0, *e;
816 if (as->parms[1].items)
818 if (as->parms[0].items)
821 printf("Name ID Owner Creator\n");
822 for (startindex = 0; startindex != -1; startindex = nextstartindex) {
824 pr_ListEntries(flag, startindex, &nentries, &entriesp,
827 afs_com_err(whoami, code, "; unable to list entries");
833 /* Now display each of the entries we read */
834 for (i = 0, e = entriesp; i < nentries; i++, e++) {
835 printf("%-25s %6d %6d %7d \n", e->name, e->id, e->owner,
845 ChownGroup(struct cmd_syndesc *as, void *arock)
851 name = as->parms[0].items->data;
852 owner = as->parms[1].items->data;
853 code = pr_ChangeEntry(name, "", 0, owner);
855 afs_com_err(whoami, code, "; unable to change owner of %s to %s", name,
861 ChangeName(struct cmd_syndesc *as, void *arock)
867 oldname = as->parms[0].items->data;
868 newname = as->parms[1].items->data;
869 code = pr_ChangeEntry(oldname, newname, 0, "");
871 afs_com_err(whoami, code, "; unable to change name of %s to %s", oldname,
877 ListMax(struct cmd_syndesc *as, void *arock)
880 afs_int32 maxUser, maxGroup;
882 code = pr_ListMaxUserId(&maxUser);
884 afs_com_err(whoami, code, "getting maximum user id");
886 code = pr_ListMaxGroupId(&maxGroup);
888 afs_com_err(whoami, code, "getting maximum group id");
890 printf("Max user id is %d and max group id is %d.\n", maxUser,
898 SetMaxCommand(struct cmd_syndesc *as, void *arock)
904 if (as->parms[1].items) {
906 code = util_GetInt32(as->parms[1].items->data, &maxid);
908 afs_com_err(whoami, code, "because id was: '%s'",
909 as->parms[1].items->data);
911 code = pr_SetMaxUserId(maxid);
913 afs_com_err(whoami, code, "so couldn't set Max User Id to %d",
917 if (as->parms[0].items) {
919 code = util_GetInt32(as->parms[0].items->data, &maxid);
921 afs_com_err(whoami, code, "because id was: '%s'",
922 as->parms[0].items->data);
924 code = pr_SetMaxGroupId(maxid);
926 afs_com_err(whoami, code, "so couldn't set Max Group Id to %d",
930 if (!as->parms[0].items && !as->parms[1].items) {
932 fprintf(stderr, "Must specify at least one of group or user.\n");
938 SetFields(struct cmd_syndesc *as, void *arock)
944 afs_int32 mask, flags=0, ngroups, nusers;
946 if (GetNameOrId(as, &ids, &names))
953 if (as->parms[1].items) { /* privacy bits */
954 char *access = as->parms[1].items->data;
957 if (strpbrk(access, "76543210") != 0) { /* all octal digits */
958 sscanf(access, "%lo", (long unsigned int *) &flags);
959 } else { /* interpret flag bit names */
960 if (strlen(access) != 5) {
962 fprintf(stderr, "Access bits must be of the form 'somar', not %s\n",
966 if (strpbrk(access, "somar-") == 0)
969 for (i = 0; i < 5; i++) {
970 if (access[i] == flags_upcase[i])
972 else if (access[i] == flags_dncase[i])
974 else if (access[i] == '-')
978 "Access bits out of order or illegal:\n must be a combination of letters from '%s' or '%s' or hyphen, not %s\n",
979 flags_upcase, flags_dncase, access);
982 flags <<= flags_shift[i];
983 if (flags_shift[i] == 1) {
990 mask |= PR_SF_ALLBITS;
992 if (as->parms[2].items) { /* limitgroups */
993 code = util_GetInt32(as->parms[2].items->data, &ngroups);
995 afs_com_err(whoami, code, "because ngroups was: '%s'",
996 as->parms[2].items->data);
999 mask |= PR_SF_NGROUPS;
1002 for (i = 0; i < ids.idlist_len; i++) {
1003 afs_int32 id = ids.idlist_val[i];
1004 char *name = names.namelist_val[i];
1005 if (id == ANONYMOUSID)
1007 code = pr_SetFieldsEntry(id, mask, flags, ngroups, nusers);
1009 afs_com_err(whoami, code, "; unable to set fields for %s (id: %d)",
1015 free(ids.idlist_val);
1016 if (names.namelist_val)
1017 free(names.namelist_val);
1022 ListOwned(struct cmd_syndesc *as, void *arock)
1031 if (GetNameOrId(as, &ids, &names))
1034 for (i = 0; i < ids.idlist_len; i++) {
1035 afs_int32 oid = ids.idlist_val[i];
1036 char *name = names.namelist_val[i];
1038 if (oid == ANONYMOUSID)
1042 printf("Groups owned by %s (id: %d) are:\n", name, oid);
1044 printf("Orphaned groups are:\n");
1047 list.namelist_val = 0;
1048 list.namelist_len = 0;
1049 code = pr_ListOwned(oid, &list, &more);
1051 afs_com_err(whoami, code,
1052 "; unable to get owner list for %s (id: %d)", name,
1057 for (j = 0; j < list.namelist_len; j++)
1058 printf(" %s\n", list.namelist_val[j]);
1059 if (list.namelist_val)
1060 free(list.namelist_val);
1065 free(ids.idlist_val);
1066 if (names.namelist_val)
1067 free(names.namelist_val);
1072 add_std_args(struct cmd_syndesc *ts)
1076 if (asprintf(&test_help, "use config file in %s",
1077 AFSDIR_SERVER_ETC_DIRPATH) < 0) {
1078 test_help = strdup("use server config file");
1082 cmd_AddParm(ts, "-cell", CMD_SINGLE, CMD_OPTIONAL, "cell name");
1083 cmd_AddParm(ts, "-noauth", CMD_FLAG, CMD_OPTIONAL, "run unauthenticated");
1084 cmd_AddParm(ts, "-test", CMD_FLAG, CMD_OPTIONAL | CMD_HIDE, test_help);
1085 cmd_AddParm(ts, "-force", CMD_FLAG, CMD_OPTIONAL,
1086 "Continue oper despite reasonable errors");
1087 cmd_AddParm(ts, "-localauth", CMD_FLAG, CMD_OPTIONAL,
1088 "use local authentication");
1089 cmd_AddParm(ts, "-auth", CMD_FLAG, CMD_OPTIONAL,
1090 "use user's authentication (default)");
1091 cmd_AddParm(ts, "-encrypt", CMD_FLAG, CMD_OPTIONAL,
1092 "encrypt commands");
1093 cmd_AddParm(ts, "-config", CMD_SINGLE, CMD_OPTIONAL, "config location");
1098 static void add_NameOrId_args (ts)
1099 struct cmd_syndesc *ts;
1101 cmd_AddParm(ts,"-name",CMD_LIST,CMD_OPTIONAL,"user or group name");
1102 cmd_AddParm(ts,"-id",CMD_LIST,CMD_OPTIONAL,"user or group id");
1106 #include "AFS_component_version_number.c"
1109 main(int argc, char **argv)
1112 struct cmd_syndesc *ts;
1117 char *parsev[CMD_MAXPARMS];
1119 struct authstate state;
1126 WSAStartup(0x0101, &WSAjunk);
1129 #ifdef AFS_AIX32_ENV
1131 * The following signal action for AIX is necessary so that in case of a
1132 * crash (i.e. core is generated) we can include the user's data section
1133 * in the core dump. Unfortunately, by default, only a partial core is
1134 * generated which, in many cases, isn't too useful.
1136 struct sigaction nsa;
1138 sigemptyset(&nsa.sa_mask);
1139 nsa.sa_handler = SIG_DFL;
1140 nsa.sa_flags = SA_FULLDUMP;
1141 sigaction(SIGSEGV, &nsa, NULL);
1144 memset(&state, 0, sizeof(state));
1145 state.sec = 1; /* default is auth */
1147 ts = cmd_CreateSyntax("creategroup", CreateGroup, NULL, 0,
1148 "create a new group");
1149 cmd_AddParm(ts, "-name", CMD_LIST, 0, "group name");
1150 cmd_AddParm(ts, "-owner", CMD_SINGLE, CMD_OPTIONAL, "owner of the group");
1151 cmd_AddParm(ts, "-id", CMD_LIST, CMD_OPTIONAL,
1152 "id (negated) for the group");
1154 cmd_CreateAlias(ts, "cg");
1156 ts = cmd_CreateSyntax("createuser", CreateUser, NULL, 0, "create a new user");
1157 cmd_AddParm(ts, "-name", CMD_LIST, 0, "user name");
1158 cmd_AddParm(ts, "-id", CMD_LIST, CMD_OPTIONAL, "user id");
1160 cmd_CreateAlias(ts, "cu");
1162 ts = cmd_CreateSyntax("adduser", AddToGroup, NULL, 0, "add a user to a group");
1163 cmd_AddParm(ts, "-user", CMD_LIST, 0, "user name");
1164 cmd_AddParm(ts, "-group", CMD_LIST, 0, "group name");
1167 ts = cmd_CreateSyntax("removeuser", RemoveFromGroup, NULL, 0,
1168 "remove a user from a group");
1169 cmd_AddParm(ts, "-user", CMD_LIST, 0, "user name");
1170 cmd_AddParm(ts, "-group", CMD_LIST, 0, "group name");
1173 ts = cmd_CreateSyntax("membership", ListMembership, NULL, 0,
1174 "list membership of a user or group");
1175 cmd_AddParm(ts, "-nameorid", CMD_LIST, 0, "user or group name or id");
1176 cmd_AddParm(ts, "-supergroups", CMD_FLAG, CMD_OPTIONAL, "show supergroups");
1177 cmd_AddParm(ts, "-expandgroups", CMD_FLAG, CMD_OPTIONAL, "expand super and sub group membership");
1179 cmd_CreateAlias(ts, "groups");
1181 ts = cmd_CreateSyntax("delete", Delete, NULL, 0,
1182 "delete a user or group from database");
1183 cmd_AddParm(ts, "-nameorid", CMD_LIST, 0, "user or group name or id");
1186 ts = cmd_CreateSyntax("examine", CheckEntry, NULL, 0, "examine an entry");
1187 cmd_AddParm(ts, "-nameorid", CMD_LIST, 0, "user or group name or id");
1189 cmd_CreateAlias(ts, "check");
1191 ts = cmd_CreateSyntax("chown", ChownGroup, NULL, 0,
1192 "change ownership of a group");
1193 cmd_AddParm(ts, "-name", CMD_SINGLE, 0, "group name");
1194 cmd_AddParm(ts, "-owner", CMD_SINGLE, 0, "new owner");
1197 ts = cmd_CreateSyntax("rename", ChangeName, NULL, 0, "rename user or group");
1198 cmd_AddParm(ts, "-oldname", CMD_SINGLE, 0, "old name");
1199 cmd_AddParm(ts, "-newname", CMD_SINGLE, 0, "new name");
1201 cmd_CreateAlias(ts, "chname");
1203 ts = cmd_CreateSyntax("listmax", ListMax, NULL, 0, "list max id");
1206 ts = cmd_CreateSyntax("setmax", SetMaxCommand, NULL, 0, "set max id");
1207 cmd_AddParm(ts, "-group", CMD_SINGLE, CMD_OPTIONAL, "group max");
1208 cmd_AddParm(ts, "-user", CMD_SINGLE, CMD_OPTIONAL, "user max");
1211 ts = cmd_CreateSyntax("setfields", SetFields, NULL, 0,
1212 "set fields for an entry");
1213 cmd_AddParm(ts, "-nameorid", CMD_LIST, 0, "user or group name or id");
1214 cmd_AddParm(ts, "-access", CMD_SINGLE, CMD_OPTIONAL, "set privacy flags");
1215 cmd_AddParm(ts, "-groupquota", CMD_SINGLE, CMD_OPTIONAL,
1216 "set limit on group creation");
1219 ts = cmd_CreateSyntax("listowned", ListOwned, NULL, 0,
1220 "list groups owned by an entry or zero id gets orphaned groups");
1221 cmd_AddParm(ts, "-nameorid", CMD_LIST, 0, "user or group name or id");
1224 ts = cmd_CreateSyntax("listentries", ListEntries, NULL, 0,
1225 "list users/groups in the protection database");
1226 cmd_AddParm(ts, "-users", CMD_FLAG, CMD_OPTIONAL, "list user entries");
1227 cmd_AddParm(ts, "-groups", CMD_FLAG, CMD_OPTIONAL, "list group entries");
1230 ts = cmd_CreateSyntax("interactive", pts_Interactive, NULL, 0,
1231 "enter interactive mode");
1233 cmd_CreateAlias(ts, "in");
1235 ts = cmd_CreateSyntax("quit", pts_Quit, NULL, 0, "exit program");
1238 ts = cmd_CreateSyntax("source", pts_Source, NULL, 0, "read commands from file");
1239 cmd_AddParm(ts, "-file", CMD_SINGLE, 0, "filename");
1242 ts = cmd_CreateSyntax("sleep", pts_Sleep, NULL, 0, "pause for a bit");
1243 cmd_AddParm(ts, "-delay", CMD_SINGLE, 0, "seconds");
1246 cmd_SetBeforeProc(GetGlobals, &state);
1250 if (cmd_Dispatch(argc, argv)) {
1251 CleanUp(NULL, NULL);
1254 while (source && !finished) {
1255 if (isatty(fileno(source)))
1256 fprintf(stderr, "pts> ");
1257 if (!fgets(line, sizeof line, source)) {
1263 for (cp = line; *cp; ++cp)
1273 cmd_ParseLine(line, parsev, &parsec,
1274 sizeof(parsev) / sizeof(*parsev));
1276 afs_com_err(whoami, code, "parsing line: <%s>", line);
1280 parsev[0] = argv[0];
1281 cmd_Dispatch(parsec, parsev);
1283 cmd_FreeArgv(parsev);
1285 CleanUp(NULL, NULL);