]> jfr.im git - irc/rqf/shadowircd.git/blob - src/s_gline.c
Argh, wrong replace caused by MS VS 2005 interface.
[irc/rqf/shadowircd.git] / src / s_gline.c
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 "channel.h"
29 #include "client.h"
30 #include "common.h"
31 #include "config.h"
32 #include "irc_string.h"
33 #include "ircd.h"
34 #include "hostmask.h"
35 #include "numeric.h"
36 #include "s_conf.h"
37 #include "scache.h"
38 #include "send.h"
39 #include "msg.h"
40 #include "s_serv.h"
41 #include "s_gline.h"
42 #include "hash.h"
43
44 rb_dlink_list glines;
45
46 static void expire_glines(void);
47 static void expire_pending_glines(void);
48
49 /* add_gline
50 *
51 * inputs - pointer to struct ConfItem
52 * output - none
53 * Side effects - links in given struct ConfItem into gline link list
54 */
55 void
56 add_gline(struct ConfItem *aconf)
57 {
58 rb_dlinkAddTailAlloc(aconf, &glines);
59 add_conf_by_address(aconf->host, CONF_GLINE, aconf->user, aconf);
60 }
61
62 /*
63 * find_is_glined
64 * inputs - hostname
65 * - username
66 * output - pointer to struct ConfItem if user@host glined
67 * side effects -
68 */
69 struct ConfItem *
70 find_is_glined(const char *host, const char *user)
71 {
72 rb_dlink_node *gline_node;
73 struct ConfItem *kill_ptr;
74
75 RB_DLINK_FOREACH(gline_node, glines.head)
76 {
77 kill_ptr = gline_node->data;
78 if((kill_ptr->user && (!user || match(kill_ptr->user, user)))
79 && (kill_ptr->host && (!host || match(kill_ptr->host, host))))
80 {
81 return (kill_ptr);
82 }
83 }
84
85 return (NULL);
86 }
87
88 /*
89 * cleanup_glines
90 *
91 * inputs - NONE
92 * output - NONE
93 * side effects - expire gline lists
94 * This is an event started off in ircd.c
95 */
96 void
97 cleanup_glines(void *unused)
98 {
99 expire_glines();
100 expire_pending_glines();
101 }
102
103 /*
104 * expire_glines
105 *
106 * inputs - NONE
107 * output - NONE
108 * side effects -
109 *
110 * Go through the gline list, expire any needed.
111 */
112 static void
113 expire_glines()
114 {
115 rb_dlink_node *gline_node;
116 rb_dlink_node *next_node;
117 struct ConfItem *kill_ptr;
118
119 RB_DLINK_FOREACH_SAFE(gline_node, next_node, glines.head)
120 {
121 kill_ptr = gline_node->data;
122
123 /* these are in chronological order */
124 if(kill_ptr->hold > CurrentTime)
125 break;
126
127 rb_dlinkDestroy(gline_node, &glines);
128 delete_one_address_conf(kill_ptr->host, kill_ptr);
129 }
130 }
131
132 /*
133 * expire_pending_glines
134 *
135 * inputs - NONE
136 * output - NONE
137 * side effects -
138 *
139 * Go through the pending gline list, expire any that haven't had
140 * enough "votes" in the time period allowed
141 */
142 static void
143 expire_pending_glines()
144 {
145 rb_dlink_node *pending_node;
146 rb_dlink_node *next_node;
147 struct gline_pending *glp_ptr;
148
149 RB_DLINK_FOREACH_SAFE(pending_node, next_node, pending_glines.head)
150 {
151 glp_ptr = pending_node->data;
152
153 if(((glp_ptr->last_gline_time + GLINE_PENDING_EXPIRE) <=
154 CurrentTime) || find_is_glined(glp_ptr->host, glp_ptr->user))
155
156 {
157 rb_free(glp_ptr->reason1);
158 rb_free(glp_ptr->reason2);
159 rb_free(glp_ptr);
160 rb_dlinkDestroy(pending_node, &pending_glines);
161 }
162 }
163 }