ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/src/conf_resv.c
Revision: 7939
Committed: Fri Jan 27 14:53:49 2017 UTC (8 years, 7 months ago) by michael
Content type: text/x-csrc
File size: 6133 byte(s)
Log Message:
- conf_resv.c:resv_find(): remove explicit initialization on 'node' and 'list'

File Contents

# Content
1 /*
2 * ircd-hybrid: an advanced, lightweight Internet Relay Chat Daemon (ircd)
3 *
4 * Copyright (c) 2001-2017 ircd-hybrid development team
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
19 * USA
20 */
21
22 /*! \file conf_resv.c
23 * \brief Functions to reserve(jupe) a nick/channel.
24 * \version $Id$
25 */
26
27 #include "stdinc.h"
28 #include "list.h"
29 #include "send.h"
30 #include "client.h"
31 #include "memory.h"
32 #include "ircd.h"
33 #include "irc_string.h"
34 #include "ircd_defs.h"
35 #include "misc.h"
36 #include "conf.h"
37 #include "conf_resv.h"
38 #include "hostmask.h"
39
40
41 static dlink_list resv_chan_list;
42 static dlink_list resv_nick_list;
43
44
45 const dlink_list *
46 resv_chan_get_list(void)
47 {
48 return &resv_chan_list;
49 }
50
51 const dlink_list *
52 resv_nick_get_list(void)
53 {
54 return &resv_nick_list;
55 }
56
57 void
58 resv_delete(struct ResvItem *resv)
59 {
60 while (resv->exempt_list.head)
61 {
62 struct ResvExemptItem *exempt = resv->exempt_list.head->data;
63
64 dlinkDelete(&exempt->node, &resv->exempt_list);
65 xfree(exempt->name);
66 xfree(exempt->user);
67 xfree(exempt->host);
68 xfree(exempt);
69 }
70
71 dlinkDelete(&resv->node, resv->list);
72 xfree(resv->mask);
73 xfree(resv->reason);
74 xfree(resv);
75 }
76
77 /* create_resv()
78 *
79 * inputs - name of nick to create resv for
80 * - reason for resv
81 * - 1 if from ircd.conf, 0 if from elsewhere
82 * output - pointer to struct ResvNick
83 * side effects -
84 */
85 struct ResvItem *
86 resv_make(const char *mask, const char *reason, const dlink_list *elist)
87 {
88 dlink_list *list;
89
90 if (resv_find(mask, irccmp))
91 return NULL;
92
93 if (IsChanPrefix(*mask))
94 list = &resv_chan_list;
95 else
96 list = &resv_nick_list;
97
98 struct ResvItem *resv = xcalloc(sizeof(*resv));
99 resv->list = list;
100 resv->mask = xstrdup(mask);
101 resv->reason = xstrndup(reason, IRCD_MIN(strlen(reason), REASONLEN));
102 dlinkAdd(resv, &resv->node, resv->list);
103
104 if (elist)
105 {
106 dlink_node *node;
107
108 DLINK_FOREACH(node, elist->head)
109 {
110 char nick[NICKLEN + 1];
111 char user[USERLEN + 1];
112 char host[HOSTLEN + 1];
113 struct split_nuh_item nuh;
114 char *s = node->data;
115
116 if (strlen(s) == 2 && IsAlpha(*(s + 1) && IsAlpha(*(s + 2))))
117 {
118 #ifdef HAVE_LIBGEOIP
119 struct ResvExemptItem *exempt = xcalloc(sizeof(*exempt));
120 exempt->name = xstrdup(s);
121 exempt->country_id = GeoIP_id_by_code(s);
122 dlinkAdd(exempt, &exempt->node, &resv->exempt_list);
123 #endif
124 }
125 else
126 {
127 nuh.nuhmask = s;
128 nuh.nickptr = nick;
129 nuh.userptr = user;
130 nuh.hostptr = host;
131
132 nuh.nicksize = sizeof(nick);
133 nuh.usersize = sizeof(user);
134 nuh.hostsize = sizeof(host);
135
136 split_nuh(&nuh);
137
138 struct ResvExemptItem *exempt = xcalloc(sizeof(*exempt));
139 exempt->name = xstrdup(nick);
140 exempt->user = xstrdup(user);
141 exempt->host = xstrdup(host);
142 exempt->type = parse_netmask(host, &exempt->addr, &exempt->bits);
143 dlinkAdd(exempt, &exempt->node, &resv->exempt_list);
144 }
145 }
146 }
147
148 return resv;
149 }
150
151 struct ResvItem *
152 resv_find(const char *name, int (*compare)(const char *, const char *))
153 {
154 dlink_node *node;
155 dlink_list *list;
156
157 if (IsChanPrefix(*name))
158 list = &resv_chan_list;
159 else
160 list = &resv_nick_list;
161
162 DLINK_FOREACH(node, list->head)
163 {
164 struct ResvItem *resv = node->data;
165
166 if (!compare(resv->mask, name))
167 return resv;
168 }
169
170 return NULL;
171 }
172
173 int
174 resv_exempt_find(const struct Client *client_p, const struct ResvItem *resv)
175 {
176 dlink_node *node;
177
178 DLINK_FOREACH(node, resv->exempt_list.head)
179 {
180 const struct ResvExemptItem *exempt = node->data;
181
182 if (exempt->country_id)
183 {
184 if (exempt->country_id == client_p->connection->country_id)
185 return 1;
186 }
187 else if (!match(exempt->name, client_p->name) && !match(exempt->user, client_p->username))
188 {
189 switch (exempt->type)
190 {
191 case HM_HOST:
192 if (!match(exempt->host, client_p->host) || !match(exempt->host, client_p->sockhost))
193 return 1;
194 break;
195 case HM_IPV4:
196 if (client_p->connection->aftype == AF_INET)
197 if (match_ipv4(&client_p->connection->ip, &exempt->addr, exempt->bits))
198 return 1;
199 break;
200 case HM_IPV6:
201 if (client_p->connection->aftype == AF_INET6)
202 if (match_ipv6(&client_p->connection->ip, &exempt->addr, exempt->bits))
203 return 1;
204 break;
205 default:
206 assert(0);
207 }
208 }
209 }
210
211 return 0;
212 }
213
214 void
215 resv_clear(void)
216 {
217 dlink_list *tab[] = { &resv_chan_list, &resv_nick_list, NULL };
218
219 for (dlink_list **list = tab; *list; ++list)
220 {
221 dlink_node *node = NULL, *node_next = NULL;
222
223 DLINK_FOREACH_SAFE(node, node_next, (*list)->head)
224 {
225 struct ResvItem *resv = node->data;
226
227 if (!resv->in_database)
228 resv_delete(resv);
229 }
230 }
231 }
232
233 void
234 resv_expire(void)
235 {
236 dlink_list *tab[] = { &resv_chan_list, &resv_nick_list, NULL };
237
238 for (dlink_list **list = tab; *list; ++list)
239 {
240 dlink_node *node = NULL, *node_next = NULL;
241
242 DLINK_FOREACH_SAFE(node, node_next, (*list)->head)
243 {
244 struct ResvItem *resv = node->data;
245
246 if (!resv->expire || resv->expire > CurrentTime)
247 continue;
248
249 if (ConfigGeneral.tkline_expire_notices)
250 sendto_realops_flags(UMODE_SERVNOTICE, L_ALL, SEND_NOTICE, "Temporary RESV for [%s] expired",
251 resv->mask);
252 resv_delete(resv);
253 }
254 }
255 }

Properties

Name Value
svn:eol-style native
svn:keywords Id