| 1 |
/* |
| 2 |
* ircd-hybrid: an advanced, lightweight Internet Relay Chat Daemon (ircd) |
| 3 |
* |
| 4 |
* Copyright (c) 1997-2018 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 conf.c |
| 23 |
* \brief Configuration file functions. |
| 24 |
* \version $Id$ |
| 25 |
*/ |
| 26 |
|
| 27 |
#include "stdinc.h" |
| 28 |
#include "list.h" |
| 29 |
#include "ircd_defs.h" |
| 30 |
#include "parse.h" |
| 31 |
#include "conf.h" |
| 32 |
#include "conf_cluster.h" |
| 33 |
#include "conf_gecos.h" |
| 34 |
#include "conf_pseudo.h" |
| 35 |
#include "conf_resv.h" |
| 36 |
#include "conf_service.h" |
| 37 |
#include "conf_shared.h" |
| 38 |
#include "server.h" |
| 39 |
#include "channel.h" |
| 40 |
#include "client.h" |
| 41 |
#include "event.h" |
| 42 |
#include "irc_string.h" |
| 43 |
#include "s_bsd.h" |
| 44 |
#include "ircd.h" |
| 45 |
#include "listener.h" |
| 46 |
#include "hostmask.h" |
| 47 |
#include "modules.h" |
| 48 |
#include "numeric.h" |
| 49 |
#include "fdlist.h" |
| 50 |
#include "log.h" |
| 51 |
#include "send.h" |
| 52 |
#include "memory.h" |
| 53 |
#include "res.h" |
| 54 |
#include "userhost.h" |
| 55 |
#include "user.h" |
| 56 |
#include "channel_mode.h" |
| 57 |
#include "misc.h" |
| 58 |
#include "conf_db.h" |
| 59 |
#include "conf_class.h" |
| 60 |
#include "motd.h" |
| 61 |
#include "ipcache.h" |
| 62 |
#include "isupport.h" |
| 63 |
#include "whowas.h" |
| 64 |
|
| 65 |
|
| 66 |
struct config_channel_entry ConfigChannel; |
| 67 |
struct config_serverhide_entry ConfigServerHide; |
| 68 |
struct config_general_entry ConfigGeneral; |
| 69 |
struct config_log_entry ConfigLog = { .use_logging = 1 }; |
| 70 |
struct config_serverinfo_entry ConfigServerInfo; |
| 71 |
struct config_admin_entry ConfigAdminInfo; |
| 72 |
struct conf_parser_context conf_parser_ctx; |
| 73 |
|
| 74 |
/* general conf items link list root, other than k lines etc. */ |
| 75 |
dlink_list connect_items; |
| 76 |
dlink_list operator_items; |
| 77 |
|
| 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 |
* inputs - pointer to struct MaskItem |
| 87 |
* - 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 |
conf_dns_callback(void *vptr, const struct irc_ssaddr *addr, const char *name, size_t namelength) |
| 96 |
{ |
| 97 |
struct MaskItem *const conf = vptr; |
| 98 |
|
| 99 |
conf->dns_pending = 0; |
| 100 |
|
| 101 |
if (addr) |
| 102 |
memcpy(&conf->addr, addr, sizeof(conf->addr)); |
| 103 |
else |
| 104 |
conf->dns_failed = 1; |
| 105 |
} |
| 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 |
conf_dns_lookup(struct MaskItem *conf) |
| 115 |
{ |
| 116 |
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 |
{ |
| 138 |
case CONF_OPER: |
| 139 |
return &operator_items; |
| 140 |
break; |
| 141 |
case CONF_SERVER: |
| 142 |
return &connect_items; |
| 143 |
break; |
| 144 |
default: |
| 145 |
return NULL; |
| 146 |
} |
| 147 |
} |
| 148 |
|
| 149 |
struct MaskItem * |
| 150 |
conf_make(enum maskitem_type type) |
| 151 |
{ |
| 152 |
struct MaskItem *const conf = xcalloc(sizeof(*conf)); |
| 153 |
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 |
dlink_node *node = NULL, *node_next = NULL; |
| 168 |
dlink_list *list = NULL; |
| 169 |
|
| 170 |
if ((list = map_to_list(conf->type))) |
| 171 |
dlinkFindDelete(list, conf); |
| 172 |
|
| 173 |
xfree(conf->name); |
| 174 |
|
| 175 |
if (conf->dns_pending) |
| 176 |
delete_resolver_queries(conf); |
| 177 |
if (conf->passwd) |
| 178 |
memset(conf->passwd, 0, strlen(conf->passwd)); |
| 179 |
if (conf->spasswd) |
| 180 |
memset(conf->spasswd, 0, strlen(conf->spasswd)); |
| 181 |
|
| 182 |
conf->class = NULL; |
| 183 |
|
| 184 |
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 |
|
| 193 |
DLINK_FOREACH_SAFE(node, node_next, conf->hub_list.head) |
| 194 |
{ |
| 195 |
xfree(node->data); |
| 196 |
dlinkDelete(node, &conf->hub_list); |
| 197 |
free_dlink_node(node); |
| 198 |
} |
| 199 |
|
| 200 |
DLINK_FOREACH_SAFE(node, node_next, conf->leaf_list.head) |
| 201 |
{ |
| 202 |
xfree(node->data); |
| 203 |
dlinkDelete(node, &conf->leaf_list); |
| 204 |
free_dlink_node(node); |
| 205 |
} |
| 206 |
|
| 207 |
xfree(conf); |
| 208 |
} |
| 209 |
|
| 210 |
/* attach_iline() |
| 211 |
* |
| 212 |
* inputs - client pointer |
| 213 |
* - conf pointer |
| 214 |
* output - |
| 215 |
* side effects - do actual attach |
| 216 |
*/ |
| 217 |
static int |
| 218 |
attach_iline(struct Client *client_p, struct MaskItem *conf) |
| 219 |
{ |
| 220 |
const struct ClassItem *const class = conf->class; |
| 221 |
struct ip_entry *ip_found; |
| 222 |
int a_limit_reached = 0; |
| 223 |
unsigned int local = 0, global = 0; |
| 224 |
|
| 225 |
ip_found = ipcache_find_or_add_address(&client_p->connection->ip); |
| 226 |
ip_found->count++; |
| 227 |
AddFlag(client_p, FLAGS_IPHASH); |
| 228 |
|
| 229 |
userhost_count(client_p->sockhost, &global, &local); |
| 230 |
|
| 231 |
/* 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 |
else if (class->max_local && local >= class->max_local) /* XXX: redundant */ |
| 240 |
a_limit_reached = 1; |
| 241 |
else if (class->max_global && global >= class->max_global) |
| 242 |
a_limit_reached = 1; |
| 243 |
|
| 244 |
if (a_limit_reached) |
| 245 |
{ |
| 246 |
if (!IsConfExemptLimits(conf)) |
| 247 |
return TOO_MANY; /* Already at maximum allowed */ |
| 248 |
|
| 249 |
sendto_one_notice(client_p, &me, ":*** Your connection class is full, " |
| 250 |
"but you have exceed_limit = yes;"); |
| 251 |
} |
| 252 |
|
| 253 |
return conf_attach(client_p, conf); |
| 254 |
} |
| 255 |
|
| 256 |
/* verify_access() |
| 257 |
* |
| 258 |
* 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 |
*/ |
| 262 |
static int |
| 263 |
verify_access(struct Client *client_p) |
| 264 |
{ |
| 265 |
struct MaskItem *conf = NULL; |
| 266 |
|
| 267 |
if (HasFlag(client_p, FLAGS_GOTID)) |
| 268 |
{ |
| 269 |
conf = find_address_conf(client_p->host, client_p->username, |
| 270 |
&client_p->connection->ip, |
| 271 |
client_p->connection->aftype, |
| 272 |
client_p->connection->password); |
| 273 |
} |
| 274 |
else |
| 275 |
{ |
| 276 |
char non_ident[USERLEN + 1] = "~"; |
| 277 |
|
| 278 |
strlcpy(non_ident + 1, client_p->username, sizeof(non_ident) - 1); |
| 279 |
conf = find_address_conf(client_p->host, non_ident, |
| 280 |
&client_p->connection->ip, |
| 281 |
client_p->connection->aftype, |
| 282 |
client_p->connection->password); |
| 283 |
} |
| 284 |
|
| 285 |
if (!conf) |
| 286 |
return NOT_AUTHORIZED; |
| 287 |
|
| 288 |
assert(IsConfClient(conf) || IsConfKill(conf)); |
| 289 |
|
| 290 |
if (IsConfClient(conf)) |
| 291 |
{ |
| 292 |
if (IsConfRedir(conf)) |
| 293 |
{ |
| 294 |
sendto_one_numeric(client_p, &me, RPL_REDIR, |
| 295 |
conf->name ? conf->name : "", |
| 296 |
conf->port); |
| 297 |
return NOT_AUTHORIZED; |
| 298 |
} |
| 299 |
|
| 300 |
if (IsConfDoSpoofIp(conf)) |
| 301 |
{ |
| 302 |
if (IsConfSpoofNotice(conf)) |
| 303 |
sendto_realops_flags(UMODE_SERVNOTICE, L_ADMIN, SEND_NOTICE, "%s spoofing: %s as %s", |
| 304 |
client_p->name, client_p->host, conf->name); |
| 305 |
|
| 306 |
strlcpy(client_p->host, conf->name, sizeof(client_p->host)); |
| 307 |
} |
| 308 |
|
| 309 |
return attach_iline(client_p, conf); |
| 310 |
} |
| 311 |
|
| 312 |
sendto_one_notice(client_p, &me, ":*** Banned: %s", conf->reason); |
| 313 |
return BANNED_CLIENT; |
| 314 |
} |
| 315 |
|
| 316 |
/* check_client() |
| 317 |
* |
| 318 |
* 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 |
*/ |
| 329 |
int |
| 330 |
check_client(struct Client *source_p) |
| 331 |
{ |
| 332 |
int i; |
| 333 |
|
| 334 |
if ((i = verify_access(source_p))) |
| 335 |
ilog(LOG_TYPE_IRCD, "Access denied: %s[%s]", |
| 336 |
source_p->name, source_p->sockhost); |
| 337 |
|
| 338 |
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 |
client_get_name(source_p, SHOW_IP), |
| 344 |
source_p->sockhost); |
| 345 |
ilog(LOG_TYPE_IRCD, "Too many connections on IP from %s.", |
| 346 |
client_get_name(source_p, SHOW_IP)); |
| 347 |
++ServerStats.is_ref; |
| 348 |
exit_client(source_p, "No more connections allowed on that IP"); |
| 349 |
break; |
| 350 |
|
| 351 |
case I_LINE_FULL: |
| 352 |
sendto_realops_flags(UMODE_FULL, L_ALL, SEND_NOTICE, |
| 353 |
"auth {} block is full for %s (%s).", |
| 354 |
client_get_name(source_p, SHOW_IP), |
| 355 |
source_p->sockhost); |
| 356 |
ilog(LOG_TYPE_IRCD, "Too many connections from %s.", |
| 357 |
client_get_name(source_p, SHOW_IP)); |
| 358 |
++ServerStats.is_ref; |
| 359 |
exit_client(source_p, "No more connections allowed in your connection class"); |
| 360 |
break; |
| 361 |
|
| 362 |
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 |
"Unauthorized client connection from %s on [%s/%u].", |
| 367 |
client_get_name(source_p, SHOW_IP), |
| 368 |
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 |
client_get_name(source_p, SHOW_IP), |
| 372 |
source_p->connection->listener->name, |
| 373 |
source_p->connection->listener->port); |
| 374 |
|
| 375 |
++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 |
} |
| 388 |
|
| 389 |
return !(i < 0); |
| 390 |
} |
| 391 |
|
| 392 |
/*! \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 |
*/ |
| 397 |
void |
| 398 |
conf_detach(struct Client *client_p, enum maskitem_type type) |
| 399 |
{ |
| 400 |
dlink_node *node, *node_next; |
| 401 |
|
| 402 |
DLINK_FOREACH_SAFE(node, node_next, client_p->connection->confs.head) |
| 403 |
{ |
| 404 |
struct MaskItem *conf = node->data; |
| 405 |
|
| 406 |
assert(conf->type & (CONF_CLIENT | CONF_OPER | CONF_SERVER)); |
| 407 |
assert(conf->ref_count > 0); |
| 408 |
assert(conf->class->ref_count > 0); |
| 409 |
|
| 410 |
if (!(conf->type & type)) |
| 411 |
continue; |
| 412 |
|
| 413 |
dlinkDelete(node, &client_p->connection->confs); |
| 414 |
free_dlink_node(node); |
| 415 |
|
| 416 |
if (conf->type == CONF_CLIENT) |
| 417 |
remove_from_cidr_check(&client_p->connection->ip, conf->class); |
| 418 |
|
| 419 |
if (--conf->class->ref_count == 0 && conf->class->active == 0) |
| 420 |
{ |
| 421 |
class_free(conf->class); |
| 422 |
conf->class = NULL; |
| 423 |
} |
| 424 |
|
| 425 |
if (--conf->ref_count == 0 && conf->active == 0) |
| 426 |
conf_free(conf); |
| 427 |
} |
| 428 |
} |
| 429 |
|
| 430 |
/*! \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 |
*/ |
| 436 |
int |
| 437 |
conf_attach(struct Client *client_p, struct MaskItem *conf) |
| 438 |
{ |
| 439 |
if (dlinkFind(&client_p->connection->confs, conf)) |
| 440 |
return 1; |
| 441 |
|
| 442 |
if (conf->type == CONF_CLIENT) |
| 443 |
if (cidr_limit_reached(IsConfExemptLimits(conf), |
| 444 |
&client_p->connection->ip, conf->class)) |
| 445 |
return TOO_MANY; /* Already at maximum allowed */ |
| 446 |
|
| 447 |
conf->class->ref_count++; |
| 448 |
conf->ref_count++; |
| 449 |
|
| 450 |
dlinkAdd(conf, make_dlink_node(), &client_p->connection->confs); |
| 451 |
|
| 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 |
struct MaskItem * |
| 465 |
find_conf_name(dlink_list *list, const char *name, enum maskitem_type type) |
| 466 |
{ |
| 467 |
dlink_node *node = NULL; |
| 468 |
|
| 469 |
DLINK_FOREACH(node, list->head) |
| 470 |
{ |
| 471 |
struct MaskItem *conf = node->data; |
| 472 |
|
| 473 |
if (conf->type == type) |
| 474 |
{ |
| 475 |
if (conf->name && !irccmp(conf->name, name)) |
| 476 |
return conf; |
| 477 |
} |
| 478 |
} |
| 479 |
|
| 480 |
return NULL; |
| 481 |
} |
| 482 |
|
| 483 |
/*! \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 |
*/ |
| 487 |
struct MaskItem * |
| 488 |
connect_find(const char *name, int (*compare)(const char *, const char *)) |
| 489 |
{ |
| 490 |
dlink_node *node; |
| 491 |
|
| 492 |
DLINK_FOREACH(node, connect_items.head) |
| 493 |
{ |
| 494 |
struct MaskItem *conf = node->data; |
| 495 |
|
| 496 |
if (!compare(name, conf->name)) |
| 497 |
return conf; |
| 498 |
} |
| 499 |
|
| 500 |
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 |
* output - NULL or pointer to found struct MaskItem |
| 510 |
* side effects - looks for an exact match on name field |
| 511 |
*/ |
| 512 |
struct MaskItem * |
| 513 |
operator_find(const struct Client *who, const char *name) |
| 514 |
{ |
| 515 |
dlink_node *node = NULL; |
| 516 |
|
| 517 |
DLINK_FOREACH(node, operator_items.head) |
| 518 |
{ |
| 519 |
struct MaskItem *conf = node->data; |
| 520 |
|
| 521 |
if (!irccmp(conf->name, name)) |
| 522 |
{ |
| 523 |
if (!who) |
| 524 |
return conf; |
| 525 |
|
| 526 |
if (!match(conf->user, who->username)) |
| 527 |
{ |
| 528 |
switch (conf->htype) |
| 529 |
{ |
| 530 |
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 |
if (!conf->class->max_total || conf->class->ref_count < conf->class->max_total) |
| 539 |
return conf; |
| 540 |
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 |
} |
| 550 |
} |
| 551 |
} |
| 552 |
} |
| 553 |
|
| 554 |
return NULL; |
| 555 |
} |
| 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 |
assert(class_default == class_get_list()->tail->data); |
| 573 |
|
| 574 |
ConfigServerInfo.network_name = xstrdup(NETWORK_NAME_DEFAULT); |
| 575 |
ConfigServerInfo.network_desc = xstrdup(NETWORK_DESC_DEFAULT); |
| 576 |
|
| 577 |
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 |
|
| 582 |
ConfigServerInfo.default_max_clients = MAXCLIENTS_MAX; |
| 583 |
ConfigServerInfo.max_nick_length = 9; |
| 584 |
ConfigServerInfo.max_topic_length = 80; |
| 585 |
ConfigServerInfo.hub = 0; |
| 586 |
|
| 587 |
log_del_all(); |
| 588 |
|
| 589 |
ConfigLog.use_logging = 1; |
| 590 |
|
| 591 |
ConfigChannel.disable_fake_channels = 0; |
| 592 |
ConfigChannel.invite_client_count = 10; |
| 593 |
ConfigChannel.invite_client_time = 300; |
| 594 |
ConfigChannel.invite_delay_channel = 5; |
| 595 |
ConfigChannel.invite_expire_time = 1800; |
| 596 |
ConfigChannel.knock_client_count = 1; |
| 597 |
ConfigChannel.knock_client_time = 300; |
| 598 |
ConfigChannel.knock_delay_channel = 60; |
| 599 |
ConfigChannel.max_channels = 25; |
| 600 |
ConfigChannel.max_invites = 20; |
| 601 |
ConfigChannel.max_bans = 100; |
| 602 |
ConfigChannel.max_bans_large = 500; |
| 603 |
ConfigChannel.default_join_flood_count = 18; |
| 604 |
ConfigChannel.default_join_flood_time = 6; |
| 605 |
|
| 606 |
ConfigServerHide.flatten_links = 0; |
| 607 |
ConfigServerHide.flatten_links_delay = 300; |
| 608 |
ConfigServerHide.hidden = 0; |
| 609 |
ConfigServerHide.hide_servers = 0; |
| 610 |
ConfigServerHide.hide_services = 0; |
| 611 |
ConfigServerHide.hidden_name = xstrdup(NETWORK_NAME_DEFAULT); |
| 612 |
ConfigServerHide.hide_server_ips = 0; |
| 613 |
ConfigServerHide.disable_remote_commands = 0; |
| 614 |
|
| 615 |
ConfigGeneral.away_count = 2; |
| 616 |
ConfigGeneral.away_time = 10; |
| 617 |
ConfigGeneral.max_watch = 50; |
| 618 |
ConfigGeneral.whowas_history_length = 15000; |
| 619 |
ConfigGeneral.cycle_on_host_change = 1; |
| 620 |
ConfigGeneral.dline_min_cidr = 16; |
| 621 |
ConfigGeneral.dline_min_cidr6 = 48; |
| 622 |
ConfigGeneral.kline_min_cidr = 16; |
| 623 |
ConfigGeneral.kline_min_cidr6 = 48; |
| 624 |
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 |
ConfigGeneral.default_floodtime = 1; |
| 631 |
ConfigGeneral.failed_oper_notice = 1; |
| 632 |
ConfigGeneral.dots_in_ident = 0; |
| 633 |
ConfigGeneral.min_nonwildcard = 4; |
| 634 |
ConfigGeneral.min_nonwildcard_simple = 3; |
| 635 |
ConfigGeneral.max_accept = 50; |
| 636 |
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 |
ConfigGeneral.ts_warn_delta = 30; |
| 641 |
ConfigGeneral.ts_max_delta = 600; |
| 642 |
ConfigGeneral.warn_no_connect_block = 1; |
| 643 |
ConfigGeneral.stats_e_disabled = 0; |
| 644 |
ConfigGeneral.stats_i_oper_only = 1; /* 1 = masked */ |
| 645 |
ConfigGeneral.stats_k_oper_only = 1; /* 1 = masked */ |
| 646 |
ConfigGeneral.stats_o_oper_only = 1; |
| 647 |
ConfigGeneral.stats_m_oper_only = 1; |
| 648 |
ConfigGeneral.stats_P_oper_only = 0; |
| 649 |
ConfigGeneral.stats_u_oper_only = 0; |
| 650 |
ConfigGeneral.caller_id_wait = 60; |
| 651 |
ConfigGeneral.opers_bypass_callerid = 1; |
| 652 |
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 |
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 |
ConfigGeneral.oper_umodes = UMODE_BOTS | UMODE_LOCOPS | UMODE_SERVNOTICE | UMODE_WALLOP; |
| 662 |
ConfigGeneral.throttle_count = 1; |
| 663 |
ConfigGeneral.throttle_time = 1; |
| 664 |
} |
| 665 |
|
| 666 |
static void |
| 667 |
validate_conf(void) |
| 668 |
{ |
| 669 |
if (EmptyString(ConfigServerInfo.network_name)) |
| 670 |
ConfigServerInfo.network_name = xstrdup(NETWORK_NAME_DEFAULT); |
| 671 |
|
| 672 |
if (EmptyString(ConfigServerInfo.network_desc)) |
| 673 |
ConfigServerInfo.network_desc = xstrdup(NETWORK_DESC_DEFAULT); |
| 674 |
} |
| 675 |
|
| 676 |
/* read_conf() |
| 677 |
* |
| 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 |
lineno = 1; |
| 686 |
|
| 687 |
set_default_conf(); /* Set default values prior to conf parsing */ |
| 688 |
conf_parser_ctx.pass = 1; |
| 689 |
yyparse(); /* Pick up the classes first */ |
| 690 |
|
| 691 |
rewind(file); |
| 692 |
|
| 693 |
conf_parser_ctx.pass = 2; |
| 694 |
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 |
whowas_trim(); /* Attempt to trim whowas list if necessary */ |
| 698 |
class_delete_marked(); /* Delete unused classes that are marked for deletion */ |
| 699 |
} |
| 700 |
|
| 701 |
/* 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 |
void |
| 708 |
conf_rehash(int sig) |
| 709 |
{ |
| 710 |
if (sig) |
| 711 |
{ |
| 712 |
sendto_realops_flags(UMODE_SERVNOTICE, L_ALL, SEND_NOTICE, |
| 713 |
"Got signal SIGHUP, reloading configuration file(s)"); |
| 714 |
ilog(LOG_TYPE_IRCD, "Got signal SIGHUP, reloading configuration file(s)"); |
| 715 |
} |
| 716 |
|
| 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 |
/* 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 |
void |
| 733 |
lookup_confhost(struct MaskItem *conf) |
| 734 |
{ |
| 735 |
struct addrinfo hints, *res; |
| 736 |
|
| 737 |
/* |
| 738 |
* Do name lookup now on hostnames given and store the |
| 739 |
* 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 |
if (getaddrinfo(conf->host, NULL, &hints, &res)) |
| 750 |
{ |
| 751 |
conf_dns_lookup(conf); |
| 752 |
return; |
| 753 |
} |
| 754 |
|
| 755 |
assert(res); |
| 756 |
|
| 757 |
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 |
freeaddrinfo(res); |
| 762 |
} |
| 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 |
struct ip_entry *ip_found = NULL; |
| 775 |
const struct MaskItem *conf = find_dline_conf(addr, aftype); |
| 776 |
|
| 777 |
if (conf) |
| 778 |
{ |
| 779 |
/* DLINE exempt also gets you out of static limits/pacing... */ |
| 780 |
if (conf->type == CONF_EXEMPT) |
| 781 |
return 0; |
| 782 |
return BANNED_CLIENT; |
| 783 |
} |
| 784 |
|
| 785 |
ip_found = ipcache_find_or_add_address(addr); |
| 786 |
|
| 787 |
if ((CurrentTime - ip_found->last_attempt) < ConfigGeneral.throttle_time) |
| 788 |
{ |
| 789 |
if (ip_found->connection_count >= ConfigGeneral.throttle_count) |
| 790 |
return TOO_FAST; |
| 791 |
|
| 792 |
++ip_found->connection_count; |
| 793 |
} |
| 794 |
else |
| 795 |
ip_found->connection_count = 1; |
| 796 |
|
| 797 |
ip_found->last_attempt = CurrentTime; |
| 798 |
return 0; |
| 799 |
} |
| 800 |
|
| 801 |
/* 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 |
gecos_expire(); |
| 813 |
resv_expire(); |
| 814 |
} |
| 815 |
|
| 816 |
/* oper_privs_as_string() |
| 817 |
* |
| 818 |
* inputs - pointer to client_p |
| 819 |
* output - pointer to static string showing oper privs |
| 820 |
* side effects - return as string, the oper privs as derived from port |
| 821 |
*/ |
| 822 |
static const struct oper_flags |
| 823 |
{ |
| 824 |
const unsigned int flag; |
| 825 |
const unsigned char c; |
| 826 |
} flag_table[] = { |
| 827 |
{ OPER_FLAG_ADMIN, 'A' }, |
| 828 |
{ 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 |
{ OPER_FLAG_KLINE, 'K' }, |
| 838 |
{ 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 |
{ 0, '\0' } |
| 856 |
}; |
| 857 |
|
| 858 |
const char * |
| 859 |
oper_privs_as_string(const unsigned int flags) |
| 860 |
{ |
| 861 |
static char buf[sizeof(flag_table) / sizeof(flag_table[0])]; |
| 862 |
char *p = buf; |
| 863 |
|
| 864 |
for (const struct oper_flags *tab = flag_table; tab->flag; ++tab) |
| 865 |
if (flags & tab->flag) |
| 866 |
*p++ = tab->c; |
| 867 |
|
| 868 |
if (p == buf) |
| 869 |
*p++ = '0'; |
| 870 |
|
| 871 |
*p = '\0'; |
| 872 |
|
| 873 |
return buf; |
| 874 |
} |
| 875 |
|
| 876 |
/* |
| 877 |
* Input: A client to find the active operator {} name for. |
| 878 |
* Output: The nick!user@host{oper} of the oper. |
| 879 |
* "oper" is server name for remote opers |
| 880 |
* Side effects: None. |
| 881 |
*/ |
| 882 |
const char * |
| 883 |
get_oper_name(const struct Client *client_p) |
| 884 |
{ |
| 885 |
static char buffer[IRCD_BUFSIZE]; |
| 886 |
|
| 887 |
if (IsServer(client_p)) |
| 888 |
return client_p->name; |
| 889 |
|
| 890 |
if (MyConnect(client_p)) |
| 891 |
{ |
| 892 |
const dlink_node *const node = client_p->connection->confs.head; |
| 893 |
|
| 894 |
if (node) |
| 895 |
{ |
| 896 |
const struct MaskItem *const conf = node->data; |
| 897 |
|
| 898 |
if (conf->type == CONF_OPER) |
| 899 |
{ |
| 900 |
snprintf(buffer, sizeof(buffer), "%s!%s@%s{%s}", client_p->name, |
| 901 |
client_p->username, client_p->host, conf->name); |
| 902 |
return buffer; |
| 903 |
} |
| 904 |
} |
| 905 |
|
| 906 |
/* |
| 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 |
*/ |
| 910 |
assert(0); /* Oper without oper conf! */ |
| 911 |
} |
| 912 |
|
| 913 |
snprintf(buffer, sizeof(buffer), "%s!%s@%s{%s}", client_p->name, |
| 914 |
client_p->username, client_p->host, client_p->servptr->name); |
| 915 |
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 |
dlink_node *node = NULL, *node_next = NULL; |
| 928 |
dlink_list *free_items [] = { |
| 929 |
&connect_items, &operator_items, NULL |
| 930 |
}; |
| 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 |
|
| 938 |
for (; *iterator; iterator++) |
| 939 |
{ |
| 940 |
DLINK_FOREACH_SAFE(node, node_next, (*iterator)->head) |
| 941 |
{ |
| 942 |
struct MaskItem *conf = node->data; |
| 943 |
|
| 944 |
conf->active = 0; |
| 945 |
dlinkDelete(&conf->node, *iterator); |
| 946 |
|
| 947 |
if (!conf->ref_count) |
| 948 |
conf_free(conf); |
| 949 |
} |
| 950 |
} |
| 951 |
|
| 952 |
/* |
| 953 |
* Don't delete the class table, rather mark all entries for deletion. |
| 954 |
* The table is cleaned up by class_delete_marked. - avalon |
| 955 |
*/ |
| 956 |
class_mark_for_deletion(); |
| 957 |
|
| 958 |
clear_out_address_conf(); |
| 959 |
|
| 960 |
modules_conf_clear(); /* Clear modules {} items */ |
| 961 |
|
| 962 |
motd_clear(); /* Clear motd {} items and re-cache default motd */ |
| 963 |
|
| 964 |
cluster_clear(); /* Clear cluster {} items */ |
| 965 |
|
| 966 |
gecos_clear(); /* Clear gecos {} items */ |
| 967 |
|
| 968 |
resv_clear(); /* Clear resv {} items */ |
| 969 |
|
| 970 |
service_clear(); /* Clear service {} items */ |
| 971 |
|
| 972 |
shared_clear(); /* Clear shared {} items */ |
| 973 |
|
| 974 |
pseudo_clear(); /* Clear pseudo {} items */ |
| 975 |
|
| 976 |
/* Clean out ConfigServerInfo */ |
| 977 |
xfree(ConfigServerInfo.description); |
| 978 |
ConfigServerInfo.description = NULL; |
| 979 |
xfree(ConfigServerInfo.network_name); |
| 980 |
ConfigServerInfo.network_name = NULL; |
| 981 |
xfree(ConfigServerInfo.network_desc); |
| 982 |
ConfigServerInfo.network_desc = NULL; |
| 983 |
xfree(ConfigServerInfo.rsa_private_key_file); |
| 984 |
ConfigServerInfo.rsa_private_key_file = NULL; |
| 985 |
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 |
|
| 996 |
/* Clean out ConfigAdminInfo */ |
| 997 |
xfree(ConfigAdminInfo.name); |
| 998 |
ConfigAdminInfo.name = NULL; |
| 999 |
xfree(ConfigAdminInfo.email); |
| 1000 |
ConfigAdminInfo.email = NULL; |
| 1001 |
xfree(ConfigAdminInfo.description); |
| 1002 |
ConfigAdminInfo.description = NULL; |
| 1003 |
|
| 1004 |
/* Clean out ConfigServerHide */ |
| 1005 |
xfree(ConfigServerHide.flatten_links_file); |
| 1006 |
ConfigServerHide.flatten_links_file = NULL; |
| 1007 |
xfree(ConfigServerHide.hidden_name); |
| 1008 |
ConfigServerHide.hidden_name = NULL; |
| 1009 |
|
| 1010 |
/* Clean out listeners */ |
| 1011 |
listener_close_marked(); |
| 1012 |
} |
| 1013 |
|
| 1014 |
static void |
| 1015 |
conf_handle_tls(int cold) |
| 1016 |
{ |
| 1017 |
if (!tls_new_cred()) |
| 1018 |
{ |
| 1019 |
if (cold) |
| 1020 |
{ |
| 1021 |
ilog(LOG_TYPE_IRCD, "Error while initializing TLS"); |
| 1022 |
exit(EXIT_FAILURE); |
| 1023 |
} |
| 1024 |
else |
| 1025 |
{ |
| 1026 |
/* Failed to load new settings/certs, old ones remain active */ |
| 1027 |
sendto_realops_flags(UMODE_SERVNOTICE, L_ALL, SEND_NOTICE, |
| 1028 |
"Error reloading TLS settings, check the ircd log"); // report_crypto_errors logs this |
| 1029 |
} |
| 1030 |
} |
| 1031 |
} |
| 1032 |
|
| 1033 |
/* read_conf_files() |
| 1034 |
* |
| 1035 |
* inputs - cold start YES or NO |
| 1036 |
* output - none |
| 1037 |
* side effects - read all conf files needed, ircd.conf kline.conf etc. |
| 1038 |
*/ |
| 1039 |
void |
| 1040 |
read_conf_files(int cold) |
| 1041 |
{ |
| 1042 |
const char *filename = NULL; |
| 1043 |
char chanmodes[IRCD_BUFSIZE] = ""; |
| 1044 |
char chanlimit[IRCD_BUFSIZE] = ""; |
| 1045 |
|
| 1046 |
conf_parser_ctx.boot = cold; |
| 1047 |
filename = ConfigGeneral.configfile; |
| 1048 |
|
| 1049 |
/* We need to know the initial filename for the yyerror() to report |
| 1050 |
FIXME: The full path is in conffilenamebuf first time since we |
| 1051 |
don't know anything else |
| 1052 |
|
| 1053 |
- Gozem 2002-07-21 |
| 1054 |
*/ |
| 1055 |
strlcpy(conffilebuf, filename, sizeof(conffilebuf)); |
| 1056 |
|
| 1057 |
if ((conf_parser_ctx.conf_file = fopen(filename, "r")) == NULL) |
| 1058 |
{ |
| 1059 |
if (cold) |
| 1060 |
{ |
| 1061 |
ilog(LOG_TYPE_IRCD, "Unable to read configuration file '%s': %s", |
| 1062 |
filename, strerror(errno)); |
| 1063 |
exit(EXIT_FAILURE); |
| 1064 |
} |
| 1065 |
else |
| 1066 |
{ |
| 1067 |
sendto_realops_flags(UMODE_SERVNOTICE, L_ADMIN, SEND_NOTICE, |
| 1068 |
"Unable to read configuration file '%s': %s", |
| 1069 |
filename, strerror(errno)); |
| 1070 |
return; |
| 1071 |
} |
| 1072 |
} |
| 1073 |
|
| 1074 |
if (!cold) |
| 1075 |
clear_out_old_conf(); |
| 1076 |
|
| 1077 |
read_conf(conf_parser_ctx.conf_file); |
| 1078 |
fclose(conf_parser_ctx.conf_file); |
| 1079 |
|
| 1080 |
log_reopen_all(); |
| 1081 |
conf_handle_tls(cold); |
| 1082 |
|
| 1083 |
isupport_add("NICKLEN", NULL, ConfigServerInfo.max_nick_length); |
| 1084 |
isupport_add("NETWORK", ConfigServerInfo.network_name, -1); |
| 1085 |
|
| 1086 |
snprintf(chanmodes, sizeof(chanmodes), "beI:%u", ConfigChannel.max_bans); |
| 1087 |
isupport_add("MAXLIST", chanmodes, -1); |
| 1088 |
isupport_add("MAXTARGETS", NULL, ConfigGeneral.max_targets); |
| 1089 |
isupport_add("CHANTYPES", "#", -1); |
| 1090 |
|
| 1091 |
snprintf(chanlimit, sizeof(chanlimit), "#:%u", |
| 1092 |
ConfigChannel.max_channels); |
| 1093 |
isupport_add("CHANLIMIT", chanlimit, -1); |
| 1094 |
snprintf(chanmodes, sizeof(chanmodes), "%s", "beI,k,l,cimnprstuCLMNORST"); |
| 1095 |
isupport_add("CHANNELLEN", NULL, CHANNELLEN); |
| 1096 |
isupport_add("TOPICLEN", NULL, ConfigServerInfo.max_topic_length); |
| 1097 |
isupport_add("CHANMODES", chanmodes, -1); |
| 1098 |
} |
| 1099 |
|
| 1100 |
/* conf_add_class_to_conf() |
| 1101 |
* |
| 1102 |
* inputs - pointer to config item |
| 1103 |
* output - NONE |
| 1104 |
* side effects - Add a class pointer to a conf |
| 1105 |
*/ |
| 1106 |
void |
| 1107 |
conf_add_class_to_conf(struct MaskItem *conf, const char *name) |
| 1108 |
{ |
| 1109 |
if (EmptyString(name) || (conf->class = class_find(name, 1)) == NULL) |
| 1110 |
{ |
| 1111 |
conf->class = class_default; |
| 1112 |
|
| 1113 |
if (conf->type == CONF_CLIENT || conf->type == CONF_OPER) |
| 1114 |
sendto_realops_flags(UMODE_SERVNOTICE, L_ADMIN, SEND_NOTICE, |
| 1115 |
"Warning *** Defaulting to default class for %s@%s", |
| 1116 |
conf->user, conf->host); |
| 1117 |
else |
| 1118 |
sendto_realops_flags(UMODE_SERVNOTICE, L_ADMIN, SEND_NOTICE, |
| 1119 |
"Warning *** Defaulting to default class for %s", |
| 1120 |
conf->name); |
| 1121 |
} |
| 1122 |
} |
| 1123 |
|
| 1124 |
/* yyerror() |
| 1125 |
* |
| 1126 |
* inputs - message from parser |
| 1127 |
* output - NONE |
| 1128 |
* side effects - message to opers and log file entry is made |
| 1129 |
*/ |
| 1130 |
void |
| 1131 |
yyerror(const char *msg) |
| 1132 |
{ |
| 1133 |
if (conf_parser_ctx.pass != 1) |
| 1134 |
return; |
| 1135 |
|
| 1136 |
const char *p = stripws(linebuf); |
| 1137 |
sendto_realops_flags(UMODE_SERVNOTICE, L_ADMIN, SEND_NOTICE, |
| 1138 |
"\"%s\", line %u: %s: %s", |
| 1139 |
conffilebuf, lineno, msg, p); |
| 1140 |
ilog(LOG_TYPE_IRCD, "\"%s\", line %u: %s: %s", |
| 1141 |
conffilebuf, lineno, msg, p); |
| 1142 |
} |
| 1143 |
|
| 1144 |
void |
| 1145 |
conf_error_report(const char *msg) |
| 1146 |
{ |
| 1147 |
const char *p = stripws(linebuf); |
| 1148 |
sendto_realops_flags(UMODE_SERVNOTICE, L_ADMIN, SEND_NOTICE, |
| 1149 |
"\"%s\", line %u: %s: %s", |
| 1150 |
conffilebuf, lineno, msg, p); |
| 1151 |
ilog(LOG_TYPE_IRCD, "\"%s\", line %u: %s: %s", |
| 1152 |
conffilebuf, lineno, msg, p); |
| 1153 |
} |
| 1154 |
|
| 1155 |
/* |
| 1156 |
* valid_tkline() |
| 1157 |
* |
| 1158 |
* inputs - pointer to ascii string to check |
| 1159 |
* - whether the specified time is in seconds or minutes |
| 1160 |
* output - -1 not enough parameters |
| 1161 |
* - 0 if not an integer number, else the number |
| 1162 |
* side effects - none |
| 1163 |
* Originally written by Dianora (Diane, db@db.net) |
| 1164 |
*/ |
| 1165 |
uintmax_t |
| 1166 |
valid_tkline(const char *data, const int minutes) |
| 1167 |
{ |
| 1168 |
const unsigned char *p = (const unsigned char *)data; |
| 1169 |
unsigned char tmpch = '\0'; |
| 1170 |
uintmax_t result = 0; |
| 1171 |
|
| 1172 |
while ((tmpch = *p++)) |
| 1173 |
{ |
| 1174 |
if (!IsDigit(tmpch)) |
| 1175 |
return 0; |
| 1176 |
|
| 1177 |
result *= 10; |
| 1178 |
result += (tmpch & 0xF); |
| 1179 |
} |
| 1180 |
|
| 1181 |
/* |
| 1182 |
* In the degenerate case where oper does a /quote kline 0 user@host :reason |
| 1183 |
* i.e. they specifically use 0, I am going to return 1 instead as a return |
| 1184 |
* value of non-zero is used to flag it as a temporary kline |
| 1185 |
*/ |
| 1186 |
if (result == 0) |
| 1187 |
result = 1; |
| 1188 |
|
| 1189 |
/* |
| 1190 |
* If the incoming time is in seconds convert it to minutes for the purpose |
| 1191 |
* of this calculation |
| 1192 |
*/ |
| 1193 |
if (!minutes) |
| 1194 |
result = result / 60; |
| 1195 |
|
| 1196 |
if (result > MAX_TDKLINE_TIME) |
| 1197 |
result = MAX_TDKLINE_TIME; |
| 1198 |
|
| 1199 |
result = result * 60; /* Turn it into seconds */ |
| 1200 |
|
| 1201 |
return result; |
| 1202 |
} |
| 1203 |
|
| 1204 |
/* valid_wild_card_simple() |
| 1205 |
* |
| 1206 |
* inputs - data to check for sufficient non-wildcard characters |
| 1207 |
* outputs - 1 if valid, else 0 |
| 1208 |
* side effects - none |
| 1209 |
*/ |
| 1210 |
int |
| 1211 |
valid_wild_card_simple(const char *data) |
| 1212 |
{ |
| 1213 |
const unsigned char *p = (const unsigned char *)data; |
| 1214 |
unsigned char tmpch = '\0'; |
| 1215 |
unsigned int nonwild = 0, wild = 0; |
| 1216 |
|
| 1217 |
while ((tmpch = *p++)) |
| 1218 |
{ |
| 1219 |
if (tmpch == '\\' && *p) |
| 1220 |
{ |
| 1221 |
++p; |
| 1222 |
if (++nonwild >= ConfigGeneral.min_nonwildcard_simple) |
| 1223 |
return 1; |
| 1224 |
} |
| 1225 |
else if (!IsMWildChar(tmpch)) |
| 1226 |
{ |
| 1227 |
if (++nonwild >= ConfigGeneral.min_nonwildcard_simple) |
| 1228 |
return 1; |
| 1229 |
} |
| 1230 |
else |
| 1231 |
++wild; |
| 1232 |
} |
| 1233 |
|
| 1234 |
return !wild; |
| 1235 |
} |
| 1236 |
|
| 1237 |
/* valid_wild_card() |
| 1238 |
* |
| 1239 |
* input - pointer to client |
| 1240 |
* - int flag, 0 for no warning oper 1 for warning oper |
| 1241 |
* - count of following varargs to check |
| 1242 |
* output - 0 if not valid, 1 if valid |
| 1243 |
* side effects - NOTICE is given to source_p if warn is 1 |
| 1244 |
*/ |
| 1245 |
int |
| 1246 |
valid_wild_card(int count, ...) |
| 1247 |
{ |
| 1248 |
unsigned char tmpch = '\0'; |
| 1249 |
unsigned int nonwild = 0; |
| 1250 |
va_list args; |
| 1251 |
|
| 1252 |
/* |
| 1253 |
* Now we must check the user and host to make sure there |
| 1254 |
* are at least NONWILDCHARS non-wildcard characters in |
| 1255 |
* them, otherwise assume they are attempting to kline |
| 1256 |
* *@* or some variant of that. This code will also catch |
| 1257 |
* people attempting to kline *@*.tld, as long as NONWILDCHARS |
| 1258 |
* is greater than 3. In that case, there are only 3 non-wild |
| 1259 |
* characters (tld), so if NONWILDCHARS is 4, the kline will |
| 1260 |
* be disallowed. |
| 1261 |
* -wnder |
| 1262 |
*/ |
| 1263 |
|
| 1264 |
va_start(args, count); |
| 1265 |
|
| 1266 |
while (count--) |
| 1267 |
{ |
| 1268 |
const unsigned char *p = va_arg(args, const unsigned char *); |
| 1269 |
if (p == NULL) |
| 1270 |
continue; |
| 1271 |
|
| 1272 |
while ((tmpch = *p++)) |
| 1273 |
{ |
| 1274 |
if (!IsKWildChar(tmpch)) |
| 1275 |
{ |
| 1276 |
/* |
| 1277 |
* If we find enough non-wild characters, we can |
| 1278 |
* break - no point in searching further. |
| 1279 |
*/ |
| 1280 |
if (++nonwild >= ConfigGeneral.min_nonwildcard) |
| 1281 |
{ |
| 1282 |
va_end(args); |
| 1283 |
return 1; |
| 1284 |
} |
| 1285 |
} |
| 1286 |
} |
| 1287 |
} |
| 1288 |
|
| 1289 |
va_end(args); |
| 1290 |
return 0; |
| 1291 |
} |
| 1292 |
|
| 1293 |
/* find_user_host() |
| 1294 |
* |
| 1295 |
* inputs - pointer to client placing kline |
| 1296 |
* - pointer to user_host_or_nick |
| 1297 |
* - pointer to user buffer |
| 1298 |
* - pointer to host buffer |
| 1299 |
* output - 0 if not ok to kline, 1 to kline i.e. if valid user host |
| 1300 |
* side effects - |
| 1301 |
*/ |
| 1302 |
static int |
| 1303 |
find_user_host(struct Client *source_p, char *user_host_or_nick, |
| 1304 |
char *luser, char *lhost) |
| 1305 |
{ |
| 1306 |
struct Client *target_p = NULL; |
| 1307 |
char *hostp = NULL; |
| 1308 |
|
| 1309 |
if (lhost == NULL) |
| 1310 |
{ |
| 1311 |
strlcpy(luser, user_host_or_nick, USERLEN*4 + 1); |
| 1312 |
return 1; |
| 1313 |
} |
| 1314 |
|
| 1315 |
if ((hostp = strchr(user_host_or_nick, '@')) || *user_host_or_nick == '*') |
| 1316 |
{ |
| 1317 |
/* Explicit user@host mask given */ |
| 1318 |
if (hostp) /* I'm a little user@host */ |
| 1319 |
{ |
| 1320 |
*(hostp++) = '\0'; /* short and squat */ |
| 1321 |
|
| 1322 |
if (*user_host_or_nick) |
| 1323 |
strlcpy(luser, user_host_or_nick, USERLEN*4 + 1); /* here is my user */ |
| 1324 |
else |
| 1325 |
strcpy(luser, "*"); |
| 1326 |
|
| 1327 |
if (*hostp) |
| 1328 |
strlcpy(lhost, hostp, HOSTLEN + 1); /* here is my host */ |
| 1329 |
else |
| 1330 |
strcpy(lhost, "*"); |
| 1331 |
} |
| 1332 |
else |
| 1333 |
{ |
| 1334 |
luser[0] = '*'; /* no @ found, assume its *@somehost */ |
| 1335 |
luser[1] = '\0'; |
| 1336 |
strlcpy(lhost, user_host_or_nick, HOSTLEN*4 + 1); |
| 1337 |
} |
| 1338 |
|
| 1339 |
return 1; |
| 1340 |
} |
| 1341 |
else |
| 1342 |
{ |
| 1343 |
/* Try to find user@host mask from nick */ |
| 1344 |
/* Okay to use source_p as the first param, because source_p == client_p */ |
| 1345 |
if ((target_p = |
| 1346 |
find_chasing(source_p, user_host_or_nick)) == NULL) |
| 1347 |
return 0; /* find_chasing sends ERR_NOSUCHNICK */ |
| 1348 |
|
| 1349 |
if (HasFlag(target_p, FLAGS_EXEMPTKLINE)) |
| 1350 |
{ |
| 1351 |
if (IsClient(source_p)) |
| 1352 |
sendto_one_notice(source_p, &me, ":%s is E-lined", target_p->name); |
| 1353 |
return 0; |
| 1354 |
} |
| 1355 |
|
| 1356 |
/* |
| 1357 |
* Turn the "user" bit into "*user", blow away '~' |
| 1358 |
* if found in original user name (non-idented) |
| 1359 |
*/ |
| 1360 |
strlcpy(luser, target_p->username, USERLEN*4 + 1); |
| 1361 |
|
| 1362 |
if (target_p->username[0] == '~') |
| 1363 |
luser[0] = '*'; |
| 1364 |
|
| 1365 |
strlcpy(lhost, target_p->sockhost, HOSTLEN*4 + 1); |
| 1366 |
return 1; |
| 1367 |
} |
| 1368 |
|
| 1369 |
return 0; |
| 1370 |
} |
| 1371 |
|
| 1372 |
/* XXX should this go into a separate file ? -Dianora */ |
| 1373 |
/* parse_aline |
| 1374 |
* |
| 1375 |
* input - pointer to cmd name being used |
| 1376 |
* - pointer to client using cmd |
| 1377 |
* - parc parameter count |
| 1378 |
* - parv[] list of parameters to parse |
| 1379 |
* - parse_flags bit map of things to test |
| 1380 |
* - pointer to user or string to parse into |
| 1381 |
* - pointer to host or NULL to parse into if non NULL |
| 1382 |
* - pointer to optional tkline time or NULL |
| 1383 |
* - pointer to target_server to parse into if non NULL |
| 1384 |
* - pointer to reason to parse into |
| 1385 |
* |
| 1386 |
* output - 1 if valid, 0 if not valid |
| 1387 |
* side effects - A generalised k/d/x etc. line parser, |
| 1388 |
* "ALINE [time] user@host|string [ON] target :reason" |
| 1389 |
* will parse returning a parsed user, host if |
| 1390 |
* h_p pointer is non NULL, string otherwise. |
| 1391 |
* if tkline_time pointer is non NULL a tk line will be set |
| 1392 |
* to non zero if found. |
| 1393 |
* if tkline_time pointer is NULL and tk line is found, |
| 1394 |
* error is reported. |
| 1395 |
* if target_server is NULL and an "ON" is found error |
| 1396 |
* is reported. |
| 1397 |
* if reason pointer is NULL ignore pointer, |
| 1398 |
* this allows use of parse_a_line in unkline etc. |
| 1399 |
* |
| 1400 |
* - Dianora |
| 1401 |
*/ |
| 1402 |
int |
| 1403 |
parse_aline(const char *cmd, struct Client *source_p, |
| 1404 |
int parc, char **parv, |
| 1405 |
char **up_p, char **h_p, uintmax_t *tkline_time, |
| 1406 |
char **target_server, char **reason) |
| 1407 |
{ |
| 1408 |
uintmax_t found_tkline_time=0; |
| 1409 |
static char default_reason[] = CONF_NOREASON; |
| 1410 |
static char user[USERLEN*4+1]; |
| 1411 |
static char host[HOSTLEN*4+1]; |
| 1412 |
|
| 1413 |
parv++; |
| 1414 |
parc--; |
| 1415 |
|
| 1416 |
found_tkline_time = valid_tkline(*parv, TK_MINUTES); |
| 1417 |
|
| 1418 |
if (found_tkline_time) |
| 1419 |
{ |
| 1420 |
parv++; |
| 1421 |
parc--; |
| 1422 |
|
| 1423 |
if (tkline_time) |
| 1424 |
*tkline_time = found_tkline_time; |
| 1425 |
else |
| 1426 |
{ |
| 1427 |
sendto_one_notice(source_p, &me, ":temp_line not supported by %s", cmd); |
| 1428 |
return 0; |
| 1429 |
} |
| 1430 |
} |
| 1431 |
|
| 1432 |
if (parc == 0) |
| 1433 |
{ |
| 1434 |
sendto_one_numeric(source_p, &me, ERR_NEEDMOREPARAMS, cmd); |
| 1435 |
return 0; |
| 1436 |
} |
| 1437 |
|
| 1438 |
if (h_p == NULL) |
| 1439 |
*up_p = *parv; |
| 1440 |
else |
| 1441 |
{ |
| 1442 |
if (find_user_host(source_p, *parv, user, host) == 0) |
| 1443 |
return 0; |
| 1444 |
|
| 1445 |
*up_p = user; |
| 1446 |
*h_p = host; |
| 1447 |
} |
| 1448 |
|
| 1449 |
parc--; |
| 1450 |
parv++; |
| 1451 |
|
| 1452 |
if (parc) |
| 1453 |
{ |
| 1454 |
if (irccmp(*parv, "ON") == 0) |
| 1455 |
{ |
| 1456 |
parc--; |
| 1457 |
parv++; |
| 1458 |
|
| 1459 |
if (!HasOFlag(source_p, OPER_FLAG_REMOTEBAN)) |
| 1460 |
{ |
| 1461 |
sendto_one_numeric(source_p, &me, ERR_NOPRIVS, "remoteban"); |
| 1462 |
return 0; |
| 1463 |
} |
| 1464 |
|
| 1465 |
if (parc == 0 || EmptyString(*parv)) |
| 1466 |
{ |
| 1467 |
sendto_one_numeric(source_p, &me, ERR_NEEDMOREPARAMS, cmd); |
| 1468 |
return 0; |
| 1469 |
} |
| 1470 |
|
| 1471 |
*target_server = *parv; |
| 1472 |
parc--; |
| 1473 |
parv++; |
| 1474 |
} |
| 1475 |
else |
| 1476 |
{ |
| 1477 |
/* Make sure target_server *is* NULL if no ON server found |
| 1478 |
* caller probably NULL'd it first, but no harm to do it again -db |
| 1479 |
*/ |
| 1480 |
if (target_server) |
| 1481 |
*target_server = NULL; |
| 1482 |
} |
| 1483 |
} |
| 1484 |
|
| 1485 |
if (reason) |
| 1486 |
{ |
| 1487 |
if (parc && !EmptyString(*parv)) |
| 1488 |
*reason = *parv; |
| 1489 |
else |
| 1490 |
*reason = default_reason; |
| 1491 |
} |
| 1492 |
|
| 1493 |
return 1; |
| 1494 |
} |
| 1495 |
|
| 1496 |
/* match_conf_password() |
| 1497 |
* |
| 1498 |
* inputs - pointer to given password |
| 1499 |
* - pointer to Conf |
| 1500 |
* output - 1 or 0 if match |
| 1501 |
* side effects - none |
| 1502 |
*/ |
| 1503 |
int |
| 1504 |
match_conf_password(const char *password, const struct MaskItem *conf) |
| 1505 |
{ |
| 1506 |
const char *encr = NULL; |
| 1507 |
|
| 1508 |
if (EmptyString(password) || EmptyString(conf->passwd)) |
| 1509 |
return 0; |
| 1510 |
|
| 1511 |
if (conf->flags & CONF_FLAGS_ENCRYPTED) |
| 1512 |
encr = crypt(password, conf->passwd); |
| 1513 |
else |
| 1514 |
encr = password; |
| 1515 |
|
| 1516 |
return encr && !strcmp(encr, conf->passwd); |
| 1517 |
} |
| 1518 |
|
| 1519 |
/* |
| 1520 |
* split_nuh |
| 1521 |
* |
| 1522 |
* inputs - pointer to original mask (modified in place) |
| 1523 |
* - pointer to pointer where nick should go |
| 1524 |
* - pointer to pointer where user should go |
| 1525 |
* - pointer to pointer where host should go |
| 1526 |
* output - NONE |
| 1527 |
* side effects - mask is modified in place |
| 1528 |
* If nick pointer is NULL, ignore writing to it |
| 1529 |
* this allows us to use this function elsewhere. |
| 1530 |
* |
| 1531 |
* mask nick user host |
| 1532 |
* ---------------------- ------- ------- ------ |
| 1533 |
* Dianora!db@db.net Dianora db db.net |
| 1534 |
* Dianora Dianora * * |
| 1535 |
* db.net * * db.net |
| 1536 |
* OR if nick pointer is NULL |
| 1537 |
* Dianora - * Dianora |
| 1538 |
* Dianora! Dianora * * |
| 1539 |
* Dianora!@ Dianora * * |
| 1540 |
* Dianora!db Dianora db * |
| 1541 |
* Dianora!@db.net Dianora * db.net |
| 1542 |
* db@db.net * db db.net |
| 1543 |
* !@ * * * |
| 1544 |
* @ * * * |
| 1545 |
* ! * * * |
| 1546 |
*/ |
| 1547 |
void |
| 1548 |
split_nuh(struct split_nuh_item *const iptr) |
| 1549 |
{ |
| 1550 |
char *p = NULL, *q = NULL; |
| 1551 |
|
| 1552 |
if (iptr->nickptr) |
| 1553 |
strlcpy(iptr->nickptr, "*", iptr->nicksize); |
| 1554 |
|
| 1555 |
if (iptr->userptr) |
| 1556 |
strlcpy(iptr->userptr, "*", iptr->usersize); |
| 1557 |
|
| 1558 |
if (iptr->hostptr) |
| 1559 |
strlcpy(iptr->hostptr, "*", iptr->hostsize); |
| 1560 |
|
| 1561 |
if ((p = strchr(iptr->nuhmask, '!'))) |
| 1562 |
{ |
| 1563 |
*p = '\0'; |
| 1564 |
|
| 1565 |
if (iptr->nickptr && *iptr->nuhmask) |
| 1566 |
strlcpy(iptr->nickptr, iptr->nuhmask, iptr->nicksize); |
| 1567 |
|
| 1568 |
if ((q = strchr(++p, '@'))) |
| 1569 |
{ |
| 1570 |
*q++ = '\0'; |
| 1571 |
|
| 1572 |
if (*p) |
| 1573 |
strlcpy(iptr->userptr, p, iptr->usersize); |
| 1574 |
|
| 1575 |
if (*q) |
| 1576 |
strlcpy(iptr->hostptr, q, iptr->hostsize); |
| 1577 |
} |
| 1578 |
else |
| 1579 |
{ |
| 1580 |
if (*p) |
| 1581 |
strlcpy(iptr->userptr, p, iptr->usersize); |
| 1582 |
} |
| 1583 |
} |
| 1584 |
else |
| 1585 |
{ |
| 1586 |
/* No ! found so lets look for a user@host */ |
| 1587 |
if ((p = strchr(iptr->nuhmask, '@'))) |
| 1588 |
{ |
| 1589 |
/* if found a @ */ |
| 1590 |
*p++ = '\0'; |
| 1591 |
|
| 1592 |
if (*iptr->nuhmask) |
| 1593 |
strlcpy(iptr->userptr, iptr->nuhmask, iptr->usersize); |
| 1594 |
|
| 1595 |
if (*p) |
| 1596 |
strlcpy(iptr->hostptr, p, iptr->hostsize); |
| 1597 |
} |
| 1598 |
else |
| 1599 |
{ |
| 1600 |
/* No @ found */ |
| 1601 |
if (!iptr->nickptr || strpbrk(iptr->nuhmask, ".:")) |
| 1602 |
strlcpy(iptr->hostptr, iptr->nuhmask, iptr->hostsize); |
| 1603 |
else |
| 1604 |
strlcpy(iptr->nickptr, iptr->nuhmask, iptr->nicksize); |
| 1605 |
} |
| 1606 |
} |
| 1607 |
} |