ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/branches/8.2.x/src/resv.c
Revision: 1859
Committed: Thu Apr 25 15:09:36 2013 UTC (10 years, 11 months ago) by michael
Content type: text/x-csrc
Original Path: ircd-hybrid/trunk/src/resv.c
File size: 5922 byte(s)
Log Message:
- Minor fixes to new resv exempt code

File Contents

# Content
1 /*
2 * ircd-hybrid: an advanced Internet Relay Chat Daemon(ircd).
3 * resv.c: Functions to reserve(jupe) a nick/channel.
4 *
5 * Copyright (C) 2001-2002 Hybrid Development Team
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
20 * USA
21 *
22 * $Id$
23 */
24
25 #include "stdinc.h"
26 #include "list.h"
27 #include "ircd.h"
28 #include "send.h"
29 #include "client.h"
30 #include "memory.h"
31 #include "numeric.h"
32 #include "resv.h"
33 #include "hash.h"
34 #include "irc_string.h"
35 #include "ircd_defs.h"
36 #include "s_misc.h"
37 #include "conf.h"
38 #include "conf_db.h"
39 #include "channel.h"
40 #include "hostmask.h"
41
42 dlink_list resv_channel_list = { NULL, NULL, 0 };
43
44
45 /* create_resv()
46 *
47 * inputs - name of nick to create resv for
48 * - reason for resv
49 * - 1 if from ircd.conf, 0 if from elsewhere
50 * output - pointer to struct ResvNick
51 * side effects -
52 */
53 struct MaskItem *
54 create_resv(const char *name, const char *reason, const dlink_list *list)
55 {
56 struct MaskItem *conf = NULL;
57 enum maskitem_type type;
58
59 if (name == NULL || reason == NULL)
60 return NULL;
61
62 if (IsChanPrefix(*name))
63 type = CONF_CRESV;
64 else
65 type = CONF_NRESV;
66
67 if (find_exact_name_conf(type, NULL, name, NULL, NULL))
68 return NULL;
69
70 conf = conf_make(type);
71 conf->name = xstrdup(name);
72 conf->reason = xstrndup(reason, IRCD_MIN(strlen(reason), REASONLEN));
73
74 if (list)
75 {
76 if (strlen(name) == 2 && IsAlpha(*(name + 1) && IsAlpha(*(name + 2))))
77 {
78 struct exempt *exptr = MyMalloc(sizeof(*exptr));
79
80 exptr->name = xstrdup(name);
81 exptr->coid = GeoIP_id_by_code(name);
82 dlinkAdd(exptr, &exptr->node, &conf->exempt_list);
83 }
84 else
85 {
86 dlink_node *ptr = NULL;
87
88 DLINK_FOREACH(ptr, list->head)
89 {
90 char nick[NICKLEN + 1];
91 char user[USERLEN + 1];
92 char host[HOSTLEN + 1];
93 struct split_nuh_item nuh;
94 struct exempt *exptr = NULL;
95
96 nuh.nuhmask = name;
97 nuh.nickptr = nick;
98 nuh.userptr = user;
99 nuh.hostptr = host;
100
101 nuh.nicksize = sizeof(nick);
102 nuh.usersize = sizeof(user);
103 nuh.hostsize = sizeof(host);
104
105 split_nuh(&nuh);
106
107 exptr = MyMalloc(sizeof(*exptr));
108 exptr->name = xstrdup(name);
109 exptr->user = xstrdup(user);
110 exptr->host = xstrdup(host);
111 exptr->type = parse_netmask(host, &exptr->addr, &exptr->bits);
112 dlinkAdd(exptr, &exptr->node, &conf->exempt_list);
113 }
114 }
115 }
116
117 return conf;
118 }
119
120 int
121 resv_find_exempt(const struct Client *who, const struct MaskItem *conf)
122 {
123 const dlink_node *ptr = NULL;
124
125 DLINK_FOREACH(ptr, conf->exempt_list.head)
126 {
127 const struct exempt *exptr = ptr->data;
128
129 if (exptr->coid)
130 {
131 if (exptr->coid == who->localClient->country_id)
132 return 1;
133 }
134 else if (!match(exptr->name, who->name) && !match(exptr->user, who->username))
135 {
136 switch (exptr->type)
137 {
138 case HM_HOST:
139 if (!match(exptr->host, who->host) || !match(exptr->host, who->sockhost))
140 return 1;
141 break;
142 case HM_IPV4:
143 if (who->localClient->aftype == AF_INET)
144 if (match_ipv4(&who->localClient->ip, &exptr->addr, exptr->bits))
145 return 1;
146 break;
147 #ifdef IPV6
148 case HM_IPV6:
149 if (who->localClient->aftype == AF_INET6)
150 if (match_ipv6(&who->localClient->ip, &exptr->addr, exptr->bits))
151 return 1;
152 break;
153 #endif
154 default:
155 assert(0);
156 }
157 }
158 }
159
160 return 0;
161 }
162
163 /* match_find_resv()
164 *
165 * inputs - pointer to name
166 * output - pointer to a struct ResvChannel
167 * side effects - Finds a reserved channel whose name matches 'name',
168 * if can't find one returns NULL.
169 */
170 struct MaskItem *
171 match_find_resv(const char *name)
172 {
173 dlink_node *ptr = NULL;
174
175 if (EmptyString(name))
176 return NULL;
177
178 DLINK_FOREACH(ptr, resv_channel_list.head)
179 {
180 struct MaskItem *conf = ptr->data;
181
182 if (!match(conf->name, name))
183 return conf;
184 }
185
186 return NULL;
187 }
188
189 /* report_resv()
190 *
191 * inputs - pointer to client pointer to report to.
192 * output - NONE
193 * side effects - report all resvs to client.
194 */
195 void
196 report_resv(struct Client *source_p)
197 {
198 dlink_node *ptr = NULL;
199 struct MaskItem *conf = NULL;
200
201 DLINK_FOREACH(ptr, resv_channel_list.head)
202 {
203 conf = ptr->data;
204 sendto_one(source_p, form_str(RPL_STATSQLINE),
205 me.name, source_p->name,
206 conf->until ? 'q' : 'Q', conf->count,
207 conf->name, conf->reason);
208 }
209
210 DLINK_FOREACH(ptr, nresv_items.head)
211 {
212 conf = ptr->data;
213 sendto_one(source_p, form_str(RPL_STATSQLINE),
214 me.name, source_p->name,
215 conf->until ? 'q' : 'Q', conf->count,
216 conf->name, conf->reason);
217 }
218 }
219
220 /* valid_wild_card_simple()
221 *
222 * inputs - data to check for sufficient non-wildcard characters
223 * outputs - 1 if valid, else 0
224 * side effects - none
225 */
226 int
227 valid_wild_card_simple(const char *data)
228 {
229 const unsigned char *p = (const unsigned char *)data;
230 int nonwild = 0;
231
232 while (*p != '\0')
233 {
234 if ((*p == '\\' && *++p) || (*p && !IsMWildChar(*p)))
235 if (++nonwild == ConfigFileEntry.min_nonwildcard_simple)
236 return 1;
237 if (*p != '\0')
238 ++p;
239 }
240
241 return 0;
242 }

Properties

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