1 |
adx |
30 |
/* |
2 |
michael |
2916 |
* ircd-hybrid: an advanced, lightweight Internet Relay Chat Daemon (ircd) |
3 |
adx |
30 |
* |
4 |
michael |
8279 |
* Copyright (c) 1997-2018 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 conf.c |
23 |
|
|
* \brief Configuration file functions. |
24 |
|
|
* \version $Id$ |
25 |
|
|
*/ |
26 |
|
|
|
27 |
adx |
30 |
#include "stdinc.h" |
28 |
michael |
1011 |
#include "list.h" |
29 |
adx |
30 |
#include "ircd_defs.h" |
30 |
michael |
1309 |
#include "conf.h" |
31 |
michael |
7217 |
#include "conf_cluster.h" |
32 |
michael |
7304 |
#include "conf_gecos.h" |
33 |
michael |
4545 |
#include "conf_pseudo.h" |
34 |
michael |
7234 |
#include "conf_resv.h" |
35 |
michael |
7248 |
#include "conf_service.h" |
36 |
michael |
7209 |
#include "conf_shared.h" |
37 |
michael |
3347 |
#include "server.h" |
38 |
adx |
30 |
#include "channel.h" |
39 |
|
|
#include "client.h" |
40 |
|
|
#include "event.h" |
41 |
|
|
#include "irc_string.h" |
42 |
|
|
#include "s_bsd.h" |
43 |
|
|
#include "ircd.h" |
44 |
|
|
#include "listener.h" |
45 |
|
|
#include "hostmask.h" |
46 |
|
|
#include "modules.h" |
47 |
|
|
#include "numeric.h" |
48 |
|
|
#include "fdlist.h" |
49 |
michael |
1309 |
#include "log.h" |
50 |
adx |
30 |
#include "send.h" |
51 |
|
|
#include "memory.h" |
52 |
michael |
3322 |
#include "res.h" |
53 |
adx |
30 |
#include "userhost.h" |
54 |
michael |
3347 |
#include "user.h" |
55 |
adx |
30 |
#include "channel_mode.h" |
56 |
michael |
1243 |
#include "parse.h" |
57 |
michael |
3347 |
#include "misc.h" |
58 |
michael |
1622 |
#include "conf_db.h" |
59 |
michael |
1632 |
#include "conf_class.h" |
60 |
michael |
2150 |
#include "motd.h" |
61 |
michael |
4325 |
#include "ipcache.h" |
62 |
michael |
6185 |
#include "isupport.h" |
63 |
michael |
7437 |
#include "whowas.h" |
64 |
adx |
30 |
|
65 |
michael |
2872 |
|
66 |
michael |
5602 |
struct config_channel_entry ConfigChannel; |
67 |
michael |
5644 |
struct config_serverhide_entry ConfigServerHide; |
68 |
michael |
5602 |
struct config_general_entry ConfigGeneral; |
69 |
michael |
5644 |
struct config_log_entry ConfigLog = { .use_logging = 1 }; |
70 |
|
|
struct config_serverinfo_entry ConfigServerInfo; |
71 |
|
|
struct config_admin_entry ConfigAdminInfo; |
72 |
michael |
5602 |
struct conf_parser_context conf_parser_ctx; |
73 |
|
|
|
74 |
adx |
30 |
/* general conf items link list root, other than k lines etc. */ |
75 |
michael |
7401 |
dlink_list connect_items; |
76 |
michael |
6628 |
dlink_list operator_items; |
77 |
adx |
30 |
|
78 |
|
|
extern unsigned int lineno; |
79 |
|
|
extern char linebuf[]; |
80 |
|
|
extern char conffilebuf[IRCD_BUFSIZE]; |
81 |
|
|
extern int yyparse(); /* defined in y.tab.c */ |
82 |
|
|
|
83 |
|
|
|
84 |
|
|
/* conf_dns_callback() |
85 |
|
|
* |
86 |
michael |
1632 |
* inputs - pointer to struct MaskItem |
87 |
adx |
30 |
* - pointer to DNSReply reply |
88 |
|
|
* output - none |
89 |
|
|
* side effects - called when resolver query finishes |
90 |
|
|
* if the query resulted in a successful search, hp will contain |
91 |
|
|
* a non-null pointer, otherwise hp will be null. |
92 |
|
|
* if successful save hp in the conf item it was called with |
93 |
|
|
*/ |
94 |
|
|
static void |
95 |
michael |
4408 |
conf_dns_callback(void *vptr, const struct irc_ssaddr *addr, const char *name, size_t namelength) |
96 |
adx |
30 |
{ |
97 |
michael |
4874 |
struct MaskItem *const conf = vptr; |
98 |
adx |
30 |
|
99 |
michael |
1632 |
conf->dns_pending = 0; |
100 |
adx |
30 |
|
101 |
michael |
3235 |
if (addr) |
102 |
michael |
1632 |
memcpy(&conf->addr, addr, sizeof(conf->addr)); |
103 |
michael |
992 |
else |
104 |
michael |
1632 |
conf->dns_failed = 1; |
105 |
adx |
30 |
} |
106 |
|
|
|
107 |
|
|
/* conf_dns_lookup() |
108 |
|
|
* |
109 |
|
|
* do a nameserver lookup of the conf host |
110 |
|
|
* if the conf entry is currently doing a ns lookup do nothing, otherwise |
111 |
|
|
* allocate a dns_query and start ns lookup. |
112 |
|
|
*/ |
113 |
|
|
static void |
114 |
michael |
1632 |
conf_dns_lookup(struct MaskItem *conf) |
115 |
adx |
30 |
{ |
116 |
michael |
4982 |
if (conf->dns_pending) |
117 |
|
|
return; |
118 |
|
|
|
119 |
|
|
conf->dns_pending = 1; |
120 |
|
|
|
121 |
|
|
if (conf->aftype == AF_INET) |
122 |
|
|
gethost_byname_type(conf_dns_callback, conf, conf->host, T_A); |
123 |
|
|
else |
124 |
|
|
gethost_byname_type(conf_dns_callback, conf, conf->host, T_AAAA); |
125 |
|
|
} |
126 |
|
|
|
127 |
|
|
/* map_to_list() |
128 |
|
|
* |
129 |
|
|
* inputs - ConfType conf |
130 |
|
|
* output - pointer to dlink_list to use |
131 |
|
|
* side effects - none |
132 |
|
|
*/ |
133 |
|
|
static dlink_list * |
134 |
|
|
map_to_list(enum maskitem_type type) |
135 |
|
|
{ |
136 |
|
|
switch (type) |
137 |
adx |
30 |
{ |
138 |
michael |
4982 |
case CONF_OPER: |
139 |
michael |
6628 |
return &operator_items; |
140 |
michael |
4982 |
break; |
141 |
|
|
case CONF_SERVER: |
142 |
michael |
7401 |
return &connect_items; |
143 |
michael |
4982 |
break; |
144 |
|
|
default: |
145 |
|
|
return NULL; |
146 |
adx |
30 |
} |
147 |
|
|
} |
148 |
|
|
|
149 |
michael |
1632 |
struct MaskItem * |
150 |
|
|
conf_make(enum maskitem_type type) |
151 |
|
|
{ |
152 |
michael |
7032 |
struct MaskItem *const conf = xcalloc(sizeof(*conf)); |
153 |
michael |
1632 |
dlink_list *list = NULL; |
154 |
|
|
|
155 |
|
|
conf->type = type; |
156 |
|
|
conf->active = 1; |
157 |
|
|
conf->aftype = AF_INET; |
158 |
|
|
|
159 |
|
|
if ((list = map_to_list(type))) |
160 |
|
|
dlinkAdd(conf, &conf->node, list); |
161 |
|
|
return conf; |
162 |
|
|
} |
163 |
|
|
|
164 |
|
|
void |
165 |
|
|
conf_free(struct MaskItem *conf) |
166 |
|
|
{ |
167 |
michael |
4815 |
dlink_node *node = NULL, *node_next = NULL; |
168 |
michael |
1636 |
dlink_list *list = NULL; |
169 |
|
|
|
170 |
michael |
4511 |
if ((list = map_to_list(conf->type))) |
171 |
michael |
4523 |
dlinkFindDelete(list, conf); |
172 |
michael |
4511 |
|
173 |
michael |
7032 |
xfree(conf->name); |
174 |
michael |
1632 |
|
175 |
|
|
if (conf->dns_pending) |
176 |
|
|
delete_resolver_queries(conf); |
177 |
michael |
3235 |
if (conf->passwd) |
178 |
michael |
1632 |
memset(conf->passwd, 0, strlen(conf->passwd)); |
179 |
michael |
3235 |
if (conf->spasswd) |
180 |
michael |
1632 |
memset(conf->spasswd, 0, strlen(conf->spasswd)); |
181 |
|
|
|
182 |
|
|
conf->class = NULL; |
183 |
|
|
|
184 |
michael |
7032 |
xfree(conf->passwd); |
185 |
|
|
xfree(conf->spasswd); |
186 |
|
|
xfree(conf->reason); |
187 |
|
|
xfree(conf->certfp); |
188 |
|
|
xfree(conf->whois); |
189 |
|
|
xfree(conf->user); |
190 |
|
|
xfree(conf->host); |
191 |
|
|
xfree(conf->cipher_list); |
192 |
michael |
1632 |
|
193 |
michael |
4815 |
DLINK_FOREACH_SAFE(node, node_next, conf->hub_list.head) |
194 |
michael |
1632 |
{ |
195 |
michael |
7032 |
xfree(node->data); |
196 |
michael |
4815 |
dlinkDelete(node, &conf->hub_list); |
197 |
|
|
free_dlink_node(node); |
198 |
michael |
1632 |
} |
199 |
|
|
|
200 |
michael |
4815 |
DLINK_FOREACH_SAFE(node, node_next, conf->leaf_list.head) |
201 |
michael |
1632 |
{ |
202 |
michael |
7032 |
xfree(node->data); |
203 |
michael |
4815 |
dlinkDelete(node, &conf->leaf_list); |
204 |
|
|
free_dlink_node(node); |
205 |
michael |
1632 |
} |
206 |
adx |
30 |
|
207 |
michael |
7032 |
xfree(conf); |
208 |
adx |
30 |
} |
209 |
|
|
|
210 |
michael |
4982 |
/* attach_iline() |
211 |
adx |
30 |
* |
212 |
michael |
4982 |
* inputs - client pointer |
213 |
|
|
* - conf pointer |
214 |
|
|
* output - |
215 |
|
|
* side effects - do actual attach |
216 |
adx |
30 |
*/ |
217 |
michael |
4982 |
static int |
218 |
|
|
attach_iline(struct Client *client_p, struct MaskItem *conf) |
219 |
adx |
30 |
{ |
220 |
michael |
4982 |
const struct ClassItem *const class = conf->class; |
221 |
|
|
struct ip_entry *ip_found; |
222 |
|
|
int a_limit_reached = 0; |
223 |
michael |
7624 |
unsigned int local = 0, global = 0; |
224 |
michael |
2916 |
|
225 |
michael |
4982 |
ip_found = ipcache_find_or_add_address(&client_p->connection->ip); |
226 |
|
|
ip_found->count++; |
227 |
|
|
AddFlag(client_p, FLAGS_IPHASH); |
228 |
adx |
30 |
|
229 |
michael |
7624 |
userhost_count(client_p->sockhost, &global, &local); |
230 |
adx |
30 |
|
231 |
michael |
4982 |
/* XXX blah. go down checking the various silly limits |
232 |
|
|
* setting a_limit_reached if any limit is reached. |
233 |
|
|
* - Dianora |
234 |
|
|
*/ |
235 |
|
|
if (class->max_total && class->ref_count >= class->max_total) |
236 |
|
|
a_limit_reached = 1; |
237 |
|
|
else if (class->max_perip && ip_found->count > class->max_perip) |
238 |
|
|
a_limit_reached = 1; |
239 |
michael |
7624 |
else if (class->max_local && local >= class->max_local) /* XXX: redundant */ |
240 |
michael |
4982 |
a_limit_reached = 1; |
241 |
|
|
else if (class->max_global && global >= class->max_global) |
242 |
|
|
a_limit_reached = 1; |
243 |
adx |
30 |
|
244 |
michael |
4982 |
if (a_limit_reached) |
245 |
|
|
{ |
246 |
|
|
if (!IsConfExemptLimits(conf)) |
247 |
|
|
return TOO_MANY; /* Already at maximum allowed */ |
248 |
adx |
30 |
|
249 |
michael |
4982 |
sendto_one_notice(client_p, &me, ":*** Your connection class is full, " |
250 |
|
|
"but you have exceed_limit = yes;"); |
251 |
adx |
30 |
} |
252 |
|
|
|
253 |
michael |
8395 |
return conf_attach(client_p, conf); |
254 |
adx |
30 |
} |
255 |
|
|
|
256 |
|
|
/* verify_access() |
257 |
|
|
* |
258 |
michael |
4982 |
* inputs - pointer to client to verify |
259 |
|
|
* output - 0 if success -'ve if not |
260 |
|
|
* side effect - find the first (best) I line to attach. |
261 |
adx |
30 |
*/ |
262 |
|
|
static int |
263 |
michael |
1644 |
verify_access(struct Client *client_p) |
264 |
adx |
30 |
{ |
265 |
michael |
1949 |
struct MaskItem *conf = NULL; |
266 |
adx |
30 |
|
267 |
michael |
6313 |
if (HasFlag(client_p, FLAGS_GOTID)) |
268 |
adx |
30 |
{ |
269 |
michael |
1632 |
conf = find_address_conf(client_p->host, client_p->username, |
270 |
michael |
4588 |
&client_p->connection->ip, |
271 |
|
|
client_p->connection->aftype, |
272 |
|
|
client_p->connection->password); |
273 |
adx |
30 |
} |
274 |
|
|
else |
275 |
|
|
{ |
276 |
michael |
5583 |
char non_ident[USERLEN + 1] = "~"; |
277 |
|
|
|
278 |
michael |
2182 |
strlcpy(non_ident + 1, client_p->username, sizeof(non_ident) - 1); |
279 |
michael |
4982 |
conf = find_address_conf(client_p->host, non_ident, |
280 |
michael |
4588 |
&client_p->connection->ip, |
281 |
|
|
client_p->connection->aftype, |
282 |
|
|
client_p->connection->password); |
283 |
adx |
30 |
} |
284 |
|
|
|
285 |
michael |
5805 |
if (!conf) |
286 |
|
|
return NOT_AUTHORIZED; |
287 |
|
|
|
288 |
|
|
assert(IsConfClient(conf) || IsConfKill(conf)); |
289 |
|
|
|
290 |
|
|
if (IsConfClient(conf)) |
291 |
adx |
30 |
{ |
292 |
michael |
5805 |
if (IsConfRedir(conf)) |
293 |
adx |
30 |
{ |
294 |
michael |
5805 |
sendto_one_numeric(client_p, &me, RPL_REDIR, |
295 |
|
|
conf->name ? conf->name : "", |
296 |
|
|
conf->port); |
297 |
|
|
return NOT_AUTHORIZED; |
298 |
|
|
} |
299 |
adx |
30 |
|
300 |
michael |
5805 |
if (IsConfDoSpoofIp(conf)) |
301 |
|
|
{ |
302 |
|
|
if (IsConfSpoofNotice(conf)) |
303 |
michael |
6318 |
sendto_realops_flags(UMODE_SERVNOTICE, L_ADMIN, SEND_NOTICE, "%s spoofing: %s as %s", |
304 |
michael |
5805 |
client_p->name, client_p->host, conf->name); |
305 |
michael |
4982 |
|
306 |
michael |
5805 |
strlcpy(client_p->host, conf->name, sizeof(client_p->host)); |
307 |
adx |
30 |
} |
308 |
michael |
4982 |
|
309 |
michael |
5805 |
return attach_iline(client_p, conf); |
310 |
adx |
30 |
} |
311 |
|
|
|
312 |
michael |
5805 |
sendto_one_notice(client_p, &me, ":*** Banned: %s", conf->reason); |
313 |
|
|
return BANNED_CLIENT; |
314 |
adx |
30 |
} |
315 |
|
|
|
316 |
michael |
4982 |
/* check_client() |
317 |
adx |
30 |
* |
318 |
michael |
4982 |
* inputs - pointer to client |
319 |
|
|
* output - 0 = Success |
320 |
|
|
* NOT_AUTHORIZED (-1) = Access denied (no I line match) |
321 |
|
|
* IRCD_SOCKET_ERROR (-2) = Bad socket. |
322 |
|
|
* I_LINE_FULL (-3) = I-line is full |
323 |
|
|
* TOO_MANY (-4) = Too many connections from hostname |
324 |
|
|
* BANNED_CLIENT (-5) = K-lined |
325 |
|
|
* side effects - Ordinary client access check. |
326 |
|
|
* Look for conf lines which have the same |
327 |
|
|
* status as the flags passed. |
328 |
adx |
30 |
*/ |
329 |
michael |
4982 |
int |
330 |
|
|
check_client(struct Client *source_p) |
331 |
adx |
30 |
{ |
332 |
michael |
4982 |
int i; |
333 |
adx |
30 |
|
334 |
michael |
4982 |
if ((i = verify_access(source_p))) |
335 |
|
|
ilog(LOG_TYPE_IRCD, "Access denied: %s[%s]", |
336 |
|
|
source_p->name, source_p->sockhost); |
337 |
adx |
30 |
|
338 |
michael |
4982 |
switch (i) |
339 |
|
|
{ |
340 |
|
|
case TOO_MANY: |
341 |
|
|
sendto_realops_flags(UMODE_FULL, L_ALL, SEND_NOTICE, |
342 |
|
|
"Too many on IP for %s (%s).", |
343 |
michael |
7997 |
client_get_name(source_p, SHOW_IP), |
344 |
michael |
4982 |
source_p->sockhost); |
345 |
|
|
ilog(LOG_TYPE_IRCD, "Too many connections on IP from %s.", |
346 |
michael |
7997 |
client_get_name(source_p, SHOW_IP)); |
347 |
michael |
4982 |
++ServerStats.is_ref; |
348 |
|
|
exit_client(source_p, "No more connections allowed on that IP"); |
349 |
|
|
break; |
350 |
adx |
30 |
|
351 |
michael |
4982 |
case I_LINE_FULL: |
352 |
|
|
sendto_realops_flags(UMODE_FULL, L_ALL, SEND_NOTICE, |
353 |
|
|
"auth {} block is full for %s (%s).", |
354 |
michael |
7997 |
client_get_name(source_p, SHOW_IP), |
355 |
michael |
4982 |
source_p->sockhost); |
356 |
|
|
ilog(LOG_TYPE_IRCD, "Too many connections from %s.", |
357 |
michael |
7997 |
client_get_name(source_p, SHOW_IP)); |
358 |
michael |
4982 |
++ServerStats.is_ref; |
359 |
|
|
exit_client(source_p, "No more connections allowed in your connection class"); |
360 |
|
|
break; |
361 |
adx |
30 |
|
362 |
michael |
4982 |
case NOT_AUTHORIZED: |
363 |
|
|
/* jdc - lists server name & port connections are on */ |
364 |
|
|
/* a purely cosmetical change */ |
365 |
|
|
sendto_realops_flags(UMODE_UNAUTH, L_ALL, SEND_NOTICE, |
366 |
michael |
7537 |
"Unauthorized client connection from %s on [%s/%u].", |
367 |
michael |
7997 |
client_get_name(source_p, SHOW_IP), |
368 |
michael |
4982 |
source_p->connection->listener->name, |
369 |
|
|
source_p->connection->listener->port); |
370 |
|
|
ilog(LOG_TYPE_IRCD, "Unauthorized client connection from %s on [%s/%u].", |
371 |
michael |
7997 |
client_get_name(source_p, SHOW_IP), |
372 |
michael |
4982 |
source_p->connection->listener->name, |
373 |
|
|
source_p->connection->listener->port); |
374 |
adx |
30 |
|
375 |
michael |
4982 |
++ServerStats.is_ref; |
376 |
|
|
exit_client(source_p, "You are not authorized to use this server"); |
377 |
|
|
break; |
378 |
|
|
|
379 |
|
|
case BANNED_CLIENT: |
380 |
|
|
++ServerStats.is_ref; |
381 |
|
|
exit_client(source_p, "Banned"); |
382 |
|
|
break; |
383 |
|
|
|
384 |
|
|
case 0: |
385 |
|
|
default: |
386 |
|
|
break; |
387 |
adx |
30 |
} |
388 |
|
|
|
389 |
michael |
4982 |
return !(i < 0); |
390 |
adx |
30 |
} |
391 |
|
|
|
392 |
michael |
8395 |
/*! \brief Disassociate configuration from the client. Also removes a class |
393 |
|
|
* from the list if marked for deleting. |
394 |
|
|
* \param client_p Client to operate on |
395 |
|
|
* \param type Type of conf to detach |
396 |
adx |
30 |
*/ |
397 |
michael |
1632 |
void |
398 |
michael |
8395 |
conf_detach(struct Client *client_p, enum maskitem_type type) |
399 |
adx |
30 |
{ |
400 |
michael |
8395 |
dlink_node *node, *node_next; |
401 |
adx |
30 |
|
402 |
michael |
4815 |
DLINK_FOREACH_SAFE(node, node_next, client_p->connection->confs.head) |
403 |
adx |
30 |
{ |
404 |
michael |
4815 |
struct MaskItem *conf = node->data; |
405 |
adx |
30 |
|
406 |
michael |
1645 |
assert(conf->type & (CONF_CLIENT | CONF_OPER | CONF_SERVER)); |
407 |
|
|
assert(conf->ref_count > 0); |
408 |
|
|
assert(conf->class->ref_count > 0); |
409 |
adx |
30 |
|
410 |
michael |
1645 |
if (!(conf->type & type)) |
411 |
|
|
continue; |
412 |
michael |
671 |
|
413 |
michael |
4815 |
dlinkDelete(node, &client_p->connection->confs); |
414 |
|
|
free_dlink_node(node); |
415 |
michael |
1644 |
|
416 |
michael |
2278 |
if (conf->type == CONF_CLIENT) |
417 |
michael |
4588 |
remove_from_cidr_check(&client_p->connection->ip, conf->class); |
418 |
adx |
30 |
|
419 |
michael |
1645 |
if (--conf->class->ref_count == 0 && conf->class->active == 0) |
420 |
|
|
{ |
421 |
|
|
class_free(conf->class); |
422 |
|
|
conf->class = NULL; |
423 |
adx |
30 |
} |
424 |
michael |
1645 |
|
425 |
|
|
if (--conf->ref_count == 0 && conf->active == 0) |
426 |
|
|
conf_free(conf); |
427 |
adx |
30 |
} |
428 |
|
|
} |
429 |
|
|
|
430 |
michael |
8395 |
/*! \brief Associate a specific configuration entry to a *local* client (this |
431 |
|
|
* is the one which used in accepting the connection). Note, that this |
432 |
|
|
* automatically changes the attachment if there was an old one. |
433 |
|
|
* \param client_p Client to attach the conf to |
434 |
|
|
* \param conf Configuration record to attach |
435 |
adx |
30 |
*/ |
436 |
|
|
int |
437 |
michael |
8395 |
conf_attach(struct Client *client_p, struct MaskItem *conf) |
438 |
adx |
30 |
{ |
439 |
michael |
4588 |
if (dlinkFind(&client_p->connection->confs, conf)) |
440 |
adx |
30 |
return 1; |
441 |
|
|
|
442 |
michael |
1632 |
if (conf->type == CONF_CLIENT) |
443 |
|
|
if (cidr_limit_reached(IsConfExemptLimits(conf), |
444 |
michael |
4588 |
&client_p->connection->ip, conf->class)) |
445 |
michael |
1394 |
return TOO_MANY; /* Already at maximum allowed */ |
446 |
adx |
30 |
|
447 |
michael |
1632 |
conf->class->ref_count++; |
448 |
michael |
1644 |
conf->ref_count++; |
449 |
adx |
30 |
|
450 |
michael |
4588 |
dlinkAdd(conf, make_dlink_node(), &client_p->connection->confs); |
451 |
adx |
30 |
|
452 |
|
|
return 0; |
453 |
|
|
} |
454 |
|
|
|
455 |
|
|
/* find_conf_name() |
456 |
|
|
* |
457 |
|
|
* inputs - pointer to conf link list to search |
458 |
|
|
* - pointer to name to find |
459 |
|
|
* - int mask of type of conf to find |
460 |
|
|
* output - NULL or pointer to conf found |
461 |
|
|
* side effects - find a conf entry which matches the name |
462 |
|
|
* and has the given mask. |
463 |
|
|
*/ |
464 |
michael |
1632 |
struct MaskItem * |
465 |
|
|
find_conf_name(dlink_list *list, const char *name, enum maskitem_type type) |
466 |
adx |
30 |
{ |
467 |
michael |
4815 |
dlink_node *node = NULL; |
468 |
adx |
30 |
|
469 |
michael |
4815 |
DLINK_FOREACH(node, list->head) |
470 |
adx |
30 |
{ |
471 |
michael |
4815 |
struct MaskItem *conf = node->data; |
472 |
michael |
2916 |
|
473 |
adx |
30 |
if (conf->type == type) |
474 |
|
|
{ |
475 |
michael |
4596 |
if (conf->name && !irccmp(conf->name, name)) |
476 |
|
|
return conf; |
477 |
adx |
30 |
} |
478 |
|
|
} |
479 |
|
|
|
480 |
|
|
return NULL; |
481 |
|
|
} |
482 |
|
|
|
483 |
michael |
8391 |
/*! \brief Find a connect {} conf that has a name that matches \a name. |
484 |
|
|
* \param name Name to match |
485 |
|
|
* \param compare Pointer to function to be used for string matching |
486 |
adx |
30 |
*/ |
487 |
michael |
1632 |
struct MaskItem * |
488 |
michael |
8391 |
connect_find(const char *name, int (*compare)(const char *, const char *)) |
489 |
adx |
30 |
{ |
490 |
michael |
8391 |
dlink_node *node; |
491 |
adx |
30 |
|
492 |
michael |
7401 |
DLINK_FOREACH(node, connect_items.head) |
493 |
adx |
30 |
{ |
494 |
michael |
7401 |
struct MaskItem *conf = node->data; |
495 |
adx |
30 |
|
496 |
michael |
8391 |
if (!compare(name, conf->name)) |
497 |
michael |
7401 |
return conf; |
498 |
|
|
} |
499 |
michael |
2916 |
|
500 |
adx |
30 |
return NULL; |
501 |
|
|
} |
502 |
|
|
|
503 |
|
|
/* find_exact_name_conf() |
504 |
|
|
* |
505 |
|
|
* inputs - type of link list to look in |
506 |
|
|
* - pointer to name string to find |
507 |
|
|
* - pointer to user |
508 |
|
|
* - pointer to host |
509 |
michael |
1632 |
* output - NULL or pointer to found struct MaskItem |
510 |
adx |
30 |
* side effects - looks for an exact match on name field |
511 |
|
|
*/ |
512 |
michael |
1632 |
struct MaskItem * |
513 |
michael |
7403 |
operator_find(const struct Client *who, const char *name) |
514 |
adx |
30 |
{ |
515 |
michael |
4815 |
dlink_node *node = NULL; |
516 |
adx |
30 |
|
517 |
michael |
7401 |
DLINK_FOREACH(node, operator_items.head) |
518 |
adx |
30 |
{ |
519 |
michael |
7401 |
struct MaskItem *conf = node->data; |
520 |
|
|
|
521 |
|
|
if (!irccmp(conf->name, name)) |
522 |
adx |
30 |
{ |
523 |
michael |
7401 |
if (!who) |
524 |
|
|
return conf; |
525 |
michael |
1285 |
|
526 |
michael |
7401 |
if (!match(conf->user, who->username)) |
527 |
adx |
30 |
{ |
528 |
michael |
7401 |
switch (conf->htype) |
529 |
michael |
1285 |
{ |
530 |
michael |
7401 |
case HM_HOST: |
531 |
|
|
if (!match(conf->host, who->host) || !match(conf->host, who->sockhost)) |
532 |
|
|
if (!conf->class->max_total || conf->class->ref_count < conf->class->max_total) |
533 |
|
|
return conf; |
534 |
|
|
break; |
535 |
|
|
case HM_IPV4: |
536 |
|
|
if (who->connection->aftype == AF_INET) |
537 |
|
|
if (match_ipv4(&who->connection->ip, &conf->addr, conf->bits)) |
538 |
michael |
1637 |
if (!conf->class->max_total || conf->class->ref_count < conf->class->max_total) |
539 |
|
|
return conf; |
540 |
michael |
7401 |
break; |
541 |
|
|
case HM_IPV6: |
542 |
|
|
if (who->connection->aftype == AF_INET6) |
543 |
|
|
if (match_ipv6(&who->connection->ip, &conf->addr, conf->bits)) |
544 |
|
|
if (!conf->class->max_total || conf->class->ref_count < conf->class->max_total) |
545 |
|
|
return conf; |
546 |
|
|
break; |
547 |
|
|
default: |
548 |
|
|
assert(0); |
549 |
michael |
1285 |
} |
550 |
adx |
30 |
} |
551 |
|
|
} |
552 |
|
|
} |
553 |
michael |
2182 |
|
554 |
|
|
return NULL; |
555 |
adx |
30 |
} |
556 |
|
|
|
557 |
|
|
/* set_default_conf() |
558 |
|
|
* |
559 |
|
|
* inputs - NONE |
560 |
|
|
* output - NONE |
561 |
|
|
* side effects - Set default values here. |
562 |
|
|
* This is called **PRIOR** to parsing the |
563 |
|
|
* configuration file. If you want to do some validation |
564 |
|
|
* of values later, put them in validate_conf(). |
565 |
|
|
*/ |
566 |
|
|
static void |
567 |
|
|
set_default_conf(void) |
568 |
|
|
{ |
569 |
|
|
/* verify init_class() ran, this should be an unnecessary check |
570 |
|
|
* but its not much work. |
571 |
|
|
*/ |
572 |
michael |
1644 |
assert(class_default == class_get_list()->tail->data); |
573 |
adx |
30 |
|
574 |
michael |
4340 |
ConfigServerInfo.network_name = xstrdup(NETWORK_NAME_DEFAULT); |
575 |
|
|
ConfigServerInfo.network_desc = xstrdup(NETWORK_DESC_DEFAULT); |
576 |
adx |
30 |
|
577 |
michael |
4340 |
memset(&ConfigServerInfo.ip, 0, sizeof(ConfigServerInfo.ip)); |
578 |
|
|
ConfigServerInfo.specific_ipv4_vhost = 0; |
579 |
|
|
memset(&ConfigServerInfo.ip6, 0, sizeof(ConfigServerInfo.ip6)); |
580 |
|
|
ConfigServerInfo.specific_ipv6_vhost = 0; |
581 |
adx |
30 |
|
582 |
michael |
5489 |
ConfigServerInfo.default_max_clients = MAXCLIENTS_MAX; |
583 |
michael |
4340 |
ConfigServerInfo.max_nick_length = 9; |
584 |
|
|
ConfigServerInfo.max_topic_length = 80; |
585 |
|
|
ConfigServerInfo.hub = 0; |
586 |
michael |
4313 |
|
587 |
michael |
1831 |
log_del_all(); |
588 |
michael |
1247 |
|
589 |
michael |
4340 |
ConfigLog.use_logging = 1; |
590 |
adx |
30 |
|
591 |
michael |
1243 |
ConfigChannel.disable_fake_channels = 0; |
592 |
michael |
3860 |
ConfigChannel.invite_client_count = 10; |
593 |
|
|
ConfigChannel.invite_client_time = 300; |
594 |
michael |
6792 |
ConfigChannel.invite_delay_channel = 5; |
595 |
michael |
7793 |
ConfigChannel.invite_expire_time = 1800; |
596 |
michael |
3860 |
ConfigChannel.knock_client_count = 1; |
597 |
|
|
ConfigChannel.knock_client_time = 300; |
598 |
adx |
30 |
ConfigChannel.knock_delay_channel = 60; |
599 |
michael |
3933 |
ConfigChannel.max_channels = 25; |
600 |
michael |
7766 |
ConfigChannel.max_invites = 20; |
601 |
michael |
8046 |
ConfigChannel.max_bans = 100; |
602 |
|
|
ConfigChannel.max_bans_large = 500; |
603 |
michael |
5489 |
ConfigChannel.default_join_flood_count = 18; |
604 |
|
|
ConfigChannel.default_join_flood_time = 6; |
605 |
adx |
30 |
|
606 |
michael |
1243 |
ConfigServerHide.flatten_links = 0; |
607 |
michael |
6597 |
ConfigServerHide.flatten_links_delay = 300; |
608 |
michael |
1243 |
ConfigServerHide.hidden = 0; |
609 |
|
|
ConfigServerHide.hide_servers = 0; |
610 |
michael |
1851 |
ConfigServerHide.hide_services = 0; |
611 |
michael |
1646 |
ConfigServerHide.hidden_name = xstrdup(NETWORK_NAME_DEFAULT); |
612 |
michael |
1243 |
ConfigServerHide.hide_server_ips = 0; |
613 |
michael |
2196 |
ConfigServerHide.disable_remote_commands = 0; |
614 |
adx |
30 |
|
615 |
michael |
4340 |
ConfigGeneral.away_count = 2; |
616 |
|
|
ConfigGeneral.away_time = 10; |
617 |
michael |
6740 |
ConfigGeneral.max_watch = 50; |
618 |
michael |
7437 |
ConfigGeneral.whowas_history_length = 15000; |
619 |
michael |
4340 |
ConfigGeneral.cycle_on_host_change = 1; |
620 |
michael |
5805 |
ConfigGeneral.dline_min_cidr = 16; |
621 |
|
|
ConfigGeneral.dline_min_cidr6 = 48; |
622 |
|
|
ConfigGeneral.kline_min_cidr = 16; |
623 |
|
|
ConfigGeneral.kline_min_cidr6 = 48; |
624 |
michael |
4340 |
ConfigGeneral.invisible_on_connect = 1; |
625 |
|
|
ConfigGeneral.tkline_expire_notices = 1; |
626 |
|
|
ConfigGeneral.ignore_bogus_ts = 0; |
627 |
|
|
ConfigGeneral.disable_auth = 0; |
628 |
|
|
ConfigGeneral.kill_chase_time_limit = 90; |
629 |
|
|
ConfigGeneral.default_floodcount = 8; |
630 |
michael |
7858 |
ConfigGeneral.default_floodtime = 1; |
631 |
michael |
4340 |
ConfigGeneral.failed_oper_notice = 1; |
632 |
|
|
ConfigGeneral.dots_in_ident = 0; |
633 |
|
|
ConfigGeneral.min_nonwildcard = 4; |
634 |
|
|
ConfigGeneral.min_nonwildcard_simple = 3; |
635 |
michael |
6740 |
ConfigGeneral.max_accept = 50; |
636 |
michael |
4340 |
ConfigGeneral.anti_nick_flood = 0; |
637 |
|
|
ConfigGeneral.max_nick_time = 20; |
638 |
|
|
ConfigGeneral.max_nick_changes = 5; |
639 |
|
|
ConfigGeneral.anti_spam_exit_message_time = 0; |
640 |
michael |
6956 |
ConfigGeneral.ts_warn_delta = 30; |
641 |
|
|
ConfigGeneral.ts_max_delta = 600; |
642 |
michael |
4340 |
ConfigGeneral.warn_no_connect_block = 1; |
643 |
|
|
ConfigGeneral.stats_e_disabled = 0; |
644 |
michael |
5025 |
ConfigGeneral.stats_i_oper_only = 1; /* 1 = masked */ |
645 |
michael |
4340 |
ConfigGeneral.stats_k_oper_only = 1; /* 1 = masked */ |
646 |
michael |
5025 |
ConfigGeneral.stats_o_oper_only = 1; |
647 |
|
|
ConfigGeneral.stats_m_oper_only = 1; |
648 |
michael |
4340 |
ConfigGeneral.stats_P_oper_only = 0; |
649 |
|
|
ConfigGeneral.stats_u_oper_only = 0; |
650 |
|
|
ConfigGeneral.caller_id_wait = 60; |
651 |
michael |
7949 |
ConfigGeneral.opers_bypass_callerid = 1; |
652 |
michael |
4340 |
ConfigGeneral.pace_wait = 10; |
653 |
|
|
ConfigGeneral.pace_wait_simple = 1; |
654 |
|
|
ConfigGeneral.short_motd = 0; |
655 |
|
|
ConfigGeneral.ping_cookie = 0; |
656 |
|
|
ConfigGeneral.no_oper_flood = 0; |
657 |
|
|
ConfigGeneral.max_targets = MAX_TARGETS_DEFAULT; |
658 |
michael |
5506 |
ConfigGeneral.oper_only_umodes = UMODE_DEBUG | UMODE_LOCOPS | UMODE_HIDDEN | UMODE_FARCONNECT | |
659 |
|
|
UMODE_UNAUTH | UMODE_EXTERNAL | UMODE_BOTS | UMODE_NCHANGE | |
660 |
|
|
UMODE_SPY | UMODE_FULL | UMODE_SKILL | UMODE_REJ | UMODE_CCONN; |
661 |
michael |
4340 |
ConfigGeneral.oper_umodes = UMODE_BOTS | UMODE_LOCOPS | UMODE_SERVNOTICE | UMODE_WALLOP; |
662 |
|
|
ConfigGeneral.throttle_count = 1; |
663 |
|
|
ConfigGeneral.throttle_time = 1; |
664 |
adx |
30 |
} |
665 |
|
|
|
666 |
|
|
static void |
667 |
|
|
validate_conf(void) |
668 |
|
|
{ |
669 |
michael |
5039 |
if (EmptyString(ConfigServerInfo.network_name)) |
670 |
michael |
4340 |
ConfigServerInfo.network_name = xstrdup(NETWORK_NAME_DEFAULT); |
671 |
adx |
30 |
|
672 |
michael |
5039 |
if (EmptyString(ConfigServerInfo.network_desc)) |
673 |
michael |
4340 |
ConfigServerInfo.network_desc = xstrdup(NETWORK_DESC_DEFAULT); |
674 |
adx |
30 |
} |
675 |
|
|
|
676 |
michael |
2916 |
/* read_conf() |
677 |
michael |
1363 |
* |
678 |
|
|
* inputs - file descriptor pointing to config file to use |
679 |
|
|
* output - None |
680 |
|
|
* side effects - Read configuration file. |
681 |
|
|
*/ |
682 |
|
|
static void |
683 |
|
|
read_conf(FILE *file) |
684 |
|
|
{ |
685 |
michael |
7746 |
lineno = 1; |
686 |
michael |
1363 |
|
687 |
michael |
3375 |
set_default_conf(); /* Set default values prior to conf parsing */ |
688 |
michael |
1363 |
conf_parser_ctx.pass = 1; |
689 |
michael |
3375 |
yyparse(); /* Pick up the classes first */ |
690 |
michael |
1363 |
|
691 |
|
|
rewind(file); |
692 |
|
|
|
693 |
|
|
conf_parser_ctx.pass = 2; |
694 |
michael |
3375 |
yyparse(); /* Load the values from the conf */ |
695 |
|
|
validate_conf(); /* Check to make sure some values are still okay. */ |
696 |
|
|
/* Some global values are also loaded here. */ |
697 |
michael |
7437 |
whowas_trim(); /* Attempt to trim whowas list if necessary */ |
698 |
michael |
3375 |
class_delete_marked(); /* Delete unused classes that are marked for deletion */ |
699 |
michael |
1363 |
} |
700 |
|
|
|
701 |
michael |
4982 |
/* conf_rehash() |
702 |
|
|
* |
703 |
|
|
* Actual REHASH service routine. Called with sig == 0 if it has been called |
704 |
|
|
* as a result of an operator issuing this command, else assume it has been |
705 |
|
|
* called as a result of the server receiving a HUP signal. |
706 |
|
|
*/ |
707 |
michael |
5776 |
void |
708 |
michael |
4982 |
conf_rehash(int sig) |
709 |
|
|
{ |
710 |
|
|
if (sig) |
711 |
michael |
7639 |
{ |
712 |
michael |
6318 |
sendto_realops_flags(UMODE_SERVNOTICE, L_ALL, SEND_NOTICE, |
713 |
michael |
4982 |
"Got signal SIGHUP, reloading configuration file(s)"); |
714 |
michael |
7639 |
ilog(LOG_TYPE_IRCD, "Got signal SIGHUP, reloading configuration file(s)"); |
715 |
|
|
} |
716 |
michael |
4982 |
|
717 |
|
|
restart_resolver(); |
718 |
|
|
|
719 |
|
|
/* don't close listeners until we know we can go ahead with the rehash */ |
720 |
|
|
|
721 |
|
|
read_conf_files(0); |
722 |
|
|
|
723 |
|
|
load_conf_modules(); |
724 |
|
|
check_conf_klines(); |
725 |
|
|
} |
726 |
|
|
|
727 |
adx |
30 |
/* lookup_confhost() |
728 |
|
|
* |
729 |
|
|
* start DNS lookups of all hostnames in the conf |
730 |
|
|
* line and convert an IP addresses in a.b.c.d number for to IP#s. |
731 |
|
|
*/ |
732 |
michael |
1647 |
void |
733 |
michael |
1632 |
lookup_confhost(struct MaskItem *conf) |
734 |
adx |
30 |
{ |
735 |
|
|
struct addrinfo hints, *res; |
736 |
|
|
|
737 |
michael |
3375 |
/* |
738 |
|
|
* Do name lookup now on hostnames given and store the |
739 |
adx |
30 |
* ip numbers in conf structure. |
740 |
|
|
*/ |
741 |
|
|
memset(&hints, 0, sizeof(hints)); |
742 |
|
|
|
743 |
|
|
hints.ai_family = AF_UNSPEC; |
744 |
|
|
hints.ai_socktype = SOCK_STREAM; |
745 |
|
|
|
746 |
|
|
/* Get us ready for a bind() and don't bother doing dns lookup */ |
747 |
|
|
hints.ai_flags = AI_PASSIVE | AI_NUMERICHOST; |
748 |
|
|
|
749 |
michael |
1632 |
if (getaddrinfo(conf->host, NULL, &hints, &res)) |
750 |
adx |
30 |
{ |
751 |
michael |
1632 |
conf_dns_lookup(conf); |
752 |
adx |
30 |
return; |
753 |
|
|
} |
754 |
|
|
|
755 |
michael |
3235 |
assert(res); |
756 |
adx |
30 |
|
757 |
michael |
1632 |
memcpy(&conf->addr, res->ai_addr, res->ai_addrlen); |
758 |
|
|
conf->addr.ss_len = res->ai_addrlen; |
759 |
|
|
conf->addr.ss.ss_family = res->ai_family; |
760 |
|
|
|
761 |
michael |
1123 |
freeaddrinfo(res); |
762 |
adx |
30 |
} |
763 |
|
|
|
764 |
|
|
/* conf_connect_allowed() |
765 |
|
|
* |
766 |
|
|
* inputs - pointer to inaddr |
767 |
|
|
* - int type ipv4 or ipv6 |
768 |
|
|
* output - BANNED or accepted |
769 |
|
|
* side effects - none |
770 |
|
|
*/ |
771 |
|
|
int |
772 |
|
|
conf_connect_allowed(struct irc_ssaddr *addr, int aftype) |
773 |
|
|
{ |
774 |
michael |
3877 |
struct ip_entry *ip_found = NULL; |
775 |
michael |
6549 |
const struct MaskItem *conf = find_dline_conf(addr, aftype); |
776 |
adx |
30 |
|
777 |
michael |
3235 |
if (conf) |
778 |
michael |
6549 |
{ |
779 |
|
|
/* DLINE exempt also gets you out of static limits/pacing... */ |
780 |
|
|
if (conf->type == CONF_EXEMPT) |
781 |
|
|
return 0; |
782 |
adx |
30 |
return BANNED_CLIENT; |
783 |
michael |
6549 |
} |
784 |
adx |
30 |
|
785 |
michael |
4325 |
ip_found = ipcache_find_or_add_address(addr); |
786 |
adx |
30 |
|
787 |
michael |
4340 |
if ((CurrentTime - ip_found->last_attempt) < ConfigGeneral.throttle_time) |
788 |
adx |
30 |
{ |
789 |
michael |
4340 |
if (ip_found->connection_count >= ConfigGeneral.throttle_count) |
790 |
michael |
3877 |
return TOO_FAST; |
791 |
michael |
4055 |
|
792 |
|
|
++ip_found->connection_count; |
793 |
adx |
30 |
} |
794 |
michael |
3877 |
else |
795 |
|
|
ip_found->connection_count = 1; |
796 |
adx |
30 |
|
797 |
|
|
ip_found->last_attempt = CurrentTime; |
798 |
|
|
return 0; |
799 |
|
|
} |
800 |
|
|
|
801 |
michael |
4982 |
/* cleanup_tklines() |
802 |
|
|
* |
803 |
|
|
* inputs - NONE |
804 |
|
|
* output - NONE |
805 |
|
|
* side effects - call function to expire temporary k/d lines |
806 |
|
|
* This is an event started off in ircd.c |
807 |
|
|
*/ |
808 |
|
|
void |
809 |
|
|
cleanup_tklines(void *unused) |
810 |
|
|
{ |
811 |
|
|
hostmask_expire_temporary(); |
812 |
michael |
7304 |
gecos_expire(); |
813 |
michael |
7282 |
resv_expire(); |
814 |
michael |
4982 |
} |
815 |
|
|
|
816 |
adx |
30 |
/* oper_privs_as_string() |
817 |
|
|
* |
818 |
michael |
58 |
* inputs - pointer to client_p |
819 |
adx |
30 |
* output - pointer to static string showing oper privs |
820 |
|
|
* side effects - return as string, the oper privs as derived from port |
821 |
|
|
*/ |
822 |
michael |
7226 |
static const struct oper_flags |
823 |
michael |
58 |
{ |
824 |
michael |
1644 |
const unsigned int flag; |
825 |
michael |
58 |
const unsigned char c; |
826 |
michael |
7226 |
} flag_table[] = { |
827 |
michael |
2012 |
{ OPER_FLAG_ADMIN, 'A' }, |
828 |
michael |
6691 |
{ OPER_FLAG_CLOSE, 'B' }, |
829 |
|
|
{ OPER_FLAG_CONNECT, 'C' }, |
830 |
|
|
{ OPER_FLAG_CONNECT_REMOTE, 'D' }, |
831 |
|
|
{ OPER_FLAG_DIE, 'E' }, |
832 |
|
|
{ OPER_FLAG_DLINE, 'F' }, |
833 |
|
|
{ OPER_FLAG_GLOBOPS, 'G' }, |
834 |
|
|
{ OPER_FLAG_JOIN_RESV, 'H' }, |
835 |
|
|
{ OPER_FLAG_KILL, 'I' }, |
836 |
|
|
{ OPER_FLAG_KILL_REMOTE, 'J' }, |
837 |
michael |
4019 |
{ OPER_FLAG_KLINE, 'K' }, |
838 |
michael |
6691 |
{ OPER_FLAG_LOCOPS, 'L' }, |
839 |
|
|
{ OPER_FLAG_MODULE, 'M' }, |
840 |
|
|
{ OPER_FLAG_NICK_RESV, 'N' }, |
841 |
|
|
{ OPER_FLAG_OPME, 'O' }, |
842 |
|
|
{ OPER_FLAG_REHASH, 'P' }, |
843 |
|
|
{ OPER_FLAG_REMOTEBAN, 'Q' }, |
844 |
|
|
{ OPER_FLAG_RESTART, 'R' }, |
845 |
|
|
{ OPER_FLAG_RESV, 'S' }, |
846 |
|
|
{ OPER_FLAG_SET, 'T' }, |
847 |
|
|
{ OPER_FLAG_SQUIT, 'U' }, |
848 |
|
|
{ OPER_FLAG_SQUIT_REMOTE, 'V' }, |
849 |
|
|
{ OPER_FLAG_UNDLINE, 'W' }, |
850 |
|
|
{ OPER_FLAG_UNKLINE, 'X' }, |
851 |
|
|
{ OPER_FLAG_UNRESV, 'Y' }, |
852 |
|
|
{ OPER_FLAG_UNXLINE, 'Z' }, |
853 |
|
|
{ OPER_FLAG_WALLOPS, 'a' }, |
854 |
|
|
{ OPER_FLAG_XLINE, 'b' }, |
855 |
michael |
1294 |
{ 0, '\0' } |
856 |
michael |
58 |
}; |
857 |
adx |
30 |
|
858 |
michael |
5639 |
const char * |
859 |
michael |
7226 |
oper_privs_as_string(const unsigned int flags) |
860 |
adx |
30 |
{ |
861 |
michael |
8310 |
static char buf[sizeof(flag_table) / sizeof(flag_table[0])]; |
862 |
michael |
7226 |
char *p = buf; |
863 |
adx |
30 |
|
864 |
michael |
7226 |
for (const struct oper_flags *tab = flag_table; tab->flag; ++tab) |
865 |
|
|
if (flags & tab->flag) |
866 |
|
|
*p++ = tab->c; |
867 |
michael |
58 |
|
868 |
michael |
7226 |
if (p == buf) |
869 |
|
|
*p++ = '0'; |
870 |
michael |
6700 |
|
871 |
michael |
7226 |
*p = '\0'; |
872 |
michael |
58 |
|
873 |
michael |
7226 |
return buf; |
874 |
adx |
30 |
} |
875 |
|
|
|
876 |
|
|
/* |
877 |
michael |
4298 |
* Input: A client to find the active operator {} name for. |
878 |
adx |
30 |
* Output: The nick!user@host{oper} of the oper. |
879 |
|
|
* "oper" is server name for remote opers |
880 |
|
|
* Side effects: None. |
881 |
|
|
*/ |
882 |
michael |
1364 |
const char * |
883 |
adx |
30 |
get_oper_name(const struct Client *client_p) |
884 |
|
|
{ |
885 |
michael |
5514 |
static char buffer[IRCD_BUFSIZE]; |
886 |
adx |
30 |
|
887 |
michael |
4628 |
if (IsServer(client_p)) |
888 |
|
|
return client_p->name; |
889 |
|
|
|
890 |
adx |
30 |
if (MyConnect(client_p)) |
891 |
|
|
{ |
892 |
michael |
4977 |
const dlink_node *const node = client_p->connection->confs.head; |
893 |
|
|
|
894 |
|
|
if (node) |
895 |
adx |
30 |
{ |
896 |
michael |
4937 |
const struct MaskItem *const conf = node->data; |
897 |
adx |
30 |
|
898 |
michael |
4937 |
if (conf->type == CONF_OPER) |
899 |
adx |
30 |
{ |
900 |
michael |
2182 |
snprintf(buffer, sizeof(buffer), "%s!%s@%s{%s}", client_p->name, |
901 |
michael |
1147 |
client_p->username, client_p->host, conf->name); |
902 |
michael |
2182 |
return buffer; |
903 |
adx |
30 |
} |
904 |
|
|
} |
905 |
|
|
|
906 |
michael |
4298 |
/* |
907 |
|
|
* Probably should assert here for now. If there is an oper out there |
908 |
|
|
* with no operator {} conf attached, it would be good for us to know... |
909 |
adx |
30 |
*/ |
910 |
michael |
4298 |
assert(0); /* Oper without oper conf! */ |
911 |
adx |
30 |
} |
912 |
|
|
|
913 |
michael |
1147 |
snprintf(buffer, sizeof(buffer), "%s!%s@%s{%s}", client_p->name, |
914 |
michael |
2182 |
client_p->username, client_p->host, client_p->servptr->name); |
915 |
adx |
30 |
return buffer; |
916 |
|
|
} |
917 |
|
|
|
918 |
|
|
/* clear_out_old_conf() |
919 |
|
|
* |
920 |
|
|
* inputs - none |
921 |
|
|
* output - none |
922 |
|
|
* side effects - Clear out the old configuration |
923 |
|
|
*/ |
924 |
|
|
static void |
925 |
|
|
clear_out_old_conf(void) |
926 |
|
|
{ |
927 |
michael |
4815 |
dlink_node *node = NULL, *node_next = NULL; |
928 |
adx |
30 |
dlink_list *free_items [] = { |
929 |
michael |
7401 |
&connect_items, &operator_items, NULL |
930 |
adx |
30 |
}; |
931 |
|
|
|
932 |
|
|
dlink_list ** iterator = free_items; /* C is dumb */ |
933 |
|
|
|
934 |
|
|
/* We only need to free anything allocated by yyparse() here. |
935 |
|
|
* Resetting structs, etc, is taken care of by set_default_conf(). |
936 |
|
|
*/ |
937 |
michael |
2916 |
|
938 |
michael |
5003 |
for (; *iterator; iterator++) |
939 |
adx |
30 |
{ |
940 |
michael |
4815 |
DLINK_FOREACH_SAFE(node, node_next, (*iterator)->head) |
941 |
adx |
30 |
{ |
942 |
michael |
4815 |
struct MaskItem *conf = node->data; |
943 |
michael |
1632 |
|
944 |
michael |
4523 |
conf->active = 0; |
945 |
michael |
7304 |
dlinkDelete(&conf->node, *iterator); |
946 |
michael |
1632 |
|
947 |
michael |
7304 |
if (!conf->ref_count) |
948 |
|
|
conf_free(conf); |
949 |
adx |
30 |
} |
950 |
|
|
} |
951 |
|
|
|
952 |
michael |
671 |
/* |
953 |
michael |
5583 |
* Don't delete the class table, rather mark all entries for deletion. |
954 |
|
|
* The table is cleaned up by class_delete_marked. - avalon |
955 |
adx |
30 |
*/ |
956 |
michael |
1632 |
class_mark_for_deletion(); |
957 |
michael |
671 |
|
958 |
adx |
30 |
clear_out_address_conf(); |
959 |
|
|
|
960 |
michael |
7245 |
modules_conf_clear(); /* Clear modules {} items */ |
961 |
adx |
30 |
|
962 |
michael |
7229 |
motd_clear(); /* Clear motd {} items and re-cache default motd */ |
963 |
|
|
|
964 |
michael |
7217 |
cluster_clear(); /* Clear cluster {} items */ |
965 |
michael |
4545 |
|
966 |
michael |
7304 |
gecos_clear(); /* Clear gecos {} items */ |
967 |
|
|
|
968 |
michael |
7282 |
resv_clear(); /* Clear resv {} items */ |
969 |
|
|
|
970 |
michael |
7248 |
service_clear(); /* Clear service {} items */ |
971 |
|
|
|
972 |
michael |
7209 |
shared_clear(); /* Clear shared {} items */ |
973 |
|
|
|
974 |
michael |
7217 |
pseudo_clear(); /* Clear pseudo {} items */ |
975 |
|
|
|
976 |
michael |
5583 |
/* Clean out ConfigServerInfo */ |
977 |
michael |
7032 |
xfree(ConfigServerInfo.description); |
978 |
michael |
4340 |
ConfigServerInfo.description = NULL; |
979 |
michael |
7032 |
xfree(ConfigServerInfo.network_name); |
980 |
michael |
4340 |
ConfigServerInfo.network_name = NULL; |
981 |
michael |
7032 |
xfree(ConfigServerInfo.network_desc); |
982 |
michael |
4340 |
ConfigServerInfo.network_desc = NULL; |
983 |
michael |
7032 |
xfree(ConfigServerInfo.rsa_private_key_file); |
984 |
michael |
4340 |
ConfigServerInfo.rsa_private_key_file = NULL; |
985 |
michael |
7105 |
xfree(ConfigServerInfo.ssl_certificate_file); |
986 |
|
|
ConfigServerInfo.ssl_certificate_file = NULL; |
987 |
|
|
xfree(ConfigServerInfo.ssl_dh_param_file); |
988 |
|
|
ConfigServerInfo.ssl_dh_param_file = NULL; |
989 |
|
|
xfree(ConfigServerInfo.ssl_dh_elliptic_curve); |
990 |
|
|
ConfigServerInfo.ssl_dh_elliptic_curve = NULL; |
991 |
|
|
xfree(ConfigServerInfo.ssl_cipher_list); |
992 |
|
|
ConfigServerInfo.ssl_cipher_list = NULL; |
993 |
|
|
xfree(ConfigServerInfo.ssl_message_digest_algorithm); |
994 |
|
|
ConfigServerInfo.ssl_message_digest_algorithm = NULL; |
995 |
adx |
30 |
|
996 |
michael |
5583 |
/* Clean out ConfigAdminInfo */ |
997 |
michael |
7032 |
xfree(ConfigAdminInfo.name); |
998 |
michael |
4340 |
ConfigAdminInfo.name = NULL; |
999 |
michael |
7032 |
xfree(ConfigAdminInfo.email); |
1000 |
michael |
4340 |
ConfigAdminInfo.email = NULL; |
1001 |
michael |
7032 |
xfree(ConfigAdminInfo.description); |
1002 |
michael |
4340 |
ConfigAdminInfo.description = NULL; |
1003 |
adx |
30 |
|
1004 |
michael |
7032 |
xfree(ConfigServerHide.flatten_links_file); |
1005 |
michael |
6599 |
ConfigServerHide.flatten_links_file = NULL; |
1006 |
|
|
|
1007 |
michael |
5583 |
/* Clean out listeners */ |
1008 |
michael |
6367 |
listener_close_marked(); |
1009 |
adx |
30 |
} |
1010 |
|
|
|
1011 |
michael |
7105 |
static void |
1012 |
|
|
conf_handle_tls(int cold) |
1013 |
|
|
{ |
1014 |
|
|
if (!tls_new_cred()) |
1015 |
|
|
{ |
1016 |
|
|
if (cold) |
1017 |
|
|
{ |
1018 |
|
|
ilog(LOG_TYPE_IRCD, "Error while initializing TLS"); |
1019 |
michael |
7230 |
exit(EXIT_FAILURE); |
1020 |
michael |
7105 |
} |
1021 |
|
|
else |
1022 |
|
|
{ |
1023 |
|
|
/* Failed to load new settings/certs, old ones remain active */ |
1024 |
|
|
sendto_realops_flags(UMODE_SERVNOTICE, L_ALL, SEND_NOTICE, |
1025 |
|
|
"Error reloading TLS settings, check the ircd log"); // report_crypto_errors logs this |
1026 |
|
|
} |
1027 |
|
|
} |
1028 |
|
|
} |
1029 |
|
|
|
1030 |
michael |
4982 |
/* read_conf_files() |
1031 |
|
|
* |
1032 |
|
|
* inputs - cold start YES or NO |
1033 |
|
|
* output - none |
1034 |
|
|
* side effects - read all conf files needed, ircd.conf kline.conf etc. |
1035 |
|
|
*/ |
1036 |
|
|
void |
1037 |
|
|
read_conf_files(int cold) |
1038 |
|
|
{ |
1039 |
|
|
const char *filename = NULL; |
1040 |
|
|
char chanmodes[IRCD_BUFSIZE] = ""; |
1041 |
|
|
char chanlimit[IRCD_BUFSIZE] = ""; |
1042 |
|
|
|
1043 |
|
|
conf_parser_ctx.boot = cold; |
1044 |
|
|
filename = ConfigGeneral.configfile; |
1045 |
|
|
|
1046 |
|
|
/* We need to know the initial filename for the yyerror() to report |
1047 |
|
|
FIXME: The full path is in conffilenamebuf first time since we |
1048 |
|
|
don't know anything else |
1049 |
|
|
|
1050 |
|
|
- Gozem 2002-07-21 |
1051 |
|
|
*/ |
1052 |
|
|
strlcpy(conffilebuf, filename, sizeof(conffilebuf)); |
1053 |
|
|
|
1054 |
|
|
if ((conf_parser_ctx.conf_file = fopen(filename, "r")) == NULL) |
1055 |
|
|
{ |
1056 |
|
|
if (cold) |
1057 |
|
|
{ |
1058 |
|
|
ilog(LOG_TYPE_IRCD, "Unable to read configuration file '%s': %s", |
1059 |
|
|
filename, strerror(errno)); |
1060 |
michael |
6645 |
exit(EXIT_FAILURE); |
1061 |
michael |
4982 |
} |
1062 |
|
|
else |
1063 |
|
|
{ |
1064 |
michael |
6318 |
sendto_realops_flags(UMODE_SERVNOTICE, L_ADMIN, SEND_NOTICE, |
1065 |
michael |
4982 |
"Unable to read configuration file '%s': %s", |
1066 |
|
|
filename, strerror(errno)); |
1067 |
|
|
return; |
1068 |
|
|
} |
1069 |
|
|
} |
1070 |
|
|
|
1071 |
|
|
if (!cold) |
1072 |
|
|
clear_out_old_conf(); |
1073 |
|
|
|
1074 |
|
|
read_conf(conf_parser_ctx.conf_file); |
1075 |
|
|
fclose(conf_parser_ctx.conf_file); |
1076 |
|
|
|
1077 |
|
|
log_reopen_all(); |
1078 |
michael |
7105 |
conf_handle_tls(cold); |
1079 |
michael |
4982 |
|
1080 |
michael |
6185 |
isupport_add("NICKLEN", NULL, ConfigServerInfo.max_nick_length); |
1081 |
|
|
isupport_add("NETWORK", ConfigServerInfo.network_name, -1); |
1082 |
michael |
4982 |
|
1083 |
michael |
6842 |
snprintf(chanmodes, sizeof(chanmodes), "beI:%u", ConfigChannel.max_bans); |
1084 |
michael |
6185 |
isupport_add("MAXLIST", chanmodes, -1); |
1085 |
|
|
isupport_add("MAXTARGETS", NULL, ConfigGeneral.max_targets); |
1086 |
|
|
isupport_add("CHANTYPES", "#", -1); |
1087 |
michael |
4982 |
|
1088 |
michael |
6842 |
snprintf(chanlimit, sizeof(chanlimit), "#:%u", |
1089 |
michael |
4982 |
ConfigChannel.max_channels); |
1090 |
michael |
6185 |
isupport_add("CHANLIMIT", chanlimit, -1); |
1091 |
michael |
8046 |
snprintf(chanmodes, sizeof(chanmodes), "%s", "beI,k,l,cimnprstuCLMORST"); |
1092 |
michael |
6185 |
isupport_add("CHANNELLEN", NULL, CHANNELLEN); |
1093 |
|
|
isupport_add("TOPICLEN", NULL, ConfigServerInfo.max_topic_length); |
1094 |
|
|
isupport_add("CHANMODES", chanmodes, -1); |
1095 |
michael |
4982 |
} |
1096 |
|
|
|
1097 |
adx |
30 |
/* conf_add_class_to_conf() |
1098 |
|
|
* |
1099 |
|
|
* inputs - pointer to config item |
1100 |
|
|
* output - NONE |
1101 |
michael |
2916 |
* side effects - Add a class pointer to a conf |
1102 |
adx |
30 |
*/ |
1103 |
|
|
void |
1104 |
michael |
5797 |
conf_add_class_to_conf(struct MaskItem *conf, const char *name) |
1105 |
adx |
30 |
{ |
1106 |
michael |
5797 |
if (EmptyString(name) || (conf->class = class_find(name, 1)) == NULL) |
1107 |
adx |
30 |
{ |
1108 |
michael |
1632 |
conf->class = class_default; |
1109 |
michael |
671 |
|
1110 |
michael |
4941 |
if (conf->type == CONF_CLIENT || conf->type == CONF_OPER) |
1111 |
michael |
6318 |
sendto_realops_flags(UMODE_SERVNOTICE, L_ADMIN, SEND_NOTICE, |
1112 |
michael |
2182 |
"Warning *** Defaulting to default class for %s@%s", |
1113 |
|
|
conf->user, conf->host); |
1114 |
adx |
30 |
else |
1115 |
michael |
6318 |
sendto_realops_flags(UMODE_SERVNOTICE, L_ADMIN, SEND_NOTICE, |
1116 |
michael |
2182 |
"Warning *** Defaulting to default class for %s", |
1117 |
|
|
conf->name); |
1118 |
adx |
30 |
} |
1119 |
|
|
} |
1120 |
|
|
|
1121 |
|
|
/* yyerror() |
1122 |
|
|
* |
1123 |
|
|
* inputs - message from parser |
1124 |
|
|
* output - NONE |
1125 |
|
|
* side effects - message to opers and log file entry is made |
1126 |
|
|
*/ |
1127 |
|
|
void |
1128 |
|
|
yyerror(const char *msg) |
1129 |
|
|
{ |
1130 |
michael |
967 |
if (conf_parser_ctx.pass != 1) |
1131 |
adx |
30 |
return; |
1132 |
|
|
|
1133 |
michael |
7789 |
const char *p = stripws(linebuf); |
1134 |
michael |
6318 |
sendto_realops_flags(UMODE_SERVNOTICE, L_ADMIN, SEND_NOTICE, |
1135 |
michael |
1618 |
"\"%s\", line %u: %s: %s", |
1136 |
michael |
7746 |
conffilebuf, lineno, msg, p); |
1137 |
michael |
1247 |
ilog(LOG_TYPE_IRCD, "\"%s\", line %u: %s: %s", |
1138 |
michael |
7746 |
conffilebuf, lineno, msg, p); |
1139 |
adx |
30 |
} |
1140 |
|
|
|
1141 |
michael |
1751 |
void |
1142 |
|
|
conf_error_report(const char *msg) |
1143 |
|
|
{ |
1144 |
michael |
7789 |
const char *p = stripws(linebuf); |
1145 |
michael |
6318 |
sendto_realops_flags(UMODE_SERVNOTICE, L_ADMIN, SEND_NOTICE, |
1146 |
michael |
1751 |
"\"%s\", line %u: %s: %s", |
1147 |
michael |
7777 |
conffilebuf, lineno, msg, p); |
1148 |
michael |
1751 |
ilog(LOG_TYPE_IRCD, "\"%s\", line %u: %s: %s", |
1149 |
michael |
7777 |
conffilebuf, lineno, msg, p); |
1150 |
michael |
1751 |
} |
1151 |
|
|
|
1152 |
adx |
30 |
/* |
1153 |
|
|
* valid_tkline() |
1154 |
michael |
2916 |
* |
1155 |
adx |
30 |
* inputs - pointer to ascii string to check |
1156 |
|
|
* - whether the specified time is in seconds or minutes |
1157 |
|
|
* output - -1 not enough parameters |
1158 |
|
|
* - 0 if not an integer number, else the number |
1159 |
|
|
* side effects - none |
1160 |
|
|
* Originally written by Dianora (Diane, db@db.net) |
1161 |
|
|
*/ |
1162 |
michael |
7330 |
uintmax_t |
1163 |
michael |
2313 |
valid_tkline(const char *data, const int minutes) |
1164 |
adx |
30 |
{ |
1165 |
michael |
2313 |
const unsigned char *p = (const unsigned char *)data; |
1166 |
|
|
unsigned char tmpch = '\0'; |
1167 |
michael |
7330 |
uintmax_t result = 0; |
1168 |
adx |
30 |
|
1169 |
michael |
2313 |
while ((tmpch = *p++)) |
1170 |
adx |
30 |
{ |
1171 |
michael |
2313 |
if (!IsDigit(tmpch)) |
1172 |
michael |
1121 |
return 0; |
1173 |
michael |
1120 |
|
1174 |
|
|
result *= 10; |
1175 |
michael |
2313 |
result += (tmpch & 0xF); |
1176 |
adx |
30 |
} |
1177 |
|
|
|
1178 |
michael |
1120 |
/* |
1179 |
michael |
2916 |
* In the degenerate case where oper does a /quote kline 0 user@host :reason |
1180 |
michael |
5583 |
* i.e. they specifically use 0, I am going to return 1 instead as a return |
1181 |
|
|
* value of non-zero is used to flag it as a temporary kline |
1182 |
adx |
30 |
*/ |
1183 |
|
|
if (result == 0) |
1184 |
|
|
result = 1; |
1185 |
|
|
|
1186 |
michael |
2916 |
/* |
1187 |
adx |
30 |
* If the incoming time is in seconds convert it to minutes for the purpose |
1188 |
|
|
* of this calculation |
1189 |
|
|
*/ |
1190 |
|
|
if (!minutes) |
1191 |
michael |
2916 |
result = result / 60; |
1192 |
adx |
30 |
|
1193 |
|
|
if (result > MAX_TDKLINE_TIME) |
1194 |
|
|
result = MAX_TDKLINE_TIME; |
1195 |
|
|
|
1196 |
michael |
5583 |
result = result * 60; /* Turn it into seconds */ |
1197 |
adx |
30 |
|
1198 |
|
|
return result; |
1199 |
|
|
} |
1200 |
|
|
|
1201 |
michael |
2130 |
/* valid_wild_card_simple() |
1202 |
|
|
* |
1203 |
|
|
* inputs - data to check for sufficient non-wildcard characters |
1204 |
|
|
* outputs - 1 if valid, else 0 |
1205 |
|
|
* side effects - none |
1206 |
|
|
*/ |
1207 |
|
|
int |
1208 |
|
|
valid_wild_card_simple(const char *data) |
1209 |
|
|
{ |
1210 |
|
|
const unsigned char *p = (const unsigned char *)data; |
1211 |
|
|
unsigned char tmpch = '\0'; |
1212 |
michael |
6332 |
unsigned int nonwild = 0, wild = 0; |
1213 |
michael |
2130 |
|
1214 |
|
|
while ((tmpch = *p++)) |
1215 |
|
|
{ |
1216 |
michael |
4265 |
if (tmpch == '\\' && *p) |
1217 |
michael |
2130 |
{ |
1218 |
|
|
++p; |
1219 |
michael |
4340 |
if (++nonwild >= ConfigGeneral.min_nonwildcard_simple) |
1220 |
michael |
2130 |
return 1; |
1221 |
|
|
} |
1222 |
|
|
else if (!IsMWildChar(tmpch)) |
1223 |
|
|
{ |
1224 |
michael |
4340 |
if (++nonwild >= ConfigGeneral.min_nonwildcard_simple) |
1225 |
michael |
2130 |
return 1; |
1226 |
|
|
} |
1227 |
michael |
6332 |
else |
1228 |
|
|
++wild; |
1229 |
michael |
2130 |
} |
1230 |
|
|
|
1231 |
michael |
6332 |
return !wild; |
1232 |
michael |
2130 |
} |
1233 |
|
|
|
1234 |
adx |
30 |
/* valid_wild_card() |
1235 |
|
|
* |
1236 |
|
|
* input - pointer to client |
1237 |
|
|
* - int flag, 0 for no warning oper 1 for warning oper |
1238 |
|
|
* - count of following varargs to check |
1239 |
|
|
* output - 0 if not valid, 1 if valid |
1240 |
|
|
* side effects - NOTICE is given to source_p if warn is 1 |
1241 |
|
|
*/ |
1242 |
|
|
int |
1243 |
michael |
7429 |
valid_wild_card(int count, ...) |
1244 |
adx |
30 |
{ |
1245 |
michael |
3931 |
unsigned char tmpch = '\0'; |
1246 |
michael |
3870 |
unsigned int nonwild = 0; |
1247 |
adx |
30 |
va_list args; |
1248 |
|
|
|
1249 |
|
|
/* |
1250 |
|
|
* Now we must check the user and host to make sure there |
1251 |
|
|
* are at least NONWILDCHARS non-wildcard characters in |
1252 |
|
|
* them, otherwise assume they are attempting to kline |
1253 |
|
|
* *@* or some variant of that. This code will also catch |
1254 |
|
|
* people attempting to kline *@*.tld, as long as NONWILDCHARS |
1255 |
|
|
* is greater than 3. In that case, there are only 3 non-wild |
1256 |
|
|
* characters (tld), so if NONWILDCHARS is 4, the kline will |
1257 |
|
|
* be disallowed. |
1258 |
|
|
* -wnder |
1259 |
|
|
*/ |
1260 |
|
|
|
1261 |
|
|
va_start(args, count); |
1262 |
|
|
|
1263 |
|
|
while (count--) |
1264 |
|
|
{ |
1265 |
michael |
3931 |
const unsigned char *p = va_arg(args, const unsigned char *); |
1266 |
adx |
30 |
if (p == NULL) |
1267 |
|
|
continue; |
1268 |
|
|
|
1269 |
|
|
while ((tmpch = *p++)) |
1270 |
|
|
{ |
1271 |
|
|
if (!IsKWildChar(tmpch)) |
1272 |
|
|
{ |
1273 |
|
|
/* |
1274 |
|
|
* If we find enough non-wild characters, we can |
1275 |
|
|
* break - no point in searching further. |
1276 |
|
|
*/ |
1277 |
michael |
4340 |
if (++nonwild >= ConfigGeneral.min_nonwildcard) |
1278 |
michael |
2659 |
{ |
1279 |
|
|
va_end(args); |
1280 |
adx |
30 |
return 1; |
1281 |
michael |
2659 |
} |
1282 |
adx |
30 |
} |
1283 |
|
|
} |
1284 |
|
|
} |
1285 |
|
|
|
1286 |
michael |
2659 |
va_end(args); |
1287 |
adx |
30 |
return 0; |
1288 |
|
|
} |
1289 |
|
|
|
1290 |
michael |
4982 |
/* find_user_host() |
1291 |
|
|
* |
1292 |
|
|
* inputs - pointer to client placing kline |
1293 |
|
|
* - pointer to user_host_or_nick |
1294 |
|
|
* - pointer to user buffer |
1295 |
|
|
* - pointer to host buffer |
1296 |
|
|
* output - 0 if not ok to kline, 1 to kline i.e. if valid user host |
1297 |
|
|
* side effects - |
1298 |
|
|
*/ |
1299 |
|
|
static int |
1300 |
|
|
find_user_host(struct Client *source_p, char *user_host_or_nick, |
1301 |
michael |
5783 |
char *luser, char *lhost) |
1302 |
michael |
4982 |
{ |
1303 |
|
|
struct Client *target_p = NULL; |
1304 |
|
|
char *hostp = NULL; |
1305 |
|
|
|
1306 |
|
|
if (lhost == NULL) |
1307 |
|
|
{ |
1308 |
|
|
strlcpy(luser, user_host_or_nick, USERLEN*4 + 1); |
1309 |
|
|
return 1; |
1310 |
|
|
} |
1311 |
|
|
|
1312 |
|
|
if ((hostp = strchr(user_host_or_nick, '@')) || *user_host_or_nick == '*') |
1313 |
|
|
{ |
1314 |
|
|
/* Explicit user@host mask given */ |
1315 |
|
|
if (hostp) /* I'm a little user@host */ |
1316 |
|
|
{ |
1317 |
|
|
*(hostp++) = '\0'; /* short and squat */ |
1318 |
|
|
|
1319 |
|
|
if (*user_host_or_nick) |
1320 |
|
|
strlcpy(luser, user_host_or_nick, USERLEN*4 + 1); /* here is my user */ |
1321 |
|
|
else |
1322 |
|
|
strcpy(luser, "*"); |
1323 |
|
|
|
1324 |
|
|
if (*hostp) |
1325 |
|
|
strlcpy(lhost, hostp, HOSTLEN + 1); /* here is my host */ |
1326 |
|
|
else |
1327 |
|
|
strcpy(lhost, "*"); |
1328 |
|
|
} |
1329 |
|
|
else |
1330 |
|
|
{ |
1331 |
|
|
luser[0] = '*'; /* no @ found, assume its *@somehost */ |
1332 |
|
|
luser[1] = '\0'; |
1333 |
|
|
strlcpy(lhost, user_host_or_nick, HOSTLEN*4 + 1); |
1334 |
|
|
} |
1335 |
|
|
|
1336 |
|
|
return 1; |
1337 |
|
|
} |
1338 |
|
|
else |
1339 |
|
|
{ |
1340 |
|
|
/* Try to find user@host mask from nick */ |
1341 |
|
|
/* Okay to use source_p as the first param, because source_p == client_p */ |
1342 |
|
|
if ((target_p = |
1343 |
|
|
find_chasing(source_p, user_host_or_nick)) == NULL) |
1344 |
|
|
return 0; /* find_chasing sends ERR_NOSUCHNICK */ |
1345 |
|
|
|
1346 |
michael |
6313 |
if (HasFlag(target_p, FLAGS_EXEMPTKLINE)) |
1347 |
michael |
4982 |
{ |
1348 |
|
|
if (IsClient(source_p)) |
1349 |
|
|
sendto_one_notice(source_p, &me, ":%s is E-lined", target_p->name); |
1350 |
|
|
return 0; |
1351 |
|
|
} |
1352 |
|
|
|
1353 |
|
|
/* |
1354 |
michael |
5583 |
* Turn the "user" bit into "*user", blow away '~' |
1355 |
michael |
4982 |
* if found in original user name (non-idented) |
1356 |
|
|
*/ |
1357 |
|
|
strlcpy(luser, target_p->username, USERLEN*4 + 1); |
1358 |
|
|
|
1359 |
|
|
if (target_p->username[0] == '~') |
1360 |
|
|
luser[0] = '*'; |
1361 |
|
|
|
1362 |
michael |
6831 |
strlcpy(lhost, target_p->sockhost, HOSTLEN*4 + 1); |
1363 |
michael |
4982 |
return 1; |
1364 |
|
|
} |
1365 |
|
|
|
1366 |
|
|
return 0; |
1367 |
|
|
} |
1368 |
|
|
|
1369 |
adx |
30 |
/* XXX should this go into a separate file ? -Dianora */ |
1370 |
|
|
/* parse_aline |
1371 |
|
|
* |
1372 |
|
|
* input - pointer to cmd name being used |
1373 |
|
|
* - pointer to client using cmd |
1374 |
|
|
* - parc parameter count |
1375 |
|
|
* - parv[] list of parameters to parse |
1376 |
|
|
* - parse_flags bit map of things to test |
1377 |
|
|
* - pointer to user or string to parse into |
1378 |
|
|
* - pointer to host or NULL to parse into if non NULL |
1379 |
michael |
2916 |
* - pointer to optional tkline time or NULL |
1380 |
adx |
30 |
* - pointer to target_server to parse into if non NULL |
1381 |
|
|
* - pointer to reason to parse into |
1382 |
|
|
* |
1383 |
michael |
5776 |
* output - 1 if valid, 0 if not valid |
1384 |
adx |
30 |
* side effects - A generalised k/d/x etc. line parser, |
1385 |
|
|
* "ALINE [time] user@host|string [ON] target :reason" |
1386 |
|
|
* will parse returning a parsed user, host if |
1387 |
|
|
* h_p pointer is non NULL, string otherwise. |
1388 |
|
|
* if tkline_time pointer is non NULL a tk line will be set |
1389 |
|
|
* to non zero if found. |
1390 |
|
|
* if tkline_time pointer is NULL and tk line is found, |
1391 |
|
|
* error is reported. |
1392 |
|
|
* if target_server is NULL and an "ON" is found error |
1393 |
|
|
* is reported. |
1394 |
|
|
* if reason pointer is NULL ignore pointer, |
1395 |
db |
936 |
* this allows use of parse_a_line in unkline etc. |
1396 |
adx |
30 |
* |
1397 |
|
|
* - Dianora |
1398 |
|
|
*/ |
1399 |
|
|
int |
1400 |
|
|
parse_aline(const char *cmd, struct Client *source_p, |
1401 |
michael |
2182 |
int parc, char **parv, |
1402 |
michael |
7429 |
char **up_p, char **h_p, uintmax_t *tkline_time, |
1403 |
michael |
2182 |
char **target_server, char **reason) |
1404 |
adx |
30 |
{ |
1405 |
michael |
7429 |
uintmax_t found_tkline_time=0; |
1406 |
michael |
5823 |
static char default_reason[] = CONF_NOREASON; |
1407 |
adx |
30 |
static char user[USERLEN*4+1]; |
1408 |
|
|
static char host[HOSTLEN*4+1]; |
1409 |
|
|
|
1410 |
|
|
parv++; |
1411 |
|
|
parc--; |
1412 |
|
|
|
1413 |
|
|
found_tkline_time = valid_tkline(*parv, TK_MINUTES); |
1414 |
|
|
|
1415 |
michael |
4982 |
if (found_tkline_time) |
1416 |
adx |
30 |
{ |
1417 |
|
|
parv++; |
1418 |
|
|
parc--; |
1419 |
|
|
|
1420 |
michael |
4982 |
if (tkline_time) |
1421 |
adx |
30 |
*tkline_time = found_tkline_time; |
1422 |
|
|
else |
1423 |
|
|
{ |
1424 |
michael |
3110 |
sendto_one_notice(source_p, &me, ":temp_line not supported by %s", cmd); |
1425 |
michael |
5776 |
return 0; |
1426 |
adx |
30 |
} |
1427 |
|
|
} |
1428 |
|
|
|
1429 |
|
|
if (parc == 0) |
1430 |
|
|
{ |
1431 |
michael |
3109 |
sendto_one_numeric(source_p, &me, ERR_NEEDMOREPARAMS, cmd); |
1432 |
michael |
5776 |
return 0; |
1433 |
adx |
30 |
} |
1434 |
|
|
|
1435 |
|
|
if (h_p == NULL) |
1436 |
|
|
*up_p = *parv; |
1437 |
|
|
else |
1438 |
|
|
{ |
1439 |
michael |
5783 |
if (find_user_host(source_p, *parv, user, host) == 0) |
1440 |
michael |
5776 |
return 0; |
1441 |
adx |
30 |
|
1442 |
|
|
*up_p = user; |
1443 |
|
|
*h_p = host; |
1444 |
|
|
} |
1445 |
michael |
2916 |
|
1446 |
adx |
30 |
parc--; |
1447 |
|
|
parv++; |
1448 |
|
|
|
1449 |
michael |
4982 |
if (parc) |
1450 |
adx |
30 |
{ |
1451 |
|
|
if (irccmp(*parv, "ON") == 0) |
1452 |
|
|
{ |
1453 |
|
|
parc--; |
1454 |
|
|
parv++; |
1455 |
|
|
|
1456 |
michael |
1219 |
if (!HasOFlag(source_p, OPER_FLAG_REMOTEBAN)) |
1457 |
adx |
30 |
{ |
1458 |
michael |
3109 |
sendto_one_numeric(source_p, &me, ERR_NOPRIVS, "remoteban"); |
1459 |
michael |
5776 |
return 0; |
1460 |
adx |
30 |
} |
1461 |
|
|
|
1462 |
|
|
if (parc == 0 || EmptyString(*parv)) |
1463 |
|
|
{ |
1464 |
michael |
3109 |
sendto_one_numeric(source_p, &me, ERR_NEEDMOREPARAMS, cmd); |
1465 |
michael |
5776 |
return 0; |
1466 |
adx |
30 |
} |
1467 |
|
|
|
1468 |
|
|
*target_server = *parv; |
1469 |
|
|
parc--; |
1470 |
|
|
parv++; |
1471 |
|
|
} |
1472 |
|
|
else |
1473 |
|
|
{ |
1474 |
|
|
/* Make sure target_server *is* NULL if no ON server found |
1475 |
|
|
* caller probably NULL'd it first, but no harm to do it again -db |
1476 |
|
|
*/ |
1477 |
michael |
4982 |
if (target_server) |
1478 |
michael |
2182 |
*target_server = NULL; |
1479 |
adx |
30 |
} |
1480 |
|
|
} |
1481 |
|
|
|
1482 |
michael |
4982 |
if (reason) |
1483 |
adx |
30 |
{ |
1484 |
michael |
4982 |
if (parc && !EmptyString(*parv)) |
1485 |
adx |
30 |
*reason = *parv; |
1486 |
|
|
else |
1487 |
michael |
5823 |
*reason = default_reason; |
1488 |
adx |
30 |
} |
1489 |
|
|
|
1490 |
|
|
return 1; |
1491 |
|
|
} |
1492 |
|
|
|
1493 |
|
|
/* match_conf_password() |
1494 |
|
|
* |
1495 |
|
|
* inputs - pointer to given password |
1496 |
|
|
* - pointer to Conf |
1497 |
|
|
* output - 1 or 0 if match |
1498 |
|
|
* side effects - none |
1499 |
|
|
*/ |
1500 |
|
|
int |
1501 |
michael |
1632 |
match_conf_password(const char *password, const struct MaskItem *conf) |
1502 |
adx |
30 |
{ |
1503 |
|
|
const char *encr = NULL; |
1504 |
|
|
|
1505 |
michael |
1632 |
if (EmptyString(password) || EmptyString(conf->passwd)) |
1506 |
adx |
30 |
return 0; |
1507 |
|
|
|
1508 |
michael |
1632 |
if (conf->flags & CONF_FLAGS_ENCRYPTED) |
1509 |
|
|
encr = crypt(password, conf->passwd); |
1510 |
adx |
30 |
else |
1511 |
|
|
encr = password; |
1512 |
|
|
|
1513 |
michael |
3263 |
return encr && !strcmp(encr, conf->passwd); |
1514 |
adx |
30 |
} |
1515 |
|
|
|
1516 |
|
|
/* |
1517 |
|
|
* split_nuh |
1518 |
|
|
* |
1519 |
|
|
* inputs - pointer to original mask (modified in place) |
1520 |
|
|
* - pointer to pointer where nick should go |
1521 |
|
|
* - pointer to pointer where user should go |
1522 |
|
|
* - pointer to pointer where host should go |
1523 |
|
|
* output - NONE |
1524 |
|
|
* side effects - mask is modified in place |
1525 |
|
|
* If nick pointer is NULL, ignore writing to it |
1526 |
|
|
* this allows us to use this function elsewhere. |
1527 |
|
|
* |
1528 |
|
|
* mask nick user host |
1529 |
|
|
* ---------------------- ------- ------- ------ |
1530 |
|
|
* Dianora!db@db.net Dianora db db.net |
1531 |
|
|
* Dianora Dianora * * |
1532 |
|
|
* db.net * * db.net |
1533 |
|
|
* OR if nick pointer is NULL |
1534 |
|
|
* Dianora - * Dianora |
1535 |
|
|
* Dianora! Dianora * * |
1536 |
|
|
* Dianora!@ Dianora * * |
1537 |
|
|
* Dianora!db Dianora db * |
1538 |
|
|
* Dianora!@db.net Dianora * db.net |
1539 |
|
|
* db@db.net * db db.net |
1540 |
|
|
* !@ * * * |
1541 |
|
|
* @ * * * |
1542 |
|
|
* ! * * * |
1543 |
|
|
*/ |
1544 |
|
|
void |
1545 |
michael |
593 |
split_nuh(struct split_nuh_item *const iptr) |
1546 |
adx |
30 |
{ |
1547 |
|
|
char *p = NULL, *q = NULL; |
1548 |
|
|
|
1549 |
michael |
593 |
if (iptr->nickptr) |
1550 |
|
|
strlcpy(iptr->nickptr, "*", iptr->nicksize); |
1551 |
michael |
4982 |
|
1552 |
michael |
593 |
if (iptr->userptr) |
1553 |
|
|
strlcpy(iptr->userptr, "*", iptr->usersize); |
1554 |
michael |
4982 |
|
1555 |
michael |
593 |
if (iptr->hostptr) |
1556 |
|
|
strlcpy(iptr->hostptr, "*", iptr->hostsize); |
1557 |
|
|
|
1558 |
|
|
if ((p = strchr(iptr->nuhmask, '!'))) |
1559 |
adx |
30 |
{ |
1560 |
|
|
*p = '\0'; |
1561 |
|
|
|
1562 |
michael |
3375 |
if (iptr->nickptr && *iptr->nuhmask) |
1563 |
michael |
593 |
strlcpy(iptr->nickptr, iptr->nuhmask, iptr->nicksize); |
1564 |
adx |
30 |
|
1565 |
michael |
2525 |
if ((q = strchr(++p, '@'))) |
1566 |
|
|
{ |
1567 |
michael |
593 |
*q++ = '\0'; |
1568 |
|
|
|
1569 |
michael |
3375 |
if (*p) |
1570 |
michael |
593 |
strlcpy(iptr->userptr, p, iptr->usersize); |
1571 |
adx |
30 |
|
1572 |
michael |
3375 |
if (*q) |
1573 |
michael |
593 |
strlcpy(iptr->hostptr, q, iptr->hostsize); |
1574 |
adx |
30 |
} |
1575 |
|
|
else |
1576 |
|
|
{ |
1577 |
michael |
3375 |
if (*p) |
1578 |
michael |
593 |
strlcpy(iptr->userptr, p, iptr->usersize); |
1579 |
adx |
30 |
} |
1580 |
|
|
} |
1581 |
michael |
593 |
else |
1582 |
adx |
30 |
{ |
1583 |
michael |
593 |
/* No ! found so lets look for a user@host */ |
1584 |
|
|
if ((p = strchr(iptr->nuhmask, '@'))) |
1585 |
adx |
30 |
{ |
1586 |
michael |
593 |
/* if found a @ */ |
1587 |
|
|
*p++ = '\0'; |
1588 |
adx |
30 |
|
1589 |
michael |
3375 |
if (*iptr->nuhmask) |
1590 |
michael |
593 |
strlcpy(iptr->userptr, iptr->nuhmask, iptr->usersize); |
1591 |
adx |
30 |
|
1592 |
michael |
3375 |
if (*p) |
1593 |
michael |
593 |
strlcpy(iptr->hostptr, p, iptr->hostsize); |
1594 |
adx |
30 |
} |
1595 |
michael |
593 |
else |
1596 |
adx |
30 |
{ |
1597 |
michael |
5583 |
/* No @ found */ |
1598 |
michael |
593 |
if (!iptr->nickptr || strpbrk(iptr->nuhmask, ".:")) |
1599 |
|
|
strlcpy(iptr->hostptr, iptr->nuhmask, iptr->hostsize); |
1600 |
adx |
30 |
else |
1601 |
michael |
593 |
strlcpy(iptr->nickptr, iptr->nuhmask, iptr->nicksize); |
1602 |
adx |
30 |
} |
1603 |
|
|
} |
1604 |
|
|
} |