]> jfr.im git - irc/rqf/shadowircd.git/blame - src/s_gline.c
macro replacement
[irc/rqf/shadowircd.git] / src / s_gline.c
CommitLineData
212380e3 1/*
2 * ircd-ratbox: A slightly useful ircd.
3 * s_gline.c: GLine global ban functions.
4 *
5 * Copyright (C) 1990 Jarkko Oikarinen and University of Oulu, Co Center
6 * Copyright (C) 1996-2002 Hybrid Development Team
7 * Copyright (C) 2002-2005 ircd-ratbox development team
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 2 of the License, or
12 * (at your option) 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307
22 * USA
23 *
24 * $Id: s_gline.c 254 2005-09-21 23:35:12Z nenolod $
25 */
26
27#include "stdinc.h"
28#include "tools.h"
29#include "channel.h"
30#include "client.h"
31#include "common.h"
32#include "config.h"
33#include "irc_string.h"
34#include "ircd.h"
35#include "hostmask.h"
36#include "numeric.h"
37#include "commio.h"
38#include "s_conf.h"
39#include "scache.h"
40#include "send.h"
41#include "msg.h"
42#include "s_serv.h"
43#include "s_gline.h"
44#include "hash.h"
45#include "event.h"
46#include "memory.h"
47
af81d5a0 48rb_dlink_list glines;
212380e3 49
50static void expire_glines(void);
51static void expire_pending_glines(void);
52
53/* add_gline
54 *
55 * inputs - pointer to struct ConfItem
56 * output - none
57 * Side effects - links in given struct ConfItem into gline link list
58 */
59void
60add_gline(struct ConfItem *aconf)
61{
af81d5a0 62 rb_dlinkAddTailAlloc(aconf, &glines);
212380e3 63 add_conf_by_address(aconf->host, CONF_GLINE, aconf->user, aconf);
64}
65
66/*
67 * find_is_glined
68 * inputs - hostname
69 * - username
70 * output - pointer to struct ConfItem if user@host glined
71 * side effects -
72 */
73struct ConfItem *
74find_is_glined(const char *host, const char *user)
75{
af81d5a0 76 rb_dlink_node *gline_node;
212380e3 77 struct ConfItem *kill_ptr;
78
8e69bb4e 79 RB_DLINK_FOREACH(gline_node, glines.head)
212380e3 80 {
81 kill_ptr = gline_node->data;
82 if((kill_ptr->user && (!user || match(kill_ptr->user, user)))
83 && (kill_ptr->host && (!host || match(kill_ptr->host, host))))
84 {
85 return (kill_ptr);
86 }
87 }
88
89 return (NULL);
90}
91
92/*
93 * cleanup_glines
94 *
95 * inputs - NONE
96 * output - NONE
97 * side effects - expire gline lists
98 * This is an event started off in ircd.c
99 */
100void
101cleanup_glines(void *unused)
102{
103 expire_glines();
104 expire_pending_glines();
105}
106
107/*
108 * expire_glines
109 *
110 * inputs - NONE
111 * output - NONE
112 * side effects -
113 *
114 * Go through the gline list, expire any needed.
115 */
116static void
117expire_glines()
118{
af81d5a0
WP
119 rb_dlink_node *gline_node;
120 rb_dlink_node *next_node;
212380e3 121 struct ConfItem *kill_ptr;
122
8e69bb4e 123 RB_DLINK_FOREACH_SAFE(gline_node, next_node, glines.head)
212380e3 124 {
125 kill_ptr = gline_node->data;
126
127 /* these are in chronological order */
128 if(kill_ptr->hold > CurrentTime)
129 break;
130
af81d5a0 131 rb_dlinkDestroy(gline_node, &glines);
212380e3 132 delete_one_address_conf(kill_ptr->host, kill_ptr);
133 }
134}
135
136/*
137 * expire_pending_glines
138 *
139 * inputs - NONE
140 * output - NONE
141 * side effects -
142 *
143 * Go through the pending gline list, expire any that haven't had
144 * enough "votes" in the time period allowed
145 */
146static void
147expire_pending_glines()
148{
af81d5a0
WP
149 rb_dlink_node *pending_node;
150 rb_dlink_node *next_node;
212380e3 151 struct gline_pending *glp_ptr;
152
8e69bb4e 153 RB_DLINK_FOREACH_SAFE(pending_node, next_node, pending_glines.head)
212380e3 154 {
155 glp_ptr = pending_node->data;
156
157 if(((glp_ptr->last_gline_time + GLINE_PENDING_EXPIRE) <=
158 CurrentTime) || find_is_glined(glp_ptr->host, glp_ptr->user))
159
160 {
161 MyFree(glp_ptr->reason1);
162 MyFree(glp_ptr->reason2);
163 MyFree(glp_ptr);
af81d5a0 164 rb_dlinkDestroy(pending_node, &pending_glines);
212380e3 165 }
166 }
167}