1 |
|
/* |
2 |
< |
* ircd-hybrid: an advanced Internet Relay Chat Daemon(ircd). |
3 |
< |
* resv.c: Functions to reserve(jupe) a nick/channel. |
2 |
> |
* ircd-hybrid: an advanced, lightweight Internet Relay Chat Daemon (ircd) |
3 |
|
* |
4 |
< |
* Copyright (C) 2001-2002 Hybrid Development Team |
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 |
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 |
18 |
> |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 |
19 |
|
* USA |
20 |
< |
* |
21 |
< |
* $Id$ |
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" |
27 |
– |
#include "ircd.h" |
29 |
|
#include "send.h" |
30 |
< |
#include "client.h" |
30 |
> |
#include "client.h" |
31 |
|
#include "memory.h" |
32 |
< |
#include "numeric.h" |
32 |
< |
#include "resv.h" |
33 |
< |
#include "hash.h" |
32 |
> |
#include "ircd.h" |
33 |
|
#include "irc_string.h" |
34 |
|
#include "ircd_defs.h" |
35 |
< |
#include "s_misc.h" |
35 |
> |
#include "misc.h" |
36 |
|
#include "conf.h" |
37 |
< |
#include "conf_db.h" |
39 |
< |
#include "channel.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 |
82 |
|
* output - pointer to struct ResvNick |
83 |
|
* side effects - |
84 |
|
*/ |
85 |
< |
struct MaskItem * |
86 |
< |
create_resv(const char *name, const char *reason, const dlink_list *list) |
85 |
> |
struct ResvItem * |
86 |
> |
resv_make(const char *mask, const char *reason, const dlink_list *elist) |
87 |
|
{ |
88 |
< |
dlink_node *ptr = NULL; |
55 |
< |
struct MaskItem *conf = NULL; |
56 |
< |
enum maskitem_type type; |
57 |
< |
|
58 |
< |
if (name == NULL || reason == NULL) |
59 |
< |
return NULL; |
88 |
> |
dlink_list *list; |
89 |
|
|
90 |
< |
if (IsChanPrefix(*name)) |
91 |
< |
type = CONF_CRESV; |
90 |
> |
if (IsChanPrefix(*mask)) |
91 |
> |
list = &resv_chan_list; |
92 |
|
else |
93 |
< |
type = CONF_NRESV; |
93 |
> |
list = &resv_nick_list; |
94 |
|
|
95 |
< |
if (find_exact_name_conf(type, NULL, name, NULL, NULL)) |
95 |
> |
if (resv_find(mask, irccmp)) |
96 |
|
return NULL; |
97 |
|
|
98 |
< |
conf = conf_make(type); |
99 |
< |
conf->name = xstrdup(name); |
100 |
< |
conf->reason = xstrndup(reason, IRCD_MIN(strlen(reason), REASONLEN)); |
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 (list) |
104 |
> |
if (elist) |
105 |
|
{ |
106 |
< |
DLINK_FOREACH(ptr, list->head) |
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 |
< |
struct exempt *exptr = NULL; |
82 |
< |
char *s = ptr->data; |
114 |
> |
char *s = node->data; |
115 |
|
|
116 |
|
if (strlen(s) == 2 && IsAlpha(*(s + 1) && IsAlpha(*(s + 2)))) |
117 |
|
{ |
118 |
|
#ifdef HAVE_LIBGEOIP |
119 |
< |
exptr = MyMalloc(sizeof(*exptr)); |
120 |
< |
exptr->name = xstrdup(s); |
121 |
< |
exptr->coid = GeoIP_id_by_code(s); |
122 |
< |
dlinkAdd(exptr, &exptr->node, &conf->exempt_list); |
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 |
135 |
|
|
136 |
|
split_nuh(&nuh); |
137 |
|
|
138 |
< |
exptr = MyMalloc(sizeof(*exptr)); |
139 |
< |
exptr->name = xstrdup(nick); |
140 |
< |
exptr->user = xstrdup(user); |
141 |
< |
exptr->host = xstrdup(host); |
142 |
< |
exptr->type = parse_netmask(host, &exptr->addr, &exptr->bits); |
143 |
< |
dlinkAdd(exptr, &exptr->node, &conf->exempt_list); |
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 conf; |
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 = 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 |
|
int |
174 |
< |
resv_find_exempt(const struct Client *who, const struct MaskItem *conf) |
174 |
> |
resv_exempt_find(const struct Client *client_p, const struct ResvItem *resv) |
175 |
|
{ |
176 |
< |
const dlink_node *ptr = NULL; |
176 |
> |
const dlink_node *node = NULL; |
177 |
|
|
178 |
< |
DLINK_FOREACH(ptr, conf->exempt_list.head) |
178 |
> |
DLINK_FOREACH(node, resv->exempt_list.head) |
179 |
|
{ |
180 |
< |
const struct exempt *exptr = ptr->data; |
180 |
> |
const struct ResvExemptItem *exempt = node->data; |
181 |
|
|
182 |
< |
if (exptr->coid) |
182 |
> |
if (exempt->country_id) |
183 |
|
{ |
184 |
< |
if (exptr->coid == who->localClient->country_id) |
184 |
> |
if (exempt->country_id == client_p->connection->country_id) |
185 |
|
return 1; |
186 |
|
} |
187 |
< |
else if (!match(exptr->name, who->name) && !match(exptr->user, who->username)) |
187 |
> |
else if (!match(exempt->name, client_p->name) && !match(exempt->user, client_p->username)) |
188 |
|
{ |
189 |
< |
switch (exptr->type) |
189 |
> |
switch (exempt->type) |
190 |
|
{ |
191 |
|
case HM_HOST: |
192 |
< |
if (!match(exptr->host, who->host) || !match(exptr->host, who->sockhost)) |
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 (who->localClient->aftype == AF_INET) |
197 |
< |
if (match_ipv4(&who->localClient->ip, &exptr->addr, exptr->bits)) |
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; |
146 |
– |
#ifdef IPV6 |
200 |
|
case HM_IPV6: |
201 |
< |
if (who->localClient->aftype == AF_INET6) |
202 |
< |
if (match_ipv6(&who->localClient->ip, &exptr->addr, exptr->bits)) |
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; |
152 |
– |
#endif |
205 |
|
default: |
206 |
|
assert(0); |
207 |
|
} |
211 |
|
return 0; |
212 |
|
} |
213 |
|
|
214 |
< |
/* match_find_resv() |
215 |
< |
* |
164 |
< |
* inputs - pointer to name |
165 |
< |
* output - pointer to a struct ResvChannel |
166 |
< |
* side effects - Finds a reserved channel whose name matches 'name', |
167 |
< |
* if can't find one returns NULL. |
168 |
< |
*/ |
169 |
< |
struct MaskItem * |
170 |
< |
match_find_resv(const char *name) |
214 |
> |
void |
215 |
> |
resv_clear(void) |
216 |
|
{ |
217 |
< |
dlink_node *ptr = NULL; |
217 |
> |
dlink_list *tab[] = { &resv_chan_list, &resv_nick_list, NULL }; |
218 |
|
|
219 |
< |
if (EmptyString(name)) |
175 |
< |
return NULL; |
176 |
< |
|
177 |
< |
DLINK_FOREACH(ptr, cresv_items.head) |
219 |
> |
for (dlink_list **list = tab; *list; ++list) |
220 |
|
{ |
221 |
< |
struct MaskItem *conf = ptr->data; |
221 |
> |
dlink_node *node = NULL, *node_next = NULL; |
222 |
|
|
223 |
< |
if (!match(conf->name, name)) |
224 |
< |
return conf; |
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 |
< |
return NULL; |
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 |
|
} |