]> jfr.im git - irc/rqf/shadowircd.git/blob - src/s_gline.c
[svn] - the new plan:
[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 "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
48 dlink_list glines;
49
50 static void expire_glines(void);
51 static 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 */
59 void
60 add_gline(struct ConfItem *aconf)
61 {
62 dlinkAddTailAlloc(aconf, &glines);
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 */
73 struct ConfItem *
74 find_is_glined(const char *host, const char *user)
75 {
76 dlink_node *gline_node;
77 struct ConfItem *kill_ptr;
78
79 DLINK_FOREACH(gline_node, glines.head)
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 */
100 void
101 cleanup_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 */
116 static void
117 expire_glines()
118 {
119 dlink_node *gline_node;
120 dlink_node *next_node;
121 struct ConfItem *kill_ptr;
122
123 DLINK_FOREACH_SAFE(gline_node, next_node, glines.head)
124 {
125 kill_ptr = gline_node->data;
126
127 /* these are in chronological order */
128 if(kill_ptr->hold > CurrentTime)
129 break;
130
131 dlinkDestroy(gline_node, &glines);
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 */
146 static void
147 expire_pending_glines()
148 {
149 dlink_node *pending_node;
150 dlink_node *next_node;
151 struct gline_pending *glp_ptr;
152
153 DLINK_FOREACH_SAFE(pending_node, next_node, pending_glines.head)
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);
164 dlinkDestroy(pending_node, &pending_glines);
165 }
166 }
167 }