]> jfr.im git - irc/rqf/shadowircd.git/blame - extensions/m_privs.c
Add PRIVS extension, a command that shows oper and some auth{} privileges.
[irc/rqf/shadowircd.git] / extensions / m_privs.c
CommitLineData
93d880f9
JT
1/*
2 * m_privs.c: Shows effective operator privileges
3 *
4 * Copyright (C) 2008 Jilles Tjoelker
5 * Copyright (C) 2008 charybdis development team
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions are
9 * met:
10 *
11 * 1.Redistributions of source code must retain the above copyright notice,
12 * this list of conditions and the following disclaimer.
13 * 2.Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3.The name of the author may not be used to endorse or promote products
17 * derived from this software without specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
20 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22 * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
23 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
25 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
27 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
28 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
30 */
31
32#include "stdinc.h"
33#include "client.h"
34#include "common.h"
35#include "numeric.h"
36#include "send.h"
37#include "msg.h"
38#include "parse.h"
39#include "modules.h"
40#include "s_conf.h"
41#include "s_newconf.h"
42
43#define RPL_PRIVS 270 /* from ircu */
44
45static int me_privs(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]);
46static int mo_privs(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]);
47
48struct Message privs_msgtab = {
49 "PRIVS", 0, 0, 0, MFLG_SLOW,
50 {mg_unreg, mg_not_oper, mg_ignore, mg_ignore, {me_privs, 0}, {mo_privs, 0}}
51};
52
53mapi_clist_av1 privs_clist[] = {
54 &privs_msgtab,
55 NULL
56};
57
58/* XXX this is a copy, not so nice */
59struct mode_table
60{
61 const char *name;
62 int mode;
63};
64
65static struct mode_table oper_table[] = {
66 /*{"encrypted", OPER_ENCRYPTED },*/
67 {"local_kill", OPER_LOCKILL },
68 {"global_kill", OPER_GLOBKILL/*|OPER_LOCKILL*/ },
69 {"remote", OPER_REMOTE },
70 {"kline", OPER_KLINE },
71 {"unkline", OPER_UNKLINE },
72 {"gline", OPER_GLINE },
73 {"nick_changes", OPER_NICKS },
74 {"rehash", OPER_REHASH },
75 {"die", OPER_DIE },
76 {"admin", OPER_ADMIN },
77 {"hidden_admin", OPER_HADMIN },
78 {"xline", OPER_XLINE },
79 {"resv", OPER_RESV },
80 {"operwall", OPER_OPERWALL },
81 {"oper_spy", OPER_SPY },
82 {"hidden_oper", OPER_INVIS },
83 {"remoteban", OPER_REMOTEBAN },
84 {"mass_notice", OPER_MASSNOTICE },
85 {NULL, 0}
86};
87
88/* there is no such table like this anywhere else */
89static struct mode_table auth_client_table[] = {
90 {"resv_exempt", FLAGS2_EXEMPTRESV },
91 {"gline_exempt", FLAGS2_EXEMPTGLINE },
92 {"kline_exempt", FLAGS2_EXEMPTKLINE },
93 {"flood_exempt", FLAGS2_EXEMPTFLOOD },
94 /*{"exceed_limit", FLAGS2_NOLIMIT }, no effect (?) */
95 {"spambot_exempt", FLAGS2_EXEMPTSPAMBOT },
96 {"shide_exempt", FLAGS2_EXEMPTSHIDE },
97 {"jupe_exempt", FLAGS2_EXEMPTJUPE },
98 {NULL, 0}
99};
100
101DECLARE_MODULE_AV1(privs, NULL, NULL, privs_clist, NULL, NULL, "");
102
103static void show_privs(struct Client *source_p, struct Client *target_p)
104{
105 char buf[512];
106 struct mode_table *p;
107
108 buf[0] = '\0';
109 p = &oper_table[0];
110 while (p->name != NULL)
111 {
112 if (target_p->flags2 & p->mode)
113 {
114 if (buf[0] != '\0')
115 strlcat(buf, " ", sizeof buf);
116 strlcat(buf, p->name, sizeof buf);
117 }
118 p++;
119 }
120 if (IsOper(target_p))
121 {
122 if (buf[0] != '\0')
123 strlcat(buf, " ", sizeof buf);
124 strlcat(buf, "O", sizeof buf);
125 }
126 p = &auth_client_table[0];
127 while (p->name != NULL)
128 {
129 if (target_p->flags2 & p->mode)
130 {
131 if (buf[0] != '\0')
132 strlcat(buf, " ", sizeof buf);
133 strlcat(buf, p->name, sizeof buf);
134 }
135 p++;
136 }
137 sendto_one_numeric(source_p, RPL_PRIVS, "%s :%s", target_p->name, buf);
138}
139
140static int me_privs(struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
141{
142 struct Client *target_p;
143
144 if (!IsOper(source_p) || parc < 2 || EmptyString(parv[1]))
145 return 0;
146
147 /* we cannot show privs for remote clients */
148 if((target_p = find_person(parv[1])) && MyClient(target_p))
149 show_privs(source_p, target_p);
150
151 return 0;
152}
153
154static int mo_privs(struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
155{
156 struct Client *target_p;
157
158 if (parc < 2 || EmptyString(parv[1]))
159 target_p = source_p;
160 else
161 {
162 target_p = find_named_person(parv[1]);
163 if (target_p == NULL)
164 {
165 sendto_one_numeric(source_p, ERR_NOSUCHNICK,
166 form_str(ERR_NOSUCHNICK), parv[1]);
167 return 0;
168 }
169 }
170
171 if (MyClient(target_p))
172 show_privs(source_p, target_p);
173 else
174 sendto_one(target_p, ":%s ENCAP %s PRIVS %s",
175 get_id(source_p, target_p),
176 target_p->servptr->name,
177 use_id(target_p));
178 return 0;
179}