/[svn]/ircd-hybrid/branches/8.2.x/src/resv.c
ViewVC logotype

Contents of /ircd-hybrid/branches/8.2.x/src/resv.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 6364 - (show annotations)
Wed Aug 19 09:59:43 2015 UTC (4 years, 10 months ago) by michael
File MIME type: text/x-chdr
File size: 4604 byte(s)
- Remove unused header includes

1 /*
2 * ircd-hybrid: an advanced, lightweight Internet Relay Chat Daemon (ircd)
3 *
4 * Copyright (c) 2001-2015 ircd-hybrid development team
5 *
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 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
19 * USA
20 */
21
22 /*! \file resv.c
23 * \brief Functions to reserve(jupe) a nick/channel.
24 * \version $Id$
25 */
26
27 #include "stdinc.h"
28 #include "list.h"
29 #include "send.h"
30 #include "client.h"
31 #include "memory.h"
32 #include "resv.h"
33 #include "irc_string.h"
34 #include "ircd_defs.h"
35 #include "misc.h"
36 #include "conf.h"
37 #include "hostmask.h"
38
39
40 /* create_resv()
41 *
42 * inputs - name of nick to create resv for
43 * - reason for resv
44 * - 1 if from ircd.conf, 0 if from elsewhere
45 * output - pointer to struct ResvNick
46 * side effects -
47 */
48 struct MaskItem *
49 create_resv(const char *name, const char *reason, const dlink_list *list)
50 {
51 dlink_node *node = NULL;
52 struct MaskItem *conf = NULL;
53 enum maskitem_type type;
54
55 if (name == NULL || reason == NULL)
56 return NULL;
57
58 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 return NULL;
65
66 conf = conf_make(type);
67 conf->name = xstrdup(name);
68 conf->reason = xstrndup(reason, IRCD_MIN(strlen(reason), REASONLEN));
69
70 if (list)
71 {
72 DLINK_FOREACH(node, list->head)
73 {
74 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 char *s = node->data;
80
81 if (strlen(s) == 2 && IsAlpha(*(s + 1) && IsAlpha(*(s + 2))))
82 {
83 #ifdef HAVE_LIBGEOIP
84 exptr = MyCalloc(sizeof(*exptr));
85 exptr->name = xstrdup(s);
86 exptr->country_id = GeoIP_id_by_code(s);
87 dlinkAdd(exptr, &exptr->node, &conf->exempt_list);
88 #endif
89 }
90 else
91 {
92 nuh.nuhmask = s;
93 nuh.nickptr = nick;
94 nuh.userptr = user;
95 nuh.hostptr = host;
96
97 nuh.nicksize = sizeof(nick);
98 nuh.usersize = sizeof(user);
99 nuh.hostsize = sizeof(host);
100
101 split_nuh(&nuh);
102
103 exptr = MyCalloc(sizeof(*exptr));
104 exptr->name = xstrdup(nick);
105 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 return conf;
114 }
115
116 int
117 resv_find_exempt(const struct Client *who, const struct MaskItem *conf)
118 {
119 const dlink_node *node = NULL;
120
121 DLINK_FOREACH(node, conf->exempt_list.head)
122 {
123 const struct exempt *exptr = node->data;
124
125 if (exptr->country_id)
126 {
127 if (exptr->country_id == who->connection->country_id)
128 return 1;
129 }
130 else if (!match(exptr->name, who->name) && !match(exptr->user, who->username))
131 {
132 switch (exptr->type)
133 {
134 case HM_HOST:
135 if (!match(exptr->host, who->host) || !match(exptr->host, who->sockhost))
136 return 1;
137 break;
138 case HM_IPV4:
139 if (who->connection->aftype == AF_INET)
140 if (match_ipv4(&who->connection->ip, &exptr->addr, exptr->bits))
141 return 1;
142 break;
143 case HM_IPV6:
144 if (who->connection->aftype == AF_INET6)
145 if (match_ipv6(&who->connection->ip, &exptr->addr, exptr->bits))
146 return 1;
147 break;
148 default:
149 assert(0);
150 }
151 }
152 }
153
154 return 0;
155 }
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 struct MaskItem *
165 match_find_resv(const char *name)
166 {
167 dlink_node *node = NULL;
168
169 if (EmptyString(name))
170 return NULL;
171
172 DLINK_FOREACH(node, cresv_items.head)
173 {
174 struct MaskItem *conf = node->data;
175
176 if (!match(conf->name, name))
177 return conf;
178 }
179
180 return NULL;
181 }

Properties

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

svnadmin@ircd-hybrid.org
ViewVC Help
Powered by ViewVC 1.1.28