]> jfr.im git - solanum.git/blame - modules/m_privs.c
modules: warning cleanups
[solanum.git] / modules / m_privs.c
CommitLineData
c728f993
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
eeabf33a
EM
43static const char privs_desc[] = "Provides the PRIVS command to inspect an operator's privileges";
44
3c7d6fcc
EM
45static void m_privs(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char *parv[]);
46static void me_privs(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char *parv[]);
47static void mo_privs(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char *parv[]);
c728f993
JT
48
49struct Message privs_msgtab = {
7baa37a9 50 "PRIVS", 0, 0, 0, 0,
ed11b18f 51 {mg_unreg, {m_privs, 0}, mg_ignore, mg_ignore, {me_privs, 0}, {mo_privs, 0}}
c728f993
JT
52};
53
54mapi_clist_av1 privs_clist[] = {
55 &privs_msgtab,
56 NULL
57};
58
59/* XXX this is a copy, not so nice */
60struct mode_table
61{
62 const char *name;
29c92cf9 63 unsigned int mode;
c728f993
JT
64};
65
c728f993
JT
66/* there is no such table like this anywhere else */
67static struct mode_table auth_client_table[] = {
68 {"resv_exempt", FLAGS2_EXEMPTRESV },
c728f993
JT
69 {"kline_exempt", FLAGS2_EXEMPTKLINE },
70 {"flood_exempt", FLAGS2_EXEMPTFLOOD },
c728f993
JT
71 {"spambot_exempt", FLAGS2_EXEMPTSPAMBOT },
72 {"shide_exempt", FLAGS2_EXEMPTSHIDE },
73 {"jupe_exempt", FLAGS2_EXEMPTJUPE },
a4721f5e 74 {"extend_chans", FLAGS2_EXTENDCHANS },
c728f993
JT
75 {NULL, 0}
76};
77
d5d35409 78DECLARE_MODULE_AV2(privs, NULL, NULL, privs_clist, NULL, NULL, NULL, NULL, privs_desc);
c728f993
JT
79
80static void show_privs(struct Client *source_p, struct Client *target_p)
81{
82 char buf[512];
83 struct mode_table *p;
84
85 buf[0] = '\0';
50f25792
AC
86 if (target_p->localClient->privset)
87 rb_strlcat(buf, target_p->localClient->privset->privs, sizeof buf);
c728f993
JT
88 if (IsOper(target_p))
89 {
90 if (buf[0] != '\0')
1f9de103
VY
91 rb_strlcat(buf, " ", sizeof buf);
92 rb_strlcat(buf, "operator:", sizeof buf);
93 rb_strlcat(buf, target_p->localClient->opername, sizeof buf);
50f25792
AC
94
95 if (target_p->localClient->privset)
96 {
97 if (buf[0] != '\0')
98 rb_strlcat(buf, " ", sizeof buf);
99 rb_strlcat(buf, "privset:", sizeof buf);
100 rb_strlcat(buf, target_p->localClient->privset->name, sizeof buf);
101 }
c728f993
JT
102 }
103 p = &auth_client_table[0];
104 while (p->name != NULL)
105 {
106 if (target_p->flags2 & p->mode)
107 {
108 if (buf[0] != '\0')
1f9de103
VY
109 rb_strlcat(buf, " ", sizeof buf);
110 rb_strlcat(buf, p->name, sizeof buf);
c728f993
JT
111 }
112 p++;
113 }
7b7e1640
JT
114 sendto_one_numeric(source_p, RPL_PRIVS, form_str(RPL_PRIVS),
115 target_p->name, buf);
c728f993
JT
116}
117
3c7d6fcc
EM
118static void
119me_privs(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
c728f993
JT
120{
121 struct Client *target_p;
122
123 if (!IsOper(source_p) || parc < 2 || EmptyString(parv[1]))
3c7d6fcc 124 return;
c728f993
JT
125
126 /* we cannot show privs for remote clients */
127 if((target_p = find_person(parv[1])) && MyClient(target_p))
128 show_privs(source_p, target_p);
c728f993
JT
129}
130
3c7d6fcc
EM
131static void
132mo_privs(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
c728f993
JT
133{
134 struct Client *target_p;
135
136 if (parc < 2 || EmptyString(parv[1]))
137 target_p = source_p;
138 else
139 {
140 target_p = find_named_person(parv[1]);
141 if (target_p == NULL)
142 {
143 sendto_one_numeric(source_p, ERR_NOSUCHNICK,
144 form_str(ERR_NOSUCHNICK), parv[1]);
3c7d6fcc 145 return;
c728f993
JT
146 }
147 }
148
149 if (MyClient(target_p))
150 show_privs(source_p, target_p);
151 else
152 sendto_one(target_p, ":%s ENCAP %s PRIVS %s",
153 get_id(source_p, target_p),
154 target_p->servptr->name,
155 use_id(target_p));
c728f993 156}
ed11b18f 157
3c7d6fcc
EM
158static void
159m_privs(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
ed11b18f
JT
160{
161 if (parc >= 2 && !EmptyString(parv[1]) &&
162 irccmp(parv[1], source_p->name)) {
163 sendto_one_numeric(source_p, ERR_NOPRIVILEGES,
164 form_str(ERR_NOPRIVILEGES));
3c7d6fcc 165 return;
ed11b18f
JT
166 }
167
168 show_privs(source_p, source_p);
ed11b18f 169}