]> jfr.im git - solanum.git/blobdiff - modules/m_grant.c
m_list: fail on invalid parameters
[solanum.git] / modules / m_grant.c
index 0021b7c00348b04f43e768f37dbd1befc08b9a1b..0f41f4c72e1a609efea3c67cc1a68de651316f05 100644 (file)
@@ -82,7 +82,7 @@ me_grant(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source
 static int do_grant(struct Client *source_p, struct Client *target_p, const char *new_privset)
 {
        int dooper = 0, dodeoper = 0;
-       struct PrivilegeSet *privset = 0;
+       struct PrivilegeSet *privset = NULL, *old_privset = NULL;
 
        if (!strcasecmp(new_privset, "deoper"))
        {
@@ -144,6 +144,8 @@ static int do_grant(struct Client *source_p, struct Client *target_p, const char
                modeparv[2] = "-o";
                modeparv[3] = NULL;
                user_mode(target_p, target_p, 3, modeparv);
+
+               return 0;
        }
 
        if (dooper)
@@ -154,25 +156,31 @@ static int do_grant(struct Client *source_p, struct Client *target_p, const char
 
                oper_up(target_p, &oper);
        }
-       else if (privset != NULL)
+       else
        {
-               privilegeset_ref(privset);
-       }
+               if (privset != NULL)
+                       privilegeset_ref(privset);
+
+               if (target_p->user->privset != NULL)
+                       old_privset = target_p->user->privset;
+
+               target_p->user->privset = privset;
 
-       if (target_p->user->privset != NULL)
-               privilegeset_unref(target_p->user->privset);
+               if (privset != NULL)
+                       sendto_server(NULL, NULL, CAP_TS6, NOCAPS, ":%s OPER %s %s",
+                                       use_id(target_p), target_p->user->opername, privset->name);
 
-       target_p->user->privset = privset;
+               report_priv_change(target_p, old_privset, privset);
 
-       if (privset != NULL)
-               sendto_server(NULL, NULL, CAP_TS6, NOCAPS, ":%s OPER %s %s",
-                               use_id(target_p), target_p->user->opername, privset->name);
+               if (old_privset != NULL)
+                       privilegeset_unref(old_privset);
 
-       const char *modeparv[4];
-       modeparv[0] = modeparv[1] = target_p->name;
-       modeparv[2] = "+";
-       modeparv[3] = NULL;
-       user_mode(target_p, target_p, 3, modeparv);
+               const char *modeparv[4];
+               modeparv[0] = modeparv[1] = target_p->name;
+               modeparv[2] = "+";
+               modeparv[3] = NULL;
+               user_mode(target_p, target_p, 3, modeparv);
+       }
 
        return 0;
 }