summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorpiaip <piaip@63ad8ddf-47c3-0310-b6dd-a9e9d9715204>2013-03-29 21:56:33 +0800
committerpiaip <piaip@63ad8ddf-47c3-0310-b6dd-a9e9d9715204>2013-03-29 21:56:33 +0800
commit3c2344bf065e5a29228163019bc2ddb8043162b4 (patch)
tree07a0f807aa4a983ac669393f88a7deeef3c14071
parentf1ef31557e970a5bc8258fbe371bd2d8d7acf516 (diff)
downloadpttbbs-3c2344bf065e5a29228163019bc2ddb8043162b4.tar
pttbbs-3c2344bf065e5a29228163019bc2ddb8043162b4.tar.gz
pttbbs-3c2344bf065e5a29228163019bc2ddb8043162b4.tar.bz2
pttbbs-3c2344bf065e5a29228163019bc2ddb8043162b4.tar.lz
pttbbs-3c2344bf065e5a29228163019bc2ddb8043162b4.tar.xz
pttbbs-3c2344bf065e5a29228163019bc2ddb8043162b4.tar.zst
pttbbs-3c2344bf065e5a29228163019bc2ddb8043162b4.zip
Tool to set role.
git-svn-id: http://opensvn.csie.org/pttbbs/trunk@5831 63ad8ddf-47c3-0310-b6dd-a9e9d9715204
-rw-r--r--pttbbs/util/Makefile2
-rw-r--r--pttbbs/util/permreport.c4
-rw-r--r--pttbbs/util/setrole.c73
3 files changed, 75 insertions, 4 deletions
diff --git a/pttbbs/util/Makefile b/pttbbs/util/Makefile
index aa686b0c..953a9134 100644
--- a/pttbbs/util/Makefile
+++ b/pttbbs/util/Makefile
@@ -23,7 +23,7 @@ CPROG_WITH_UTIL= \
angel gamblegive \
chesscountry tunepasswd buildir xchatd \
uhash_loader timecap_buildref showuser removebm \
- redir permreport
+ redir permreport setrole
# 下面是 C++ 的程式
CPP_WITH_UTIL= \
diff --git a/pttbbs/util/permreport.c b/pttbbs/util/permreport.c
index 6fcd81f9..b6d2e29b 100644
--- a/pttbbs/util/permreport.c
+++ b/pttbbs/util/permreport.c
@@ -1,4 +1,4 @@
-/* $Id: bbsctl.c 4594 2009-06-13 13:13:27Z piaip $ */
+/* $Id$ */
#include "bbs.h"
#define PERMCHECK(s) {s, #s}
@@ -64,14 +64,12 @@ int main(void) {
uint32_t *pvalue = NULL;
const char *desc = checks[i].desc;
char *list = checks[i].list;
- int is_perm = 0;
size_t need_len = sizeof(usr.userid) + sizeof(usr.realname) + 4;
if (strncmp(desc, "PERM_", 4) == 0) {
if (!checks[i].caption)
checks[i].caption = str_permid[get_offset(mask)];
pvalue = &usr.userlevel;
- is_perm = 1;
} else if (strncmp(desc, "ROLE_", 5) == 0) {
if (!checks[i].caption)
checks[i].caption = str_roleid[get_offset(mask)];
diff --git a/pttbbs/util/setrole.c b/pttbbs/util/setrole.c
new file mode 100644
index 00000000..efa45e20
--- /dev/null
+++ b/pttbbs/util/setrole.c
@@ -0,0 +1,73 @@
+/* $Id$ */
+#include "bbs.h"
+
+#define DEFINEROLE(s) {s, #s}
+
+typedef struct {
+ int role;
+ const char *name;
+} rolerec_t;
+
+rolerec_t known_roles[] = {
+ DEFINEROLE(ROLE_ANGEL_CIA),
+ DEFINEROLE(ROLE_ANGEL_ACTIVITY),
+ DEFINEROLE(ROLE_ANGEL_ARCHANGEL),
+ DEFINEROLE(ROLE_POLICE_ANONYMOUS),
+ {0}
+};
+
+void list_roles(struct userec_t *pusr) {
+ int i;
+
+ printf("%s's roles: %#08x", pusr->userid, pusr->role);
+ for (i = 0; known_roles[i].role; i++) {
+ if (pusr->role & known_roles[i].role)
+ printf(" %s", known_roles[i].name);
+ }
+ printf("\n");
+}
+
+void toggle_role(struct userec_t *pusr, const char *role) {
+ int i;
+ for (i = 0; known_roles[i].role; i++) {
+ if (strcasecmp(role, known_roles[i].name) == 0)
+ break;
+ }
+ if (!known_roles[i].role) {
+ fprintf(stderr, "Unknown role name: %s\n", role);
+ exit(1);
+ }
+ pusr->role ^= known_roles[i].role;
+}
+
+int main(int argc, char *argv[]) {
+ int unum;
+ userec_t usr;
+ const char *userid;
+
+ if (argc < 2) {
+ fprintf(stderr, "usage: %s userid [role-list-to-toggle]\n",
+ argv[0]);
+ return 1;
+ }
+ userid = argv[1];
+ argc--, argv++;
+
+ chdir(BBSHOME);
+ attach_SHM();
+
+ unum = passwd_load_user(userid, &usr);
+ if (unum < 1) {
+ fprintf(stderr, "invalid user: %s\n", userid);
+ return 1;
+ }
+
+ if (argc > 1) {
+ while (argc-- > 1)
+ toggle_role(&usr, *++argv);
+ passwd_update(unum, &usr);
+ } else {
+ list_roles(&usr);
+ }
+ return 0;
+}