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] = Send prefix
116 * parv[1] = Target: server numeric
117 * parv[2] = [+|-]<G-line mask>
118 * parv[3] = Expiration offset
123 * parv[1] = [+|-]<G-line mask>
124 * parv[2] = Expiration offset
128 int ms_gline(struct Client* cptr, struct Client* sptr, int parc, char* parv[])
130 struct Client* acptr = 0; /* Init. to avoid compiler warning. */
141 * Remove expired G-lines
143 gline_remove_expired(TStime());
146 * Remove expired bad channels
148 bad_channel_remove_expired(TStime());
151 if (IsServer(cptr)) {
152 if (find_conf_byhost(cptr->confs, sptr->name, CONF_UWORLD)) {
153 if (parc < 3 || (*parv[2] != '-' && (parc < 5 || *parv[4] == '\0')))
154 return need_more_params(sptr, "GLINE");
156 if (*parv[2] == '-') /* add mode or delete mode? */
161 if (*parv[2] == '+' || *parv[2] == '-')
162 parv[2]++; /* step past mode indicator */
165 * forward the message appropriately
167 if (0 == ircd_strcmp(parv[1], "*")) {
171 sendto_serv_butone(cptr,
172 active ? "%s " TOK_GLINE " %s +%s %s :%s" : "%s " TOK_GLINE " %s -%s",
173 NumServ(sptr), parv[1], parv[2], parv[3], parv[4]);
178 * REMOVE THIS after all servers upgraded to 2.10.01 and
179 * Uworld uses a numeric too
181 (strlen(parv[1]) != 1 && !(acptr = FindClient(parv[1])))) ||
182 (strlen(parv[1]) == 1 &&
184 !(acptr = FindNServer(parv[1]))))
185 return 0; /* no such server/user exists; forget it */
189 * REMOVE THIS after all servers upgraded to 2.10.01 and
190 * Uworld uses a numeric too
192 if (IsServer(acptr) || !MyConnect(acptr))
195 /* single destination */
197 active ? "%s " TOK_GLINE " %s +%s %s :%s" : "%s " TOK_GLINE " %s -%s",
198 NumServ(sptr), parv[1], parv[2], parv[3], parv[4]);
199 return 0; /* only the intended destination
200 should add this gline */
203 if (!(host = strchr(parv[2], '@'))) {
205 * convert user@host no @'s; assume username is '*'
212 *(host++) = '\0'; /* break up string at the '@' */
214 ip_mask = check_if_ipmask(host); /* Store this boolean */
216 if ('#' == *host || '&' == *host || '+' == *host)
217 gtype = 1; /* BAD CHANNEL GLINE */
219 for (gline = (gtype) ? BadChanGlineList : GlobalGlineList, prev = 0; gline;
222 if (0 == ircd_strcmp(gline->name, user) &&
223 0 == ircd_strcmp(gline->host, host))
228 if (!active && gline)
231 * removing the gline, notify opers
233 sendto_op_mask(SNO_GLINE, "%s removing %s for %s@%s", parv[0],
234 gtype ? "BADCHAN" : "GLINE", gline->name, gline->host);
237 write_log(GPATH, "# " TIME_T_FMT " %s removing %s for %s@%s\n",
238 TStime(), parv[0], gtype ? "BADCHAN" : "GLINE", gline->name,
242 free_gline(gline, prev); /* remove the gline */
245 { /* must be adding a gline */
246 expire = atoi(parv[3]) + TStime(); /* expire time? */
247 if (gline && gline->expire < expire)
248 { /* new expire time? */
249 /* yes, notify the opers */
250 sendto_op_mask(SNO_GLINE,
251 "%s resetting expiration time on %s for %s@%s to " TIME_T_FMT,
252 parv[0], gtype ? "BADCHAN" : "GLINE", gline->name, gline->host,
255 write_log(GPATH, "# " TIME_T_FMT " %s resetting expiration time "
256 "on %s for %s@%s to " TIME_T_FMT "\n",
257 TStime(), parv[0], gtype ? "BADCHAN" : "GLINE",
258 gline->name, gline->host, expire);
261 gline->expire = expire; /* reset the expire time */
265 for (gline = (gtype) ? BadChanGlineList : GlobalGlineList; gline; gline = gline->next)
266 if (!mmatch(gline->name, user) &&
267 (ip_mask ? GlineIsIpMask(gline) : !GlineIsIpMask(gline)) &&
268 !mmatch(gline->host, host))
269 return 0; /* found an existing G-line that matches */
272 add_gline(sptr, ip_mask, host, parv[4], user, expire, 0);
277 else if (parc < 2 || *parv[1] == '\0')
279 /* Not enough args and a user; list glines */
280 for (gline = GlobalGlineList; gline; gline = gline->next)
281 sendto_one(cptr, rpl_str(RPL_GLIST), me.name, parv[0],
282 gline->name, gline->host, gline->expire, gline->reason,
283 GlineIsActive(gline) ? (GlineIsLocal(gline) ? " (local)" : "") :
285 sendto_one(cptr, rpl_str(RPL_ENDOFGLIST), me.name, parv[0]);
292 priv = IsAnOper(cptr);
298 { /* non-oper not permitted to change things */
300 { /* oper wants to deactivate the gline */
304 else if (*parv[1] == '+')
305 { /* oper wants to activate inactive gline */
313 expire = atoi(parv[2]) + TStime(); /* oper wants to reset
319 if (!(host = strchr(parv[1], '@')))
321 user = "*"; /* no @'s; assume username is '*' */
327 *(host++) = '\0'; /* break up string at the '@' */
329 ip_mask = check_if_ipmask(host); /* Store this boolean */
331 if ('#' == *host || '&' == *host || '+' == *host)
332 #ifndef LOCAL_BADCHAN
335 gtype = 1; /* BAD CHANNEL */
339 for (gline = (gtype) ? BadChanGlineList : GlobalGlineList, prev = 0; gline;
342 if (!mmatch(gline->name, user) &&
343 (ip_mask ? GlineIsIpMask(gline) : !GlineIsIpMask(gline)) &&
344 !mmatch(gline->host, host))
352 if (priv && active && expire > CurrentTime)
354 /* Add local G-line */
355 if (parc < 4 || !strchr(parv[3], ' '))
356 return need_more_params(sptr, "GLINE");
358 add_gline(sptr, ip_mask, host, parv[3], user, expire, 1);
362 sendto_one(cptr, err_str(ERR_NOSUCHGLINE), me.name, parv[0], user,
368 if (expire <= gline->expire)
372 (active ? GlineIsActive(gline) : !GlineIsActive(gline))) &&
375 /* oper wants a list of one gline only */
376 sendto_one(cptr, rpl_str(RPL_GLIST), me.name, parv[0], gline->name,
377 gline->host, gline->expire, gline->reason,
378 GlineIsActive(gline) ? "" : " (Inactive)");
379 sendto_one(cptr, rpl_str(RPL_ENDOFGLIST), me.name, parv[0]);
384 (active ? !GlineIsActive(gline) : GlineIsActive(gline)))
386 if (active) /* reset activation on gline */
389 else if (GlineIsLocal(gline))
391 /* Remove local G-line */
392 sendto_op_mask(SNO_GLINE, "%s removed local %s for %s@%s",
393 parv[0], gtype ? "BADCHAN" : "GLINE", gline->name, gline->host);
395 write_log(GPATH, "# " TIME_T_FMT
396 " %s!%s@%s removed local %s for %s@%s\n",
397 TStime(), parv[0], cptr->user->username, cptr->user->host,
398 gtype ? "BADCHAN" : "GLINE",
399 gline->name, gline->host);
401 free_gline(gline, prev); /* remove the gline */
409 active = -1; /* for later sendto_ops and logging functions */
412 gline->expire = expire; /* reset expiration time */
414 /* inform the operators what's up */
416 { /* changing the activation */
417 sendto_op_mask(SNO_GLINE, !expire ? "%s %sactivating %s for %s@%s" :
418 "%s %sactivating %s for %s@%s and "
419 "resetting expiration time to " TIME_T_FMT,
420 parv[0], active ? "re" : "de", gtype ? "BADCHAN" : "GLINE",
421 gline->name, gline->host, gline->expire);
423 write_log(GPATH, !expire ? "# " TIME_T_FMT " %s!%s@%s %sactivating "
424 "%s for %s@%s\n" : "# " TIME_T_FMT " %s!%s@%s %sactivating %s "
425 "for %s@%s and resetting expiration time to " TIME_T_FMT "\n",
426 TStime(), parv[0], cptr->user->username, cptr->user->host,
427 active ? "re" : "de", gtype ? "BADCHAN" : "GLINE", gline->name,
428 gline->host, gline->expire);
433 { /* changing only the expiration */
434 sendto_op_mask(SNO_GLINE,
435 "%s resetting expiration time on %s for %s@%s to " TIME_T_FMT,
436 parv[0], gtype ? "BADCHAN" : "GLINE", gline->name, gline->host,
439 write_log(GPATH, "# " TIME_T_FMT " %s!%s@%s resetting expiration "
440 "time on %s for %s@%s to " TIME_T_FMT "\n", TStime(), parv[0],
441 cptr->user->username, cptr->user->host, gtype ? "BADCHAN" : "GLINE",
442 gline->name, gline->host, gline->expire);
450 * mo_gline - oper message handler
452 * parv[0] = Send prefix
456 * parv[1] = Target: server numeric
457 * parv[2] = [+|-]<G-line mask>
458 * parv[3] = Expiration offset
463 * parv[1] = [+|-]<G-line mask>
464 * parv[2] = Expiration offset
468 int mo_gline(struct Client* cptr, struct Client* sptr, int parc, char* parv[])
470 struct Client* acptr = 0; /* Init. to avoid compiler warning. */
481 * Remove expired G-lines
483 gline_remove_expired(TStime());
486 * Remove expired bad channels
488 bad_channel_remove_expired(TStime());
491 if (IsServer(cptr)) {
492 if (find_conf_byhost(cptr->confs, sptr->name, CONF_UWORLD)) {
493 if (parc < 3 || (*parv[2] != '-' && (parc < 5 || *parv[4] == '\0')))
494 return need_more_params(sptr, "GLINE");
496 if (*parv[2] == '-') /* add mode or delete mode? */
501 if (*parv[2] == '+' || *parv[2] == '-')
502 parv[2]++; /* step past mode indicator */
505 * forward the message appropriately
507 if (0 == ircd_strcmp(parv[1], "*")) {
511 sendto_serv_butone(cptr,
512 active ? "%s " TOK_GLINE " %s +%s %s :%s" : "%s " TOK_GLINE " %s -%s",
513 NumServ(sptr), parv[1], parv[2], parv[3], parv[4]);
518 * REMOVE THIS after all servers upgraded to 2.10.01 and
519 * Uworld uses a numeric too
521 (strlen(parv[1]) != 1 && !(acptr = FindClient(parv[1])))) ||
522 (strlen(parv[1]) == 1 &&
524 !(acptr = FindNServer(parv[1]))))
525 return 0; /* no such server/user exists; forget it */
529 * REMOVE THIS after all servers upgraded to 2.10.01 and
530 * Uworld uses a numeric too
532 if (IsServer(acptr) || !MyConnect(acptr))
535 /* single destination */
537 active ? "%s " TOK_GLINE " %s +%s %s :%s" : "%s " TOK_GLINE " %s -%s",
538 NumServ(sptr), parv[1], parv[2], parv[3], parv[4]);
539 return 0; /* only the intended destination
540 should add this gline */
543 if (!(host = strchr(parv[2], '@'))) {
545 * convert user@host no @'s; assume username is '*'
552 *(host++) = '\0'; /* break up string at the '@' */
554 ip_mask = check_if_ipmask(host); /* Store this boolean */
556 if ('#' == *host || '&' == *host || '+' == *host)
557 gtype = 1; /* BAD CHANNEL GLINE */
559 for (gline = (gtype) ? BadChanGlineList : GlobalGlineList, prev = 0; gline;
562 if (0 == ircd_strcmp(gline->name, user) &&
563 0 == ircd_strcmp(gline->host, host))
568 if (!active && gline)
571 * removing the gline, notify opers
573 sendto_op_mask(SNO_GLINE, "%s removing %s for %s@%s", parv[0],
574 gtype ? "BADCHAN" : "GLINE", gline->name, gline->host);
577 write_log(GPATH, "# " TIME_T_FMT " %s removing %s for %s@%s\n",
578 TStime(), parv[0], gtype ? "BADCHAN" : "GLINE", gline->name,
582 free_gline(gline, prev); /* remove the gline */
585 { /* must be adding a gline */
586 expire = atoi(parv[3]) + TStime(); /* expire time? */
587 if (gline && gline->expire < expire)
588 { /* new expire time? */
589 /* yes, notify the opers */
590 sendto_op_mask(SNO_GLINE,
591 "%s resetting expiration time on %s for %s@%s to " TIME_T_FMT,
592 parv[0], gtype ? "BADCHAN" : "GLINE", gline->name, gline->host,
595 write_log(GPATH, "# " TIME_T_FMT " %s resetting expiration time "
596 "on %s for %s@%s to " TIME_T_FMT "\n",
597 TStime(), parv[0], gtype ? "BADCHAN" : "GLINE",
598 gline->name, gline->host, expire);
601 gline->expire = expire; /* reset the expire time */
605 for (gline = (gtype) ? BadChanGlineList : GlobalGlineList; gline; gline = gline->next)
606 if (!mmatch(gline->name, user) &&
607 (ip_mask ? GlineIsIpMask(gline) : !GlineIsIpMask(gline)) &&
608 !mmatch(gline->host, host))
609 return 0; /* found an existing G-line that matches */
612 add_gline(sptr, ip_mask, host, parv[4], user, expire, 0);
617 else if (parc < 2 || *parv[1] == '\0')
619 /* Not enough args and a user; list glines */
620 for (gline = GlobalGlineList; gline; gline = gline->next)
621 sendto_one(cptr, rpl_str(RPL_GLIST), me.name, parv[0],
622 gline->name, gline->host, gline->expire, gline->reason,
623 GlineIsActive(gline) ? (GlineIsLocal(gline) ? " (local)" : "") :
625 sendto_one(cptr, rpl_str(RPL_ENDOFGLIST), me.name, parv[0]);
632 priv = IsAnOper(cptr);
638 { /* non-oper not permitted to change things */
640 { /* oper wants to deactivate the gline */
644 else if (*parv[1] == '+')
645 { /* oper wants to activate inactive gline */
653 expire = atoi(parv[2]) + TStime(); /* oper wants to reset
659 if (!(host = strchr(parv[1], '@')))
661 user = "*"; /* no @'s; assume username is '*' */
667 *(host++) = '\0'; /* break up string at the '@' */
669 ip_mask = check_if_ipmask(host); /* Store this boolean */
671 if ('#' == *host || '&' == *host || '+' == *host)
672 #ifndef LOCAL_BADCHAN
675 gtype = 1; /* BAD CHANNEL */
679 for (gline = (gtype) ? BadChanGlineList : GlobalGlineList, prev = 0; gline;
682 if (!mmatch(gline->name, user) &&
683 (ip_mask ? GlineIsIpMask(gline) : !GlineIsIpMask(gline)) &&
684 !mmatch(gline->host, host))
692 if (priv && active && expire > CurrentTime)
694 /* Add local G-line */
695 if (parc < 4 || !strchr(parv[3], ' '))
696 return need_more_params(sptr, "GLINE");
698 add_gline(sptr, ip_mask, host, parv[3], user, expire, 1);
702 sendto_one(cptr, err_str(ERR_NOSUCHGLINE), me.name, parv[0], user,
708 if (expire <= gline->expire)
712 (active ? GlineIsActive(gline) : !GlineIsActive(gline))) &&
715 /* oper wants a list of one gline only */
716 sendto_one(cptr, rpl_str(RPL_GLIST), me.name, parv[0], gline->name,
717 gline->host, gline->expire, gline->reason,
718 GlineIsActive(gline) ? "" : " (Inactive)");
719 sendto_one(cptr, rpl_str(RPL_ENDOFGLIST), me.name, parv[0]);
724 (active ? !GlineIsActive(gline) : GlineIsActive(gline)))
726 if (active) /* reset activation on gline */
729 else if (GlineIsLocal(gline))
731 /* Remove local G-line */
732 sendto_op_mask(SNO_GLINE, "%s removed local %s for %s@%s",
733 parv[0], gtype ? "BADCHAN" : "GLINE", gline->name, gline->host);
735 write_log(GPATH, "# " TIME_T_FMT
736 " %s!%s@%s removed local %s for %s@%s\n",
737 TStime(), parv[0], cptr->user->username, cptr->user->host,
738 gtype ? "BADCHAN" : "GLINE",
739 gline->name, gline->host);
741 free_gline(gline, prev); /* remove the gline */
749 active = -1; /* for later sendto_ops and logging functions */
752 gline->expire = expire; /* reset expiration time */
754 /* inform the operators what's up */
756 { /* changing the activation */
757 sendto_op_mask(SNO_GLINE, !expire ? "%s %sactivating %s for %s@%s" :
758 "%s %sactivating %s for %s@%s and "
759 "resetting expiration time to " TIME_T_FMT,
760 parv[0], active ? "re" : "de", gtype ? "BADCHAN" : "GLINE",
761 gline->name, gline->host, gline->expire);
763 write_log(GPATH, !expire ? "# " TIME_T_FMT " %s!%s@%s %sactivating "
764 "%s for %s@%s\n" : "# " TIME_T_FMT " %s!%s@%s %sactivating %s "
765 "for %s@%s and resetting expiration time to " TIME_T_FMT "\n",
766 TStime(), parv[0], cptr->user->username, cptr->user->host,
767 active ? "re" : "de", gtype ? "BADCHAN" : "GLINE", gline->name,
768 gline->host, gline->expire);
773 { /* changing only the expiration */
774 sendto_op_mask(SNO_GLINE,
775 "%s resetting expiration time on %s for %s@%s to " TIME_T_FMT,
776 parv[0], gtype ? "BADCHAN" : "GLINE", gline->name, gline->host,
779 write_log(GPATH, "# " TIME_T_FMT " %s!%s@%s resetting expiration "
780 "time on %s for %s@%s to " TIME_T_FMT "\n", TStime(), parv[0],
781 cptr->user->username, cptr->user->host, gtype ? "BADCHAN" : "GLINE",
782 gline->name, gline->host, gline->expire);
794 * parv[0] = Send prefix
798 * parv[1] = Target: server numeric
799 * parv[2] = [+|-]<G-line mask>
800 * parv[3] = Expiration offset
805 * parv[1] = [+|-]<G-line mask>
806 * parv[2] = Expiration offset
810 int m_gline(struct Client *cptr, struct Client *sptr, int parc, char *parv[])
812 struct Client* acptr = 0; /* Init. to avoid compiler warning. */
823 * Remove expired G-lines
825 gline_remove_expired(TStime());
828 * Remove expired bad channels
830 bad_channel_remove_expired(TStime());
833 if (IsServer(cptr)) {
834 if (find_conf_byhost(cptr->confs, sptr->name, CONF_UWORLD)) {
835 if (parc < 3 || (*parv[2] != '-' && (parc < 5 || *parv[4] == '\0')))
836 return need_more_params(sptr, "GLINE");
838 if (*parv[2] == '-') /* add mode or delete mode? */
843 if (*parv[2] == '+' || *parv[2] == '-')
844 parv[2]++; /* step past mode indicator */
847 * forward the message appropriately
849 if (0 == ircd_strcmp(parv[1], "*")) {
853 sendto_serv_butone(cptr,
854 active ? "%s " TOK_GLINE " %s +%s %s :%s" : "%s " TOK_GLINE " %s -%s",
855 NumServ(cptr), parv[1], parv[2], parv[3], parv[4]);
860 * REMOVE THIS after all servers upgraded to 2.10.01 and
861 * Uworld uses a numeric too
863 (strlen(parv[1]) != 1 && !(acptr = FindClient(parv[1])))) ||
864 (strlen(parv[1]) == 1 &&
866 !(acptr = FindNServer(parv[1]))))
867 return 0; /* no such server/user exists; forget it */
871 * REMOVE THIS after all servers upgraded to 2.10.01 and
872 * Uworld uses a numeric too
874 if (IsServer(acptr) || !MyConnect(acptr))
877 /* single destination */
879 active ? "%s " TOK_GLINE " %s +%s %s :%s" : "%s " TOK_GLINE " %s -%s",
880 NumServ(sptr), parv[1], parv[2], parv[3], parv[4]);
881 return 0; /* only the intended destination
882 should add this gline */
885 if (!(host = strchr(parv[2], '@'))) {
887 * convert user@host no @'s; assume username is '*'
894 *(host++) = '\0'; /* break up string at the '@' */
896 ip_mask = check_if_ipmask(host); /* Store this boolean */
898 if ('#' == *host || '&' == *host || '+' == *host)
899 gtype = 1; /* BAD CHANNEL GLINE */
901 for (gline = (gtype) ? BadChanGlineList : GlobalGlineList, prev = 0; gline;
904 if (0 == ircd_strcmp(gline->name, user) &&
905 0 == ircd_strcmp(gline->host, host))
910 if (!active && gline)
913 * removing the gline, notify opers
915 sendto_op_mask(SNO_GLINE, "%s removing %s for %s@%s", parv[0],
916 gtype ? "BADCHAN" : "GLINE", gline->name, gline->host);
919 write_log(GPATH, "# " TIME_T_FMT " %s removing %s for %s@%s\n",
920 TStime(), parv[0], gtype ? "BADCHAN" : "GLINE", gline->name,
924 free_gline(gline, prev); /* remove the gline */
927 { /* must be adding a gline */
928 expire = atoi(parv[3]) + TStime(); /* expire time? */
929 if (gline && gline->expire < expire)
930 { /* new expire time? */
931 /* yes, notify the opers */
932 sendto_op_mask(SNO_GLINE,
933 "%s resetting expiration time on %s for %s@%s to " TIME_T_FMT,
934 parv[0], gtype ? "BADCHAN" : "GLINE", gline->name, gline->host,
937 write_log(GPATH, "# " TIME_T_FMT " %s resetting expiration time "
938 "on %s for %s@%s to " TIME_T_FMT "\n",
939 TStime(), parv[0], gtype ? "BADCHAN" : "GLINE",
940 gline->name, gline->host, expire);
943 gline->expire = expire; /* reset the expire time */
947 for (gline = (gtype) ? BadChanGlineList : GlobalGlineList; gline; gline = gline->next)
948 if (!mmatch(gline->name, user) &&
949 (ip_mask ? GlineIsIpMask(gline) : !GlineIsIpMask(gline)) &&
950 !mmatch(gline->host, host))
951 return 0; /* found an existing G-line that matches */
954 add_gline(sptr, ip_mask, host, parv[4], user, expire, 0);
959 else if (parc < 2 || *parv[1] == '\0')
961 /* Not enough args and a user; list glines */
962 for (gline = GlobalGlineList; gline; gline = gline->next)
963 sendto_one(cptr, rpl_str(RPL_GLIST), me.name, parv[0],
964 gline->name, gline->host, gline->expire, gline->reason,
965 GlineIsActive(gline) ? (GlineIsLocal(gline) ? " (local)" : "") :
967 sendto_one(cptr, rpl_str(RPL_ENDOFGLIST), me.name, parv[0]);
974 priv = IsAnOper(cptr);
980 { /* non-oper not permitted to change things */
982 { /* oper wants to deactivate the gline */
986 else if (*parv[1] == '+')
987 { /* oper wants to activate inactive gline */
995 expire = atoi(parv[2]) + TStime(); /* oper wants to reset
1001 if (!(host = strchr(parv[1], '@')))
1003 user = "*"; /* no @'s; assume username is '*' */
1009 *(host++) = '\0'; /* break up string at the '@' */
1011 ip_mask = check_if_ipmask(host); /* Store this boolean */
1013 if ('#' == *host || '&' == *host || '+' == *host)
1014 #ifndef LOCAL_BADCHAN
1017 gtype = 1; /* BAD CHANNEL */
1021 for (gline = (gtype) ? BadChanGlineList : GlobalGlineList, prev = 0; gline;
1022 gline = gline->next)
1024 if (!mmatch(gline->name, user) &&
1025 (ip_mask ? GlineIsIpMask(gline) : !GlineIsIpMask(gline)) &&
1026 !mmatch(gline->host, host))
1034 if (priv && active && expire > CurrentTime)
1036 /* Add local G-line */
1037 if (parc < 4 || !strchr(parv[3], ' '))
1038 return need_more_params(sptr, "GLINE");
1040 add_gline(sptr, ip_mask, host, parv[3], user, expire, 1);
1044 sendto_one(cptr, err_str(ERR_NOSUCHGLINE), me.name, parv[0], user,
1050 if (expire <= gline->expire)
1053 if ((active == -1 ||
1054 (active ? GlineIsActive(gline) : !GlineIsActive(gline))) &&
1057 /* oper wants a list of one gline only */
1058 sendto_one(cptr, rpl_str(RPL_GLIST), me.name, parv[0], gline->name,
1059 gline->host, gline->expire, gline->reason,
1060 GlineIsActive(gline) ? "" : " (Inactive)");
1061 sendto_one(cptr, rpl_str(RPL_ENDOFGLIST), me.name, parv[0]);
1066 (active ? !GlineIsActive(gline) : GlineIsActive(gline)))
1068 if (active) /* reset activation on gline */
1071 else if (GlineIsLocal(gline))
1073 /* Remove local G-line */
1074 sendto_op_mask(SNO_GLINE, "%s removed local %s for %s@%s",
1075 parv[0], gtype ? "BADCHAN" : "GLINE", gline->name, gline->host);
1077 write_log(GPATH, "# " TIME_T_FMT
1078 " %s!%s@%s removed local %s for %s@%s\n",
1079 TStime(), parv[0], cptr->user->username, cptr->user->host,
1080 gtype ? "BADCHAN" : "GLINE",
1081 gline->name, gline->host);
1083 free_gline(gline, prev); /* remove the gline */
1091 active = -1; /* for later sendto_ops and logging functions */
1094 gline->expire = expire; /* reset expiration time */
1096 /* inform the operators what's up */
1098 { /* changing the activation */
1099 sendto_op_mask(SNO_GLINE, !expire ? "%s %sactivating %s for %s@%s" :
1100 "%s %sactivating %s for %s@%s and "
1101 "resetting expiration time to " TIME_T_FMT,
1102 parv[0], active ? "re" : "de", gtype ? "BADCHAN" : "GLINE",
1103 gline->name, gline->host, gline->expire);
1105 write_log(GPATH, !expire ? "# " TIME_T_FMT " %s!%s@%s %sactivating "
1106 "%s for %s@%s\n" : "# " TIME_T_FMT " %s!%s@%s %sactivating %s "
1107 "for %s@%s and resetting expiration time to " TIME_T_FMT "\n",
1108 TStime(), parv[0], cptr->user->username, cptr->user->host,
1109 active ? "re" : "de", gtype ? "BADCHAN" : "GLINE", gline->name,
1110 gline->host, gline->expire);
1115 { /* changing only the expiration */
1116 sendto_op_mask(SNO_GLINE,
1117 "%s resetting expiration time on %s for %s@%s to " TIME_T_FMT,
1118 parv[0], gtype ? "BADCHAN" : "GLINE", gline->name, gline->host,
1121 write_log(GPATH, "# " TIME_T_FMT " %s!%s@%s resetting expiration "
1122 "time on %s for %s@%s to " TIME_T_FMT "\n", TStime(), parv[0],
1123 cptr->user->username, cptr->user->host, gtype ? "BADCHAN" : "GLINE",
1124 gline->name, gline->host, gline->expire);