[srvx-commits] CVS: services/src modcmd.c,1.28,1.29 modcmd.h,1.9,1.10
Brought to you by:
entrope
|
From: Entrope <en...@us...> - 2002-09-18 14:50:22
|
Update of /cvsroot/srvx/services/src
In directory usw-pr-cvs1:/tmp/cvs-serv2968/src
Modified Files:
modcmd.c modcmd.h
Log Message:
allow binding and unbinding of commands with spaces in their names
fail permission checks for REQUIRE_HELPING commands if user isn't helping
define struct svccmd_list
Index: modcmd.c
===================================================================
RCS file: /cvsroot/srvx/services/src/modcmd.c,v
retrieving revision 1.28
retrieving revision 1.29
diff -C2 -r1.28 -r1.29
*** modcmd.c 16 Sep 2002 21:10:19 -0000 1.28
--- modcmd.c 18 Sep 2002 14:50:19 -0000 1.29
***************
*** 142,145 ****
--- 142,147 ----
}
+ DEFINE_LIST(svccmd_list, struct svccmd*);
+
static void
free_service_command(void *data) {
***************
*** 523,526 ****
--- 525,529 ----
if ((cmd->flags & MODCMD_REQUIRE_HELPING) && !HANDLE_FLAGGED(user->handle_info, HELPING)) {
send_message(user, bot, MCMSG_MUST_BE_HELPING);
+ return 0;
}
if (cmd->min_opserv_level > 0) {
***************
*** 894,914 ****
}
static MODCMD_FUNC(cmd_bind) {
struct service *service;
struct svccmd *template, *newcmd;
! char *svcname, *newname, *cmdname, *dot;
assert(argc > 3);
svcname = argv[1];
! newname = argv[2];
! cmdname = argv[3];
if (!(service = service_find(svcname))) {
! send_message(user, cmd->parent->bot, MCMSG_UNKNOWN_SERVICE, svcname);
return 0;
}
if ((newcmd = dict_find(service->commands, newname, NULL))) {
! send_message(user, cmd->parent->bot, MCMSG_ALREADY_BOUND, service->bot->nick, newname);
return 0;
}
--- 897,958 ----
}
+ static unsigned int
+ collapse_cmdname(unsigned char *argv[], unsigned int argc, char *dest) {
+ unsigned int ii, pos, arg;
+ if (!argc) {
+ dest[0] = 0;
+ return 0;
+ }
+ for (ii=pos=0, arg=0; argv[arg][ii]; ) {
+ if (argv[arg][ii] == '\\') {
+ if (argv[arg][ii+1]) {
+ /* escaping a real character just puts it in literally */
+ dest[pos++] = argv[arg][++ii];
+ } else if (arg == argc) {
+ /* we ran to the end of the argument list; abort */
+ break;
+ } else {
+ /* escape at end of a word is a space */
+ dest[pos++] = ' ';
+ ii = 0;
+ arg++;
+ }
+ } else {
+ /* normal characters don't need escapes */
+ dest[pos++] = argv[arg][ii++];
+ }
+ }
+ dest[pos] = 0;
+ return arg + 1;
+ }
+
static MODCMD_FUNC(cmd_bind) {
struct service *service;
struct svccmd *template, *newcmd;
! char *svcname, *dot;
! char newname[MAXLEN], cmdname[MAXLEN];
! unsigned int arg, diff;
assert(argc > 3);
svcname = argv[1];
! arg = collapse_cmdname(argv+2, argc-2, newname) + 2;
! if (!arg) {
! reply(MSG_MISSING_PARAMS, cmd->name);
! return 0;
! }
! diff = collapse_cmdname(argv+arg, argc-arg, cmdname);
! if (!diff) {
! reply(MSG_MISSING_PARAMS, cmd->name);
! return 0;
! }
! arg += diff;
if (!(service = service_find(svcname))) {
! reply(MCMSG_UNKNOWN_SERVICE, svcname);
return 0;
}
if ((newcmd = dict_find(service->commands, newname, NULL))) {
! reply(MCMSG_ALREADY_BOUND, service->bot->nick, newname);
return 0;
}
***************
*** 920,928 ****
module = module_find(cmdname);
if (!module) {
! send_message(user, cmd->parent->bot, MSG_MODULE_UNKNOWN, cmdname);
return 0;
}
count = service_bind_module(service, module);
! send_message(user, service->bot, MCMSG_MODULE_BOUND, count, module->name, service->bot->nick);
return count != 0;
}
--- 964,972 ----
module = module_find(cmdname);
if (!module) {
! reply(MSG_MODULE_UNKNOWN, cmdname);
return 0;
}
count = service_bind_module(service, module);
! reply(MCMSG_MODULE_BOUND, count, module->name, service->bot->nick);
return count != 0;
}
***************
*** 931,935 ****
newcmd->parent = service;
if (!(template = svccmd_resolve_name(newcmd, cmdname))) {
! send_message(user, cmd->parent->bot, MCMSG_UNKNOWN_COMMAND_2, cmdname, service->bot->nick);
free(newcmd->name);
free(newcmd);
--- 975,979 ----
newcmd->parent = service;
if (!(template = svccmd_resolve_name(newcmd, cmdname))) {
! reply(MCMSG_UNKNOWN_COMMAND_2, cmdname, service->bot->nick);
free(newcmd->name);
free(newcmd);
***************
*** 937,941 ****
}
if (template->alias.used) {
! send_message(user, cmd->parent->bot, MCMSG_CANNOT_DOUBLE_ALIAS);
free(newcmd->name);
free(newcmd);
--- 981,985 ----
}
if (template->alias.used) {
! reply(MCMSG_CANNOT_DOUBLE_ALIAS);
free(newcmd->name);
free(newcmd);
***************
*** 943,953 ****
}
! if (argc > 4) {
/* a more complicated alias; fix it up */
unsigned int nn;
! nn = check_alias_args(argv+3, argc-3);
! if (nn+3 < argc) {
! send_message(user, cmd->parent->bot, MCMSG_BAD_ALIAS_ARGUMENT, argv[nn+3]);
free(newcmd->name);
free(newcmd);
--- 987,997 ----
}
! if (argc > arg+1) {
/* a more complicated alias; fix it up */
unsigned int nn;
! nn = check_alias_args(argv+arg, argc-arg);
! if (nn+arg < argc) {
! reply(MCMSG_BAD_ALIAS_ARGUMENT, argv[nn+arg]);
free(newcmd->name);
free(newcmd);
***************
*** 963,967 ****
newcmd->template = template;
svccmd_insert(service, newcmd->name, newcmd, template->command);
! send_message(user, cmd->parent->bot, MCMSG_COMMAND_BOUND, newcmd->name, newcmd->parent->bot->nick);
return 1;
}
--- 1007,1011 ----
newcmd->template = template;
svccmd_insert(service, newcmd->name, newcmd, template->command);
! reply(MCMSG_COMMAND_BOUND, newcmd->name, newcmd->parent->bot->nick);
return 1;
}
***************
*** 984,1019 ****
struct userNode *bot;
struct svccmd *bound;
! const char *svcname, *cmdname;
assert(argc > 2);
svcname = argv[1];
! cmdname = argv[2];
!
if (!(service = service_find(svcname))) {
! send_message(user, cmd->parent->bot, MCMSG_UNKNOWN_SERVICE, svcname);
return 0;
}
if (!(bound = dict_find(service->commands, cmdname, NULL))) {
! send_message(user, cmd->parent->bot, MCMSG_NO_COMMAND_BOUND, service->bot->nick, cmdname);
return 0;
}
if ((bound->command->flags & MODCMD_KEEP_BOUND) && (bound->command->bind_count == 1)) {
! send_message(user, cmd->parent->bot, MCMSG_UNBIND_PROHIBITED, bound->command->name);
return 0;
}
! /* If this command is removing a binding to itself, we (and
! svccmd_invoke_argv) must take care not to dereference cmd.
! Return 0 if so - we avoid the dereference, but the
! invocation will not be logged; the alternative is to hoist
! the log message generation above the dispatch.
! */
bot = cmd->parent->bot;
-
dict_remove(service->commands, bound->name);
service_rebuild_modules(service);
send_message(user, bot, MCMSG_COMMAND_UNBOUND, cmdname, service->bot->nick);
! return cmd == bound ? 0 : 1;
}
--- 1028,1064 ----
struct userNode *bot;
struct svccmd *bound;
! const char *svcname;
! unsigned int arg;
! char cmdname[MAXLEN];
assert(argc > 2);
svcname = argv[1];
! arg = collapse_cmdname(argv+2, argc-2, cmdname) + 2;
! if (!arg) {
! reply(MSG_MISSING_PARAMS, cmd->name);
! return 0;
! }
if (!(service = service_find(svcname))) {
! reply(MCMSG_UNKNOWN_SERVICE, svcname);
return 0;
}
if (!(bound = dict_find(service->commands, cmdname, NULL))) {
! reply(MCMSG_NO_COMMAND_BOUND, service->bot->nick, cmdname);
return 0;
}
if ((bound->command->flags & MODCMD_KEEP_BOUND) && (bound->command->bind_count == 1)) {
! reply(MCMSG_UNBIND_PROHIBITED, bound->command->name);
return 0;
}
! /* If this command is removing a binding to itself, we must take
! * care not to dereference cmd.
! */
bot = cmd->parent->bot;
dict_remove(service->commands, bound->name);
service_rebuild_modules(service);
send_message(user, bot, MCMSG_COMMAND_UNBOUND, cmdname, service->bot->nick);
! return 1;
}
***************
*** 1042,1045 ****
--- 1087,1091 ----
return 0;
}
+ if (old_helpfile) close_helpfile(old_helpfile);
gettimeofday(&stop, NULL);
stop.tv_sec -= start.tv_sec;
***************
*** 1201,1227 ****
static MODCMD_FUNC(cmd_modcmd) {
struct svccmd *svccmd;
! unsigned int ii, pos, arg, changed;
char cmdname[MAXLEN];
! assert(argc >= 4);
! for (ii=pos=0, arg=1; argv[arg][ii]; ) {
! if (argv[arg][ii] == '\\') {
! if (argv[arg][ii+1]) {
! /* escaping a real character just puts it in literally */
! cmdname[pos++] = argv[arg][++ii];
! } else {
! /* escape at end of a word is a space */
! cmdname[pos++] = ' ';
! ii = 0;
! arg++;
! }
! } else {
! /* normal characters don't need escapes */
! cmdname[pos++] = argv[arg][ii++];
! }
}
- cmdname[pos] = 0;
if (!(svccmd = svccmd_resolve_name(cmd, cmdname))) {
! send_message(user, cmd->parent->bot, MCMSG_UNKNOWN_COMMAND_2, cmdname, cmd->parent->bot->nick);
return 0;
}
--- 1247,1261 ----
static MODCMD_FUNC(cmd_modcmd) {
struct svccmd *svccmd;
! unsigned int arg, changed;
char cmdname[MAXLEN];
! assert(argc >= 2);
! arg = collapse_cmdname(argv+1, argc-1, cmdname) + 1;
! if (!arg || (arg+2 < argc)) {
! reply(MSG_MISSING_PARAMS, cmd->name);
! return 0;
}
if (!(svccmd = svccmd_resolve_name(cmd, cmdname))) {
! reply(MCMSG_UNKNOWN_COMMAND_2, cmdname, cmd->parent->bot->nick);
return 0;
}
***************
*** 1229,1233 ****
for (arg++; arg+1 < argc; arg += 2) {
if (svccmd_configure(svccmd, user, cmd->parent->bot, argv[arg], argv[arg+1])) {
! send_message(user, cmd->parent->bot, MCMSG_COMMAND_MODIFIED, argv[arg], svccmd->name);
changed = 1;
}
--- 1263,1267 ----
for (arg++; arg+1 < argc; arg += 2) {
if (svccmd_configure(svccmd, user, cmd->parent->bot, argv[arg], argv[arg+1])) {
! reply(MCMSG_COMMAND_MODIFIED, argv[arg], svccmd->name);
changed = 1;
}
Index: modcmd.h
===================================================================
RCS file: /cvsroot/srvx/services/src/modcmd.h,v
retrieving revision 1.9
retrieving revision 1.10
diff -C2 -r1.9 -r1.10
*** modcmd.h 15 Sep 2002 00:01:12 -0000 1.9
--- modcmd.h 18 Sep 2002 14:50:19 -0000 1.10
***************
*** 38,41 ****
--- 38,43 ----
typedef MODCMD_FUNC(modcmd_func_t);
+ DECLARE_LIST(svccmd_list, struct svccmd*);
+
#if defined(__GNUC__) && (__GNUC__ < 3)
#define reply(FMT...) send_message(user, cmd->parent->bot, FMT)
|