]> jfr.im git - irc/rqf/shadowircd.git/blob - extensions/m_sendbans.c
Don't suggest putting values in an enum that are not in the enum.
[irc/rqf/shadowircd.git] / extensions / m_sendbans.c
1 /*
2 * m_sendbans.c: sends all permanent resvs and xlines to given server
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 "ircd.h"
36 #include "match.h"
37 #include "numeric.h"
38 #include "s_conf.h"
39 #include "s_serv.h"
40 #include "s_newconf.h"
41 #include "send.h"
42 #include "msg.h"
43 #include "hash.h"
44 #include "modules.h"
45
46 static int mo_sendbans(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]);
47
48 struct Message sendbans_msgtab = {
49 "SENDBANS", 0, 0, 0, MFLG_SLOW,
50 {mg_unreg, mg_not_oper, mg_ignore, mg_ignore, mg_ignore, {mo_sendbans, 2}}
51 };
52
53 mapi_clist_av1 sendbans_clist[] = {
54 &sendbans_msgtab,
55 NULL
56 };
57
58 DECLARE_MODULE_AV1(sendbans, NULL, NULL, sendbans_clist, NULL, NULL, "$Revision$");
59
60 static const char *expand_xline(const char *mask)
61 {
62 static char buf[512];
63 const char *p;
64 char *q;
65
66 if (!strchr(mask, ' '))
67 return mask;
68 if (strlen(mask) > 250)
69 return NULL;
70 p = mask;
71 q = buf;
72 while (*p != '\0')
73 {
74 if (*p == ' ')
75 *q++ = '\\', *q++ = 's';
76 else
77 *q++ = *p;
78 p++;
79 }
80 *q = '\0';
81 return buf;
82 }
83
84 static int mo_sendbans(struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
85 {
86 struct ConfItem *aconf;
87 rb_dlink_node *ptr;
88 int i, count;
89 const char *target, *mask2;
90 struct Client *server_p;
91
92 if (!IsOperRemoteBan(source_p))
93 {
94 sendto_one(source_p, form_str(ERR_NOPRIVS),
95 me.name, source_p->name, "remoteban");
96 return 0;
97 }
98 if (!IsOperXline(source_p))
99 {
100 sendto_one(source_p, form_str(ERR_NOPRIVS),
101 me.name, source_p->name, "xline");
102 return 0;
103 }
104 if (!IsOperResv(source_p))
105 {
106 sendto_one(source_p, form_str(ERR_NOPRIVS),
107 me.name, source_p->name, "resv");
108 return 0;
109 }
110
111 target = parv[1];
112 count = 0;
113 RB_DLINK_FOREACH(ptr, global_serv_list.head)
114 {
115 server_p = ptr->data;
116 if (IsMe(server_p))
117 continue;
118 if (match(target, server_p->name))
119 count++;
120 }
121 if (count == 0)
122 {
123 sendto_one_numeric(source_p, ERR_NOSUCHSERVER,
124 form_str(ERR_NOSUCHSERVER), target);
125 return 0;
126 }
127
128 sendto_realops_snomask(SNO_GENERAL, L_NETWIDE,
129 "%s!%s@%s is sending resvs and xlines to %s",
130 source_p->name, source_p->username, source_p->host,
131 target);
132
133 RB_DLINK_FOREACH(ptr, resv_conf_list.head)
134 {
135 aconf = ptr->data;
136 if (aconf->hold)
137 continue;
138 sendto_match_servs(source_p, target,
139 CAP_ENCAP, NOCAPS,
140 "ENCAP %s RESV 0 %s 0 :%s",
141 target, aconf->name, aconf->passwd);
142 }
143
144 HASH_WALK(i, R_MAX, ptr, resvTable)
145 {
146 aconf = ptr->data;
147 if (aconf->hold)
148 continue;
149 sendto_match_servs(source_p, target,
150 CAP_ENCAP, NOCAPS,
151 "ENCAP %s RESV 0 %s 0 :%s",
152 target, aconf->name, aconf->passwd);
153 }
154 HASH_WALK_END
155
156 RB_DLINK_FOREACH(ptr, xline_conf_list.head)
157 {
158 aconf = ptr->data;
159 if (aconf->hold)
160 continue;
161 mask2 = expand_xline(aconf->name);
162 if (mask2 == NULL)
163 {
164 sendto_one_notice(source_p, ":Skipping xline [%s]",
165 aconf->name);
166 continue;
167 }
168 sendto_match_servs(source_p, target,
169 CAP_ENCAP, NOCAPS,
170 "ENCAP %s XLINE 0 %s 2 :%s",
171 target, mask2, aconf->passwd);
172 }
173
174 return 0;
175 }