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.
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
84 * No need to include handlers.h here the signatures must match
85 * and we don't need to force a rebuild of all the handlers everytime
86 * we add a new one to the list. --Bleep
94 #include "ircd_reply.h"
95 #include "ircd_string.h"
110 * ms_gline - server message handler
112 * parv[0] = Sender prefix
113 * parv[1] = Target: server numeric
114 * parv[2] = (+|-)<G-line mask>
115 * parv[3] = G-line lifetime
121 * From somewhere else:
123 * parv[4] = Last modification time
128 ms_gline(struct Client *cptr, struct Client *sptr, int parc, char *parv[])
130 struct Client *acptr = 0;
131 struct Gline *agline;
132 unsigned int flags = 0;
133 time_t expire_off, lastmod = 0;
134 char *mask = parv[2], *target = parv[1], *reason;
137 if (!find_conf_byhost(cptr->confs, sptr->name, CONF_UWORLD))
138 return need_more_params(sptr, "GLINE");
141 flags |= GLINE_FORCE;
142 } else if (parc > 5) {
143 lastmod = atoi(parv[4]);
146 return need_more_params(sptr, "GLINE");
148 if (!(target[0] == '*' && target[1] == '\0')) {
149 if (!(acptr = FindNServer(target)))
150 return 0; /* no such server */
152 if (!IsMe(acptr)) { /* manually propagate */
154 sendcmdto_one(acptr, CMD_GLINE, sptr, "%s %s %s :%s", target, mask,
157 sendcmdto_one(acptr, CMD_GLINE, sptr, "%s %s %s %s :%s", target, mask,
158 parv[3], parv[4], reason);
163 flags |= GLINE_LOCAL;
168 else if (*mask == '+') {
169 flags |= GLINE_ACTIVE;
172 flags |= GLINE_ACTIVE;
174 expire_off = atoi(parv[3]);
176 agline = gline_find(mask, GLINE_ANY | GLINE_EXACT);
179 if (GlineIsLocal(agline) && !(flags & GLINE_LOCAL)) /* global over local */
181 else if (!lastmod || GlineLastMod(agline) < lastmod) { /* new mod */
182 if (flags & GLINE_ACTIVE)
183 return gline_activate(cptr, sptr, agline, lastmod);
185 return gline_deactivate(cptr, sptr, agline, lastmod);
186 } else if (GlineLastMod(agline) == lastmod)
189 return gline_resend(cptr, agline); /* other server desynched WRT gline */
192 return gline_add(cptr, sptr, mask, reason, expire_off, lastmod, flags);
196 * mo_gline - oper message handler
198 * parv[0] = Sender prefix
199 * parv[1] = [[+|-]<G-line mask>]
203 * parv[2] = [Expiration offset]
204 * parv[3] = [Comment]
209 * parv[3] = [Expiration offset]
210 * parv[4] = [Comment]
214 mo_gline(struct Client *cptr, struct Client *sptr, int parc, char *parv[])
216 struct Client *acptr = 0;
217 struct Gline *agline;
218 unsigned int flags = 0;
220 char *mask = parv[1], *target = 0, *reason;
223 return gline_list(sptr, 0);
226 flags |= GLINE_ACTIVE;
228 } else if (*mask == '-')
231 return gline_list(sptr, mask);
235 send_error_to_client(sptr, ERR_NOPRIVILEGES);
241 expire_off = atoi(parv[2]);
243 flags |= GLINE_LOCAL;
244 } else if (parc > 4) {
246 expire_off = atoi(parv[3]);
249 return need_more_params(sptr, "GLINE");
252 if (!(target[0] == '*' && target[1] == '\0')) {
253 if (!(acptr = find_match_server(target)))
254 return send_error_to_client(sptr, ERR_NOSUCHSERVER, target);
256 if (!IsMe(acptr)) { /* manually propagate, since we don't set it */
258 return send_error_to_client(sptr, ERR_NOPRIVILEGES);
260 sendcmdto_one(acptr, CMD_GLINE, sptr, "%C %c%s %s %Tu :%s", acptr,
261 flags & GLINE_ACTIVE ? '?' : '-', mask, parv[3],
266 flags |= GLINE_LOCAL;
267 } else if (!IsOper(sptr))
268 return send_error_to_client(sptr, ERR_NOPRIVILEGES);
271 #ifndef CONFIG_OPERCMDS
272 if (!(flags & GLINE_LOCAL))
273 return send_error_to_client(sptr, ERR_DISABLED, "GLINE");
274 #endif /* CONFIG_OPERCMDS */
276 agline = gline_find(mask, GLINE_ANY | GLINE_EXACT);
279 if (GlineIsLocal(agline) && !(flags & GLINE_LOCAL)) /* global over local */
282 if (flags & GLINE_ACTIVE)
283 return gline_activate(cptr, sptr, agline,
284 GlineLastMod(agline) ? TStime() : 0);
286 return gline_deactivate(cptr, sptr, agline,
287 GlineLastMod(agline) ? TStime() : 0);
291 return gline_add(cptr, sptr, mask, reason, expire_off, TStime(), flags);
295 * m_gline - user message handler
297 * parv[0] = Sender prefix
298 * parv[1] = [<server name>]
302 m_gline(struct Client *cptr, struct Client *sptr, int parc, char *parv[])
305 return send_error_to_client(sptr, ERR_NOSUCHGLINE, "");
307 return gline_list(sptr, parv[1]);