ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/src/conf_resv.c
Revision: 8752
Committed: Tue Jan 1 11:07:01 2019 UTC (6 years, 7 months ago) by michael
Content type: text/x-csrc
File size: 5564 byte(s)
Log Message:
- Update copyright years

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 8752 * Copyright (c) 2001-2019 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 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 michael 7286 dlinkAdd(resv, &resv->node, resv->list);
100 adx 30
101 michael 7282 if (elist)
102 michael 1858 {
103 michael 7282 dlink_node *node;
104    
105     DLINK_FOREACH(node, elist->head)
106 michael 1858 {
107 michael 1860 char nick[NICKLEN + 1];
108     char user[USERLEN + 1];
109     char host[HOSTLEN + 1];
110     struct split_nuh_item nuh;
111 michael 4815 char *s = node->data;
112 michael 1858
113 michael 8314 nuh.nuhmask = s;
114     nuh.nickptr = nick;
115     nuh.userptr = user;
116     nuh.hostptr = host;
117 michael 1858
118 michael 8314 nuh.nicksize = sizeof(nick);
119     nuh.usersize = sizeof(user);
120     nuh.hostsize = sizeof(host);
121 michael 1858
122 michael 8314 split_nuh(&nuh);
123 michael 1858
124 michael 8314 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 michael 1858 }
131     }
132    
133 michael 7282 return resv;
134 adx 30 }
135    
136 michael 7282 struct ResvItem *
137     resv_find(const char *name, int (*compare)(const char *, const char *))
138     {
139 michael 7939 dlink_node *node;
140     dlink_list *list;
141 michael 7282
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 michael 8672 if (compare(resv->mask, name) == 0)
152 michael 7282 return resv;
153     }
154    
155     return NULL;
156     }
157    
158 michael 8658 bool
159 michael 7282 resv_exempt_find(const struct Client *client_p, const struct ResvItem *resv)
160 adx 30 {
161 michael 7687 dlink_node *node;
162 adx 30
163 michael 7282 DLINK_FOREACH(node, resv->exempt_list.head)
164 michael 1858 {
165 michael 7282 const struct ResvExemptItem *exempt = node->data;
166 adx 30
167 michael 8672 if (match(exempt->name, client_p->name) == 0 && match(exempt->user, client_p->username) == 0)
168 michael 1858 {
169 michael 7282 switch (exempt->type)
170 michael 1858 {
171     case HM_HOST:
172 michael 8672 if (match(exempt->host, client_p->host) == 0 || match(exempt->host, client_p->sockhost) == 0)
173 michael 8658 return true;
174 michael 1858 break;
175     case HM_IPV4:
176 michael 8500 if (client_p->ip.ss.ss_family == AF_INET)
177 michael 8496 if (match_ipv4(&client_p->ip, &exempt->addr, exempt->bits))
178 michael 8658 return true;
179 michael 1858 break;
180     case HM_IPV6:
181 michael 8500 if (client_p->ip.ss.ss_family == AF_INET6)
182 michael 8496 if (match_ipv6(&client_p->ip, &exempt->addr, exempt->bits))
183 michael 8658 return true;
184 michael 1858 break;
185     default:
186     assert(0);
187     }
188     }
189     }
190 adx 30
191 michael 8658 return false;
192 adx 30 }
193    
194 michael 7282 void
195     resv_clear(void)
196 adx 30 {
197 michael 7282 dlink_list *tab[] = { &resv_chan_list, &resv_nick_list, NULL };
198 adx 30
199 michael 7282 for (dlink_list **list = tab; *list; ++list)
200     {
201 michael 8059 dlink_node *node, *node_next;
202 adx 30
203 michael 7282 DLINK_FOREACH_SAFE(node, node_next, (*list)->head)
204     {
205     struct ResvItem *resv = node->data;
206    
207 michael 8656 if (resv->in_database == false)
208 michael 7282 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 adx 30 {
220 michael 8059 dlink_node *node, *node_next;
221 adx 30
222 michael 7282 DLINK_FOREACH_SAFE(node, node_next, (*list)->head)
223     {
224     struct ResvItem *resv = node->data;
225    
226 michael 8473 if (resv->expire == 0 || resv->expire > CurrentTime)
227 michael 7282 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 adx 30 }
235     }

Properties

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