ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/branches/8.2.x/src/conf_resv.c
Revision: 8927
Committed: Mon Apr 22 11:08:47 2019 UTC (4 years, 11 months ago) by michael
Content type: text/x-csrc
File size: 5578 byte(s)
Log Message:
- Killed CurrentTime

File Contents

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

Properties

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