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