]>
jfr.im git - irc/quakenet/snircd.git/blob - ircd/m_gline.c
2 * IRC - Internet Relay Chat, ircd/m_gline.c
3 * Copyright (C) 1990 Jarkko Oikarinen and
4 * University of Oulu, Computing Center
6 * See file AUTHORS in IRC package for additional names of
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)
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.
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.
23 * $Id: m_gline.c,v 1.26.2.1 2006/06/09 02:13:51 entrope Exp $
27 * m_functions execute protocol messages on this server:
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...).
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.
39 * (!IsServer(cptr)) => (cptr == sptr), because
40 * prefixes are taken *only* from servers...
43 * (sptr == cptr) => the message didn't
46 * (sptr != cptr && IsServer(sptr) means
47 * the prefix specified servername. (?)
49 * (sptr != cptr && !IsServer(sptr) means
50 * that message originated from a remote
55 * (!IsServer(sptr)) means that, sptr can safely
56 * taken as defining the target structure of the
57 * message in this server.
59 * *Always* true (if 'parse' and others are working correct):
61 * 1) sptr->from == cptr (note: cptr->from == cptr)
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 ]
68 * parc number of variable parameter strings (if zero,
69 * parv is allowed to be NULL)
71 * parv a NULL terminated list of parameter pointers,
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*
79 * note: it is guaranteed that parv[0]..parv[parc-1] are all
88 #include "ircd_features.h"
90 #include "ircd_reply.h"
91 #include "ircd_string.h"
100 /* #include <assert.h> -- Now using assert in ircd_log.h */
105 * ms_gline - server message handler
107 * parv[0] = Sender prefix
108 * parv[1] = Target: server numeric
109 * parv[2] = (+|-)<G-line mask>
110 * parv[3] = G-line lifetime
116 * From somewhere else:
118 * parv[4] = Last modification time
123 ms_gline(struct Client
*cptr
, struct Client
*sptr
, int parc
, char *parv
[])
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";
134 flags
|= GLINE_OPERFORCE
; /* assume oper had WIDE_GLINE */
137 if ((parc
== 3 && *mask
== '-') || parc
== 5)
139 if (!find_conf_byhost(cli_confs(cptr
), cli_name(sptr
), CONF_UWORLD
))
140 return need_more_params(sptr
, "GLINE");
142 flags
|= GLINE_FORCE
;
145 lastmod
= atoi(parv
[4]);
147 return need_more_params(sptr
, "GLINE");
150 reason
= parv
[parc
- 1];
153 flags
|= GLINE_FORCE
;
155 if (!(target
[0] == '*' && target
[1] == '\0')) {
156 if (!( (acptr
= FindNServer(target
)) ||
157 (acptr
= SeekServer(target
)) ) )
158 return 0; /* no such server */
160 if (!IsMe(acptr
)) { /* manually propagate */
162 sendcmdto_one(sptr
, CMD_GLINE
, acptr
,
163 (parc
== 3) ? "%s %s" : "%s %s %s :%s", target
, mask
,
166 sendcmdto_one(sptr
, CMD_GLINE
, acptr
, "%s %s%s %s %s :%s", target
,
167 flags
& GLINE_OPERFORCE
? "!" : "", mask
, parv
[3],
173 /* For asuka we don't want glines sent this way treated as local
174 * flags |= GLINE_LOCAL;
180 else if (*mask
== '+') {
181 flags
|= GLINE_ACTIVE
;
184 flags
|= GLINE_ACTIVE
;
186 expire_off
= parc
< 5 ? 0 : atoi(parv
[3]);
188 agline
= gline_find(mask
, GLINE_ANY
| GLINE_EXACT
);
191 if (GlineIsLocal(agline
) && !(flags
& GLINE_LOCAL
)) /* global over local */
193 else if (!lastmod
&& ((flags
& GLINE_ACTIVE
) == GlineIsRemActive(agline
)))
194 return gline_propagate(cptr
, sptr
, agline
);
195 else if (!lastmod
|| GlineLastMod(agline
) < lastmod
) { /* new mod */
196 if (flags
& GLINE_ACTIVE
)
197 return gline_activate(cptr
, sptr
, agline
, lastmod
, flags
);
199 return gline_deactivate(cptr
, sptr
, agline
, lastmod
, flags
);
200 } else if (GlineLastMod(agline
) == lastmod
|| IsBurstOrBurstAck(cptr
))
203 return gline_resend(cptr
, agline
); /* other server desynched WRT gline */
204 } else if (parc
== 3 && !(flags
& GLINE_ACTIVE
)) {
205 /* U-lined server removing a G-line we don't have; propagate the removal
208 if (!(flags
& GLINE_LOCAL
))
209 sendcmdto_serv_butone(sptr
, CMD_GLINE
, cptr
, "* -%s", mask
);
212 return need_more_params(sptr
, "GLINE");
214 return gline_add(cptr
, sptr
, mask
, reason
, expire_off
, lastmod
, flags
);
218 * mo_gline - oper message handler
220 * parv[0] = Sender prefix
221 * parv[1] = [[+|-]<G-line mask>]
223 * Local (to me) style:
225 * parv[2] = [Expiration offset]
226 * parv[3] = [Comment]
228 * Global (or remote local) style:
231 * parv[3] = [Expiration offset]
232 * parv[4] = [Comment]
236 mo_gline(struct Client
*cptr
, struct Client
*sptr
, int parc
, char *parv
[])
238 struct Client
*acptr
= 0;
239 struct Gline
*agline
;
240 unsigned int flags
= 0;
242 char *mask
= parv
[1], *target
= 0, *reason
;
245 return gline_list(sptr
, 0);
250 if (HasPriv(sptr
, PRIV_WIDE_GLINE
))
251 flags
|= GLINE_OPERFORCE
;
255 flags
|= GLINE_ACTIVE
;
258 } else if (*mask
== '-')
261 return gline_list(sptr
, mask
);
264 expire_off
= atoi(parv
[2]);
266 flags
|= GLINE_LOCAL
;
267 } else if (parc
> 4) {
269 expire_off
= atoi(parv
[3]);
272 return need_more_params(sptr
, "GLINE");
276 if (!(target
[0] == '*' && target
[1] == '\0'))
278 if (!(acptr
= find_match_server(target
)))
279 return send_reply(sptr
, ERR_NOSUCHSERVER
, target
);
281 /* manually propagate, since we don't set it */
284 if (!feature_bool(FEAT_CONFIG_OPERCMDS
))
285 return send_reply(sptr
, ERR_DISABLED
, "GLINE");
287 if (!HasPriv(sptr
, PRIV_GLINE
))
288 return send_reply(sptr
, ERR_NOPRIVILEGES
);
290 sendcmdto_one(sptr
, CMD_GLINE
, acptr
, "%C %s%c%s %s %Tu :%s", acptr
,
291 flags
& GLINE_OPERFORCE
? "!" : "",
292 flags
& GLINE_ACTIVE
? '+' : '-', mask
, parv
[3],
296 flags
|= GLINE_LOCAL
;
300 if (!(flags
& GLINE_LOCAL
) && !feature_bool(FEAT_CONFIG_OPERCMDS
))
301 return send_reply(sptr
, ERR_DISABLED
, "GLINE");
303 if (!HasPriv(sptr
, (flags
& GLINE_LOCAL
? PRIV_LOCAL_GLINE
: PRIV_GLINE
)))
304 return send_reply(sptr
, ERR_NOPRIVILEGES
);
306 agline
= gline_find(mask
, GLINE_ANY
| GLINE_EXACT
);
309 if (GlineIsLocal(agline
) && !(flags
& GLINE_LOCAL
)) /* global over local */
312 if (!GlineLastMod(agline
)) /* force mods to Uworld-set G-lines local */
313 flags
|= GLINE_LOCAL
;
315 if (flags
& GLINE_ACTIVE
)
316 return gline_activate(cptr
, sptr
, agline
,
317 GlineLastMod(agline
) ? TStime() : 0, flags
);
319 return gline_deactivate(cptr
, sptr
, agline
,
320 GlineLastMod(agline
) ? TStime() : 0, flags
);
324 return gline_add(cptr
, sptr
, mask
, reason
, expire_off
, TStime(), flags
);
328 * m_gline - user message handler
330 * parv[0] = Sender prefix
331 * parv[1] = [<server name>]
335 m_gline(struct Client
*cptr
, struct Client
*sptr
, int parc
, char *parv
[])
337 if (feature_bool(FEAT_HIS_USERGLINE
))
338 return send_reply(sptr
, ERR_DISABLED
, "GLINE");
341 return send_reply(sptr
, ERR_NOSUCHGLINE
, "");
343 return gline_list(sptr
, parv
[1]);