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