]> jfr.im git - solanum.git/blobdiff - modules/m_grant.c
m_list: fail on invalid parameters
[solanum.git] / modules / m_grant.c
index ed097004615ff12934bbbe398aedbae979c7aef9..0f41f4c72e1a609efea3c67cc1a68de651316f05 100644 (file)
@@ -15,8 +15,8 @@
 #include "s_newconf.h"
 #include "msgbuf.h"
 
-static int mo_grant(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char *parv[]);
-static int me_grant(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char *parv[]);
+static void mo_grant(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char *parv[]);
+static void me_grant(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char *parv[]);
 
 static int do_grant(struct Client *source_p, struct Client *target_p, const char *new_privset);
 
@@ -27,9 +27,11 @@ struct Message grant_msgtab = {
 
 mapi_clist_av1 grant_clist[] = { &grant_msgtab, NULL };
 
-DECLARE_MODULE_AV1(grant, NULL, NULL, grant_clist, NULL, NULL, "$Revision$");
+static const char grant_desc[] = "Allows operators to set or remove operator privileges on other users";
 
-static int
+DECLARE_MODULE_AV2(grant, NULL, NULL, grant_clist, NULL, NULL, NULL, NULL, grant_desc);
+
+static void
 mo_grant(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
 {
        struct Client *target_p;
@@ -37,7 +39,7 @@ mo_grant(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source
        if(!HasPrivilege(source_p, "oper:grant"))
        {
                sendto_one(source_p, form_str(ERR_NOPRIVS), me.name, source_p->name, "grant");
-               return 0;
+               return;
        }
 
        target_p = find_named_person(parv[1]);
@@ -45,7 +47,7 @@ mo_grant(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source
        {
                sendto_one_numeric(source_p, ERR_NOSUCHNICK,
                                form_str(ERR_NOSUCHNICK), parv[1]);
-               return 0;
+               return;
        }
 
        if (MyClient(target_p))
@@ -58,11 +60,9 @@ mo_grant(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source
                                get_id(source_p, target_p), target_p->servptr->name,
                                get_id(target_p, target_p), parv[2]);
        }
-
-       return 0;
 }
 
-static int
+static void
 me_grant(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
 {
        struct Client *target_p;
@@ -72,36 +72,25 @@ me_grant(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source
        {
                sendto_one_numeric(source_p, ERR_NOSUCHNICK,
                                form_str(ERR_NOSUCHNICK), parv[1]);
-               return 0;
-       }
-
-       if(!find_shared_conf(source_p->username, source_p->host,
-                               source_p->servptr->name, SHARED_GRANT))
-       {
-               sendto_one(source_p, ":%s NOTICE %s :You don't have an appropriate shared"
-                       "block to grant privilege on this server.", me.name, source_p->name);
-               return 0;
+               return;
        }
 
        do_grant(source_p, target_p, parv[2]);
-
-       return 0;
 }
 
 
 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 (!strcmp(new_privset, "deoper"))
+       if (!strcasecmp(new_privset, "deoper"))
        {
                if (!IsOper(target_p))
                {
                        sendto_one_notice(source_p, ":You can't deoper someone who isn't an oper.");
                        return 0;
                }
-               new_privset = "default";
                dodeoper = 1;
 
                sendto_one_notice(target_p, ":%s is deopering you.", source_p->name);
@@ -120,6 +109,12 @@ static int do_grant(struct Client *source_p, struct Client *target_p, const char
                        sendto_one_notice(source_p, ":%s already has privilege set %s.", target_p->name, target_p->user->privset->name);
                        return 0;
                }
+
+               if (ConfigFileEntry.oper_secure_only && !IsSecureClient(target_p))
+               {
+                       sendto_one_notice(source_p, ":Cannot GRANT %s, opers must be using secure connections.", target_p->name);
+                       return 0;
+               }
        }
 
        if (!dodeoper)
@@ -149,32 +144,43 @@ 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)
        {
-               struct oper_conf oper;
+               struct oper_conf oper = {0};
                oper.name = "<grant>";
-               oper.umodes = 0;
-               oper.snomask = 0;
                oper.privset = privset;
 
                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;
-       const char *modeparv[4];
-       modeparv[0] = modeparv[1] = target_p->name;
-       modeparv[2] = "+";
-       modeparv[3] = NULL;
-       user_mode(target_p, target_p, 3, modeparv);
+               report_priv_change(target_p, old_privset, privset);
+
+               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);
+       }
 
        return 0;
 }