]> jfr.im git - solanum.git/blobdiff - modules/m_privs.c
Merge pull request #279 from edk0/operhide
[solanum.git] / modules / m_privs.c
index 1d24aad5ad9235ffbd809cc8bce00f0d4e84d71e..c71327dce7937d29f24f24a816abdd12f9d36156 100644 (file)
@@ -31,7 +31,6 @@
 
 #include "stdinc.h"
 #include "client.h"
-#include "common.h"
 #include "numeric.h"
 #include "send.h"
 #include "msg.h"
 #include "s_conf.h"
 #include "s_newconf.h"
 
-static int me_privs(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]);
-static int mo_privs(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]);
+static const char privs_desc[] = "Provides the PRIVS command to inspect an operator's privileges";
+
+static void m_privs(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char *parv[]);
+static void me_privs(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char *parv[]);
+static void mo_privs(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char *parv[]);
 
 struct Message privs_msgtab = {
-       "PRIVS", 0, 0, 0, MFLG_SLOW,
-       {mg_unreg, mg_not_oper, mg_ignore, mg_ignore, {me_privs, 0}, {mo_privs, 0}}
+       "PRIVS", 0, 0, 0, 0,
+       {mg_unreg, {m_privs, 0}, mg_ignore, mg_ignore, {me_privs, 0}, {mo_privs, 0}}
 };
 
 mapi_clist_av1 privs_clist[] = {
@@ -53,25 +55,30 @@ mapi_clist_av1 privs_clist[] = {
        NULL
 };
 
-/* XXX this is a copy, not so nice */
+/* XXX this is a copy, not so nice
+ *
+ * Sort of... it's int in newconf.c since oper confs don't need 64-bit wide flags.
+ * --Elizafox
+ */
 struct mode_table
 {
        const char *name;
-       int mode;
+       uint64_t mode;
 };
 
 /* there is no such table like this anywhere else */
 static struct mode_table auth_client_table[] = {
-       {"resv_exempt",         FLAGS2_EXEMPTRESV       },
-       {"kline_exempt",        FLAGS2_EXEMPTKLINE      },
-       {"flood_exempt",        FLAGS2_EXEMPTFLOOD      },
-       {"spambot_exempt",      FLAGS2_EXEMPTSPAMBOT    },
-       {"shide_exempt",        FLAGS2_EXEMPTSHIDE      },
-       {"jupe_exempt",         FLAGS2_EXEMPTJUPE       },
+       {"resv_exempt",         FLAGS_EXEMPTRESV        },
+       {"kline_exempt",        FLAGS_EXEMPTKLINE       },
+       {"flood_exempt",        FLAGS_EXEMPTFLOOD       },
+       {"spambot_exempt",      FLAGS_EXEMPTSPAMBOT     },
+       {"shide_exempt",        FLAGS_EXEMPTSHIDE       },
+       {"jupe_exempt",         FLAGS_EXEMPTJUPE        },
+       {"extend_chans",        FLAGS_EXTENDCHANS       },
        {NULL, 0}
 };
 
-DECLARE_MODULE_AV1(privs, NULL, NULL, privs_clist, NULL, NULL, "");
+DECLARE_MODULE_AV2(privs, NULL, NULL, privs_clist, NULL, NULL, NULL, NULL, privs_desc);
 
 static void show_privs(struct Client *source_p, struct Client *target_p)
 {
@@ -99,7 +106,7 @@ static void show_privs(struct Client *source_p, struct Client *target_p)
        p = &auth_client_table[0];
        while (p->name != NULL)
        {
-               if (target_p->flags2 & p->mode)
+               if (target_p->flags & p->mode)
                {
                        if (buf[0] != '\0')
                                rb_strlcat(buf, " ", sizeof buf);
@@ -111,21 +118,21 @@ static void show_privs(struct Client *source_p, struct Client *target_p)
                        target_p->name, buf);
 }
 
-static int me_privs(struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
+static void
+me_privs(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
 {
        struct Client *target_p;
 
        if (!IsOper(source_p) || parc < 2 || EmptyString(parv[1]))
-               return 0;
+               return;
 
        /* we cannot show privs for remote clients */
        if((target_p = find_person(parv[1])) && MyClient(target_p))
                show_privs(source_p, target_p);
-
-       return 0;
 }
 
-static int mo_privs(struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
+static void
+mo_privs(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
 {
        struct Client *target_p;
 
@@ -138,7 +145,7 @@ static int mo_privs(struct Client *client_p, struct Client *source_p, int parc,
                {
                        sendto_one_numeric(source_p, ERR_NOSUCHNICK,
                                           form_str(ERR_NOSUCHNICK), parv[1]);
-                       return 0;
+                       return;
                }
        }
 
@@ -149,5 +156,17 @@ static int mo_privs(struct Client *client_p, struct Client *source_p, int parc,
                                get_id(source_p, target_p),
                                target_p->servptr->name,
                                use_id(target_p));
-       return 0;
+}
+
+static void
+m_privs(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
+{
+       if (parc >= 2 && !EmptyString(parv[1]) &&
+                       irccmp(parv[1], source_p->name)) {
+               sendto_one_numeric(source_p, ERR_NOPRIVILEGES,
+                                  form_str(ERR_NOPRIVILEGES));
+               return;
+       }
+
+       show_privs(source_p, source_p);
 }