From f3c60e6c6280d6447c195fac44870fafbdcdad77 Mon Sep 17 00:00:00 2001 From: Mike Belopuhov Date: Thu, 6 Mar 2014 16:27:45 +0100 Subject: [PATCH] After some deliberation we have decided that if modtab is enabled then it should be possible to steal the moderation. --- cmd.c | 14 +++++++++++--- icb.c | 7 ++----- icb.h | 2 +- 3 files changed, 14 insertions(+), 9 deletions(-) diff --git a/cmd.c b/cmd.c index 9384347..cf8731c 100644 --- a/cmd.c +++ b/cmd.c @@ -302,8 +302,8 @@ icb_cmd_pass(struct icb_session *is, char *arg) struct icb_session *s; char whom[ICB_MAXNICKLEN]; - if (!ig->mod) { /* if there is no mod, let anyone grab it */ - if (icb_pass(ig, ig->mod, is) < 0) + if (!ig->mod) { /* if there is no mod, try grabbing it */ + if (icb_modpermit(is, 0) && icb_pass(ig, ig->mod, is) < 0) icb_error(is, "Acquiring group moderation failed."); } else if (icb_ismod(ig, is)) { if (strlen(arg) == 0) { @@ -320,8 +320,16 @@ icb_cmd_pass(struct icb_session *is, char *arg) icb_status(is, STATUS_NOTIFY, "No such user"); return; } - if (icb_pass(ig, ig->mod, s) < 0) + if (icb_modpermit(s, 0) && icb_pass(ig, ig->mod, s) < 0) icb_error(s, "Acquiring group moderation failed."); + } else { + /* + * if group is moderated and we're not the moderator, + * but modtab is enabled, then check the permission + * and pass moderation if successful. + */ + if (icb_modpermit(is, 1) && icb_pass(ig, ig->mod, is) < 0) + icb_error(is, "Acquiring group moderation failed."); } } diff --git a/icb.c b/icb.c index a5c8803..14cb5d9 100644 --- a/icb.c +++ b/icb.c @@ -36,7 +36,6 @@ void icb_command(struct icb_session *, char *, char *); void icb_groupmsg(struct icb_session *, char *); void icb_login(struct icb_session *, char *, char *, char *); int icb_dowho(struct icb_session *, struct icb_group *); -int icb_modpermit(struct icb_session *); char *icb_nextfield(char **); /* @@ -546,12 +545,12 @@ icb_ismod(struct icb_group *ig, struct icb_session *is) * been populated */ int -icb_modpermit(struct icb_session *is) +icb_modpermit(struct icb_session *is, int enforce) { extern char modtab[ICB_MTABLEN][ICB_MAXNICKLEN]; extern int modtabcnt; - if (modtabcnt == 0 || + if ((enforce ? 0 : modtabcnt == 0) || bsearch(is->nick, modtab, modtabcnt, ICB_MAXNICKLEN, (int (*)(const void *, const void *))strcmp)) return (1); @@ -572,8 +571,6 @@ icb_pass(struct icb_group *ig, struct icb_session *from, return (-1); if (!from && !to) return (-1); - if (to && !icb_modpermit(to)) - return (-1); ig->mod = to; if (to) icb_status(to, STATUS_NOTIFY, "%s just passed you moderation" diff --git a/icb.h b/icb.h index 6bada12..4b8cb5d 100644 --- a/icb.h +++ b/icb.h @@ -128,7 +128,7 @@ void icb_error(struct icb_session *, const char *, ...); void icb_init(struct icbd_callbacks *); void icb_input(struct icb_session *); inline int icb_ismod(struct icb_group *, struct icb_session *); -int icb_modpermit(struct icb_session *); +int icb_modpermit(struct icb_session *, int); int icb_pass(struct icb_group *, struct icb_session *, struct icb_session *); void icb_privmsg(struct icb_session *, char *, char *);