ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/src/conf_resv.c
Revision: 5347
Committed: Sun Jan 11 12:42:20 2015 UTC (10 years, 7 months ago) by michael
Content type: text/x-csrc
Original Path: ircd-hybrid/trunk/src/resv.c
File size: 4703 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 5347 * Copyright (c) 2001-2015 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 2916 /*! \file resv.c
23     * \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 "ircd.h"
30     #include "send.h"
31 michael 2916 #include "client.h"
32 adx 30 #include "memory.h"
33     #include "numeric.h"
34     #include "resv.h"
35     #include "hash.h"
36     #include "irc_string.h"
37     #include "ircd_defs.h"
38 michael 3347 #include "misc.h"
39 michael 1309 #include "conf.h"
40 michael 1622 #include "conf_db.h"
41 michael 1858 #include "channel.h"
42     #include "hostmask.h"
43 adx 30
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 4815 dlink_node *node = 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 4815 DLINK_FOREACH(node, 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 michael 4815 char *s = node->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 3504 exptr = MyCalloc(sizeof(*exptr));
90 michael 1860 exptr->name = xstrdup(s);
91 michael 4822 exptr->country_id = GeoIP_id_by_code(s);
92 michael 1860 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 michael 3504 exptr = MyCalloc(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 4815 const dlink_node *node = NULL;
125 adx 30
126 michael 4815 DLINK_FOREACH(node, conf->exempt_list.head)
127 michael 1858 {
128 michael 4815 const struct exempt *exptr = node->data;
129 adx 30
130 michael 4822 if (exptr->country_id)
131 michael 1858 {
132 michael 4822 if (exptr->country_id == who->connection->country_id)
133 michael 1858 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 michael 4588 if (who->connection->aftype == AF_INET)
145     if (match_ipv4(&who->connection->ip, &exptr->addr, exptr->bits))
146 michael 1858 return 1;
147     break;
148     case HM_IPV6:
149 michael 4588 if (who->connection->aftype == AF_INET6)
150     if (match_ipv6(&who->connection->ip, &exptr->addr, exptr->bits))
151 michael 1858 return 1;
152     break;
153     default:
154     assert(0);
155     }
156     }
157     }
158 adx 30
159 michael 1858 return 0;
160 adx 30 }
161    
162     /* match_find_resv()
163     *
164     * inputs - pointer to name
165     * output - pointer to a struct ResvChannel
166     * side effects - Finds a reserved channel whose name matches 'name',
167     * if can't find one returns NULL.
168     */
169 michael 1632 struct MaskItem *
170 adx 30 match_find_resv(const char *name)
171     {
172 michael 4815 dlink_node *node = NULL;
173 adx 30
174     if (EmptyString(name))
175     return NULL;
176    
177 michael 4815 DLINK_FOREACH(node, cresv_items.head)
178 adx 30 {
179 michael 4815 struct MaskItem *conf = node->data;
180 adx 30
181 michael 1825 if (!match(conf->name, name))
182 michael 1632 return conf;
183 adx 30 }
184    
185     return NULL;
186     }

Properties

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