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 |
|
43 |
/* create_resv() |
44 |
* |
45 |
* inputs - name of nick to create resv for |
46 |
* - reason for resv |
47 |
* - 1 if from ircd.conf, 0 if from elsewhere |
48 |
* output - pointer to struct ResvNick |
49 |
* side effects - |
50 |
*/ |
51 |
struct MaskItem * |
52 |
create_resv(const char *name, const char *reason, const dlink_list *list) |
53 |
{ |
54 |
dlink_node *ptr = NULL; |
55 |
struct MaskItem *conf = NULL; |
56 |
enum maskitem_type type; |
57 |
|
58 |
if (name == NULL || reason == NULL) |
59 |
return NULL; |
60 |
|
61 |
if (IsChanPrefix(*name)) |
62 |
type = CONF_CRESV; |
63 |
else |
64 |
type = CONF_NRESV; |
65 |
|
66 |
if (find_exact_name_conf(type, NULL, name, NULL, NULL)) |
67 |
return NULL; |
68 |
|
69 |
conf = conf_make(type); |
70 |
conf->name = xstrdup(name); |
71 |
conf->reason = xstrndup(reason, IRCD_MIN(strlen(reason), REASONLEN)); |
72 |
|
73 |
if (list) |
74 |
{ |
75 |
DLINK_FOREACH(ptr, list->head) |
76 |
{ |
77 |
char nick[NICKLEN + 1]; |
78 |
char user[USERLEN + 1]; |
79 |
char host[HOSTLEN + 1]; |
80 |
struct split_nuh_item nuh; |
81 |
struct exempt *exptr = NULL; |
82 |
char *s = ptr->data; |
83 |
|
84 |
if (strlen(s) == 2 && IsAlpha(*(s + 1) && IsAlpha(*(s + 2)))) |
85 |
{ |
86 |
#ifdef HAVE_LIBGEOIP |
87 |
exptr = MyMalloc(sizeof(*exptr)); |
88 |
exptr->name = xstrdup(s); |
89 |
exptr->coid = GeoIP_id_by_code(s); |
90 |
dlinkAdd(exptr, &exptr->node, &conf->exempt_list); |
91 |
#endif |
92 |
} |
93 |
else |
94 |
{ |
95 |
nuh.nuhmask = s; |
96 |
nuh.nickptr = nick; |
97 |
nuh.userptr = user; |
98 |
nuh.hostptr = host; |
99 |
|
100 |
nuh.nicksize = sizeof(nick); |
101 |
nuh.usersize = sizeof(user); |
102 |
nuh.hostsize = sizeof(host); |
103 |
|
104 |
split_nuh(&nuh); |
105 |
|
106 |
exptr = MyMalloc(sizeof(*exptr)); |
107 |
exptr->name = xstrdup(nick); |
108 |
exptr->user = xstrdup(user); |
109 |
exptr->host = xstrdup(host); |
110 |
exptr->type = parse_netmask(host, &exptr->addr, &exptr->bits); |
111 |
dlinkAdd(exptr, &exptr->node, &conf->exempt_list); |
112 |
} |
113 |
} |
114 |
} |
115 |
|
116 |
return conf; |
117 |
} |
118 |
|
119 |
int |
120 |
resv_find_exempt(const struct Client *who, const struct MaskItem *conf) |
121 |
{ |
122 |
const dlink_node *ptr = NULL; |
123 |
|
124 |
DLINK_FOREACH(ptr, conf->exempt_list.head) |
125 |
{ |
126 |
const struct exempt *exptr = ptr->data; |
127 |
|
128 |
if (exptr->coid) |
129 |
{ |
130 |
if (exptr->coid == who->localClient->country_id) |
131 |
return 1; |
132 |
} |
133 |
else if (!match(exptr->name, who->name) && !match(exptr->user, who->username)) |
134 |
{ |
135 |
switch (exptr->type) |
136 |
{ |
137 |
case HM_HOST: |
138 |
if (!match(exptr->host, who->host) || !match(exptr->host, who->sockhost)) |
139 |
return 1; |
140 |
break; |
141 |
case HM_IPV4: |
142 |
if (who->localClient->aftype == AF_INET) |
143 |
if (match_ipv4(&who->localClient->ip, &exptr->addr, exptr->bits)) |
144 |
return 1; |
145 |
break; |
146 |
#ifdef IPV6 |
147 |
case HM_IPV6: |
148 |
if (who->localClient->aftype == AF_INET6) |
149 |
if (match_ipv6(&who->localClient->ip, &exptr->addr, exptr->bits)) |
150 |
return 1; |
151 |
break; |
152 |
#endif |
153 |
default: |
154 |
assert(0); |
155 |
} |
156 |
} |
157 |
} |
158 |
|
159 |
return 0; |
160 |
} |
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 |
struct MaskItem * |
170 |
match_find_resv(const char *name) |
171 |
{ |
172 |
dlink_node *ptr = NULL; |
173 |
|
174 |
if (EmptyString(name)) |
175 |
return NULL; |
176 |
|
177 |
DLINK_FOREACH(ptr, cresv_items.head) |
178 |
{ |
179 |
struct MaskItem *conf = ptr->data; |
180 |
|
181 |
if (!match(conf->name, name)) |
182 |
return conf; |
183 |
} |
184 |
|
185 |
return NULL; |
186 |
} |