* directory or online at http://www.openafs.org/dl/license10.html
*/
-/*
- * (3) add new pts commands:
- *
- * Interactive - allow the pts command
- * to be run interactively.
- * Quit - quit interactive mode.
- * Source - allow input to come from a file(s).
- * Sleep - pause for a specified number
- * of seconds.
- *
- */
-
#include <afsconfig.h>
#include <afs/param.h>
-RCSID
- ("$Header$");
#include <stdio.h>
#include <string.h>
#ifdef AFS_NT40_ENV
#include <winsock2.h>
#include <WINNT/afsevent.h>
+#include <WINNT/afsreg.h>
#else
#include <netinet/in.h>
#endif
#include <rx/rx.h>
#include <rx/xdr.h>
#include "ptclient.h"
+#include "ptuser.h"
#include "pterror.h"
+#include "ptprototypes.h"
#include <afs/afsutil.h>
#include <afs/com_err.h>
char *whoami;
int force = 0;
-#if defined(SUPERGROUPS)
-
-/*
- * Add new pts commands:
- *
- * Interactive - allow the pts command to be run interactively.
- * Quit - quit interactive mode.
- * Source - allow input to come from a file(s).
- * Sleep - pause for a specified number of seconds.
- */
-
static int finished;
static FILE *source;
extern struct ubik_client *pruclient;
FILE *s_file;
} *shead;
-int
-Interactive(struct cmd_syndesc *as, char *arock)
+struct authstate {
+ int sec;
+ const char *confdir;
+ char cell[MAXCELLCHARS];
+};
+
+static int CleanUp(struct cmd_syndesc *as, void *arock);
+
+static int
+pts_Interactive(struct cmd_syndesc *as, void *arock)
{
+ source = stdin;
finished = 0;
return 0;
}
-int
-Quit(struct cmd_syndesc *as, char *arock)
+static int
+pts_Quit(struct cmd_syndesc *as, void *arock)
{
finished = 1;
return 0;
}
-int
-Source(struct cmd_syndesc *as, char *arock)
+static int
+pts_Source(struct cmd_syndesc *as, void *arock)
{
FILE *fd;
struct sourcestack *sp;
return 0;
}
-int
-Sleep(struct cmd_syndesc *as, char *arock)
+static int
+pts_Sleep(struct cmd_syndesc *as, void *arock)
{
int delay;
if (!as->parms[0].items) {
return 1;
}
delay = atoi(as->parms[0].items->data);
+#ifdef AFS_PTHREAD_ENV
+ sleep(delay);
+#else
IOMGR_Sleep(delay);
+#endif
+ return 0;
}
-int
-popsource()
+static int
+popsource(void)
{
register struct sourcestack *sp;
if (!(sp = shead))
return 1;
}
-#endif /* SUPERGROUPS */
-
int
-osi_audit()
+osi_audit(void)
{
/* OK, this REALLY sucks bigtime, but I can't tell who is calling
* afsconf_CheckAuth easily, and only *SERVERS* should be calling osi_audit
return 0;
}
-int
-GetGlobals(struct cmd_syndesc *as, char *arock)
+#ifdef AFS_NT40_ENV
+static DWORD
+win32_enableCrypt(void)
{
- register afs_int32 code;
- char *cell;
- afs_int32 sec = 1;
+ HKEY parmKey;
+ DWORD dummyLen;
+ DWORD cryptall = 0;
+ DWORD code;
+
+ /* Look up configuration parameters in Registry */
+ code = RegOpenKeyEx(HKEY_LOCAL_MACHINE, AFSREG_CLT_SVC_PARAM_SUBKEY,
+ 0, (IsWow64()?KEY_WOW64_64KEY:0)|KEY_QUERY_VALUE, &parmKey);
+ if (code != ERROR_SUCCESS) {
+ dummyLen = sizeof(cryptall);
+ RegQueryValueEx(parmKey, "SecurityLevel", NULL, NULL,
+ (BYTE *) &cryptall, &dummyLen);
+ }
+ RegCloseKey (parmKey);
+
+ return cryptall;
+}
+#endif /* AFS_NT40_ENV */
+
+static int
+GetGlobals(struct cmd_syndesc *as, void *arock)
+{
+ struct authstate *state = (struct authstate *) arock;
+ afs_int32 code;
+ char *cell = NULL;
+ afs_int32 sec;
+ int changed = 0;
+ const char* confdir;
whoami = as->a0name;
if (!strcmp(as->name, "help"))
return 0;
- if (as->parms[16].items)
+
+ if (*state->cell) {
+ cell = state->cell;
+ }
+ sec = state->sec;
+
+ if (state->confdir == NULL) {
+ changed = 1;
+ }
+
+ if (as->parms[16].items) {
+ changed = 1;
cell = as->parms[16].items->data;
- else
- cell = 0;
- if (as->parms[17].items)
+ }
+ if (as->parms[17].items) { /* -noauth */
+ changed = 1;
sec = 0;
-
- if (as->parms[18].items) { /* testing? */
- code = pr_Initialize(sec, AFSDIR_SERVER_ETC_DIRPATH, cell);
+ }
+ if (as->parms[20].items) { /* -localauth */
+ changed = 1;
+ sec = 2;
+ }
+ if (as->parms[21].items) { /* -auth */
+ changed = 1;
+ sec = 1;
+ }
+ if (as->parms[22].items /* -encrypt */
+#ifdef AFS_NT40_ENV
+ || win32_enableCrypt()
+#endif /* AFS_NT40_ENV */
+ ) {
+ changed = 1;
+ sec = 3;
+ }
+ if (as->parms[18].items || as->parms[20].items) { /* -test, -localauth */
+ changed = 1;
+ confdir = AFSDIR_SERVER_ETC_DIRPATH;
} else {
- code = pr_Initialize(sec, AFSDIR_CLIENT_ETC_DIRPATH, cell);
+ if (sec == 2)
+ confdir = AFSDIR_SERVER_ETC_DIRPATH;
+ else
+ confdir = AFSDIR_CLIENT_ETC_DIRPATH;
+ }
+ if (changed) {
+ CleanUp(as, arock);
+ code = pr_Initialize(sec, confdir, cell);
+ } else {
+ code = 0;
}
if (code) {
afs_com_err(whoami, code, "while initializing");
return code;
}
+ state->sec = sec;
+ state->confdir = confdir;
+ if (cell && cell != state->cell)
+ strncpy(state->cell, cell, MAXCELLCHARS-1);
+
+ force = 0;
if (as->parms[19].items)
force = 1;
+
return code;
}
-int
-CleanUp(struct cmd_syndesc *as, char *arock)
+static int
+CleanUp(struct cmd_syndesc *as, void *arock)
{
-#if defined(SUPERGROUPS)
if (as && !strcmp(as->name, "help"))
return 0;
if (pruclient) {
pr_End();
rx_Finalize();
}
-#else
- if (!strcmp(as->name, "help"))
- return 0;
- /* Need to shutdown the ubik_client & other connections */
- pr_End();
- rx_Finalize();
-#endif /* SUPERGROUPS */
-
return 0;
}
-int
-CreateGroup(struct cmd_syndesc *as, char *arock)
+static int
+CreateGroup(struct cmd_syndesc *as, void *arock)
{
register afs_int32 code;
afs_int32 id;
id);
return code;
}
-#if defined(SUPERGROUPS)
- if (id == 0) {
+
+ if (id == 0) {
printf("0 isn't a valid user id; aborting\n");
return EINVAL;
}
-#endif
+
idi = idi->next;
} else
id = 0;
return 0;
}
-int
-CreateUser(struct cmd_syndesc *as, char *arock)
+static int
+CreateUser(struct cmd_syndesc *as, void *arock)
{
register afs_int32 code;
afs_int32 id;
#ifdef notdef
-int
-GetNameOrId(register struct cmd_syndesc *as, struct idlist *lids, struct namelist *lnames)
+static int
+GetNameOrId(struct cmd_syndesc *as, struct idlist *lids, struct namelist *lnames)
{
register afs_int32 code = 0;
int n = 0;
#endif
-int
-GetNameOrId(register struct cmd_syndesc *as, struct idlist *lids, struct namelist *lnames)
+static int
+GetNameOrId(struct cmd_syndesc *as, struct idlist *lids,
+ struct namelist *lnames)
{
register afs_int32 code = 0;
int n = 0, nd = 0, nm = 0, id, x;
}
-int
-AddToGroup(struct cmd_syndesc *as, char *arock)
+static int
+AddToGroup(struct cmd_syndesc *as, void *arock)
{
register afs_int32 code;
struct cmd_item *u, *g;
return 0;
}
-int
-RemoveFromGroup(struct cmd_syndesc *as, char *arock)
+static int
+RemoveFromGroup(struct cmd_syndesc *as, void *arock)
{
register afs_int32 code;
struct cmd_item *u, *g;
return 0;
}
-int
-ListMembership(struct cmd_syndesc *as, char *arock)
+static int
+ListMembership(struct cmd_syndesc *as, void *arock)
{
register afs_int32 code;
idlist ids;
return 0;
}
-int
-Delete(struct cmd_syndesc *as, char *arock)
+static int
+Delete(struct cmd_syndesc *as, void *arock)
{
register afs_int32 code;
idlist ids;
char *flags_dncase = "s mar"; /* legal member acces values */
int flags_shift[5] = { 2, 1, 2, 2, 1 }; /* bits for each */
-int
-CheckEntry(struct cmd_syndesc *as, char *arock)
+static int
+CheckEntry(struct cmd_syndesc *as, void *arock)
{
register afs_int32 code;
afs_int32 rcode = 1;
return (rcode);
}
-int
-ListEntries(struct cmd_syndesc *as, char *arock)
+static int
+ListEntries(struct cmd_syndesc *as, void *arock)
{
afs_int32 code = 0;
afs_int32 flag, startindex, nentries, nextstartindex;
pr_ListEntries(flag, startindex, &nentries, &entriesp,
&nextstartindex);
if (code) {
- afs_com_err(whoami, code, "; unable to list entries\n");
+ afs_com_err(whoami, code, "; unable to list entries");
if (entriesp)
free(entriesp);
break;
return code;
}
-int
-ChownGroup(struct cmd_syndesc *as, char *arock)
+static int
+ChownGroup(struct cmd_syndesc *as, void *arock)
{
register afs_int32 code;
char *name;
return code;
}
-int
-ChangeName(struct cmd_syndesc *as, char *arock)
+static int
+ChangeName(struct cmd_syndesc *as, void *arock)
{
register afs_int32 code;
char *oldname;
return code;
}
-int
-ListMax(struct cmd_syndesc *as, char *arock)
+static int
+ListMax(struct cmd_syndesc *as, void *arock)
{
register afs_int32 code;
afs_int32 maxUser, maxGroup;
return code;
}
-int
-SetMax(struct cmd_syndesc *as, char *arock)
+static int
+SetMaxCommand(struct cmd_syndesc *as, void *arock)
{
register afs_int32 code;
afs_int32 maxid;
return code;
}
-int
-SetFields(struct cmd_syndesc *as, char *arock)
+static int
+SetFields(struct cmd_syndesc *as, void *arock)
{
register afs_int32 code;
idlist ids;
int new;
if (strpbrk(access, "76543210") != 0) { /* all octal digits */
- sscanf(access, "%lo", &flags);
+ sscanf(access, "%lo", (long unsigned int *) &flags);
} else { /* interpret flag bit names */
if (strlen(access) != 5) {
form_error:
return 0;
}
-int
-ListOwned(struct cmd_syndesc *as, char *arock)
+static int
+ListOwned(struct cmd_syndesc *as, void *arock)
{
register afs_int32 code;
idlist ids;
}
static void
-add_std_args(register struct cmd_syndesc *ts)
+add_std_args(struct cmd_syndesc *ts)
{
char test_help[AFSDIR_PATH_MAX];
cmd_AddParm(ts, "-test", CMD_FLAG, CMD_OPTIONAL | CMD_HIDE, test_help);
cmd_AddParm(ts, "-force", CMD_FLAG, CMD_OPTIONAL,
"Continue oper despite reasonable errors");
+ cmd_AddParm(ts, "-localauth", CMD_FLAG, CMD_OPTIONAL,
+ "use local authentication");
+ cmd_AddParm(ts, "-auth", CMD_FLAG, CMD_OPTIONAL,
+ "use user's authentication (default)");
+ cmd_AddParm(ts, "-encrypt", CMD_FLAG, CMD_OPTIONAL,
+ "encrypt commands");
}
/*
{
register afs_int32 code;
register struct cmd_syndesc *ts;
-#if defined(SUPERGROUPS)
+
char line[2048];
char *cp, *lastp;
int parsec;
char *parsev[CMD_MAXPARMS];
char *savec;
-#endif
+ struct authstate state;
+
#ifdef WIN32
WSADATA WSAjunk;
#endif
sigaction(SIGSEGV, &nsa, NULL);
#endif
- ts = cmd_CreateSyntax("creategroup", CreateGroup, 0,
+ memset(&state, 0, sizeof(state));
+ state.sec = 1; /* default is auth */
+
+ ts = cmd_CreateSyntax("creategroup", CreateGroup, NULL,
"create a new group");
cmd_AddParm(ts, "-name", CMD_LIST, 0, "group name");
cmd_AddParm(ts, "-owner", CMD_SINGLE, CMD_OPTIONAL, "owner of the group");
add_std_args(ts);
cmd_CreateAlias(ts, "cg");
- ts = cmd_CreateSyntax("createuser", CreateUser, 0, "create a new user");
+ ts = cmd_CreateSyntax("createuser", CreateUser, NULL, "create a new user");
cmd_AddParm(ts, "-name", CMD_LIST, 0, "user name");
cmd_AddParm(ts, "-id", CMD_LIST, CMD_OPTIONAL, "user id");
add_std_args(ts);
cmd_CreateAlias(ts, "cu");
- ts = cmd_CreateSyntax("adduser", AddToGroup, 0, "add a user to a group");
+ ts = cmd_CreateSyntax("adduser", AddToGroup, NULL, "add a user to a group");
cmd_AddParm(ts, "-user", CMD_LIST, 0, "user name");
cmd_AddParm(ts, "-group", CMD_LIST, 0, "group name");
add_std_args(ts);
- ts = cmd_CreateSyntax("removeuser", RemoveFromGroup, 0,
+ ts = cmd_CreateSyntax("removeuser", RemoveFromGroup, NULL,
"remove a user from a group");
cmd_AddParm(ts, "-user", CMD_LIST, 0, "user name");
cmd_AddParm(ts, "-group", CMD_LIST, 0, "group name");
add_std_args(ts);
- ts = cmd_CreateSyntax("membership", ListMembership, 0,
+ ts = cmd_CreateSyntax("membership", ListMembership, NULL,
"list membership of a user or group");
cmd_AddParm(ts, "-nameorid", CMD_LIST, 0, "user or group name or id");
add_std_args(ts);
cmd_CreateAlias(ts, "groups");
- ts = cmd_CreateSyntax("delete", Delete, 0,
+ ts = cmd_CreateSyntax("delete", Delete, NULL,
"delete a user or group from database");
cmd_AddParm(ts, "-nameorid", CMD_LIST, 0, "user or group name or id");
add_std_args(ts);
- ts = cmd_CreateSyntax("examine", CheckEntry, 0, "examine an entry");
+ ts = cmd_CreateSyntax("examine", CheckEntry, NULL, "examine an entry");
cmd_AddParm(ts, "-nameorid", CMD_LIST, 0, "user or group name or id");
add_std_args(ts);
cmd_CreateAlias(ts, "check");
- ts = cmd_CreateSyntax("chown", ChownGroup, 0,
+ ts = cmd_CreateSyntax("chown", ChownGroup, NULL,
"change ownership of a group");
cmd_AddParm(ts, "-name", CMD_SINGLE, 0, "group name");
cmd_AddParm(ts, "-owner", CMD_SINGLE, 0, "new owner");
add_std_args(ts);
- ts = cmd_CreateSyntax("rename", ChangeName, 0, "rename user or group");
+ ts = cmd_CreateSyntax("rename", ChangeName, NULL, "rename user or group");
cmd_AddParm(ts, "-oldname", CMD_SINGLE, 0, "old name");
cmd_AddParm(ts, "-newname", CMD_SINGLE, 0, "new name");
add_std_args(ts);
cmd_CreateAlias(ts, "chname");
- ts = cmd_CreateSyntax("listmax", ListMax, 0, "list max id");
+ ts = cmd_CreateSyntax("listmax", ListMax, NULL, "list max id");
add_std_args(ts);
- ts = cmd_CreateSyntax("setmax", SetMax, 0, "set max id");
+ ts = cmd_CreateSyntax("setmax", SetMaxCommand, NULL, "set max id");
cmd_AddParm(ts, "-group", CMD_SINGLE, CMD_OPTIONAL, "group max");
cmd_AddParm(ts, "-user", CMD_SINGLE, CMD_OPTIONAL, "user max");
add_std_args(ts);
- ts = cmd_CreateSyntax("setfields", SetFields, 0,
+ ts = cmd_CreateSyntax("setfields", SetFields, NULL,
"set fields for an entry");
cmd_AddParm(ts, "-nameorid", CMD_LIST, 0, "user or group name or id");
cmd_AddParm(ts, "-access", CMD_SINGLE, CMD_OPTIONAL, "set privacy flags");
#endif
add_std_args(ts);
- ts = cmd_CreateSyntax("listowned", ListOwned, 0,
+ ts = cmd_CreateSyntax("listowned", ListOwned, NULL,
"list groups owned by an entry or zero id gets orphaned groups");
cmd_AddParm(ts, "-nameorid", CMD_LIST, 0, "user or group name or id");
add_std_args(ts);
- ts = cmd_CreateSyntax("listentries", ListEntries, 0,
+ ts = cmd_CreateSyntax("listentries", ListEntries, NULL,
"list users/groups in the protection database");
cmd_AddParm(ts, "-users", CMD_FLAG, CMD_OPTIONAL, "list user entries");
cmd_AddParm(ts, "-groups", CMD_FLAG, CMD_OPTIONAL, "list group entries");
add_std_args(ts);
-#if defined(SUPERGROUPS)
-
- ts = cmd_CreateSyntax("interactive", Interactive, 0,
+ ts = cmd_CreateSyntax("interactive", pts_Interactive, NULL,
"enter interactive mode");
add_std_args(ts);
cmd_CreateAlias(ts, "in");
- ts = cmd_CreateSyntax("quit", Quit, 0, "exit program");
+ ts = cmd_CreateSyntax("quit", pts_Quit, NULL, "exit program");
add_std_args(ts);
- ts = cmd_CreateSyntax("source", Source, 0, "read commands from file");
+ ts = cmd_CreateSyntax("source", pts_Source, NULL, "read commands from file");
cmd_AddParm(ts, "-file", CMD_SINGLE, 0, "filename");
add_std_args(ts);
- ts = cmd_CreateSyntax("sleep", Sleep, 0, "pause for a bit");
+ ts = cmd_CreateSyntax("sleep", pts_Sleep, NULL, "pause for a bit");
cmd_AddParm(ts, "-delay", CMD_SINGLE, 0, "seconds");
add_std_args(ts);
-#endif /* SUPERGROUPS */
+ cmd_SetBeforeProc(GetGlobals, &state);
- cmd_SetBeforeProc(GetGlobals, 0);
-
-#if defined(SUPERGROUPS)
finished = 1;
- if (code = cmd_Dispatch(argc, argv)) {
+ source = NULL;
+ if ((code = cmd_Dispatch(argc, argv))) {
CleanUp(NULL, NULL);
exit(1);
}
- source = stdin;
- while (!finished) {
+ while (source && !finished) {
if (isatty(fileno(source)))
fprintf(stderr, "pts> ");
if (!fgets(line, sizeof line, source)) {
}
CleanUp(NULL, NULL);
exit(0);
-
-#else /* SUPERGROUPS */
-
- cmd_SetAfterProc(CleanUp, 0);
- code = cmd_Dispatch(argc, argv);
- exit(code != 0);
-#endif /* SUPERGROUPS */
}