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