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>
20 #include <sys/types.h>
25 #include <WINNT/afsevent.h>
26 #include <WINNT/afsreg.h>
28 #include <netinet/in.h>
30 #include <afs/cellconfig.h>
36 #include "ptprototypes.h"
37 #include <afs/afsutil.h>
38 #include <afs/com_err.h>
47 extern struct ubik_client *pruclient;
50 struct sourcestack *s_next;
57 char cell[MAXCELLCHARS];
60 static int CleanUp(struct cmd_syndesc *as, void *arock);
63 pts_Interactive(struct cmd_syndesc *as, void *arock)
71 pts_Quit(struct cmd_syndesc *as, void *arock)
78 pts_Source(struct cmd_syndesc *as, void *arock)
81 struct sourcestack *sp;
84 if (!as->parms[0].items) {
85 /* can this happen? */
88 fd = fopen(as->parms[0].items->data, "r");
90 perror(as->parms[0].items->data);
93 sp = (struct sourcestack *)malloc(sizeof *sp);
95 return errno ? errno : ENOMEM;
106 pts_Sleep(struct cmd_syndesc *as, void *arock)
109 if (!as->parms[0].items) {
110 /* can this happen? */
113 delay = atoi(as->parms[0].items->data);
114 #ifdef AFS_PTHREAD_ENV
125 register struct sourcestack *sp;
139 /* OK, this REALLY sucks bigtime, but I can't tell who is calling
140 * afsconf_CheckAuth easily, and only *SERVERS* should be calling osi_audit
141 * anyway. It's gonna give somebody fits to debug, I know, I know.
148 win32_enableCrypt(void)
155 /* Look up configuration parameters in Registry */
156 code = RegOpenKeyEx(HKEY_LOCAL_MACHINE, AFSREG_CLT_SVC_PARAM_SUBKEY,
157 0, (IsWow64()?KEY_WOW64_64KEY:0)|KEY_QUERY_VALUE, &parmKey);
158 if (code != ERROR_SUCCESS) {
159 dummyLen = sizeof(cryptall);
160 RegQueryValueEx(parmKey, "SecurityLevel", NULL, NULL,
161 (BYTE *) &cryptall, &dummyLen);
163 RegCloseKey (parmKey);
167 #endif /* AFS_NT40_ENV */
170 GetGlobals(struct cmd_syndesc *as, void *arock)
172 struct authstate *state = (struct authstate *) arock;
181 if (!strcmp(as->name, "help"))
189 if (state->confdir == NULL) {
193 if (as->parms[16].items) {
195 cell = as->parms[16].items->data;
197 if (as->parms[17].items) { /* -noauth */
201 if (as->parms[20].items) { /* -localauth */
205 if (as->parms[21].items) { /* -auth */
209 if (as->parms[22].items /* -encrypt */
211 || win32_enableCrypt()
212 #endif /* AFS_NT40_ENV */
217 if (as->parms[18].items || as->parms[20].items) { /* -test, -localauth */
219 confdir = AFSDIR_SERVER_ETC_DIRPATH;
222 confdir = AFSDIR_SERVER_ETC_DIRPATH;
224 confdir = AFSDIR_CLIENT_ETC_DIRPATH;
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)
264 register afs_int32 code;
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'",
287 afs_com_err(whoami, code, "because group id %d was not negative",
293 printf("0 isn't a valid user id; aborting\n");
301 code = pr_CreateGroup(namei->data, owner, &id);
304 afs_com_err(whoami, code,
305 "; unable to create group %s with id %d%s%s%s%s",
306 namei->data, id, owner ? " owned by '" : "",
307 owner ? owner : "", owner ? "'" : "",
308 (force ? " (ignored)" : ""));
310 afs_com_err(whoami, code, "; unable to create group %s %s",
311 namei->data, (force ? "(ignored)" : ""));
315 printf("group %s has id %d\n", namei->data, id);
322 CreateUser(struct cmd_syndesc *as, void *arock)
324 register afs_int32 code;
326 struct cmd_item *namei;
327 struct cmd_item *idi;
329 namei = as->parms[0].items;
330 idi = as->parms[1].items;
334 code = util_GetInt32(idi->data, &id);
336 afs_com_err(whoami, code, "because id was: '%s'", idi->data);
340 printf("0 isn't a valid user id; aborting\n");
347 code = pr_CreateUser(namei->data, &id);
350 afs_com_err(whoami, code,
351 "; unable to create user %s with id %d %s",
352 namei->data, id, (force ? "(ignored)" : ""));
354 afs_com_err(whoami, code, "; unable to create user %s %s",
355 namei->data, (force ? "(ignored)" : ""));
359 printf("User %s has id %d\n", namei->data, id);
368 GetNameOrId(struct cmd_syndesc *as, struct idlist *lids, struct namelist *lnames)
370 register afs_int32 code = 0;
375 if (!(as->parms[0].items || as->parms[1].items)) {
376 afs_com_err(whoami, 0, "must specify either a name or an id.");
379 if (as->parms[0].items && as->parms[1].items) {
380 afs_com_err(whoami, 0, "can't specify both a name and id.");
385 lids->idlist_len = 0;
386 lids->idlist_val = 0;
388 if (as->parms[0].items) { /* name */
389 struct namelist names; /* local copy, if not ret. names */
392 names.namelist_val = 0; /* so it gets freed later if needed */
398 n = 0; /* count names */
399 for (i = as->parms[0].items; i; i = i->next)
401 nl->namelist_val = (prname *) malloc(n * PR_MAXNAMELEN);
402 nl->namelist_len = n;
404 for (i = as->parms[0].items; i; i = i->next)
405 strncpy(nl->namelist_val[n++], i->data, PR_MAXNAMELEN);
407 code = pr_NameToId(nl, lids);
409 afs_com_err(whoami, code, "so couldn't look up names");
411 for (n = 0; n < lids->idlist_len; n++) {
412 if ((lids->idlist_val[n] == ANONYMOUSID)) {
413 afs_com_err(whoami, PRNOENT, "so couldn't look up id for %s",
414 nl->namelist_val[n]);
418 /* treat things as working if any of the lookups worked */
423 if (names.namelist_val)
424 free(names.namelist_val);
425 } else if (as->parms[1].items) { /* id */
427 for (i = as->parms[1].items; i; i = i->next)
429 lids->idlist_val = (afs_int32 *) malloc(n * sizeof(afs_int32));
430 lids->idlist_len = n;
432 for (i = as->parms[1].items; i; i = i->next) {
433 code = util_GetInt32(i->data, &lids->idlist_val[n]);
435 afs_com_err(whoami, code =
436 PRNOENT, "because a bogus id '%s' was specified",
440 if (!code && lnames) {
441 lnames->namelist_val = 0;
442 lnames->namelist_len = 0;
443 code = pr_IdToName(lids, lnames);
445 afs_com_err(whoami, code, "translating ids");
449 if (lids->idlist_val)
450 free(lids->idlist_val);
459 GetNameOrId(struct cmd_syndesc *as, struct idlist *lids,
460 struct namelist *lnames)
462 register afs_int32 code = 0;
463 int n = 0, nd = 0, nm = 0, id, x;
465 struct namelist names, tnames; /* local copy, if not ret. names */
466 struct idlist ids, tids; /* local copy, if not ret. ids */
469 for (i = as->parms[0].items; i; i = i->next)
471 lids->idlist_val = (afs_int32 *) malloc(n * sizeof(afs_int32));
472 lids->idlist_len = n;
473 ids.idlist_val = (afs_int32 *) malloc(n * sizeof(afs_int32));
475 names.namelist_val = (prname *) malloc(n * PR_MAXNAMELEN);
476 names.namelist_len = n;
478 lnames->namelist_val = (prname *) malloc(n * PR_MAXNAMELEN);
479 lnames->namelist_len = 0;
481 for (i = as->parms[0].items; i; i = i->next) {
482 tnames.namelist_val = (prname *) malloc(PR_MAXNAMELEN);
483 strncpy(tnames.namelist_val[0], i->data, PR_MAXNAMELEN);
484 tnames.namelist_len = 1;
487 code = pr_NameToId(&tnames, &tids);
488 if ((!code && (tids.idlist_val[0] != 32766))
489 || (code = util_GetInt32(i->data, &id))) {
490 /* Assume it's a name instead */
491 strncpy(names.namelist_val[nm++], i->data, PR_MAXNAMELEN);
493 ids.idlist_val[nd++] = id;
495 free(tnames.namelist_val);
497 names.namelist_len = nm;
499 tids.idlist_len = nd = nm = 0;
501 code = pr_NameToId(&names, &tids);
503 afs_com_err(whoami, code, "so couldn't look up names");
505 for (n = 0; n < tids.idlist_len; n++) {
506 if ((tids.idlist_val[n] == ANONYMOUSID)) {
507 afs_com_err(whoami, PRNOENT, "so couldn't look up id for %s",
508 names.namelist_val[n]);
511 lids->idlist_val[nd] = tids.idlist_val[n];
513 strcpy(lnames->namelist_val[nd], names.namelist_val[n]);
517 for (x = 0; x < ids.idlist_len; x++) {
518 lids->idlist_val[nd + x] = ids.idlist_val[x];
520 lids->idlist_len = nd + x;
521 if (!code && lnames) {
522 tnames.namelist_val = 0;
523 tnames.namelist_len = 0;
524 code = pr_IdToName(&ids, &tnames);
526 afs_com_err(whoami, code, "translating ids");
530 for (x = 0; x < ids.idlist_len; x++)
531 strcpy(lnames->namelist_val[nd + x], tnames.namelist_val[x]);
532 lnames->namelist_len = nd + x;
535 /* treat things as working if any of the lookups worked */
539 if (lids->idlist_val)
540 free(lids->idlist_val);
548 AddToGroup(struct cmd_syndesc *as, void *arock)
550 register afs_int32 code;
551 struct cmd_item *u, *g;
553 for (u = as->parms[0].items; u; u = u->next) {
554 for (g = as->parms[1].items; g; g = g->next) {
555 code = pr_AddToGroup(u->data, g->data);
557 afs_com_err(whoami, code,
558 "; unable to add user %s to group %s %s", u->data,
559 g->data, (force ? "(ignored)" : ""));
569 RemoveFromGroup(struct cmd_syndesc *as, void *arock)
571 register afs_int32 code;
572 struct cmd_item *u, *g;
574 for (u = as->parms[0].items; u; u = u->next) {
575 for (g = as->parms[1].items; g; g = g->next) {
576 code = pr_RemoveUserFromGroup(u->data, g->data);
578 afs_com_err(whoami, code,
579 "; unable to remove user %s from group %s %s",
580 u->data, g->data, (force ? "(ignored)" : ""));
590 ListMembership(struct cmd_syndesc *as, void *arock)
592 register afs_int32 code;
599 if (GetNameOrId(as, &ids, &names))
602 for (i = 0; i < ids.idlist_len; i++) {
603 afs_int32 id = ids.idlist_val[i];
604 char *name = names.namelist_val[i];
606 if (id == ANONYMOUSID)
607 continue; /* bad entry */
609 list.namelist_val = 0;
610 list.namelist_len = 0;
611 code = pr_IDListMembers(ids.idlist_val[i], &list);
613 afs_com_err(whoami, code, "; unable to get membership of %s (id: %d)",
618 printf("Members of %s (id: %d) are:\n", name, id);
620 printf("Groups %s (id: %d) is a member of:\n", name, id);
622 for (j = 0; j < list.namelist_len; j++)
623 printf(" %s\n", list.namelist_val[j]);
624 if (list.namelist_val)
625 free(list.namelist_val);
626 if (as->parms[1].items && id < 0) { /* -supergroups */
627 list.namelist_val = 0;
628 list.namelist_len = 0;
629 code = pr_ListSuperGroups(ids.idlist_val[i], &list);
630 if (code == RXGEN_OPCODE) {
631 continue; /* server does not support supergroups */
632 } else if (code != 0) {
633 afs_com_err(whoami, code,
634 "; unable to get supergroups of %s (id: %d)",
638 printf("Groups %s (id: %d) is a member of:\n", name, id);
639 for (j = 0; j < list.namelist_len; j++)
640 printf(" %s\n", list.namelist_val[j]);
641 if (list.namelist_val)
642 free(list.namelist_val);
646 free(ids.idlist_val);
647 if (names.namelist_val)
648 free(names.namelist_val);
653 Delete(struct cmd_syndesc *as, void *arock)
655 register afs_int32 code;
660 if (GetNameOrId(as, &ids, &names))
663 for (i = 0; i < ids.idlist_len; i++) {
664 afs_int32 id = ids.idlist_val[i];
665 char *name = names.namelist_val[i];
667 if (id == ANONYMOUSID)
670 code = pr_DeleteByID(id);
672 afs_com_err(whoami, code, "deleting %s (id: %d) %s", name, id,
673 (force ? "(ignored)" : ""));
679 free(ids.idlist_val);
680 if (names.namelist_val)
681 free(names.namelist_val);
685 /* access bit translation info */
687 char *flags_upcase = "SOMA "; /* legal all access values */
688 char *flags_dncase = "s mar"; /* legal member acces values */
689 int flags_shift[5] = { 2, 1, 2, 2, 1 }; /* bits for each */
692 CheckEntry(struct cmd_syndesc *as, void *arock)
694 register afs_int32 code;
696 int i, flag = 0, admin = 0;
697 namelist lnames, names;
700 struct prcheckentry aentry;
702 if (GetNameOrId(as, &ids, &names))
706 lids.idlist_val = (afs_int32 *) malloc(sizeof(afs_int32) * 2);
707 lnames.namelist_len = 0;
708 lnames.namelist_val = 0;
710 for (i = 0; i < ids.idlist_len; i++) {
711 afs_int32 id = ids.idlist_val[i];
713 if (id == ANONYMOUSID)
717 code = pr_ListEntry(id, &aentry);
720 afs_com_err(whoami, code, "; unable to find entry for (id: %d)", id);
724 lids.idlist_val[0] = aentry.owner;
725 lids.idlist_val[1] = aentry.creator;
726 code = pr_IdToName(&lids, &lnames);
729 afs_com_err(whoami, code,
730 "translating owner (%d) and creator (%d) ids",
731 aentry.owner, aentry.creator);
734 printf("Name: %s, id: %d, owner: %s, creator: %s,\n", aentry.name,
735 aentry.id, lnames.namelist_val[0], lnames.namelist_val[1]);
736 printf(" membership: %d", aentry.count);
739 afs_int32 flags = aentry.flags;
742 access[5] = 0; /* null-terminate the string */
743 for (j = 4; j >= 0; j--) {
762 printf(", flags: %s", access);
764 if (aentry.id == SYSADMINID)
766 else if (!pr_IsAMemberOf(aentry.name, "system:administrators", &flag)) {
771 printf(", group quota: unlimited");
773 printf(", group quota: %d", aentry.ngroups);
775 printf(", foreign user quota=%d", aentry.nusers);
780 if (lnames.namelist_val)
781 free(lnames.namelist_val);
783 free(lids.idlist_val);
785 free(ids.idlist_val);
791 ListEntries(struct cmd_syndesc *as, void *arock)
794 afs_int32 flag, startindex, nentries, nextstartindex;
795 struct prlistentries *entriesp = 0, *e;
799 if (as->parms[1].items)
801 if (as->parms[0].items)
804 printf("Name ID Owner Creator\n");
805 for (startindex = 0; startindex != -1; startindex = nextstartindex) {
807 pr_ListEntries(flag, startindex, &nentries, &entriesp,
810 afs_com_err(whoami, code, "; unable to list entries");
816 /* Now display each of the entries we read */
817 for (i = 0, e = entriesp; i < nentries; i++, e++) {
818 printf("%-25s %6d %6d %7d \n", e->name, e->id, e->owner,
828 ChownGroup(struct cmd_syndesc *as, void *arock)
830 register afs_int32 code;
834 name = as->parms[0].items->data;
835 owner = as->parms[1].items->data;
836 code = pr_ChangeEntry(name, "", 0, owner);
838 afs_com_err(whoami, code, "; unable to change owner of %s to %s", name,
844 ChangeName(struct cmd_syndesc *as, void *arock)
846 register afs_int32 code;
850 oldname = as->parms[0].items->data;
851 newname = as->parms[1].items->data;
852 code = pr_ChangeEntry(oldname, newname, 0, "");
854 afs_com_err(whoami, code, "; unable to change name of %s to %s", oldname,
860 ListMax(struct cmd_syndesc *as, void *arock)
862 register afs_int32 code;
863 afs_int32 maxUser, maxGroup;
865 code = pr_ListMaxUserId(&maxUser);
867 afs_com_err(whoami, code, "getting maximum user id");
869 code = pr_ListMaxGroupId(&maxGroup);
871 afs_com_err(whoami, code, "getting maximum group id");
873 printf("Max user id is %d and max group id is %d.\n", maxUser,
881 SetMaxCommand(struct cmd_syndesc *as, void *arock)
883 register afs_int32 code;
887 if (as->parms[1].items) {
889 code = util_GetInt32(as->parms[1].items->data, &maxid);
891 afs_com_err(whoami, code, "because id was: '%s'",
892 as->parms[1].items->data);
894 code = pr_SetMaxUserId(maxid);
896 afs_com_err(whoami, code, "so couldn't set Max User Id to %d",
900 if (as->parms[0].items) {
902 code = util_GetInt32(as->parms[0].items->data, &maxid);
904 afs_com_err(whoami, code, "because id was: '%s'",
905 as->parms[0].items->data);
907 code = pr_SetMaxGroupId(maxid);
909 afs_com_err(whoami, code, "so couldn't set Max Group Id to %d",
913 if (!as->parms[0].items && !as->parms[1].items) {
915 printf("Must specify at least one of group or user.\n");
921 SetFields(struct cmd_syndesc *as, void *arock)
923 register afs_int32 code;
927 afs_int32 mask, flags=0, ngroups, nusers;
929 if (GetNameOrId(as, &ids, &names))
936 if (as->parms[1].items) { /* privacy bits */
937 char *access = as->parms[1].items->data;
940 if (strpbrk(access, "76543210") != 0) { /* all octal digits */
941 sscanf(access, "%lo", (long unsigned int *) &flags);
942 } else { /* interpret flag bit names */
943 if (strlen(access) != 5) {
945 printf("Access bits must be of the form 'somar', not %s\n",
949 if (strpbrk(access, "somar-") == 0)
952 for (i = 0; i < 5; i++) {
953 if (access[i] == flags_upcase[i])
955 else if (access[i] == flags_dncase[i])
957 else if (access[i] == '-')
961 ("Access bits out of order or illegal:\n must be a combination of letters from '%s' or '%s' or hyphen, not %s\n",
962 flags_upcase, flags_dncase, access);
965 flags <<= flags_shift[i];
966 if (flags_shift[i] == 1) {
973 mask |= PR_SF_ALLBITS;
975 if (as->parms[2].items) { /* limitgroups */
976 code = util_GetInt32(as->parms[2].items->data, &ngroups);
978 afs_com_err(whoami, code, "because ngroups was: '%s'",
979 as->parms[2].items->data);
982 mask |= PR_SF_NGROUPS;
985 if (as->parms[3].items) { /* limitgroups */
986 code = util_GetInt32(as->parms[3].items->data, &nusers);
988 afs_com_err(whoami, code, "because nusers was: '%s'",
989 as->parms[3].items->data);
992 mask |= PR_SF_NUSERS;
996 for (i = 0; i < ids.idlist_len; i++) {
997 afs_int32 id = ids.idlist_val[i];
998 char *name = names.namelist_val[i];
999 if (id == ANONYMOUSID)
1001 code = pr_SetFieldsEntry(id, mask, flags, ngroups, nusers);
1003 afs_com_err(whoami, code, "; unable to set fields for %s (id: %d)",
1009 free(ids.idlist_val);
1010 if (names.namelist_val)
1011 free(names.namelist_val);
1016 ListOwned(struct cmd_syndesc *as, void *arock)
1018 register afs_int32 code;
1025 if (GetNameOrId(as, &ids, &names))
1028 for (i = 0; i < ids.idlist_len; i++) {
1029 afs_int32 oid = ids.idlist_val[i];
1030 char *name = names.namelist_val[i];
1032 if (oid == ANONYMOUSID)
1036 printf("Groups owned by %s (id: %d) are:\n", name, oid);
1038 printf("Orphaned groups are:\n");
1041 list.namelist_val = 0;
1042 list.namelist_len = 0;
1043 code = pr_ListOwned(oid, &list, &more);
1045 afs_com_err(whoami, code,
1046 "; unable to get owner list for %s (id: %d)", name,
1051 for (j = 0; j < list.namelist_len; j++)
1052 printf(" %s\n", list.namelist_val[j]);
1053 if (list.namelist_val)
1054 free(list.namelist_val);
1059 free(ids.idlist_val);
1060 if (names.namelist_val)
1061 free(names.namelist_val);
1066 add_std_args(struct cmd_syndesc *ts)
1068 char test_help[AFSDIR_PATH_MAX];
1070 sprintf(test_help, "use config file in %s", AFSDIR_SERVER_ETC_DIRPATH);
1073 cmd_AddParm(ts, "-cell", CMD_SINGLE, CMD_OPTIONAL, "cell name");
1074 cmd_AddParm(ts, "-noauth", CMD_FLAG, CMD_OPTIONAL, "run unauthenticated");
1075 cmd_AddParm(ts, "-test", CMD_FLAG, CMD_OPTIONAL | CMD_HIDE, test_help);
1076 cmd_AddParm(ts, "-force", CMD_FLAG, CMD_OPTIONAL,
1077 "Continue oper despite reasonable errors");
1078 cmd_AddParm(ts, "-localauth", CMD_FLAG, CMD_OPTIONAL,
1079 "use local authentication");
1080 cmd_AddParm(ts, "-auth", CMD_FLAG, CMD_OPTIONAL,
1081 "use user's authentication (default)");
1082 cmd_AddParm(ts, "-encrypt", CMD_FLAG, CMD_OPTIONAL,
1083 "encrypt commands");
1087 static void add_NameOrId_args (ts)
1088 register struct cmd_syndesc *ts;
1090 cmd_AddParm(ts,"-name",CMD_LIST,CMD_OPTIONAL,"user or group name");
1091 cmd_AddParm(ts,"-id",CMD_LIST,CMD_OPTIONAL,"user or group id");
1095 #include "AFS_component_version_number.c"
1098 main(int argc, char **argv)
1100 register afs_int32 code;
1101 register struct cmd_syndesc *ts;
1106 char *parsev[CMD_MAXPARMS];
1108 struct authstate state;
1115 WSAStartup(0x0101, &WSAjunk);
1118 #ifdef AFS_AIX32_ENV
1120 * The following signal action for AIX is necessary so that in case of a
1121 * crash (i.e. core is generated) we can include the user's data section
1122 * in the core dump. Unfortunately, by default, only a partial core is
1123 * generated which, in many cases, isn't too useful.
1125 struct sigaction nsa;
1127 sigemptyset(&nsa.sa_mask);
1128 nsa.sa_handler = SIG_DFL;
1129 nsa.sa_flags = SA_FULLDUMP;
1130 sigaction(SIGSEGV, &nsa, NULL);
1133 memset(&state, 0, sizeof(state));
1134 state.sec = 1; /* default is auth */
1136 ts = cmd_CreateSyntax("creategroup", CreateGroup, NULL,
1137 "create a new group");
1138 cmd_AddParm(ts, "-name", CMD_LIST, 0, "group name");
1139 cmd_AddParm(ts, "-owner", CMD_SINGLE, CMD_OPTIONAL, "owner of the group");
1140 cmd_AddParm(ts, "-id", CMD_LIST, CMD_OPTIONAL,
1141 "id (negated) for the group");
1143 cmd_CreateAlias(ts, "cg");
1145 ts = cmd_CreateSyntax("createuser", CreateUser, NULL, "create a new user");
1146 cmd_AddParm(ts, "-name", CMD_LIST, 0, "user name");
1147 cmd_AddParm(ts, "-id", CMD_LIST, CMD_OPTIONAL, "user id");
1149 cmd_CreateAlias(ts, "cu");
1151 ts = cmd_CreateSyntax("adduser", AddToGroup, NULL, "add a user to a group");
1152 cmd_AddParm(ts, "-user", CMD_LIST, 0, "user name");
1153 cmd_AddParm(ts, "-group", CMD_LIST, 0, "group name");
1156 ts = cmd_CreateSyntax("removeuser", RemoveFromGroup, NULL,
1157 "remove a user from a group");
1158 cmd_AddParm(ts, "-user", CMD_LIST, 0, "user name");
1159 cmd_AddParm(ts, "-group", CMD_LIST, 0, "group name");
1162 ts = cmd_CreateSyntax("membership", ListMembership, NULL,
1163 "list membership of a user or group");
1164 cmd_AddParm(ts, "-nameorid", CMD_LIST, 0, "user or group name or id");
1165 cmd_AddParm(ts, "-supergroups", CMD_FLAG, CMD_OPTIONAL, "show supergroups");
1167 cmd_CreateAlias(ts, "groups");
1169 ts = cmd_CreateSyntax("delete", Delete, NULL,
1170 "delete a user or group from database");
1171 cmd_AddParm(ts, "-nameorid", CMD_LIST, 0, "user or group name or id");
1174 ts = cmd_CreateSyntax("examine", CheckEntry, NULL, "examine an entry");
1175 cmd_AddParm(ts, "-nameorid", CMD_LIST, 0, "user or group name or id");
1177 cmd_CreateAlias(ts, "check");
1179 ts = cmd_CreateSyntax("chown", ChownGroup, NULL,
1180 "change ownership of a group");
1181 cmd_AddParm(ts, "-name", CMD_SINGLE, 0, "group name");
1182 cmd_AddParm(ts, "-owner", CMD_SINGLE, 0, "new owner");
1185 ts = cmd_CreateSyntax("rename", ChangeName, NULL, "rename user or group");
1186 cmd_AddParm(ts, "-oldname", CMD_SINGLE, 0, "old name");
1187 cmd_AddParm(ts, "-newname", CMD_SINGLE, 0, "new name");
1189 cmd_CreateAlias(ts, "chname");
1191 ts = cmd_CreateSyntax("listmax", ListMax, NULL, "list max id");
1194 ts = cmd_CreateSyntax("setmax", SetMaxCommand, NULL, "set max id");
1195 cmd_AddParm(ts, "-group", CMD_SINGLE, CMD_OPTIONAL, "group max");
1196 cmd_AddParm(ts, "-user", CMD_SINGLE, CMD_OPTIONAL, "user max");
1199 ts = cmd_CreateSyntax("setfields", SetFields, NULL,
1200 "set fields for an entry");
1201 cmd_AddParm(ts, "-nameorid", CMD_LIST, 0, "user or group name or id");
1202 cmd_AddParm(ts, "-access", CMD_SINGLE, CMD_OPTIONAL, "set privacy flags");
1203 cmd_AddParm(ts, "-groupquota", CMD_SINGLE, CMD_OPTIONAL,
1204 "set limit on group creation");
1206 cmd_AddParm(ts, "-userquota", CMD_SINGLE, CMD_OPTIONAL,
1207 "set limit on foreign user creation");
1211 ts = cmd_CreateSyntax("listowned", ListOwned, NULL,
1212 "list groups owned by an entry or zero id gets orphaned groups");
1213 cmd_AddParm(ts, "-nameorid", CMD_LIST, 0, "user or group name or id");
1216 ts = cmd_CreateSyntax("listentries", ListEntries, NULL,
1217 "list users/groups in the protection database");
1218 cmd_AddParm(ts, "-users", CMD_FLAG, CMD_OPTIONAL, "list user entries");
1219 cmd_AddParm(ts, "-groups", CMD_FLAG, CMD_OPTIONAL, "list group entries");
1222 ts = cmd_CreateSyntax("interactive", pts_Interactive, NULL,
1223 "enter interactive mode");
1225 cmd_CreateAlias(ts, "in");
1227 ts = cmd_CreateSyntax("quit", pts_Quit, NULL, "exit program");
1230 ts = cmd_CreateSyntax("source", pts_Source, NULL, "read commands from file");
1231 cmd_AddParm(ts, "-file", CMD_SINGLE, 0, "filename");
1234 ts = cmd_CreateSyntax("sleep", pts_Sleep, NULL, "pause for a bit");
1235 cmd_AddParm(ts, "-delay", CMD_SINGLE, 0, "seconds");
1238 cmd_SetBeforeProc(GetGlobals, &state);
1242 if ((code = cmd_Dispatch(argc, argv))) {
1243 CleanUp(NULL, NULL);
1246 while (source && !finished) {
1247 if (isatty(fileno(source)))
1248 fprintf(stderr, "pts> ");
1249 if (!fgets(line, sizeof line, source)) {
1255 for (cp = line; *cp; ++cp)
1265 cmd_ParseLine(line, parsev, &parsec,
1266 sizeof(parsev) / sizeof(*parsev));
1268 afs_com_err(whoami, code, "parsing line: <%s>", line);
1272 parsev[0] = argv[0];
1273 code = cmd_Dispatch(parsec, parsev);
1275 cmd_FreeArgv(parsev);
1277 CleanUp(NULL, NULL);