ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/src/conf_resv.c
Revision: 7288
Committed: Sun Feb 7 19:55:12 2016 UTC (9 years, 6 months ago) by michael
Content type: text/x-csrc
File size: 6160 byte(s)
Log Message:
- Further fixes to resv rewrite

File Contents

# User Rev Content
1 adx 30 /*
2 michael 2916 * ircd-hybrid: an advanced, lightweight Internet Relay Chat Daemon (ircd)
3 adx 30 *
4 michael 7006 * Copyright (c) 2001-2016 ircd-hybrid development team
5 adx 30 *
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 michael 4565 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
19 adx 30 * USA
20     */
21    
22 michael 7234 /*! \file conf_resv.c
23 michael 2916 * \brief Functions to reserve(jupe) a nick/channel.
24     * \version $Id$
25     */
26    
27 adx 30 #include "stdinc.h"
28 michael 1011 #include "list.h"
29 adx 30 #include "send.h"
30 michael 2916 #include "client.h"
31 adx 30 #include "memory.h"
32 michael 7282 #include "ircd.h"
33 adx 30 #include "irc_string.h"
34     #include "ircd_defs.h"
35 michael 3347 #include "misc.h"
36 michael 1309 #include "conf.h"
37 michael 7234 #include "conf_resv.h"
38 michael 1858 #include "hostmask.h"
39 adx 30
40    
41 michael 7282 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 michael 7288 xfree(resv->reason);
74 michael 7282 xfree(resv);
75     }
76    
77 michael 1858 /* create_resv()
78 adx 30 *
79 michael 1858 * inputs - name of nick to create resv for
80 adx 30 * - reason for resv
81 michael 1858 * - 1 if from ircd.conf, 0 if from elsewhere
82     * output - pointer to struct ResvNick
83 adx 30 * side effects -
84     */
85 michael 7282 struct ResvItem *
86     resv_make(const char *mask, const char *reason, const dlink_list *elist)
87 adx 30 {
88 michael 7282 dlink_list *list;
89 adx 30
90 michael 7282 if (IsChanPrefix(*mask))
91     list = &resv_chan_list;
92 michael 1858 else
93 michael 7282 list = &resv_nick_list;
94 michael 1858
95 michael 7282 if (resv_find(mask, irccmp))
96 adx 30 return NULL;
97    
98 michael 7282 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 michael 7286 dlinkAdd(resv, &resv->node, resv->list);
103 adx 30
104 michael 7282 if (elist)
105 michael 1858 {
106 michael 7282 dlink_node *node;
107    
108     DLINK_FOREACH(node, elist->head)
109 michael 1858 {
110 michael 1860 char nick[NICKLEN + 1];
111     char user[USERLEN + 1];
112     char host[HOSTLEN + 1];
113     struct split_nuh_item nuh;
114 michael 4815 char *s = node->data;
115 michael 1858
116 michael 1860 if (strlen(s) == 2 && IsAlpha(*(s + 1) && IsAlpha(*(s + 2))))
117 michael 1858 {
118 michael 1872 #ifdef HAVE_LIBGEOIP
119 michael 7282 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 michael 1872 #endif
124 michael 1860 }
125     else
126     {
127     nuh.nuhmask = s;
128 michael 1858 nuh.nickptr = nick;
129     nuh.userptr = user;
130     nuh.hostptr = host;
131    
132 michael 1859 nuh.nicksize = sizeof(nick);
133 michael 1858 nuh.usersize = sizeof(user);
134     nuh.hostsize = sizeof(host);
135    
136     split_nuh(&nuh);
137    
138 michael 7282 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 michael 1858 }
145     }
146     }
147    
148 michael 7282 return resv;
149 adx 30 }
150    
151 michael 7282 struct ResvItem *
152     resv_find(const char *name, int (*compare)(const char *, const char *))
153     {
154     dlink_node *node = NULL;
155     dlink_list *list = NULL;
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 michael 1858 int
174 michael 7282 resv_exempt_find(const struct Client *client_p, const struct ResvItem *resv)
175 adx 30 {
176 michael 4815 const dlink_node *node = NULL;
177 adx 30
178 michael 7282 DLINK_FOREACH(node, resv->exempt_list.head)
179 michael 1858 {
180 michael 7282 const struct ResvExemptItem *exempt = node->data;
181 adx 30
182 michael 7282 if (exempt->country_id)
183 michael 1858 {
184 michael 7282 if (exempt->country_id == client_p->connection->country_id)
185 michael 1858 return 1;
186     }
187 michael 7282 else if (!match(exempt->name, client_p->name) && !match(exempt->user, client_p->username))
188 michael 1858 {
189 michael 7282 switch (exempt->type)
190 michael 1858 {
191     case HM_HOST:
192 michael 7282 if (!match(exempt->host, client_p->host) || !match(exempt->host, client_p->sockhost))
193 michael 1858 return 1;
194     break;
195     case HM_IPV4:
196 michael 6690 if (client_p->connection->aftype == AF_INET)
197 michael 7282 if (match_ipv4(&client_p->connection->ip, &exempt->addr, exempt->bits))
198 michael 1858 return 1;
199     break;
200     case HM_IPV6:
201 michael 6690 if (client_p->connection->aftype == AF_INET6)
202 michael 7282 if (match_ipv6(&client_p->connection->ip, &exempt->addr, exempt->bits))
203 michael 1858 return 1;
204     break;
205     default:
206     assert(0);
207     }
208     }
209     }
210 adx 30
211 michael 1858 return 0;
212 adx 30 }
213    
214 michael 7282 void
215     resv_clear(void)
216 adx 30 {
217 michael 7282 dlink_list *tab[] = { &resv_chan_list, &resv_nick_list, NULL };
218 adx 30
219 michael 7282 for (dlink_list **list = tab; *list; ++list)
220     {
221     dlink_node *node = NULL, *node_next = NULL;
222 adx 30
223 michael 7282 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 adx 30 {
240 michael 7282 dlink_node *node = NULL, *node_next = NULL;
241 adx 30
242 michael 7282 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 adx 30 }
255     }

Properties

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