]>
Commit | Line | Data |
---|---|---|
212380e3 AC |
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" | |
212380e3 AC |
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" | |
212380e3 AC |
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" | |
212380e3 | 43 | |
330fc5c1 | 44 | rb_dlink_list glines; |
212380e3 AC |
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 | { | |
330fc5c1 | 58 | rb_dlinkAddTailAlloc(aconf, &glines); |
212380e3 AC |
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 | { | |
330fc5c1 | 72 | rb_dlink_node *gline_node; |
212380e3 AC |
73 | struct ConfItem *kill_ptr; |
74 | ||
5cefa1d6 | 75 | RB_DLINK_FOREACH(gline_node, glines.head) |
212380e3 AC |
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 | { | |
330fc5c1 AC |
115 | rb_dlink_node *gline_node; |
116 | rb_dlink_node *next_node; | |
212380e3 AC |
117 | struct ConfItem *kill_ptr; |
118 | ||
5cefa1d6 | 119 | RB_DLINK_FOREACH_SAFE(gline_node, next_node, glines.head) |
212380e3 AC |
120 | { |
121 | kill_ptr = gline_node->data; | |
122 | ||
123 | /* these are in chronological order */ | |
124 | if(kill_ptr->hold > CurrentTime) | |
125 | break; | |
126 | ||
330fc5c1 | 127 | rb_dlinkDestroy(gline_node, &glines); |
212380e3 AC |
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 | { | |
330fc5c1 AC |
145 | rb_dlink_node *pending_node; |
146 | rb_dlink_node *next_node; | |
212380e3 AC |
147 | struct gline_pending *glp_ptr; |
148 | ||
5cefa1d6 | 149 | RB_DLINK_FOREACH_SAFE(pending_node, next_node, pending_glines.head) |
212380e3 AC |
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 | { | |
637c4932 VY |
157 | rb_free(glp_ptr->reason1); |
158 | rb_free(glp_ptr->reason2); | |
159 | rb_free(glp_ptr); | |
330fc5c1 | 160 | rb_dlinkDestroy(pending_node, &pending_glines); |
212380e3 AC |
161 | } |
162 | } | |
163 | } |