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-2018 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 "tools.h" |
27 |
< |
#include "common.h" |
28 |
< |
#include "fdlist.h" |
29 |
< |
#include "ircd.h" |
28 |
> |
#include "list.h" |
29 |
|
#include "send.h" |
30 |
< |
#include "client.h" |
30 |
> |
#include "client.h" |
31 |
|
#include "memory.h" |
32 |
< |
#include "numeric.h" |
34 |
< |
#include "resv.h" |
35 |
< |
#include "hash.h" |
32 |
> |
#include "ircd.h" |
33 |
|
#include "irc_string.h" |
34 |
|
#include "ircd_defs.h" |
35 |
< |
#include "s_conf.h" |
35 |
> |
#include "misc.h" |
36 |
> |
#include "conf.h" |
37 |
> |
#include "conf_resv.h" |
38 |
> |
#include "hostmask.h" |
39 |
|
|
40 |
– |
dlink_list resv_channel_list = { NULL, NULL, 0 }; |
40 |
|
|
41 |
+ |
static dlink_list resv_chan_list; |
42 |
+ |
static dlink_list resv_nick_list; |
43 |
|
|
43 |
– |
/* create_channel_resv() |
44 |
– |
* |
45 |
– |
* inputs - name of channel to create resv for |
46 |
– |
* - reason for resv |
47 |
– |
* - flag, 1 for from ircd.conf 0 from elsehwere |
48 |
– |
* output - pointer to struct ResvChannel |
49 |
– |
* side effects - |
50 |
– |
*/ |
51 |
– |
struct ConfItem * |
52 |
– |
create_channel_resv(char *name, char *reason, int in_conf) |
53 |
– |
{ |
54 |
– |
struct ConfItem *conf; |
55 |
– |
struct ResvChannel *resv_p; |
56 |
– |
|
57 |
– |
if (name == NULL || reason == NULL) |
58 |
– |
return NULL; |
44 |
|
|
45 |
< |
if (hash_find_resv(name)) |
46 |
< |
return NULL; |
47 |
< |
|
48 |
< |
if (strlen(reason) > REASONLEN) |
49 |
< |
reason[REASONLEN] = '\0'; |
45 |
> |
const dlink_list * |
46 |
> |
resv_chan_get_list(void) |
47 |
> |
{ |
48 |
> |
return &resv_chan_list; |
49 |
> |
} |
50 |
|
|
51 |
< |
conf = make_conf_item(CRESV_TYPE); |
52 |
< |
resv_p = map_to_conf(conf); |
51 |
> |
const dlink_list * |
52 |
> |
resv_nick_get_list(void) |
53 |
> |
{ |
54 |
> |
return &resv_nick_list; |
55 |
> |
} |
56 |
|
|
57 |
< |
strlcpy(resv_p->name, name, sizeof(resv_p->name)); |
58 |
< |
DupString(resv_p->reason, reason); |
59 |
< |
resv_p->conf = in_conf; |
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 |
< |
dlinkAdd(resv_p, &resv_p->node, &resv_channel_list); |
65 |
< |
hash_add_resv(resv_p); |
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 |
< |
return conf; |
71 |
> |
dlinkDelete(&resv->node, resv->list); |
72 |
> |
xfree(resv->mask); |
73 |
> |
xfree(resv->reason); |
74 |
> |
xfree(resv); |
75 |
|
} |
76 |
|
|
77 |
< |
/* create_nick_resv() |
77 |
> |
/* create_resv() |
78 |
|
* |
79 |
|
* inputs - name of nick to create resv for |
80 |
|
* - reason for resv |
82 |
|
* output - pointer to struct ResvNick |
83 |
|
* side effects - |
84 |
|
*/ |
85 |
< |
struct ConfItem * |
86 |
< |
create_nick_resv(char *name, char *reason, int in_conf) |
85 |
> |
struct ResvItem * |
86 |
> |
resv_make(const char *mask, const char *reason, const dlink_list *elist) |
87 |
|
{ |
88 |
< |
struct ConfItem *conf; |
91 |
< |
struct MatchItem *resv_p; |
88 |
> |
dlink_list *list; |
89 |
|
|
90 |
< |
if (name == NULL || reason == NULL) |
90 |
> |
if (resv_find(mask, irccmp)) |
91 |
|
return NULL; |
92 |
|
|
93 |
< |
if (find_matching_name_conf(NRESV_TYPE, name, NULL, NULL, 0)) |
94 |
< |
return NULL; |
95 |
< |
|
96 |
< |
if (strlen(reason) > REASONLEN) |
97 |
< |
reason[REASONLEN] = '\0'; |
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 |
< |
conf = make_conf_item(NRESV_TYPE); |
105 |
< |
resv_p = map_to_conf(conf); |
104 |
> |
if (elist) |
105 |
> |
{ |
106 |
> |
dlink_node *node; |
107 |
|
|
108 |
< |
DupString(conf->name, name); |
109 |
< |
DupString(resv_p->reason, reason); |
110 |
< |
resv_p->action = in_conf; |
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 |
> |
nuh.nuhmask = s; |
117 |
> |
nuh.nickptr = nick; |
118 |
> |
nuh.userptr = user; |
119 |
> |
nuh.hostptr = host; |
120 |
> |
|
121 |
> |
nuh.nicksize = sizeof(nick); |
122 |
> |
nuh.usersize = sizeof(user); |
123 |
> |
nuh.hostsize = sizeof(host); |
124 |
> |
|
125 |
> |
split_nuh(&nuh); |
126 |
> |
|
127 |
> |
struct ResvExemptItem *exempt = xcalloc(sizeof(*exempt)); |
128 |
> |
exempt->name = xstrdup(nick); |
129 |
> |
exempt->user = xstrdup(user); |
130 |
> |
exempt->host = xstrdup(host); |
131 |
> |
exempt->type = parse_netmask(host, &exempt->addr, &exempt->bits); |
132 |
> |
dlinkAdd(exempt, &exempt->node, &resv->exempt_list); |
133 |
> |
} |
134 |
> |
} |
135 |
|
|
136 |
< |
return conf; |
136 |
> |
return resv; |
137 |
|
} |
138 |
|
|
139 |
< |
/* clear_conf_resv() |
140 |
< |
* |
114 |
< |
* inputs - none |
115 |
< |
* output - none |
116 |
< |
* side effects - All resvs are cleared out |
117 |
< |
*/ |
118 |
< |
void |
119 |
< |
clear_conf_resv(void) |
139 |
> |
struct ResvItem * |
140 |
> |
resv_find(const char *name, int (*compare)(const char *, const char *)) |
141 |
|
{ |
142 |
< |
dlink_node *ptr; |
143 |
< |
dlink_node *next_ptr; |
123 |
< |
struct ResvChannel *resv_cp; |
142 |
> |
dlink_node *node; |
143 |
> |
dlink_list *list; |
144 |
|
|
145 |
< |
DLINK_FOREACH_SAFE(ptr, next_ptr, resv_channel_list.head) |
146 |
< |
{ |
147 |
< |
resv_cp = ptr->data; |
148 |
< |
delete_channel_resv(resv_cp); |
129 |
< |
} |
130 |
< |
} |
145 |
> |
if (IsChanPrefix(*name)) |
146 |
> |
list = &resv_chan_list; |
147 |
> |
else |
148 |
> |
list = &resv_nick_list; |
149 |
|
|
150 |
< |
/* delete_channel_resv() |
151 |
< |
* |
152 |
< |
* inputs - pointer to channel resv to delete |
135 |
< |
* output - none |
136 |
< |
* side effects - given struct ResvChannel * is removed |
137 |
< |
*/ |
138 |
< |
int |
139 |
< |
delete_channel_resv(struct ResvChannel *resv_p) |
140 |
< |
{ |
141 |
< |
struct ConfItem *conf; |
142 |
< |
assert(resv_p != NULL); |
150 |
> |
DLINK_FOREACH(node, list->head) |
151 |
> |
{ |
152 |
> |
struct ResvItem *resv = node->data; |
153 |
|
|
154 |
< |
hash_del_resv(resv_p); |
155 |
< |
dlinkDelete(&resv_p->node, &resv_channel_list); |
156 |
< |
MyFree(resv_p->reason); |
147 |
< |
conf = unmap_conf_item(resv_p); |
148 |
< |
delete_conf_item(conf); |
154 |
> |
if (!compare(resv->mask, name)) |
155 |
> |
return resv; |
156 |
> |
} |
157 |
|
|
158 |
< |
return 1; |
158 |
> |
return NULL; |
159 |
|
} |
160 |
|
|
161 |
< |
/* match_find_resv() |
162 |
< |
* |
155 |
< |
* inputs - pointer to name |
156 |
< |
* output - pointer to a struct ResvChannel |
157 |
< |
* side effects - Finds a reserved channel whose name matches 'name', |
158 |
< |
* if can't find one returns NULL. |
159 |
< |
*/ |
160 |
< |
struct ResvChannel * |
161 |
< |
match_find_resv(const char *name) |
161 |
> |
int |
162 |
> |
resv_exempt_find(const struct Client *client_p, const struct ResvItem *resv) |
163 |
|
{ |
164 |
< |
dlink_node *ptr = NULL; |
164 |
< |
|
165 |
< |
if (EmptyString(name)) |
166 |
< |
return NULL; |
164 |
> |
dlink_node *node; |
165 |
|
|
166 |
< |
DLINK_FOREACH(ptr, resv_channel_list.head) |
166 |
> |
DLINK_FOREACH(node, resv->exempt_list.head) |
167 |
|
{ |
168 |
< |
struct ResvChannel *chptr = ptr->data; |
168 |
> |
const struct ResvExemptItem *exempt = node->data; |
169 |
|
|
170 |
< |
if (match_chan(name, chptr->name)) |
171 |
< |
return chptr; |
170 |
> |
if (!match(exempt->name, client_p->name) && !match(exempt->user, client_p->username)) |
171 |
> |
{ |
172 |
> |
switch (exempt->type) |
173 |
> |
{ |
174 |
> |
case HM_HOST: |
175 |
> |
if (!match(exempt->host, client_p->host) || !match(exempt->host, client_p->sockhost)) |
176 |
> |
return 1; |
177 |
> |
break; |
178 |
> |
case HM_IPV4: |
179 |
> |
if (client_p->ip.ss.ss_family == AF_INET) |
180 |
> |
if (match_ipv4(&client_p->ip, &exempt->addr, exempt->bits)) |
181 |
> |
return 1; |
182 |
> |
break; |
183 |
> |
case HM_IPV6: |
184 |
> |
if (client_p->ip.ss.ss_family == AF_INET6) |
185 |
> |
if (match_ipv6(&client_p->ip, &exempt->addr, exempt->bits)) |
186 |
> |
return 1; |
187 |
> |
break; |
188 |
> |
default: |
189 |
> |
assert(0); |
190 |
> |
} |
191 |
> |
} |
192 |
|
} |
193 |
|
|
194 |
< |
return NULL; |
194 |
> |
return 0; |
195 |
|
} |
196 |
|
|
179 |
– |
/* report_resv() |
180 |
– |
* |
181 |
– |
* inputs - pointer to client pointer to report to. |
182 |
– |
* output - NONE |
183 |
– |
* side effects - report all resvs to client. |
184 |
– |
*/ |
197 |
|
void |
198 |
< |
report_resv(struct Client *source_p) |
198 |
> |
resv_clear(void) |
199 |
|
{ |
200 |
< |
dlink_node *ptr; |
189 |
< |
struct ConfItem *conf; |
190 |
< |
struct ResvChannel *resv_cp; |
191 |
< |
struct MatchItem *resv_np; |
192 |
< |
|
193 |
< |
DLINK_FOREACH(ptr, resv_channel_list.head) |
194 |
< |
{ |
195 |
< |
resv_cp = ptr->data; |
196 |
< |
sendto_one(source_p, form_str(RPL_STATSQLINE), |
197 |
< |
me.name, source_p->name, |
198 |
< |
resv_cp->conf ? 'Q' : 'q', |
199 |
< |
resv_cp->name, resv_cp->reason); |
200 |
< |
} |
200 |
> |
dlink_list *tab[] = { &resv_chan_list, &resv_nick_list, NULL }; |
201 |
|
|
202 |
< |
DLINK_FOREACH(ptr, nresv_items.head) |
202 |
> |
for (dlink_list **list = tab; *list; ++list) |
203 |
|
{ |
204 |
< |
conf = ptr->data; |
205 |
< |
resv_np = map_to_conf(conf); |
204 |
> |
dlink_node *node, *node_next; |
205 |
|
|
206 |
< |
sendto_one(source_p, form_str(RPL_STATSQLINE), |
207 |
< |
me.name, source_p->name, |
208 |
< |
resv_np->action ? 'Q' : 'q', |
209 |
< |
conf->name, resv_np->reason); |
206 |
> |
DLINK_FOREACH_SAFE(node, node_next, (*list)->head) |
207 |
> |
{ |
208 |
> |
struct ResvItem *resv = node->data; |
209 |
> |
|
210 |
> |
if (resv->in_database == 0) |
211 |
> |
resv_delete(resv); |
212 |
> |
} |
213 |
|
} |
214 |
|
} |
215 |
|
|
216 |
< |
/* valid_wild_card_simple() |
217 |
< |
* |
216 |
< |
* inputs - data to check for sufficient non-wildcard characters |
217 |
< |
* outputs - 1 if valid, else 0 |
218 |
< |
* side effects - none |
219 |
< |
*/ |
220 |
< |
int |
221 |
< |
valid_wild_card_simple(const char *data) |
216 |
> |
void |
217 |
> |
resv_expire(void) |
218 |
|
{ |
219 |
< |
const unsigned char *p = (const unsigned char *)data; |
224 |
< |
int nonwild = 0; |
219 |
> |
dlink_list *tab[] = { &resv_chan_list, &resv_nick_list, NULL }; |
220 |
|
|
221 |
< |
while (*p != '\0') |
221 |
> |
for (dlink_list **list = tab; *list; ++list) |
222 |
|
{ |
223 |
< |
if ((*p == '\\' && *++p) || (*p && !IsMWildChar(*p))) |
229 |
< |
if (++nonwild == ConfigFileEntry.min_nonwildcard_simple) |
230 |
< |
return 1; |
231 |
< |
if (*p != '\0') |
232 |
< |
++p; |
233 |
< |
} |
223 |
> |
dlink_node *node, *node_next; |
224 |
|
|
225 |
< |
return 0; |
225 |
> |
DLINK_FOREACH_SAFE(node, node_next, (*list)->head) |
226 |
> |
{ |
227 |
> |
struct ResvItem *resv = node->data; |
228 |
> |
|
229 |
> |
if (resv->expire == 0 || resv->expire > CurrentTime) |
230 |
> |
continue; |
231 |
> |
|
232 |
> |
if (ConfigGeneral.tkline_expire_notices) |
233 |
> |
sendto_realops_flags(UMODE_SERVNOTICE, L_ALL, SEND_NOTICE, "Temporary RESV for [%s] expired", |
234 |
> |
resv->mask); |
235 |
> |
resv_delete(resv); |
236 |
> |
} |
237 |
> |
} |
238 |
|
} |