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