ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/src/conf_resv.c
Revision: 7234
Committed: Wed Feb 3 16:30:10 2016 UTC (9 years, 6 months ago) by michael
Content type: text/x-csrc
File size: 4662 byte(s)
Log Message:
- Move resv.* to conf_resv.*

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 7006 * Copyright (c) 2001-2016 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     #include "irc_string.h"
33     #include "ircd_defs.h"
34 michael 3347 #include "misc.h"
35 michael 1309 #include "conf.h"
36 michael 7234 #include "conf_resv.h"
37 michael 1858 #include "hostmask.h"
38 adx 30
39    
40 michael 1858 /* create_resv()
41 adx 30 *
42 michael 1858 * inputs - name of nick to create resv for
43 adx 30 * - reason for resv
44 michael 1858 * - 1 if from ircd.conf, 0 if from elsewhere
45     * output - pointer to struct ResvNick
46 adx 30 * side effects -
47     */
48 michael 1632 struct MaskItem *
49 michael 1858 create_resv(const char *name, const char *reason, const dlink_list *list)
50 adx 30 {
51 michael 4815 dlink_node *node = NULL;
52 michael 1632 struct MaskItem *conf = NULL;
53 michael 1858 enum maskitem_type type;
54 adx 30
55     if (name == NULL || reason == NULL)
56     return NULL;
57    
58 michael 1858 if (IsChanPrefix(*name))
59     type = CONF_CRESV;
60     else
61     type = CONF_NRESV;
62    
63     if (find_exact_name_conf(type, NULL, name, NULL, NULL))
64 adx 30 return NULL;
65    
66 michael 1858 conf = conf_make(type);
67 michael 1646 conf->name = xstrdup(name);
68     conf->reason = xstrndup(reason, IRCD_MIN(strlen(reason), REASONLEN));
69 adx 30
70 michael 1858 if (list)
71     {
72 michael 4815 DLINK_FOREACH(node, list->head)
73 michael 1858 {
74 michael 1860 char nick[NICKLEN + 1];
75     char user[USERLEN + 1];
76     char host[HOSTLEN + 1];
77     struct split_nuh_item nuh;
78     struct exempt *exptr = NULL;
79 michael 4815 char *s = node->data;
80 michael 1858
81 michael 1860 if (strlen(s) == 2 && IsAlpha(*(s + 1) && IsAlpha(*(s + 2))))
82 michael 1858 {
83 michael 1872 #ifdef HAVE_LIBGEOIP
84 michael 7032 exptr = xcalloc(sizeof(*exptr));
85 michael 1860 exptr->name = xstrdup(s);
86 michael 4822 exptr->country_id = GeoIP_id_by_code(s);
87 michael 1860 dlinkAdd(exptr, &exptr->node, &conf->exempt_list);
88 michael 1872 #endif
89 michael 1860 }
90     else
91     {
92     nuh.nuhmask = s;
93 michael 1858 nuh.nickptr = nick;
94     nuh.userptr = user;
95     nuh.hostptr = host;
96    
97 michael 1859 nuh.nicksize = sizeof(nick);
98 michael 1858 nuh.usersize = sizeof(user);
99     nuh.hostsize = sizeof(host);
100    
101     split_nuh(&nuh);
102    
103 michael 7032 exptr = xcalloc(sizeof(*exptr));
104 michael 1860 exptr->name = xstrdup(nick);
105 michael 1858 exptr->user = xstrdup(user);
106     exptr->host = xstrdup(host);
107     exptr->type = parse_netmask(host, &exptr->addr, &exptr->bits);
108     dlinkAdd(exptr, &exptr->node, &conf->exempt_list);
109     }
110     }
111     }
112    
113 adx 30 return conf;
114     }
115    
116 michael 1858 int
117 michael 6690 resv_find_exempt(const struct Client *client_p, const struct MaskItem *conf)
118 adx 30 {
119 michael 4815 const dlink_node *node = NULL;
120 adx 30
121 michael 4815 DLINK_FOREACH(node, conf->exempt_list.head)
122 michael 1858 {
123 michael 4815 const struct exempt *exptr = node->data;
124 adx 30
125 michael 4822 if (exptr->country_id)
126 michael 1858 {
127 michael 6690 if (exptr->country_id == client_p->connection->country_id)
128 michael 1858 return 1;
129     }
130 michael 6690 else if (!match(exptr->name, client_p->name) && !match(exptr->user, client_p->username))
131 michael 1858 {
132     switch (exptr->type)
133     {
134     case HM_HOST:
135 michael 6690 if (!match(exptr->host, client_p->host) || !match(exptr->host, client_p->sockhost))
136 michael 1858 return 1;
137     break;
138     case HM_IPV4:
139 michael 6690 if (client_p->connection->aftype == AF_INET)
140     if (match_ipv4(&client_p->connection->ip, &exptr->addr, exptr->bits))
141 michael 1858 return 1;
142     break;
143     case HM_IPV6:
144 michael 6690 if (client_p->connection->aftype == AF_INET6)
145     if (match_ipv6(&client_p->connection->ip, &exptr->addr, exptr->bits))
146 michael 1858 return 1;
147     break;
148     default:
149     assert(0);
150     }
151     }
152     }
153 adx 30
154 michael 1858 return 0;
155 adx 30 }
156    
157     /* match_find_resv()
158     *
159     * inputs - pointer to name
160     * output - pointer to a struct ResvChannel
161     * side effects - Finds a reserved channel whose name matches 'name',
162     * if can't find one returns NULL.
163     */
164 michael 1632 struct MaskItem *
165 adx 30 match_find_resv(const char *name)
166     {
167 michael 4815 dlink_node *node = NULL;
168 adx 30
169     if (EmptyString(name))
170     return NULL;
171    
172 michael 4815 DLINK_FOREACH(node, cresv_items.head)
173 adx 30 {
174 michael 4815 struct MaskItem *conf = node->data;
175 adx 30
176 michael 1825 if (!match(conf->name, name))
177 michael 1632 return conf;
178 adx 30 }
179    
180     return NULL;
181     }

Properties

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