]> jfr.im git - irc/quakenet/snircd.git/blob - ircd/m_gline.c
fixed autochanmodes code so it works for channel modes +CN
[irc/quakenet/snircd.git] / ircd / m_gline.c
1 /*
2 * IRC - Internet Relay Chat, ircd/m_gline.c
3 * Copyright (C) 1990 Jarkko Oikarinen and
4 * University of Oulu, Computing Center
5 *
6 * See file AUTHORS in IRC package for additional names of
7 * the programmers.
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 1, or (at your option)
12 * any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 *
23 * $Id: m_gline.c,v 1.26 2004/12/11 05:13:46 klmitch Exp $
24 */
25
26 /*
27 * m_functions execute protocol messages on this server:
28 *
29 * cptr is always NON-NULL, pointing to a *LOCAL* client
30 * structure (with an open socket connected!). This
31 * identifies the physical socket where the message
32 * originated (or which caused the m_function to be
33 * executed--some m_functions may call others...).
34 *
35 * sptr is the source of the message, defined by the
36 * prefix part of the message if present. If not
37 * or prefix not found, then sptr==cptr.
38 *
39 * (!IsServer(cptr)) => (cptr == sptr), because
40 * prefixes are taken *only* from servers...
41 *
42 * (IsServer(cptr))
43 * (sptr == cptr) => the message didn't
44 * have the prefix.
45 *
46 * (sptr != cptr && IsServer(sptr) means
47 * the prefix specified servername. (?)
48 *
49 * (sptr != cptr && !IsServer(sptr) means
50 * that message originated from a remote
51 * user (not local).
52 *
53 * combining
54 *
55 * (!IsServer(sptr)) means that, sptr can safely
56 * taken as defining the target structure of the
57 * message in this server.
58 *
59 * *Always* true (if 'parse' and others are working correct):
60 *
61 * 1) sptr->from == cptr (note: cptr->from == cptr)
62 *
63 * 2) MyConnect(sptr) <=> sptr == cptr (e.g. sptr
64 * *cannot* be a local connection, unless it's
65 * actually cptr!). [MyConnect(x) should probably
66 * be defined as (x == x->from) --msa ]
67 *
68 * parc number of variable parameter strings (if zero,
69 * parv is allowed to be NULL)
70 *
71 * parv a NULL terminated list of parameter pointers,
72 *
73 * parv[0], sender (prefix string), if not present
74 * this points to an empty string.
75 * parv[1]...parv[parc-1]
76 * pointers to additional parameters
77 * parv[parc] == NULL, *always*
78 *
79 * note: it is guaranteed that parv[0]..parv[parc-1] are all
80 * non-NULL pointers.
81 */
82 #include "config.h"
83
84 #include "client.h"
85 #include "gline.h"
86 #include "hash.h"
87 #include "ircd.h"
88 #include "ircd_features.h"
89 #include "ircd_log.h"
90 #include "ircd_reply.h"
91 #include "ircd_string.h"
92 #include "match.h"
93 #include "msg.h"
94 #include "numeric.h"
95 #include "numnicks.h"
96 #include "s_conf.h"
97 #include "s_misc.h"
98 #include "send.h"
99
100 /* #include <assert.h> -- Now using assert in ircd_log.h */
101 #include <stdlib.h>
102 #include <string.h>
103
104 /*
105 * ms_gline - server message handler
106 *
107 * parv[0] = Sender prefix
108 * parv[1] = Target: server numeric
109 * parv[2] = (+|-)<G-line mask>
110 * parv[3] = G-line lifetime
111 *
112 * From Uworld:
113 *
114 * parv[4] = Comment
115 *
116 * From somewhere else:
117 *
118 * parv[4] = Last modification time
119 * parv[5] = Comment
120 *
121 */
122 int
123 ms_gline(struct Client *cptr, struct Client *sptr, int parc, char *parv[])
124 {
125 struct Client *acptr = 0;
126 struct Gline *agline;
127 unsigned int flags = 0;
128 time_t expire_off, lastmod = 0;
129 char *mask = parv[2], *target = parv[1], *reason = "No reason";
130
131 if (*mask == '!')
132 {
133 mask++;
134 flags |= GLINE_OPERFORCE; /* assume oper had WIDE_GLINE */
135 }
136
137 if ((parc == 3 && *mask == '-') || parc == 5)
138 {
139 if (!find_conf_byhost(cli_confs(cptr), cli_name(sptr), CONF_UWORLD))
140 return need_more_params(sptr, "GLINE");
141
142 if (parc > 4)
143 reason = parv[4];
144 flags |= GLINE_FORCE;
145 }
146 else if (parc > 5)
147 {
148 lastmod = atoi(parv[4]);
149 reason = parv[5];
150 }
151 else
152 return need_more_params(sptr, "GLINE");
153
154 if (IsServer(sptr))
155 flags |= GLINE_FORCE;
156
157 if (!(target[0] == '*' && target[1] == '\0')) {
158 if (!( (acptr = FindNServer(target)) ||
159 (acptr = SeekServer(target)) ) )
160 return 0; /* no such server */
161
162 if (!IsMe(acptr)) { /* manually propagate */
163 if (!lastmod)
164 sendcmdto_one(sptr, CMD_GLINE, acptr,
165 (parc == 3) ? "%s %s" : "%s %s %s :%s", target, mask,
166 parv[3], reason);
167 else
168 sendcmdto_one(sptr, CMD_GLINE, acptr, "%s %s%s %s %s :%s", target,
169 flags & GLINE_OPERFORCE ? "!" : "", mask, parv[3],
170 parv[4], reason);
171
172 return 0;
173 }
174
175 /* For asuka we don't want glines sent this way treated as local
176 * flags |= GLINE_LOCAL;
177 */
178 }
179
180 if (*mask == '-')
181 mask++;
182 else if (*mask == '+') {
183 flags |= GLINE_ACTIVE;
184 mask++;
185 } else
186 flags |= GLINE_ACTIVE;
187
188 expire_off = parc < 5 ? 0 : atoi(parv[3]);
189
190 agline = gline_find(mask, GLINE_ANY | GLINE_EXACT);
191
192 if (agline) {
193 if (GlineIsLocal(agline) && !(flags & GLINE_LOCAL)) /* global over local */
194 gline_free(agline);
195 else if (!lastmod && ((flags & GLINE_ACTIVE) == GlineIsRemActive(agline)))
196 return gline_propagate(cptr, sptr, agline);
197 else if (!lastmod || GlineLastMod(agline) < lastmod) { /* new mod */
198 if (flags & GLINE_ACTIVE)
199 return gline_activate(cptr, sptr, agline, lastmod, flags);
200 else
201 return gline_deactivate(cptr, sptr, agline, lastmod, flags);
202 } else if (GlineLastMod(agline) == lastmod || IsBurstOrBurstAck(cptr))
203 return 0;
204 else
205 return gline_resend(cptr, agline); /* other server desynched WRT gline */
206 } else if (parc == 3 && !(flags & GLINE_ACTIVE)) {
207 /* U-lined server removing a G-line we don't have; propagate the removal
208 * anyway.
209 */
210 if (!(flags & GLINE_LOCAL))
211 sendcmdto_serv_butone(sptr, CMD_GLINE, cptr, "* -%s", mask);
212 return 0;
213 } else if (parc < 5)
214 return need_more_params(sptr, "GLINE");
215
216 return gline_add(cptr, sptr, mask, reason, expire_off, lastmod, flags);
217 }
218
219 /*
220 * mo_gline - oper message handler
221 *
222 * parv[0] = Sender prefix
223 * parv[1] = [[+|-]<G-line mask>]
224 *
225 * Local (to me) style:
226 *
227 * parv[2] = [Expiration offset]
228 * parv[3] = [Comment]
229 *
230 * Global (or remote local) style:
231 *
232 * parv[2] = [target]
233 * parv[3] = [Expiration offset]
234 * parv[4] = [Comment]
235 *
236 */
237 int
238 mo_gline(struct Client *cptr, struct Client *sptr, int parc, char *parv[])
239 {
240 struct Client *acptr = 0;
241 struct Gline *agline;
242 unsigned int flags = 0;
243 time_t expire_off;
244 char *mask = parv[1], *target = 0, *reason;
245
246 if (parc < 2)
247 return gline_list(sptr, 0);
248
249 if (*mask == '!') {
250 mask++;
251
252 if (HasPriv(sptr, PRIV_WIDE_GLINE))
253 flags |= GLINE_OPERFORCE;
254 }
255
256 if (*mask == '+') {
257 flags |= GLINE_ACTIVE;
258 mask++;
259
260 } else if (*mask == '-')
261 mask++;
262 else
263 return gline_list(sptr, mask);
264
265 if (parc == 4) {
266 expire_off = atoi(parv[2]);
267 reason = parv[3];
268 flags |= GLINE_LOCAL;
269 } else if (parc > 4) {
270 target = parv[2];
271 expire_off = atoi(parv[3]);
272 reason = parv[4];
273 } else
274 return need_more_params(sptr, "GLINE");
275
276 if (target)
277 {
278 if (!(target[0] == '*' && target[1] == '\0'))
279 {
280 if (!(acptr = find_match_server(target)))
281 return send_reply(sptr, ERR_NOSUCHSERVER, target);
282
283 /* manually propagate, since we don't set it */
284 if (!IsMe(acptr))
285 {
286 if (!feature_bool(FEAT_CONFIG_OPERCMDS))
287 return send_reply(sptr, ERR_DISABLED, "GLINE");
288
289 if (!HasPriv(sptr, PRIV_GLINE))
290 return send_reply(sptr, ERR_NOPRIVILEGES);
291
292 sendcmdto_one(sptr, CMD_GLINE, acptr, "%C %s%c%s %s %Tu :%s", acptr,
293 flags & GLINE_OPERFORCE ? "!" : "",
294 flags & GLINE_ACTIVE ? '+' : '-', mask, parv[3],
295 TStime(), reason);
296 return 0;
297 }
298 flags |= GLINE_LOCAL;
299 }
300 }
301
302 if (!(flags & GLINE_LOCAL) && !feature_bool(FEAT_CONFIG_OPERCMDS))
303 return send_reply(sptr, ERR_DISABLED, "GLINE");
304
305 if (!HasPriv(sptr, (flags & GLINE_LOCAL ? PRIV_LOCAL_GLINE : PRIV_GLINE)))
306 return send_reply(sptr, ERR_NOPRIVILEGES);
307
308 agline = gline_find(mask, GLINE_ANY | GLINE_EXACT);
309
310 if (agline) {
311 if (GlineIsLocal(agline) && !(flags & GLINE_LOCAL)) /* global over local */
312 gline_free(agline);
313 else {
314 if (!GlineLastMod(agline)) /* force mods to Uworld-set G-lines local */
315 flags |= GLINE_LOCAL;
316
317 if (flags & GLINE_ACTIVE)
318 return gline_activate(cptr, sptr, agline,
319 GlineLastMod(agline) ? TStime() : 0, flags);
320 else
321 return gline_deactivate(cptr, sptr, agline,
322 GlineLastMod(agline) ? TStime() : 0, flags);
323 }
324 }
325
326 return gline_add(cptr, sptr, mask, reason, expire_off, TStime(), flags);
327 }
328
329 /*
330 * m_gline - user message handler
331 *
332 * parv[0] = Sender prefix
333 * parv[1] = [<server name>]
334 *
335 */
336 int
337 m_gline(struct Client *cptr, struct Client *sptr, int parc, char *parv[])
338 {
339 if (feature_bool(FEAT_HIS_USERGLINE))
340 return send_reply(sptr, ERR_DISABLED, "GLINE");
341
342 if (parc < 2)
343 return send_reply(sptr, ERR_NOSUCHGLINE, "");
344
345 return gline_list(sptr, parv[1]);
346 }