ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/src/conf_resv.c
Revision: 7282
Committed: Sun Feb 7 18:04:26 2016 UTC (9 years, 6 months ago) by michael
Content type: text/x-csrc
File size: 6094 byte(s)
Log Message:
- Cleanup/separate RESV conf implementation

File Contents

# Content
1 /*
2 * ircd-hybrid: an advanced, lightweight Internet Relay Chat Daemon (ircd)
3 *
4 * Copyright (c) 2001-2016 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);
74 }
75
76 /* create_resv()
77 *
78 * inputs - name of nick to create resv for
79 * - reason for resv
80 * - 1 if from ircd.conf, 0 if from elsewhere
81 * output - pointer to struct ResvNick
82 * side effects -
83 */
84 struct ResvItem *
85 resv_make(const char *mask, const char *reason, const dlink_list *elist)
86 {
87 dlink_list *list;
88
89 if (IsChanPrefix(*mask))
90 list = &resv_chan_list;
91 else
92 list = &resv_nick_list;
93
94 if (resv_find(mask, irccmp))
95 return NULL;
96
97 struct ResvItem *resv = xcalloc(sizeof(*resv));
98 resv->list = list;
99 resv->mask = xstrdup(mask);
100 resv->reason = xstrndup(reason, IRCD_MIN(strlen(reason), REASONLEN));
101
102 if (elist)
103 {
104 dlink_node *node;
105
106 DLINK_FOREACH(node, elist->head)
107 {
108 char nick[NICKLEN + 1];
109 char user[USERLEN + 1];
110 char host[HOSTLEN + 1];
111 struct split_nuh_item nuh;
112 char *s = node->data;
113
114 if (strlen(s) == 2 && IsAlpha(*(s + 1) && IsAlpha(*(s + 2))))
115 {
116 #ifdef HAVE_LIBGEOIP
117 struct ResvExemptItem *exempt = xcalloc(sizeof(*exempt));
118 exempt->name = xstrdup(s);
119 exempt->country_id = GeoIP_id_by_code(s);
120 dlinkAdd(exempt, &exempt->node, &resv->exempt_list);
121 #endif
122 }
123 else
124 {
125 nuh.nuhmask = s;
126 nuh.nickptr = nick;
127 nuh.userptr = user;
128 nuh.hostptr = host;
129
130 nuh.nicksize = sizeof(nick);
131 nuh.usersize = sizeof(user);
132 nuh.hostsize = sizeof(host);
133
134 split_nuh(&nuh);
135
136 struct ResvExemptItem *exempt = xcalloc(sizeof(*exempt));
137 exempt->name = xstrdup(nick);
138 exempt->user = xstrdup(user);
139 exempt->host = xstrdup(host);
140 exempt->type = parse_netmask(host, &exempt->addr, &exempt->bits);
141 dlinkAdd(exempt, &exempt->node, &resv->exempt_list);
142 }
143 }
144 }
145
146 return resv;
147 }
148
149 struct ResvItem *
150 resv_find(const char *name, int (*compare)(const char *, const char *))
151 {
152 dlink_node *node = NULL;
153 dlink_list *list = NULL;
154
155 if (IsChanPrefix(*name))
156 list = &resv_chan_list;
157 else
158 list = &resv_nick_list;
159
160 DLINK_FOREACH(node, list->head)
161 {
162 struct ResvItem *resv = node->data;
163
164 if (!compare(resv->mask, name))
165 return resv;
166 }
167
168 return NULL;
169 }
170
171 int
172 resv_exempt_find(const struct Client *client_p, const struct ResvItem *resv)
173 {
174 const dlink_node *node = NULL;
175
176 DLINK_FOREACH(node, resv->exempt_list.head)
177 {
178 const struct ResvExemptItem *exempt = node->data;
179
180 if (exempt->country_id)
181 {
182 if (exempt->country_id == client_p->connection->country_id)
183 return 1;
184 }
185 else if (!match(exempt->name, client_p->name) && !match(exempt->user, client_p->username))
186 {
187 switch (exempt->type)
188 {
189 case HM_HOST:
190 if (!match(exempt->host, client_p->host) || !match(exempt->host, client_p->sockhost))
191 return 1;
192 break;
193 case HM_IPV4:
194 if (client_p->connection->aftype == AF_INET)
195 if (match_ipv4(&client_p->connection->ip, &exempt->addr, exempt->bits))
196 return 1;
197 break;
198 case HM_IPV6:
199 if (client_p->connection->aftype == AF_INET6)
200 if (match_ipv6(&client_p->connection->ip, &exempt->addr, exempt->bits))
201 return 1;
202 break;
203 default:
204 assert(0);
205 }
206 }
207 }
208
209 return 0;
210 }
211
212 void
213 resv_clear(void)
214 {
215 dlink_list *tab[] = { &resv_chan_list, &resv_nick_list, NULL };
216
217 for (dlink_list **list = tab; *list; ++list)
218 {
219 dlink_node *node = NULL, *node_next = NULL;
220
221 DLINK_FOREACH_SAFE(node, node_next, (*list)->head)
222 {
223 struct ResvItem *resv = node->data;
224
225 if (!resv->in_database)
226 resv_delete(resv);
227 }
228 }
229 }
230
231 void
232 resv_expire(void)
233 {
234 dlink_list *tab[] = { &resv_chan_list, &resv_nick_list, NULL };
235
236 for (dlink_list **list = tab; *list; ++list)
237 {
238 dlink_node *node = NULL, *node_next = NULL;
239
240 DLINK_FOREACH_SAFE(node, node_next, (*list)->head)
241 {
242 struct ResvItem *resv = node->data;
243
244 if (!resv->expire || resv->expire > CurrentTime)
245 continue;
246
247 if (ConfigGeneral.tkline_expire_notices)
248 sendto_realops_flags(UMODE_SERVNOTICE, L_ALL, SEND_NOTICE, "Temporary RESV for [%s] expired",
249 resv->mask);
250 resv_delete(resv);
251 }
252 }
253 }

Properties

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