ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/src/conf_resv.c
Revision: 1919
Committed: Tue Apr 30 13:59:53 2013 UTC (12 years, 3 months ago) by michael
Content type: text/x-csrc
Original Path: ircd-hybrid/trunk/src/resv.c
File size: 6060 byte(s)
Log Message:
- Made valid_wild_card_simple() easier to read

File Contents

# User Rev Content
1 adx 30 /*
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 knight 31 * $Id$
23 adx 30 */
24    
25     #include "stdinc.h"
26 michael 1011 #include "list.h"
27 adx 30 #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 michael 1646 #include "s_misc.h"
37 michael 1309 #include "conf.h"
38 michael 1622 #include "conf_db.h"
39 michael 1858 #include "channel.h"
40     #include "hostmask.h"
41 adx 30
42     dlink_list resv_channel_list = { NULL, NULL, 0 };
43    
44    
45 michael 1858 /* create_resv()
46 adx 30 *
47 michael 1858 * inputs - name of nick to create resv for
48 adx 30 * - reason for resv
49 michael 1858 * - 1 if from ircd.conf, 0 if from elsewhere
50     * output - pointer to struct ResvNick
51 adx 30 * side effects -
52     */
53 michael 1632 struct MaskItem *
54 michael 1858 create_resv(const char *name, const char *reason, const dlink_list *list)
55 adx 30 {
56 michael 1860 dlink_node *ptr = NULL;
57 michael 1632 struct MaskItem *conf = NULL;
58 michael 1858 enum maskitem_type type;
59 adx 30
60     if (name == NULL || reason == NULL)
61     return NULL;
62    
63 michael 1858 if (IsChanPrefix(*name))
64     type = CONF_CRESV;
65     else
66     type = CONF_NRESV;
67    
68     if (find_exact_name_conf(type, NULL, name, NULL, NULL))
69 adx 30 return NULL;
70    
71 michael 1858 conf = conf_make(type);
72 michael 1646 conf->name = xstrdup(name);
73     conf->reason = xstrndup(reason, IRCD_MIN(strlen(reason), REASONLEN));
74 adx 30
75 michael 1858 if (list)
76     {
77 michael 1860 DLINK_FOREACH(ptr, list->head)
78 michael 1858 {
79 michael 1860 char nick[NICKLEN + 1];
80     char user[USERLEN + 1];
81     char host[HOSTLEN + 1];
82     struct split_nuh_item nuh;
83     struct exempt *exptr = NULL;
84     char *s = ptr->data;
85 michael 1858
86 michael 1860 if (strlen(s) == 2 && IsAlpha(*(s + 1) && IsAlpha(*(s + 2))))
87 michael 1858 {
88 michael 1872 #ifdef HAVE_LIBGEOIP
89 michael 1860 exptr = MyMalloc(sizeof(*exptr));
90     exptr->name = xstrdup(s);
91     exptr->coid = GeoIP_id_by_code(s);
92     dlinkAdd(exptr, &exptr->node, &conf->exempt_list);
93 michael 1872 #endif
94 michael 1860 }
95     else
96     {
97     nuh.nuhmask = s;
98 michael 1858 nuh.nickptr = nick;
99     nuh.userptr = user;
100     nuh.hostptr = host;
101    
102 michael 1859 nuh.nicksize = sizeof(nick);
103 michael 1858 nuh.usersize = sizeof(user);
104     nuh.hostsize = sizeof(host);
105    
106     split_nuh(&nuh);
107    
108     exptr = MyMalloc(sizeof(*exptr));
109 michael 1860 exptr->name = xstrdup(nick);
110 michael 1858 exptr->user = xstrdup(user);
111     exptr->host = xstrdup(host);
112     exptr->type = parse_netmask(host, &exptr->addr, &exptr->bits);
113     dlinkAdd(exptr, &exptr->node, &conf->exempt_list);
114     }
115     }
116     }
117    
118 adx 30 return conf;
119     }
120    
121 michael 1858 int
122     resv_find_exempt(const struct Client *who, const struct MaskItem *conf)
123 adx 30 {
124 michael 1858 const dlink_node *ptr = NULL;
125 adx 30
126 michael 1858 DLINK_FOREACH(ptr, conf->exempt_list.head)
127     {
128     const struct exempt *exptr = ptr->data;
129 adx 30
130 michael 1858 if (exptr->coid)
131     {
132     if (exptr->coid == who->localClient->country_id)
133     return 1;
134     }
135     else if (!match(exptr->name, who->name) && !match(exptr->user, who->username))
136     {
137     switch (exptr->type)
138     {
139     case HM_HOST:
140     if (!match(exptr->host, who->host) || !match(exptr->host, who->sockhost))
141     return 1;
142     break;
143     case HM_IPV4:
144     if (who->localClient->aftype == AF_INET)
145     if (match_ipv4(&who->localClient->ip, &exptr->addr, exptr->bits))
146     return 1;
147     break;
148     #ifdef IPV6
149     case HM_IPV6:
150     if (who->localClient->aftype == AF_INET6)
151     if (match_ipv6(&who->localClient->ip, &exptr->addr, exptr->bits))
152     return 1;
153     break;
154     #endif
155     default:
156     assert(0);
157     }
158     }
159     }
160 adx 30
161 michael 1858 return 0;
162 adx 30 }
163    
164     /* match_find_resv()
165     *
166     * inputs - pointer to name
167     * output - pointer to a struct ResvChannel
168     * side effects - Finds a reserved channel whose name matches 'name',
169     * if can't find one returns NULL.
170     */
171 michael 1632 struct MaskItem *
172 adx 30 match_find_resv(const char *name)
173     {
174     dlink_node *ptr = NULL;
175    
176     if (EmptyString(name))
177     return NULL;
178    
179     DLINK_FOREACH(ptr, resv_channel_list.head)
180     {
181 michael 1632 struct MaskItem *conf = ptr->data;
182 adx 30
183 michael 1825 if (!match(conf->name, name))
184 michael 1632 return conf;
185 adx 30 }
186    
187     return NULL;
188     }
189    
190     /* report_resv()
191     *
192     * inputs - pointer to client pointer to report to.
193     * output - NONE
194     * side effects - report all resvs to client.
195     */
196     void
197     report_resv(struct Client *source_p)
198     {
199 michael 1632 dlink_node *ptr = NULL;
200     struct MaskItem *conf = NULL;
201 adx 30
202     DLINK_FOREACH(ptr, resv_channel_list.head)
203     {
204 michael 1632 conf = ptr->data;
205 michael 1834 sendto_one(source_p, form_str(RPL_STATSQLINE),
206 adx 30 me.name, source_p->name,
207 michael 1687 conf->until ? 'q' : 'Q', conf->count,
208 michael 1632 conf->name, conf->reason);
209 adx 30 }
210    
211     DLINK_FOREACH(ptr, nresv_items.head)
212     {
213 michael 1649 conf = ptr->data;
214 michael 1834 sendto_one(source_p, form_str(RPL_STATSQLINE),
215 adx 30 me.name, source_p->name,
216 michael 1687 conf->until ? 'q' : 'Q', conf->count,
217 michael 1632 conf->name, conf->reason);
218 adx 30 }
219     }
220    
221     /* valid_wild_card_simple()
222     *
223     * inputs - data to check for sufficient non-wildcard characters
224     * outputs - 1 if valid, else 0
225     * side effects - none
226     */
227     int
228     valid_wild_card_simple(const char *data)
229     {
230     const unsigned char *p = (const unsigned char *)data;
231 michael 1919 unsigned char tmpch = '\0';
232 adx 30 int nonwild = 0;
233    
234 michael 1919 while ((tmpch = *p++))
235 adx 30 {
236 michael 1919 if (tmpch == '\\')
237     {
238     ++p;
239     if (++nonwild >= ConfigFileEntry.min_nonwildcard_simple)
240 adx 30 return 1;
241 michael 1919 }
242     else if (!IsMWildChar(tmpch))
243     {
244     if (++nonwild >= ConfigFileEntry.min_nonwildcard_simple)
245     return 1;
246     }
247 adx 30 }
248    
249     return 0;
250     }

Properties

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