This patch adds a "flush" command to the xgroupset and xuserset
utilities which deletes all the groups and users from the group and user
pools respectively (except "xcpu-admin")
xuserset flush {-a | nodename}
xgroupset flush {-a | nodename}
Signed-off-by: Abhishek Kulkarni <[EMAIL PROTECTED]>
Index: utils/xgroupset.c
===================================================================
--- utils/xgroupset.c (revision 715)
+++ utils/xgroupset.c (working copy)
@@ -57,9 +57,17 @@
.uname = "xcpu-admin",
.uid = 65530,
};
+
+static char *command[] = {
+ "add",
+ "delete",
+ "flush",
+ 0
+};
enum {
Add,
Delete,
+ Flush,
};
static int groupcmd;
@@ -67,6 +75,7 @@
usage(char *name)
{
fprintf(stderr, "usage: %s [-h] {add | delete} [-A adminkey] {-a | nodeset} gname gid [gname gid ...]\n", name);
+ fprintf(stderr, " %s [-h] flush [-A adminkey] {-a | nodeset}\n", name);
exit(1);
}
@@ -82,10 +91,12 @@
return -1;
buf = malloc(sizeof(*buf) * bufsize);
- if(groupcmd == Add)
+ if (groupcmd == Add)
snprintf(buf, bufsize, "group-add %s %d\n", groupname, gid);
- else
+ else if (groupcmd == Delete)
snprintf(buf, bufsize, "group-del %s\n", groupname);
+ else /* groupcmd = Flush */
+ snprintf(buf, bufsize, "group-flush\n");
buflen = strlen(buf);
@@ -110,7 +121,7 @@
int
main(int argc, char **argv)
{
- int c, ecode;
+ int c, n, ecode;
char cmd[7];
char *nodeset, *ename;
char *adminkeyfile = "/etc/xcpu/admin_key";
@@ -135,24 +146,30 @@
}
}
- if (argc < 4)
- usage(argv[0]);
+ snprintf(cmd, 7 * sizeof(char), "%s", argv[optind++]);
+ for (c=0; command[c]; c++)
+ if (strcmp(command[c], cmd))
+ n = 1;
- snprintf(cmd, 7 * sizeof(char), "%s", argv[optind++]);
- if ((strcmp("add", cmd) && strcmp("delete", cmd))
- || (!strcmp("add", cmd) && argc < 5))
+ if (!n || argc < 2)
usage(argv[0]);
- if(!strcmp("add", cmd))
+ if (!strcmp("add", cmd)) {
groupcmd = Add;
- else
+ if (argc < 5)
+ usage(argv[0]);
+ } else if (!strcmp("delete", cmd)) {
groupcmd = Delete;
-
- if (! allflag)
+ if (argc < 4)
+ usage(argv[0]);
+ } else /* if (!strcmp("flush", cmd)) */
+ groupcmd = Flush;
+
+ if (!allflag)
nodeset = argv[optind++];
groupname = argv[optind++];
- if(groupcmd == Add)
+ if (groupcmd == Add)
gid = strtol(argv[optind++], NULL, 10);
adminkey = xauth_privkey_create(adminkeyfile);
@@ -168,12 +185,11 @@
}
endpwent();
-
if (allflag) {
char statserver[32];
sprintf(statserver, "localhost!%d", STAT_PORT);
nds = xp_nodeset_list(NULL);
- if(nds == NULL)
+ if (nds == NULL)
nds = xp_nodeset_list(statserver);
if (nds != NULL) {
nds2 = xp_nodeset_create();
@@ -186,9 +202,8 @@
}
} /* if filter is unsuccessful just use the full set */
}
- } else {
- nds = xp_nodeset_from_string(nodeset);
- }
+ } else
+ nds = xp_nodeset_from_string(nodeset);
if (!nds)
goto lerror;
Index: utils/xuserset.c
===================================================================
--- utils/xuserset.c (revision 715)
+++ utils/xuserset.c (working copy)
@@ -58,9 +58,16 @@
.uid = 65530,
};
static char userkey[4096];
+static char *command[] = {
+ "add",
+ "delete",
+ "flush",
+ 0
+};
enum {
Add,
Delete,
+ Flush,
};
static int usercmd;
@@ -68,7 +75,8 @@
usage(char *name)
{
fprintf(stderr, "usage: %s [-h] add [-A admin_keyfile] {-a | nodeset} user uid group key\n", name);
- fprintf(stderr, "usage: %s [-h] delete [-A admin_keyfile] {-a | nodeset} user\n", name);
+ fprintf(stderr, " %s [-h] delete [-A admin_keyfile] {-a | nodeset} user\n", name);
+ fprintf(stderr, " %s [-h] flush [-A admin_keyfile] {-a | nodeset}\n", name);
fprintf(stderr, "where: \n");
fprintf(stderr, "\t-h prints this message\n");
fprintf(stderr, "\tnodeset is the set of nodes to issue the command to\n");
@@ -99,12 +107,14 @@
return -1;
buf = malloc(sizeof(*buf) * bufsize);
- if(usercmd == Add) {
+ if (usercmd == Add) {
qkey = quotestrdup(userkey);
snprintf(buf, bufsize, "user-add %s %d %s %s\n", username, userid, groupname, qkey);
free(qkey);
- } else
+ } else if (usercmd == Delete)
snprintf(buf, bufsize, "user-del %s\n", username);
+ else /* usercmd == Flush */
+ snprintf(buf, bufsize, "user-flush\n");
buflen = strlen(buf);
@@ -175,22 +185,29 @@
}
}
- snprintf(cmd, 7 * sizeof(char), "%s", argv[optind++]);
- if ((strcmp("add", cmd) && strcmp("delete", cmd))
- || (!strcmp("add", cmd) && argc < 7)
- || (!strcmp("delete", cmd) && argc < 4))
+ snprintf(cmd, 7 * sizeof(char), "%s", argv[optind++]);
+ for (c=0; command[c]; c++)
+ if (!strcmp(command[c], cmd))
+ n = 1;
+ if (!n || argc < 2)
usage(argv[0]);
-
- if(!strcmp("add", cmd))
+
+ if (!strcmp("add", cmd)) {
usercmd = Add;
- else
+ if (argc < 7)
+ usage(argv[0]);
+ } else if (!strcmp("delete", cmd)) {
usercmd = Delete;
+ if (argc < 4)
+ usage(argv[0]);
+ } else /* if (!strcmp("flush", cmd)) */
+ usercmd = Flush;
- if (! allflag)
+ if (!allflag)
nodeset = argv[optind++];
username = argv[optind++];
- if(usercmd == Add) {
+ if (usercmd == Add) {
userid = strtol(argv[optind++], NULL, 10);
groupname = argv[optind++];
fd = open(argv[optind], O_RDONLY);
@@ -225,7 +242,6 @@
}
endpwent();
-
if (allflag) {
char statserver[32];
sprintf(statserver, "localhost!%d", STAT_PORT);
@@ -243,9 +259,9 @@
}
} /* if filter is unsuccessful just use the full set */
}
- } else {
+ } else
nds = xp_nodeset_from_string(nodeset);
- }
+
if (!nds)
goto lerror;
Index: xcpufs/xcpufs.c
===================================================================
--- xcpufs/xcpufs.c (revision 715)
+++ xcpufs/xcpufs.c (working copy)
@@ -1173,6 +1173,9 @@
} else if (strcmp("user-del", cmd) == 0) {
if (!ukey_del(up, args[0]))
ret = 1;
+ } else if (strcmp("user-flush", cmd) == 0) {
+ if (!ukey_flush(up))
+ ret = 1;
} else if (strcmp("group-add", cmd) == 0) {
if (nargs != 3) {
sp_werror("Usage: group-add groupname gid", EIO);
@@ -1190,6 +1193,9 @@
} else if (strcmp("group-del", cmd) == 0) {
if (!group_del(up, args[0]))
ret = 1;
+ } else if (strcmp("group-flush", cmd) == 0) {
+ if (!group_flush(up))
+ ret = 1;
} else if (strcmp("kill", cmd) == 0) {
euid = geteuid();
Index: xcpufs/xauth.c
===================================================================
--- xcpufs/xauth.c (revision 715)
+++ xcpufs/xauth.c (working copy)
@@ -102,6 +102,24 @@
}
int
+ukey_flush(Spuserpool *up)
+{
+ Spuser *user;
+
+ user = sp_priv_user_list(up);
+ if (user) {
+ while (user != NULL) {
+ if(strcmp("xcpu-admin", user->uname)) {
+ sp_priv_user_del(user);
+ sp_user_decref(user);
+ }
+ user = user->next;
+ }
+ }
+ return 0;
+}
+
+int
group_add(Spuserpool *up, char *groupname, u32 gid)
{
Spgroup *g;
@@ -131,6 +149,25 @@
}
int
+group_flush(Spuserpool *up)
+{
+ Spgroup *group;
+
+ ukey_flush(up);
+ group = sp_priv_group_list(up);
+ if (group) {
+ while (group != NULL) {
+ if(strcmp("xcpu-admin", group->gname)) {
+ sp_priv_group_del(group);
+ sp_group_decref(group);
+ }
+ group = group->next;
+ }
+ }
+ return 0;
+}
+
+int
pkey_gen(Spuser *user, char *buf, int buflen)
{
int i;
Index: xcpufs/xcpufs.h
===================================================================
--- xcpufs/xcpufs.h (revision 715)
+++ xcpufs/xcpufs.h (working copy)
@@ -211,9 +211,11 @@
int ukey_add(Spuserpool *up, char *uname, u32 uid, char *dfltgname,
char *key, int keylen);
int ukey_del(Spuserpool *up, char *uname);
+int ukey_flush(Spuserpool *up);
int pkey_gen(Spuser *user, char *buf, int buflen);
int group_add(Spuserpool *up, char *groupname, u32 gid);
int group_del(Spuserpool *up, char *groupname);
+int group_flush(Spuserpool *up);
/* proc-*.c */