--- ircd-hybrid-8/src/ircd_parser.y 2011/08/14 11:24:24 1176 +++ ircd-hybrid/trunk/src/conf_parser.y 2014/05/01 13:57:39 3435 @@ -1,8 +1,7 @@ /* - * ircd-hybrid: an advanced Internet Relay Chat Daemon(ircd). - * ircd_parser.y: Parses the ircd configuration file. + * ircd-hybrid: an advanced, lightweight Internet Relay Chat Daemon (ircd) * - * Copyright (C) 2005 by the past and present ircd coders, and others. + * Copyright (c) 2000-2014 ircd-hybrid development team * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -18,10 +17,14 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 * USA - * - * $Id$ */ +/*! \file conf_parser.y + * \brief Parses the ircd configuration file. + * \version $Id$ + */ + + %{ #define YY_NO_UNPUT @@ -32,98 +35,107 @@ #include "stdinc.h" #include "ircd.h" #include "list.h" -#include "s_conf.h" +#include "conf.h" +#include "conf_class.h" #include "event.h" -#include "s_log.h" +#include "log.h" #include "client.h" /* for UMODE_ALL only */ #include "irc_string.h" -#include "sprintf_irc.h" #include "memory.h" #include "modules.h" -#include "s_serv.h" +#include "server.h" #include "hostmask.h" #include "send.h" #include "listener.h" #include "resv.h" #include "numeric.h" -#include "s_user.h" +#include "user.h" +#include "motd.h" #ifdef HAVE_LIBCRYPTO #include #include #include +#include #endif -static char *class_name = NULL; -static struct ConfItem *yy_conf = NULL; -static struct AccessItem *yy_aconf = NULL; -static struct MatchItem *yy_match_item = NULL; -static struct ClassItem *yy_class = NULL; -static char *yy_class_name = NULL; - -static dlink_list col_conf_list = { NULL, NULL, 0 }; -static dlink_list hub_conf_list = { NULL, NULL, 0 }; -static dlink_list leaf_conf_list = { NULL, NULL, 0 }; -static unsigned int listener_flags = 0; -static unsigned int regex_ban = 0; -static char userbuf[IRCD_BUFSIZE]; -static char hostbuf[IRCD_BUFSIZE]; -static char reasonbuf[REASONLEN + 1]; -static char gecos_name[REALLEN * 4]; - -static char *resv_reason = NULL; -static char *listener_address = NULL; -static int not_atom = 0; - -struct CollectItem -{ - dlink_node node; - char *name; - char *user; - char *host; - char *passwd; - int port; - int flags; -#ifdef HAVE_LIBCRYPTO - char *rsa_public_key_file; - RSA *rsa_public_key; -#endif -}; +#include "rsa.h" -static void -free_collect_item(struct CollectItem *item) +int yylex(void); + +static struct { - MyFree(item->name); - MyFree(item->user); - MyFree(item->host); - MyFree(item->passwd); -#ifdef HAVE_LIBCRYPTO - MyFree(item->rsa_public_key_file); -#endif - MyFree(item); -} + struct { + dlink_list list; + } mask, + leaf, + hub; + + struct { + char buf[IRCD_BUFSIZE]; + } name, + user, + host, + addr, + bind, + file, + ciph, + cert, + rpass, + spass, + class; + + struct { + unsigned int value; + } flags, + modes, + size, + type, + port, + aftype, + ping_freq, + max_perip, + con_freq, + min_idle, + max_idle, + max_total, + max_global, + max_local, + max_ident, + max_sendq, + max_recvq, + cidr_bitlen_ipv4, + cidr_bitlen_ipv6, + number_per_cidr; +} block_state; static void -unhook_hub_leaf_confs(void) +reset_block_state(void) { - dlink_node *ptr; - dlink_node *next_ptr; - struct CollectItem *yy_hconf; - struct CollectItem *yy_lconf; + dlink_node *ptr = NULL, *ptr_next = NULL; + + DLINK_FOREACH_SAFE(ptr, ptr_next, block_state.mask.list.head) + { + MyFree(ptr->data); + dlinkDelete(ptr, &block_state.mask.list); + free_dlink_node(ptr); + } - DLINK_FOREACH_SAFE(ptr, next_ptr, hub_conf_list.head) + DLINK_FOREACH_SAFE(ptr, ptr_next, block_state.leaf.list.head) { - yy_hconf = ptr->data; - dlinkDelete(&yy_hconf->node, &hub_conf_list); - free_collect_item(yy_hconf); + MyFree(ptr->data); + dlinkDelete(ptr, &block_state.leaf.list); + free_dlink_node(ptr); } - DLINK_FOREACH_SAFE(ptr, next_ptr, leaf_conf_list.head) + DLINK_FOREACH_SAFE(ptr, ptr_next, block_state.hub.list.head) { - yy_lconf = ptr->data; - dlinkDelete(&yy_lconf->node, &leaf_conf_list); - free_collect_item(yy_lconf); + MyFree(ptr->data); + dlinkDelete(ptr, &block_state.hub.list); + free_dlink_node(ptr); } + + memset(&block_state, 0, sizeof(block_state)); } %} @@ -134,30 +146,21 @@ unhook_hub_leaf_confs(void) } %token ACCEPT_PASSWORD -%token ACTION %token ADMIN %token AFTYPE -%token T_ALLOW %token ANTI_NICK_FLOOD %token ANTI_SPAM_EXIT_MESSAGE_TIME %token AUTOCONN -%token T_BLOCK -%token BURST_AWAY -%token BURST_TOPICWHO -%token BYTES KBYTES MBYTES GBYTES TBYTES +%token BYTES KBYTES MBYTES %token CALLER_ID_WAIT %token CAN_FLOOD %token CHANNEL -%token CIDR_BITLEN_IPV4 -%token CIDR_BITLEN_IPV6 -%token CIPHER_PREFERENCE +%token CIDR_BITLEN_IPV4 +%token CIDR_BITLEN_IPV6 %token CLASS -%token COMPRESSED -%token COMPRESSION_LEVEL %token CONNECT %token CONNECTFREQ -%token CRYPTLINK -%token DEFAULT_CIPHER_PREFERENCE +%token CYCLE_ON_HOST_CHANGE %token DEFAULT_FLOODCOUNT %token DEFAULT_SPLIT_SERVER_COUNT %token DEFAULT_SPLIT_USER_COUNT @@ -166,232 +169,208 @@ unhook_hub_leaf_confs(void) %token DIE %token DISABLE_AUTH %token DISABLE_FAKE_CHANNELS -%token DISABLE_HIDDEN -%token DISABLE_LOCAL_CHANNELS %token DISABLE_REMOTE_COMMANDS %token DOTS_IN_IDENT -%token DURATION %token EGDPOOL_PATH %token EMAIL -%token ENABLE %token ENCRYPTED %token EXCEED_LIMIT %token EXEMPT %token FAILED_OPER_NOTICE -%token IRCD_FLAGS %token FLATTEN_LINKS -%token FFAILED_OPERLOG -%token FKILLLOG -%token FKLINELOG -%token FGLINELOG -%token FIOERRLOG -%token FOPERLOG -%token FOPERSPYLOG -%token FUSERLOG %token GECOS %token GENERAL %token GLINE -%token GLINES +%token GLINE_DURATION +%token GLINE_ENABLE %token GLINE_EXEMPT -%token GLINE_LOG -%token GLINE_TIME %token GLINE_MIN_CIDR %token GLINE_MIN_CIDR6 +%token GLINE_REQUEST_DURATION %token GLOBAL_KILL -%token IRCD_AUTH -%token NEED_IDENT %token HAVENT_READ_CONF %token HIDDEN -%token HIDDEN_ADMIN -%token HIDDEN_NAME -%token HIDDEN_OPER +%token HIDDEN_NAME +%token HIDE_IDLE_FROM_OPERS %token HIDE_SERVER_IPS %token HIDE_SERVERS -%token HIDE_SPOOF_IPS +%token HIDE_SERVICES +%token HIDE_SPOOF_IPS %token HOST %token HUB %token HUB_MASK %token IGNORE_BOGUS_TS %token INVISIBLE_ON_CONNECT %token IP +%token IRCD_AUTH +%token IRCD_FLAGS +%token IRCD_SID +%token JOIN_FLOOD_COUNT +%token JOIN_FLOOD_TIME %token KILL -%token KILL_CHASE_TIME_LIMIT +%token KILL_CHASE_TIME_LIMIT %token KLINE %token KLINE_EXEMPT -%token KLINE_REASON -%token KLINE_WITH_REASON %token KNOCK_DELAY %token KNOCK_DELAY_CHANNEL %token LEAF_MASK %token LINKS_DELAY %token LISTEN -%token T_LOG -%token LOGGING -%token LOG_LEVEL +%token MASK %token MAX_ACCEPT %token MAX_BANS +%token MAX_CHANS_PER_OPER %token MAX_CHANS_PER_USER %token MAX_GLOBAL %token MAX_IDENT +%token MAX_IDLE %token MAX_LOCAL %token MAX_NICK_CHANGES +%token MAX_NICK_LENGTH %token MAX_NICK_TIME %token MAX_NUMBER %token MAX_TARGETS +%token MAX_TOPIC_LENGTH %token MAX_WATCH -%token MESSAGE_LOCALE +%token MIN_IDLE %token MIN_NONWILDCARD %token MIN_NONWILDCARD_SIMPLE %token MODULE %token MODULES +%token MOTD %token NAME +%token NEED_IDENT %token NEED_PASSWORD %token NETWORK_DESC %token NETWORK_NAME %token NICK -%token NICK_CHANGES %token NO_CREATE_ON_SPLIT %token NO_JOIN_ON_SPLIT %token NO_OPER_FLOOD %token NO_TILDE -%token NOT %token NUMBER -%token NUMBER_PER_IDENT %token NUMBER_PER_CIDR %token NUMBER_PER_IP -%token NUMBER_PER_IP_GLOBAL -%token OPERATOR -%token OPERS_BYPASS_CALLERID -%token OPER_LOG %token OPER_ONLY_UMODES %token OPER_PASS_RESV -%token OPER_SPY_T %token OPER_UMODES -%token JOIN_FLOOD_COUNT -%token JOIN_FLOOD_TIME +%token OPERATOR +%token OPERS_BYPASS_CALLERID %token PACE_WAIT %token PACE_WAIT_SIMPLE %token PASSWORD %token PATH %token PING_COOKIE %token PING_TIME -%token PING_WARNING %token PORT %token QSTRING -%token QUIET_ON_BAN +%token RANDOM_IDLE %token REASON %token REDIRPORT %token REDIRSERV -%token REGEX_T %token REHASH -%token TREJECT_HOLD_TIME %token REMOTE %token REMOTEBAN -%token RESTRICT_CHANNELS -%token RESTRICTED -%token RSA_PRIVATE_KEY_FILE -%token RSA_PUBLIC_KEY_FILE -%token SSL_CERTIFICATE_FILE -%token T_SSL_CONNECTION_METHOD -%token T_SSLV3 -%token T_TLSV1 %token RESV %token RESV_EXEMPT -%token SECONDS MINUTES HOURS DAYS WEEKS -%token SENDQ +%token RSA_PRIVATE_KEY_FILE +%token RSA_PUBLIC_KEY_FILE +%token SECONDS MINUTES HOURS DAYS WEEKS MONTHS YEARS %token SEND_PASSWORD +%token SENDQ %token SERVERHIDE %token SERVERINFO -%token SERVLINK_PATH -%token IRCD_SID -%token TKLINE_EXPIRE_NOTICES -%token T_SHARED -%token T_CLUSTER -%token TYPE %token SHORT_MOTD -%token SILENT %token SPOOF %token SPOOF_NOTICE +%token SQUIT +%token SSL_CERTIFICATE_FILE +%token SSL_CERTIFICATE_FINGERPRINT +%token SSL_CONNECTION_REQUIRED +%token SSL_DH_PARAM_FILE %token STATS_E_DISABLED %token STATS_I_OPER_ONLY %token STATS_K_OPER_ONLY %token STATS_O_OPER_ONLY %token STATS_P_OPER_ONLY -%token TBOOL -%token TMASKED -%token T_REJECT -%token TS_MAX_DELTA -%token TS_WARN_DELTA -%token TWODOTS +%token STATS_U_OPER_ONLY %token T_ALL %token T_BOTS -%token T_SOFTCALLERID %token T_CALLERID %token T_CCONN -%token T_CCONN_FULL -%token T_CLIENT_FLOOD +%token T_CLUSTER %token T_DEAF %token T_DEBUG -%token T_DRONE +%token T_DLINE %token T_EXTERNAL +%token T_FARCONNECT +%token T_FILE %token T_FULL +%token T_GLOBOPS %token T_INVISIBLE %token T_IPV4 %token T_IPV6 %token T_LOCOPS -%token T_LOGPATH -%token T_L_CRIT -%token T_L_DEBUG -%token T_L_ERROR -%token T_L_INFO -%token T_L_NOTICE -%token T_L_TRACE -%token T_L_WARN +%token T_LOG %token T_MAX_CLIENTS %token T_NCHANGE +%token T_NONONREG %token T_OPERWALL +%token T_RECVQ %token T_REJ +%token T_RESTART %token T_SERVER +%token T_SERVICE +%token T_SERVICES_NAME %token T_SERVNOTICE +%token T_SET +%token T_SHARED +%token T_SIZE %token T_SKILL +%token T_SOFTCALLERID %token T_SPY %token T_SSL +%token T_SSL_CIPHER_LIST +%token T_SSL_CLIENT_METHOD +%token T_SSL_SERVER_METHOD +%token T_SSLV3 +%token T_TLSV1 %token T_UMODES %token T_UNAUTH +%token T_UNDLINE +%token T_UNLIMITED %token T_UNRESV %token T_UNXLINE %token T_WALLOP -%token T_SERVICE -%token T_SERVICES_NAME +%token T_WALLOPS +%token T_WEBIRC +%token TBOOL %token THROTTLE_TIME -%token TOPICBURST +%token TKLINE_EXPIRE_NOTICES +%token TMASKED %token TRUE_NO_OPER_FLOOD -%token TKLINE -%token TXLINE -%token TRESV +%token TS_MAX_DELTA +%token TS_WARN_DELTA +%token TWODOTS +%token TYPE %token UNKLINE -%token USER %token USE_EGD -%token USE_EXCEPT -%token USE_INVEX -%token USE_KNOCK %token USE_LOGGING -%token USE_WHOIS_ACTUALLY +%token USER %token VHOST %token VHOST6 -%token XLINE -%token WARN %token WARN_NO_NLINE +%token XLINE -%type QSTRING -%type NUMBER -%type timespec -%type timespec_ -%type sizespec -%type sizespec_ +%type QSTRING +%type NUMBER +%type timespec +%type timespec_ +%type sizespec +%type sizespec_ %% -conf: +conf: | conf conf_item ; @@ -399,7 +378,7 @@ conf_item: admin_entry | logging_entry | oper_entry | channel_entry - | class_entry + | class_entry | listen_entry | auth_entry | serverinfo_entry @@ -413,9 +392,9 @@ conf_item: admin_entry | deny_entry | exempt_entry | general_entry - | gline_entry | gecos_entry | modules_entry + | motd_entry | error ';' | error '}' ; @@ -446,6 +425,14 @@ timespec: NUMBER timespec_ { $$ = $1 * 60 * 60 * 24 * 7 + $3; } + | NUMBER MONTHS timespec_ + { + $$ = $1 * 60 * 60 * 24 * 7 * 4 + $3; + } + | NUMBER YEARS timespec_ + { + $$ = $1 * 60 * 60 * 24 * 365 + $3; + } ; sizespec_: { $$ = 0; } | sizespec; @@ -484,75 +471,84 @@ serverinfo_items: serverinfo_items serverinfo_item: serverinfo_name | serverinfo_vhost | serverinfo_hub | serverinfo_description | serverinfo_network_name | serverinfo_network_desc | - serverinfo_max_clients | + serverinfo_max_clients | serverinfo_max_nick_length | + serverinfo_max_topic_length | serverinfo_ssl_dh_param_file | serverinfo_rsa_private_key_file | serverinfo_vhost6 | serverinfo_sid | serverinfo_ssl_certificate_file | - serverinfo_ssl_connection_method | + serverinfo_ssl_client_method | serverinfo_ssl_server_method | + serverinfo_ssl_cipher_list | error ';' ; -serverinfo_ssl_connection_method: T_SSL_CONNECTION_METHOD +serverinfo_ssl_client_method: T_SSL_CLIENT_METHOD '=' client_method_types ';' ; +serverinfo_ssl_server_method: T_SSL_SERVER_METHOD '=' server_method_types ';' ; + +client_method_types: client_method_types ',' client_method_type_item | client_method_type_item; +client_method_type_item: T_SSLV3 { #ifdef HAVE_LIBCRYPTO - if (conf_parser_ctx.boot && conf_parser_ctx.pass == 2) - ServerInfo.tls_version = 0; + if (conf_parser_ctx.pass == 2 && ServerInfo.client_ctx) + SSL_CTX_clear_options(ServerInfo.client_ctx, SSL_OP_NO_SSLv3); #endif -} '=' method_types ';' +} | T_TLSV1 { #ifdef HAVE_LIBCRYPTO - if (conf_parser_ctx.boot && conf_parser_ctx.pass == 2) - { - if (!(ServerInfo.tls_version & CONF_SERVER_INFO_TLS_VERSION_SSLV3)) - SSL_CTX_set_options(ServerInfo.server_ctx, SSL_OP_NO_SSLv3); - if (!(ServerInfo.tls_version & CONF_SERVER_INFO_TLS_VERSION_TLSV1)) - SSL_CTX_set_options(ServerInfo.server_ctx, SSL_OP_NO_TLSv1); - } + if (conf_parser_ctx.pass == 2 && ServerInfo.client_ctx) + SSL_CTX_clear_options(ServerInfo.client_ctx, SSL_OP_NO_TLSv1); #endif }; -method_types: method_types ',' method_type_item | method_type_item; -method_type_item: T_SSLV3 +server_method_types: server_method_types ',' server_method_type_item | server_method_type_item; +server_method_type_item: T_SSLV3 { #ifdef HAVE_LIBCRYPTO - if (conf_parser_ctx.boot && conf_parser_ctx.pass == 2) - ServerInfo.tls_version |= CONF_SERVER_INFO_TLS_VERSION_SSLV3; + if (conf_parser_ctx.pass == 2 && ServerInfo.server_ctx) + SSL_CTX_clear_options(ServerInfo.server_ctx, SSL_OP_NO_SSLv3); #endif } | T_TLSV1 { #ifdef HAVE_LIBCRYPTO - if (conf_parser_ctx.boot && conf_parser_ctx.pass == 2) - ServerInfo.tls_version |= CONF_SERVER_INFO_TLS_VERSION_TLSV1; + if (conf_parser_ctx.pass == 2 && ServerInfo.server_ctx) + SSL_CTX_clear_options(ServerInfo.server_ctx, SSL_OP_NO_TLSv1); #endif }; serverinfo_ssl_certificate_file: SSL_CERTIFICATE_FILE '=' QSTRING ';' { #ifdef HAVE_LIBCRYPTO - if (conf_parser_ctx.pass == 2 && ServerInfo.server_ctx) + if (conf_parser_ctx.pass == 2 && ServerInfo.server_ctx) { if (!ServerInfo.rsa_private_key_file) { - yyerror("No rsa_private_key_file specified, SSL disabled"); + conf_error_report("No rsa_private_key_file specified, SSL disabled"); break; } if (SSL_CTX_use_certificate_file(ServerInfo.server_ctx, yylval.string, + SSL_FILETYPE_PEM) <= 0 || + SSL_CTX_use_certificate_file(ServerInfo.client_ctx, yylval.string, SSL_FILETYPE_PEM) <= 0) { - yyerror(ERR_lib_error_string(ERR_get_error())); + report_crypto_errors(); + conf_error_report("Could not open/read certificate file"); break; } if (SSL_CTX_use_PrivateKey_file(ServerInfo.server_ctx, ServerInfo.rsa_private_key_file, + SSL_FILETYPE_PEM) <= 0 || + SSL_CTX_use_PrivateKey_file(ServerInfo.client_ctx, ServerInfo.rsa_private_key_file, SSL_FILETYPE_PEM) <= 0) { - yyerror(ERR_lib_error_string(ERR_get_error())); + report_crypto_errors(); + conf_error_report("Could not read RSA private key"); break; } - if (!SSL_CTX_check_private_key(ServerInfo.server_ctx)) + if (!SSL_CTX_check_private_key(ServerInfo.server_ctx) || + !SSL_CTX_check_private_key(ServerInfo.client_ctx)) { - yyerror(ERR_lib_error_string(ERR_get_error())); + report_crypto_errors(); + conf_error_report("Could not read RSA private key"); break; } } @@ -562,88 +558,122 @@ serverinfo_ssl_certificate_file: SSL_CER serverinfo_rsa_private_key_file: RSA_PRIVATE_KEY_FILE '=' QSTRING ';' { #ifdef HAVE_LIBCRYPTO - if (conf_parser_ctx.pass == 1) + BIO *file = NULL; + + if (conf_parser_ctx.pass != 1) + break; + + if (ServerInfo.rsa_private_key) { - BIO *file; + RSA_free(ServerInfo.rsa_private_key); + ServerInfo.rsa_private_key = NULL; + } - if (ServerInfo.rsa_private_key) - { - RSA_free(ServerInfo.rsa_private_key); - ServerInfo.rsa_private_key = NULL; - } + if (ServerInfo.rsa_private_key_file) + { + MyFree(ServerInfo.rsa_private_key_file); + ServerInfo.rsa_private_key_file = NULL; + } - if (ServerInfo.rsa_private_key_file) - { - MyFree(ServerInfo.rsa_private_key_file); - ServerInfo.rsa_private_key_file = NULL; - } + ServerInfo.rsa_private_key_file = xstrdup(yylval.string); - DupString(ServerInfo.rsa_private_key_file, yylval.string); + if ((file = BIO_new_file(yylval.string, "r")) == NULL) + { + conf_error_report("File open failed, ignoring"); + break; + } - if ((file = BIO_new_file(yylval.string, "r")) == NULL) - { - yyerror("File open failed, ignoring"); - break; - } + ServerInfo.rsa_private_key = PEM_read_bio_RSAPrivateKey(file, NULL, 0, NULL); - ServerInfo.rsa_private_key = (RSA *)PEM_read_bio_RSAPrivateKey(file, NULL, - 0, NULL); + BIO_set_close(file, BIO_CLOSE); + BIO_free(file); - BIO_set_close(file, BIO_CLOSE); - BIO_free(file); + if (ServerInfo.rsa_private_key == NULL) + { + conf_error_report("Couldn't extract key, ignoring"); + break; + } - if (ServerInfo.rsa_private_key == NULL) - { - yyerror("Couldn't extract key, ignoring"); - break; - } + if (!RSA_check_key(ServerInfo.rsa_private_key)) + { + RSA_free(ServerInfo.rsa_private_key); + ServerInfo.rsa_private_key = NULL; - if (!RSA_check_key(ServerInfo.rsa_private_key)) - { - RSA_free(ServerInfo.rsa_private_key); - ServerInfo.rsa_private_key = NULL; + conf_error_report("Invalid key, ignoring"); + break; + } - yyerror("Invalid key, ignoring"); - break; - } + if (RSA_size(ServerInfo.rsa_private_key) < 128) + { + RSA_free(ServerInfo.rsa_private_key); + ServerInfo.rsa_private_key = NULL; + + conf_error_report("Ignoring serverinfo::rsa_private_key_file -- need at least a 1024 bit key size"); + } +#endif +}; + +serverinfo_ssl_dh_param_file: SSL_DH_PARAM_FILE '=' QSTRING ';' +{ +/* TBD - XXX: error reporting */ +#ifdef HAVE_LIBCRYPTO + if (conf_parser_ctx.pass == 2 && ServerInfo.server_ctx) + { + BIO *file = BIO_new_file(yylval.string, "r"); - /* require 2048 bit (256 byte) key */ - if (RSA_size(ServerInfo.rsa_private_key) != 256) + if (file) { - RSA_free(ServerInfo.rsa_private_key); - ServerInfo.rsa_private_key = NULL; + DH *dh = PEM_read_bio_DHparams(file, NULL, NULL, NULL); + + BIO_free(file); - yyerror("Not a 2048 bit key, ignoring"); + if (dh) + { + if (DH_size(dh) < 128) + conf_error_report("Ignoring serverinfo::ssl_dh_param_file -- need at least a 1024 bit DH prime size"); + else + SSL_CTX_set_tmp_dh(ServerInfo.server_ctx, dh); + + DH_free(dh); + } } } #endif }; -serverinfo_name: NAME '=' QSTRING ';' +serverinfo_ssl_cipher_list: T_SSL_CIPHER_LIST '=' QSTRING ';' +{ +#ifdef HAVE_LIBCRYPTO + if (conf_parser_ctx.pass == 2 && ServerInfo.server_ctx) + SSL_CTX_set_cipher_list(ServerInfo.server_ctx, yylval.string); +#endif +}; + +serverinfo_name: NAME '=' QSTRING ';' { /* this isn't rehashable */ if (conf_parser_ctx.pass == 2 && !ServerInfo.name) { if (valid_servname(yylval.string)) - DupString(ServerInfo.name, yylval.string); + ServerInfo.name = xstrdup(yylval.string); else { - ilog(L_ERROR, "Ignoring serverinfo::name -- invalid name. Aborting."); + conf_error_report("Ignoring serverinfo::name -- invalid name. Aborting."); exit(0); } } }; -serverinfo_sid: IRCD_SID '=' QSTRING ';' +serverinfo_sid: IRCD_SID '=' QSTRING ';' { /* this isn't rehashable */ if (conf_parser_ctx.pass == 2 && !ServerInfo.sid) { if (valid_sid(yylval.string)) - DupString(ServerInfo.sid, yylval.string); + ServerInfo.sid = xstrdup(yylval.string); else { - ilog(L_ERROR, "Ignoring serverinfo::sid -- invalid SID. Aborting."); + conf_error_report("Ignoring serverinfo::sid -- invalid SID. Aborting."); exit(0); } } @@ -654,7 +684,7 @@ serverinfo_description: DESCRIPTION '=' if (conf_parser_ctx.pass == 2) { MyFree(ServerInfo.description); - DupString(ServerInfo.description,yylval.string); + ServerInfo.description = xstrdup(yylval.string); } }; @@ -668,17 +698,17 @@ serverinfo_network_name: NETWORK_NAME '= p = '\0'; MyFree(ServerInfo.network_name); - DupString(ServerInfo.network_name, yylval.string); + ServerInfo.network_name = xstrdup(yylval.string); } }; serverinfo_network_desc: NETWORK_DESC '=' QSTRING ';' { - if (conf_parser_ctx.pass == 2) - { - MyFree(ServerInfo.network_desc); - DupString(ServerInfo.network_desc, yylval.string); - } + if (conf_parser_ctx.pass != 2) + break; + + MyFree(ServerInfo.network_desc); + ServerInfo.network_desc = xstrdup(yylval.string); }; serverinfo_vhost: VHOST '=' QSTRING ';' @@ -694,7 +724,7 @@ serverinfo_vhost: VHOST '=' QSTRING ';' hints.ai_flags = AI_PASSIVE | AI_NUMERICHOST; if (getaddrinfo(yylval.string, NULL, &hints, &res)) - ilog(L_ERROR, "Invalid netmask for server vhost(%s)", yylval.string); + ilog(LOG_TYPE_IRCD, "Invalid netmask for server vhost(%s)", yylval.string); else { assert(res != NULL); @@ -723,7 +753,7 @@ serverinfo_vhost6: VHOST6 '=' QSTRING '; hints.ai_flags = AI_PASSIVE | AI_NUMERICHOST; if (getaddrinfo(yylval.string, NULL, &hints, &res)) - ilog(L_ERROR, "Invalid netmask for server vhost6(%s)", yylval.string); + ilog(LOG_TYPE_IRCD, "Invalid netmask for server vhost6(%s)", yylval.string); else { assert(res != NULL); @@ -741,28 +771,74 @@ serverinfo_vhost6: VHOST6 '=' QSTRING '; serverinfo_max_clients: T_MAX_CLIENTS '=' NUMBER ';' { - if (conf_parser_ctx.pass == 2) + if (conf_parser_ctx.pass != 2) + break; + + if ($3 < MAXCLIENTS_MIN) { - recalc_fdlimit(NULL); + char buf[IRCD_BUFSIZE]; - if ($3 < MAXCLIENTS_MIN) - { - char buf[IRCD_BUFSIZE]; - ircsprintf(buf, "MAXCLIENTS too low, setting to %d", MAXCLIENTS_MIN); - yyerror(buf); - } - else if ($3 > MAXCLIENTS_MAX) - { - char buf[IRCD_BUFSIZE]; - ircsprintf(buf, "MAXCLIENTS too high, setting to %d", MAXCLIENTS_MAX); - yyerror(buf); - } - else - ServerInfo.max_clients = $3; + snprintf(buf, sizeof(buf), "MAXCLIENTS too low, setting to %d", MAXCLIENTS_MIN); + conf_error_report(buf); + ServerInfo.max_clients = MAXCLIENTS_MIN; + } + else if ($3 > MAXCLIENTS_MAX) + { + char buf[IRCD_BUFSIZE]; + + snprintf(buf, sizeof(buf), "MAXCLIENTS too high, setting to %d", MAXCLIENTS_MAX); + conf_error_report(buf); + ServerInfo.max_clients = MAXCLIENTS_MAX; + } + else + ServerInfo.max_clients = $3; +}; + +serverinfo_max_nick_length: MAX_NICK_LENGTH '=' NUMBER ';' +{ + if (conf_parser_ctx.pass != 2) + break; + + if ($3 < 9) + { + conf_error_report("max_nick_length too low, setting to 9"); + ServerInfo.max_nick_length = 9; + } + else if ($3 > NICKLEN) + { + char buf[IRCD_BUFSIZE]; + + snprintf(buf, sizeof(buf), "max_nick_length too high, setting to %d", NICKLEN); + conf_error_report(buf); + ServerInfo.max_nick_length = NICKLEN; + } + else + ServerInfo.max_nick_length = $3; +}; + +serverinfo_max_topic_length: MAX_TOPIC_LENGTH '=' NUMBER ';' +{ + if (conf_parser_ctx.pass != 2) + break; + + if ($3 < 80) + { + conf_error_report("max_topic_length too low, setting to 80"); + ServerInfo.max_topic_length = 80; + } + else if ($3 > TOPICLEN) + { + char buf[IRCD_BUFSIZE]; + + snprintf(buf, sizeof(buf), "max_topic_length too high, setting to %d", TOPICLEN); + conf_error_report(buf); + ServerInfo.max_topic_length = TOPICLEN; } + else + ServerInfo.max_topic_length = $3; }; -serverinfo_hub: HUB '=' TBOOL ';' +serverinfo_hub: HUB '=' TBOOL ';' { if (conf_parser_ctx.pass == 2) ServerInfo.hub = yylval.number; @@ -777,591 +853,510 @@ admin_items: admin_items admin_item | ad admin_item: admin_name | admin_description | admin_email | error ';' ; -admin_name: NAME '=' QSTRING ';' +admin_name: NAME '=' QSTRING ';' { - if (conf_parser_ctx.pass == 2) - { - MyFree(AdminInfo.name); - DupString(AdminInfo.name, yylval.string); - } + if (conf_parser_ctx.pass != 2) + break; + + MyFree(AdminInfo.name); + AdminInfo.name = xstrdup(yylval.string); }; admin_email: EMAIL '=' QSTRING ';' { - if (conf_parser_ctx.pass == 2) - { - MyFree(AdminInfo.email); - DupString(AdminInfo.email, yylval.string); - } + if (conf_parser_ctx.pass != 2) + break; + + MyFree(AdminInfo.email); + AdminInfo.email = xstrdup(yylval.string); }; admin_description: DESCRIPTION '=' QSTRING ';' { - if (conf_parser_ctx.pass == 2) - { - MyFree(AdminInfo.description); - DupString(AdminInfo.description, yylval.string); - } + if (conf_parser_ctx.pass != 2) + break; + + MyFree(AdminInfo.description); + AdminInfo.description = xstrdup(yylval.string); }; /*************************************************************************** - * section logging + * motd section ***************************************************************************/ -/* XXX */ -logging_entry: LOGGING '{' logging_items '}' ';' ; +motd_entry: MOTD +{ + if (conf_parser_ctx.pass == 2) + reset_block_state(); +} '{' motd_items '}' ';' +{ + dlink_node *ptr = NULL; -logging_items: logging_items logging_item | - logging_item ; + if (conf_parser_ctx.pass != 2) + break; -logging_item: logging_path | logging_oper_log | - logging_log_level | - logging_use_logging | logging_fuserlog | - logging_foperlog | logging_fglinelog | - logging_fklinelog | logging_killlog | - logging_foperspylog | logging_ioerrlog | - logging_ffailed_operlog | - error ';' ; + if (!block_state.file.buf[0]) + break; -logging_path: T_LOGPATH '=' QSTRING ';' - { - }; + DLINK_FOREACH(ptr, block_state.mask.list.head) + motd_add(ptr->data, block_state.file.buf); +}; -logging_oper_log: OPER_LOG '=' QSTRING ';' - { - }; +motd_items: motd_items motd_item | motd_item; +motd_item: motd_mask | motd_file | error ';' ; -logging_fuserlog: FUSERLOG '=' QSTRING ';' +motd_mask: MASK '=' QSTRING ';' { if (conf_parser_ctx.pass == 2) - strlcpy(ConfigLoggingEntry.userlog, yylval.string, - sizeof(ConfigLoggingEntry.userlog)); + dlinkAdd(xstrdup(yylval.string), make_dlink_node(), &block_state.mask.list); }; -logging_ffailed_operlog: FFAILED_OPERLOG '=' QSTRING ';' +motd_file: T_FILE '=' QSTRING ';' { if (conf_parser_ctx.pass == 2) - strlcpy(ConfigLoggingEntry.failed_operlog, yylval.string, - sizeof(ConfigLoggingEntry.failed_operlog)); + strlcpy(block_state.file.buf, yylval.string, sizeof(block_state.file.buf)); }; -logging_foperlog: FOPERLOG '=' QSTRING ';' +/*************************************************************************** + * section logging + ***************************************************************************/ +logging_entry: T_LOG '{' logging_items '}' ';' ; +logging_items: logging_items logging_item | logging_item ; + +logging_item: logging_use_logging | logging_file_entry | + error ';' ; + +logging_use_logging: USE_LOGGING '=' TBOOL ';' { if (conf_parser_ctx.pass == 2) - strlcpy(ConfigLoggingEntry.operlog, yylval.string, - sizeof(ConfigLoggingEntry.operlog)); + ConfigLoggingEntry.use_logging = yylval.number; }; -logging_foperspylog: FOPERSPYLOG '=' QSTRING ';' +logging_file_entry: { if (conf_parser_ctx.pass == 2) - strlcpy(ConfigLoggingEntry.operspylog, yylval.string, - sizeof(ConfigLoggingEntry.operspylog)); + reset_block_state(); +} T_FILE '{' logging_file_items '}' ';' +{ + if (conf_parser_ctx.pass != 2) + break; + + if (block_state.type.value && block_state.file.buf[0]) + log_set_file(block_state.type.value, block_state.size.value, + block_state.file.buf); }; -logging_fglinelog: FGLINELOG '=' QSTRING ';' +logging_file_items: logging_file_items logging_file_item | + logging_file_item ; + +logging_file_item: logging_file_name | logging_file_type | + logging_file_size | error ';' ; + +logging_file_name: NAME '=' QSTRING ';' { - if (conf_parser_ctx.pass == 2) - strlcpy(ConfigLoggingEntry.glinelog, yylval.string, - sizeof(ConfigLoggingEntry.glinelog)); -}; + if (conf_parser_ctx.pass != 2) + break; -logging_fklinelog: FKLINELOG '=' QSTRING ';' + strlcpy(block_state.file.buf, yylval.string, sizeof(block_state.file.buf)); +} + +logging_file_size: T_SIZE '=' sizespec ';' { - if (conf_parser_ctx.pass == 2) - strlcpy(ConfigLoggingEntry.klinelog, yylval.string, - sizeof(ConfigLoggingEntry.klinelog)); + block_state.size.value = $3; +} | T_SIZE '=' T_UNLIMITED ';' +{ + block_state.size.value = 0; }; -logging_ioerrlog: FIOERRLOG '=' QSTRING ';' +logging_file_type: TYPE { if (conf_parser_ctx.pass == 2) - strlcpy(ConfigLoggingEntry.ioerrlog, yylval.string, - sizeof(ConfigLoggingEntry.ioerrlog)); -}; + block_state.type.value = 0; +} '=' logging_file_type_items ';' ; -logging_killlog: FKILLLOG '=' QSTRING ';' +logging_file_type_items: logging_file_type_items ',' logging_file_type_item | logging_file_type_item; +logging_file_type_item: USER { if (conf_parser_ctx.pass == 2) - strlcpy(ConfigLoggingEntry.killlog, yylval.string, - sizeof(ConfigLoggingEntry.killlog)); -}; - -logging_log_level: LOG_LEVEL '=' T_L_CRIT ';' -{ + block_state.type.value = LOG_TYPE_USER; +} | OPERATOR +{ if (conf_parser_ctx.pass == 2) - set_log_level(L_CRIT); -} | LOG_LEVEL '=' T_L_ERROR ';' + block_state.type.value = LOG_TYPE_OPER; +} | GLINE { if (conf_parser_ctx.pass == 2) - set_log_level(L_ERROR); -} | LOG_LEVEL '=' T_L_WARN ';' + block_state.type.value = LOG_TYPE_GLINE; +} | XLINE { if (conf_parser_ctx.pass == 2) - set_log_level(L_WARN); -} | LOG_LEVEL '=' T_L_NOTICE ';' + block_state.type.value = LOG_TYPE_XLINE; +} | RESV { if (conf_parser_ctx.pass == 2) - set_log_level(L_NOTICE); -} | LOG_LEVEL '=' T_L_TRACE ';' + block_state.type.value = LOG_TYPE_RESV; +} | T_DLINE { if (conf_parser_ctx.pass == 2) - set_log_level(L_TRACE); -} | LOG_LEVEL '=' T_L_INFO ';' + block_state.type.value = LOG_TYPE_DLINE; +} | KLINE { if (conf_parser_ctx.pass == 2) - set_log_level(L_INFO); -} | LOG_LEVEL '=' T_L_DEBUG ';' + block_state.type.value = LOG_TYPE_KLINE; +} | KILL { if (conf_parser_ctx.pass == 2) - set_log_level(L_DEBUG); -}; - -logging_use_logging: USE_LOGGING '=' TBOOL ';' + block_state.type.value = LOG_TYPE_KILL; +} | T_DEBUG { if (conf_parser_ctx.pass == 2) - ConfigLoggingEntry.use_logging = yylval.number; + block_state.type.value = LOG_TYPE_DEBUG; }; + /*************************************************************************** * section oper ***************************************************************************/ -oper_entry: OPERATOR +oper_entry: OPERATOR { - if (conf_parser_ctx.pass == 2) - { - yy_conf = make_conf_item(OPER_TYPE); - yy_aconf = map_to_conf(yy_conf); - SetConfEncrypted(yy_aconf); /* Yes, the default is encrypted */ - } - else - { - MyFree(class_name); - class_name = NULL; - } -} oper_name_b '{' oper_items '}' ';' + if (conf_parser_ctx.pass != 2) + break; + + reset_block_state(); + block_state.flags.value |= CONF_FLAGS_ENCRYPTED; +} '{' oper_items '}' ';' { - if (conf_parser_ctx.pass == 2) - { - struct CollectItem *yy_tmp; - dlink_node *ptr; - dlink_node *next_ptr; + dlink_node *ptr = NULL; - conf_add_class_to_conf(yy_conf, class_name); + if (conf_parser_ctx.pass != 2) + break; - /* Now, make sure there is a copy of the "base" given oper - * block in each of the collected copies - */ + if (!block_state.name.buf[0]) + break; +#ifdef HAVE_LIBCRYPTO + if (!block_state.file.buf[0] && + !block_state.rpass.buf[0]) + break; +#else + if (!block_state.rpass.buf[0]) + break; +#endif - DLINK_FOREACH_SAFE(ptr, next_ptr, col_conf_list.head) - { - struct AccessItem *new_aconf; - struct ConfItem *new_conf; - yy_tmp = ptr->data; - - new_conf = make_conf_item(OPER_TYPE); - new_aconf = (struct AccessItem *)map_to_conf(new_conf); - - new_aconf->flags = yy_aconf->flags; - - if (yy_conf->name != NULL) - DupString(new_conf->name, yy_conf->name); - if (yy_tmp->user != NULL) - DupString(new_aconf->user, yy_tmp->user); - else - DupString(new_aconf->user, "*"); - if (yy_tmp->host != NULL) - DupString(new_aconf->host, yy_tmp->host); - else - DupString(new_aconf->host, "*"); - conf_add_class_to_conf(new_conf, class_name); - if (yy_aconf->passwd != NULL) - DupString(new_aconf->passwd, yy_aconf->passwd); + DLINK_FOREACH(ptr, block_state.mask.list.head) + { + struct MaskItem *conf = NULL; + struct split_nuh_item nuh; - new_aconf->port = yy_aconf->port; -#ifdef HAVE_LIBCRYPTO - if (yy_aconf->rsa_public_key_file != NULL) - { - BIO *file; + nuh.nuhmask = ptr->data; + nuh.nickptr = NULL; + nuh.userptr = block_state.user.buf; + nuh.hostptr = block_state.host.buf; + nuh.nicksize = 0; + nuh.usersize = sizeof(block_state.user.buf); + nuh.hostsize = sizeof(block_state.host.buf); + split_nuh(&nuh); - DupString(new_aconf->rsa_public_key_file, - yy_aconf->rsa_public_key_file); + conf = conf_make(CONF_OPER); + conf->name = xstrdup(block_state.name.buf); + conf->user = xstrdup(block_state.user.buf); + conf->host = xstrdup(block_state.host.buf); + + if (block_state.cert.buf[0]) + conf->certfp = xstrdup(block_state.cert.buf); + + if (block_state.rpass.buf[0]) + conf->passwd = xstrdup(block_state.rpass.buf); + + conf->flags = block_state.flags.value; + conf->modes = block_state.modes.value; + conf->port = block_state.port.value; + conf->htype = parse_netmask(conf->host, &conf->addr, &conf->bits); - file = BIO_new_file(yy_aconf->rsa_public_key_file, "r"); - new_aconf->rsa_public_key = (RSA *)PEM_read_bio_RSA_PUBKEY(file, - NULL, 0, NULL); - BIO_set_close(file, BIO_CLOSE); - BIO_free(file); - } -#endif + conf_add_class_to_conf(conf, block_state.class.buf); #ifdef HAVE_LIBCRYPTO - if (yy_tmp->name && (yy_tmp->passwd || yy_aconf->rsa_public_key) - && yy_tmp->host) -#else - if (yy_tmp->name && yy_tmp->passwd && yy_tmp->host) -#endif + if (block_state.file.buf[0]) + { + BIO *file = NULL; + RSA *pkey = NULL; + + if ((file = BIO_new_file(block_state.file.buf, "r")) == NULL) { - conf_add_class_to_conf(new_conf, class_name); - if (yy_tmp->name != NULL) - DupString(new_conf->name, yy_tmp->name); + conf_error_report("Ignoring rsa_public_key_file -- file doesn't exist"); + break; } - dlinkDelete(&yy_tmp->node, &col_conf_list); - free_collect_item(yy_tmp); - } + if ((pkey = PEM_read_bio_RSA_PUBKEY(file, NULL, 0, NULL)) == NULL) + conf_error_report("Ignoring rsa_public_key_file -- Key invalid; check key syntax."); - yy_conf = NULL; - yy_aconf = NULL; - - - MyFree(class_name); - class_name = NULL; + conf->rsa_public_key = pkey; + BIO_set_close(file, BIO_CLOSE); + BIO_free(file); + } +#endif /* HAVE_LIBCRYPTO */ } -}; +}; -oper_name_b: | oper_name_t; oper_items: oper_items oper_item | oper_item; oper_item: oper_name | oper_user | oper_password | oper_umodes | oper_class | oper_encrypted | - oper_rsa_public_key_file | oper_flags | error ';' ; + oper_rsa_public_key_file | oper_ssl_certificate_fingerprint | + oper_ssl_connection_required | + oper_flags | error ';' ; oper_name: NAME '=' QSTRING ';' { if (conf_parser_ctx.pass == 2) - { - if (strlen(yylval.string) > OPERNICKLEN) - yylval.string[OPERNICKLEN] = '\0'; - - MyFree(yy_conf->name); - DupString(yy_conf->name, yylval.string); - } -}; - -oper_name_t: QSTRING -{ - if (conf_parser_ctx.pass == 2) - { - if (strlen(yylval.string) > OPERNICKLEN) - yylval.string[OPERNICKLEN] = '\0'; - - MyFree(yy_conf->name); - DupString(yy_conf->name, yylval.string); - } + strlcpy(block_state.name.buf, yylval.string, sizeof(block_state.name.buf)); }; oper_user: USER '=' QSTRING ';' { if (conf_parser_ctx.pass == 2) - { - struct split_nuh_item nuh; - - nuh.nuhmask = yylval.string; - nuh.nickptr = NULL; - nuh.userptr = userbuf; - nuh.hostptr = hostbuf; - - nuh.nicksize = 0; - nuh.usersize = sizeof(userbuf); - nuh.hostsize = sizeof(hostbuf); - - split_nuh(&nuh); - - if (yy_aconf->user == NULL) - { - DupString(yy_aconf->user, userbuf); - DupString(yy_aconf->host, hostbuf); - } - else - { - struct CollectItem *yy_tmp = MyMalloc(sizeof(struct CollectItem)); - - DupString(yy_tmp->user, userbuf); - DupString(yy_tmp->host, hostbuf); - - dlinkAdd(yy_tmp, &yy_tmp->node, &col_conf_list); - } - } + dlinkAdd(xstrdup(yylval.string), make_dlink_node(), &block_state.mask.list); }; oper_password: PASSWORD '=' QSTRING ';' { if (conf_parser_ctx.pass == 2) - { - if (yy_aconf->passwd != NULL) - memset(yy_aconf->passwd, 0, strlen(yy_aconf->passwd)); - - MyFree(yy_aconf->passwd); - DupString(yy_aconf->passwd, yylval.string); - } + strlcpy(block_state.rpass.buf, yylval.string, sizeof(block_state.rpass.buf)); }; oper_encrypted: ENCRYPTED '=' TBOOL ';' { - if (conf_parser_ctx.pass == 2) - { - if (yylval.number) - SetConfEncrypted(yy_aconf); - else - ClearConfEncrypted(yy_aconf); - } + if (conf_parser_ctx.pass != 2) + break; + + if (yylval.number) + block_state.flags.value |= CONF_FLAGS_ENCRYPTED; + else + block_state.flags.value &= ~CONF_FLAGS_ENCRYPTED; }; oper_rsa_public_key_file: RSA_PUBLIC_KEY_FILE '=' QSTRING ';' { -#ifdef HAVE_LIBCRYPTO if (conf_parser_ctx.pass == 2) - { - BIO *file; - - if (yy_aconf->rsa_public_key != NULL) - { - RSA_free(yy_aconf->rsa_public_key); - yy_aconf->rsa_public_key = NULL; - } - - if (yy_aconf->rsa_public_key_file != NULL) - { - MyFree(yy_aconf->rsa_public_key_file); - yy_aconf->rsa_public_key_file = NULL; - } - - DupString(yy_aconf->rsa_public_key_file, yylval.string); - file = BIO_new_file(yylval.string, "r"); - - if (file == NULL) - { - yyerror("Ignoring rsa_public_key_file -- file doesn't exist"); - break; - } + strlcpy(block_state.file.buf, yylval.string, sizeof(block_state.file.buf)); +}; - yy_aconf->rsa_public_key = (RSA *)PEM_read_bio_RSA_PUBKEY(file, NULL, 0, NULL); +oper_ssl_certificate_fingerprint: SSL_CERTIFICATE_FINGERPRINT '=' QSTRING ';' +{ + if (conf_parser_ctx.pass == 2) + strlcpy(block_state.cert.buf, yylval.string, sizeof(block_state.cert.buf)); +}; - if (yy_aconf->rsa_public_key == NULL) - { - yyerror("Ignoring rsa_public_key_file -- Key invalid; check key syntax."); - break; - } +oper_ssl_connection_required: SSL_CONNECTION_REQUIRED '=' TBOOL ';' +{ + if (conf_parser_ctx.pass != 2) + break; - BIO_set_close(file, BIO_CLOSE); - BIO_free(file); - } -#endif /* HAVE_LIBCRYPTO */ + if (yylval.number) + block_state.flags.value |= CONF_FLAGS_SSL; + else + block_state.flags.value &= ~CONF_FLAGS_SSL; }; oper_class: CLASS '=' QSTRING ';' { if (conf_parser_ctx.pass == 2) - { - MyFree(class_name); - DupString(class_name, yylval.string); - } + strlcpy(block_state.class.buf, yylval.string, sizeof(block_state.class.buf)); }; oper_umodes: T_UMODES { if (conf_parser_ctx.pass == 2) - yy_aconf->modes = 0; + block_state.modes.value = 0; } '=' oper_umodes_items ';' ; oper_umodes_items: oper_umodes_items ',' oper_umodes_item | oper_umodes_item; oper_umodes_item: T_BOTS { if (conf_parser_ctx.pass == 2) - yy_aconf->modes |= UMODE_BOTS; + block_state.modes.value |= UMODE_BOTS; } | T_CCONN { if (conf_parser_ctx.pass == 2) - yy_aconf->modes |= UMODE_CCONN; -} | T_CCONN_FULL -{ - if (conf_parser_ctx.pass == 2) - yy_aconf->modes |= UMODE_CCONN_FULL; + block_state.modes.value |= UMODE_CCONN; } | T_DEAF { if (conf_parser_ctx.pass == 2) - yy_aconf->modes |= UMODE_DEAF; + block_state.modes.value |= UMODE_DEAF; } | T_DEBUG { if (conf_parser_ctx.pass == 2) - yy_aconf->modes |= UMODE_DEBUG; + block_state.modes.value |= UMODE_DEBUG; } | T_FULL { if (conf_parser_ctx.pass == 2) - yy_aconf->modes |= UMODE_FULL; + block_state.modes.value |= UMODE_FULL; +} | HIDDEN +{ + if (conf_parser_ctx.pass == 2) + block_state.modes.value |= UMODE_HIDDEN; } | T_SKILL { if (conf_parser_ctx.pass == 2) - yy_aconf->modes |= UMODE_SKILL; + block_state.modes.value |= UMODE_SKILL; } | T_NCHANGE { if (conf_parser_ctx.pass == 2) - yy_aconf->modes |= UMODE_NCHANGE; + block_state.modes.value |= UMODE_NCHANGE; } | T_REJ { if (conf_parser_ctx.pass == 2) - yy_aconf->modes |= UMODE_REJ; + block_state.modes.value |= UMODE_REJ; } | T_UNAUTH { if (conf_parser_ctx.pass == 2) - yy_aconf->modes |= UMODE_UNAUTH; + block_state.modes.value |= UMODE_UNAUTH; } | T_SPY { if (conf_parser_ctx.pass == 2) - yy_aconf->modes |= UMODE_SPY; + block_state.modes.value |= UMODE_SPY; } | T_EXTERNAL { if (conf_parser_ctx.pass == 2) - yy_aconf->modes |= UMODE_EXTERNAL; + block_state.modes.value |= UMODE_EXTERNAL; } | T_OPERWALL { if (conf_parser_ctx.pass == 2) - yy_aconf->modes |= UMODE_OPERWALL; + block_state.modes.value |= UMODE_OPERWALL; } | T_SERVNOTICE { if (conf_parser_ctx.pass == 2) - yy_aconf->modes |= UMODE_SERVNOTICE; + block_state.modes.value |= UMODE_SERVNOTICE; } | T_INVISIBLE { if (conf_parser_ctx.pass == 2) - yy_aconf->modes |= UMODE_INVISIBLE; + block_state.modes.value |= UMODE_INVISIBLE; } | T_WALLOP { if (conf_parser_ctx.pass == 2) - yy_aconf->modes |= UMODE_WALLOP; + block_state.modes.value |= UMODE_WALLOP; } | T_SOFTCALLERID { if (conf_parser_ctx.pass == 2) - yy_aconf->modes |= UMODE_SOFTCALLERID; + block_state.modes.value |= UMODE_SOFTCALLERID; } | T_CALLERID { if (conf_parser_ctx.pass == 2) - yy_aconf->modes |= UMODE_CALLERID; + block_state.modes.value |= UMODE_CALLERID; } | T_LOCOPS { if (conf_parser_ctx.pass == 2) - yy_aconf->modes |= UMODE_LOCOPS; + block_state.modes.value |= UMODE_LOCOPS; +} | T_NONONREG +{ + if (conf_parser_ctx.pass == 2) + block_state.modes.value |= UMODE_REGONLY; +} | T_FARCONNECT +{ + if (conf_parser_ctx.pass == 2) + block_state.modes.value |= UMODE_FARCONNECT; }; oper_flags: IRCD_FLAGS { + if (conf_parser_ctx.pass == 2) + block_state.port.value = 0; } '=' oper_flags_items ';'; oper_flags_items: oper_flags_items ',' oper_flags_item | oper_flags_item; -oper_flags_item: NOT { not_atom = 1; } oper_flags_item_atom - | { not_atom = 0; } oper_flags_item_atom; - -oper_flags_item_atom: GLOBAL_KILL +oper_flags_item: KILL ':' REMOTE { if (conf_parser_ctx.pass == 2) - { - if (not_atom)yy_aconf->port &= ~OPER_FLAG_GLOBAL_KILL; - else yy_aconf->port |= OPER_FLAG_GLOBAL_KILL; - } -} | REMOTE + block_state.port.value |= OPER_FLAG_KILL_REMOTE; +} | KILL { if (conf_parser_ctx.pass == 2) - { - if (not_atom) yy_aconf->port &= ~OPER_FLAG_REMOTE; - else yy_aconf->port |= OPER_FLAG_REMOTE; - } + block_state.port.value |= OPER_FLAG_KILL; +} | CONNECT ':' REMOTE +{ + if (conf_parser_ctx.pass == 2) + block_state.port.value |= OPER_FLAG_CONNECT_REMOTE; +} | CONNECT +{ + if (conf_parser_ctx.pass == 2) + block_state.port.value |= OPER_FLAG_CONNECT; +} | SQUIT ':' REMOTE +{ + if (conf_parser_ctx.pass == 2) + block_state.port.value |= OPER_FLAG_SQUIT_REMOTE; +} | SQUIT +{ + if (conf_parser_ctx.pass == 2) + block_state.port.value |= OPER_FLAG_SQUIT; } | KLINE { if (conf_parser_ctx.pass == 2) - { - if (not_atom) yy_aconf->port &= ~OPER_FLAG_K; - else yy_aconf->port |= OPER_FLAG_K; - } + block_state.port.value |= OPER_FLAG_K; } | UNKLINE { if (conf_parser_ctx.pass == 2) - { - if (not_atom) yy_aconf->port &= ~OPER_FLAG_UNKLINE; - else yy_aconf->port |= OPER_FLAG_UNKLINE; - } + block_state.port.value |= OPER_FLAG_UNKLINE; +} | T_DLINE +{ + if (conf_parser_ctx.pass == 2) + block_state.port.value |= OPER_FLAG_DLINE; +} | T_UNDLINE +{ + if (conf_parser_ctx.pass == 2) + block_state.port.value |= OPER_FLAG_UNDLINE; } | XLINE { if (conf_parser_ctx.pass == 2) - { - if (not_atom) yy_aconf->port &= ~OPER_FLAG_X; - else yy_aconf->port |= OPER_FLAG_X; - } + block_state.port.value |= OPER_FLAG_XLINE; +} | T_UNXLINE +{ + if (conf_parser_ctx.pass == 2) + block_state.port.value |= OPER_FLAG_UNXLINE; } | GLINE { if (conf_parser_ctx.pass == 2) - { - if (not_atom) yy_aconf->port &= ~OPER_FLAG_GLINE; - else yy_aconf->port |= OPER_FLAG_GLINE; - } + block_state.port.value |= OPER_FLAG_GLINE; } | DIE { if (conf_parser_ctx.pass == 2) - { - if (not_atom) yy_aconf->port &= ~OPER_FLAG_DIE; - else yy_aconf->port |= OPER_FLAG_DIE; - } + block_state.port.value |= OPER_FLAG_DIE; +} | T_RESTART +{ + if (conf_parser_ctx.pass == 2) + block_state.port.value |= OPER_FLAG_RESTART; } | REHASH { if (conf_parser_ctx.pass == 2) - { - if (not_atom) yy_aconf->port &= ~OPER_FLAG_REHASH; - else yy_aconf->port |= OPER_FLAG_REHASH; - } + block_state.port.value |= OPER_FLAG_REHASH; } | ADMIN { if (conf_parser_ctx.pass == 2) - { - if (not_atom) yy_aconf->port &= ~OPER_FLAG_ADMIN; - else yy_aconf->port |= OPER_FLAG_ADMIN; - } -} | HIDDEN_ADMIN + block_state.port.value |= OPER_FLAG_ADMIN; +} | T_OPERWALL { if (conf_parser_ctx.pass == 2) - { - if (not_atom) yy_aconf->port &= ~OPER_FLAG_HIDDEN_ADMIN; - else yy_aconf->port |= OPER_FLAG_HIDDEN_ADMIN; - } -} | NICK_CHANGES + block_state.port.value |= OPER_FLAG_OPERWALL; +} | T_GLOBOPS { if (conf_parser_ctx.pass == 2) - { - if (not_atom) yy_aconf->port &= ~OPER_FLAG_N; - else yy_aconf->port |= OPER_FLAG_N; - } -} | T_OPERWALL + block_state.port.value |= OPER_FLAG_GLOBOPS; +} | T_WALLOPS { if (conf_parser_ctx.pass == 2) - { - if (not_atom) yy_aconf->port &= ~OPER_FLAG_OPERWALL; - else yy_aconf->port |= OPER_FLAG_OPERWALL; - } -} | OPER_SPY_T + block_state.port.value |= OPER_FLAG_WALLOPS; +} | T_LOCOPS { if (conf_parser_ctx.pass == 2) - { - if (not_atom) yy_aconf->port &= ~OPER_FLAG_OPER_SPY; - else yy_aconf->port |= OPER_FLAG_OPER_SPY; - } -} | HIDDEN_OPER + block_state.port.value |= OPER_FLAG_LOCOPS; +} | REMOTEBAN { if (conf_parser_ctx.pass == 2) - { - if (not_atom) yy_aconf->port &= ~OPER_FLAG_HIDDEN_OPER; - else yy_aconf->port |= OPER_FLAG_HIDDEN_OPER; - } -} | REMOTEBAN + block_state.port.value |= OPER_FLAG_REMOTEBAN; +} | T_SET { if (conf_parser_ctx.pass == 2) - { - if (not_atom) yy_aconf->port &= ~OPER_FLAG_REMOTEBAN; - else yy_aconf->port |= OPER_FLAG_REMOTEBAN; - } -} | ENCRYPTED + block_state.port.value |= OPER_FLAG_SET; +} | MODULE { if (conf_parser_ctx.pass == 2) - { - if (not_atom) ClearConfEncrypted(yy_aconf); - else SetConfEncrypted(yy_aconf); - } + block_state.port.value |= OPER_FLAG_MODULE; }; @@ -1370,61 +1365,69 @@ oper_flags_item_atom: GLOBAL_KILL ***************************************************************************/ class_entry: CLASS { - if (conf_parser_ctx.pass == 1) - { - yy_conf = make_conf_item(CLASS_TYPE); - yy_class = map_to_conf(yy_conf); - } -} class_name_b '{' class_items '}' ';' -{ - if (conf_parser_ctx.pass == 1) - { - struct ConfItem *cconf = NULL; - struct ClassItem *class = NULL; - - if (yy_class_name == NULL) - delete_conf_item(yy_conf); - else - { - cconf = find_exact_name_conf(CLASS_TYPE, yy_class_name, NULL, NULL); + if (conf_parser_ctx.pass != 1) + break; - if (cconf != NULL) /* The class existed already */ - { - int user_count = 0; - - rebuild_cidr_class(cconf, yy_class); - - class = map_to_conf(cconf); - - user_count = class->curr_user_count; - memcpy(class, yy_class, sizeof(*class)); - class->curr_user_count = user_count; - class->active = 1; + reset_block_state(); - delete_conf_item(yy_conf); - - MyFree(cconf->name); /* Allows case change of class name */ - cconf->name = yy_class_name; - } - else /* Brand new class */ - { - MyFree(yy_conf->name); /* just in case it was allocated */ - yy_conf->name = yy_class_name; - yy_class->active = 1; - } - } - - yy_class_name = NULL; - } + block_state.ping_freq.value = DEFAULT_PINGFREQUENCY; + block_state.con_freq.value = DEFAULT_CONNECTFREQUENCY; + block_state.max_total.value = MAXIMUM_LINKS_DEFAULT; + block_state.max_sendq.value = DEFAULT_SENDQ; + block_state.max_recvq.value = DEFAULT_RECVQ; +} '{' class_items '}' ';' +{ + struct ClassItem *class = NULL; + + if (conf_parser_ctx.pass != 1) + break; + + if (!block_state.class.buf[0]) + break; + + if (!(class = class_find(block_state.class.buf, 0))) + class = class_make(); + + class->active = 1; + MyFree(class->name); + class->name = xstrdup(block_state.class.buf); + class->ping_freq = block_state.ping_freq.value; + class->max_perip = block_state.max_perip.value; + class->con_freq = block_state.con_freq.value; + class->max_total = block_state.max_total.value; + class->max_global = block_state.max_global.value; + class->max_local = block_state.max_local.value; + class->max_ident = block_state.max_ident.value; + class->max_sendq = block_state.max_sendq.value; + class->max_recvq = block_state.max_recvq.value; + + if (block_state.min_idle.value > block_state.max_idle.value) + { + block_state.min_idle.value = 0; + block_state.max_idle.value = 0; + block_state.flags.value &= ~CLASS_FLAGS_FAKE_IDLE; + } + + class->flags = block_state.flags.value; + class->min_idle = block_state.min_idle.value; + class->max_idle = block_state.max_idle.value; + + if (class->number_per_cidr && block_state.number_per_cidr.value) + if ((class->cidr_bitlen_ipv4 && block_state.cidr_bitlen_ipv4.value) || + (class->cidr_bitlen_ipv6 && block_state.cidr_bitlen_ipv6.value)) + if ((class->cidr_bitlen_ipv4 != block_state.cidr_bitlen_ipv4.value) || + (class->cidr_bitlen_ipv6 != block_state.cidr_bitlen_ipv6.value)) + rebuild_cidr_list(class); + + class->cidr_bitlen_ipv4 = block_state.cidr_bitlen_ipv4.value; + class->cidr_bitlen_ipv6 = block_state.cidr_bitlen_ipv6.value; + class->number_per_cidr = block_state.number_per_cidr.value; }; -class_name_b: | class_name_t; - class_items: class_items class_item | class_item; class_item: class_name | class_cidr_bitlen_ipv4 | class_cidr_bitlen_ipv6 | class_ping_time | - class_ping_warning | class_number_per_cidr | class_number_per_ip | class_connectfreq | @@ -1432,144 +1435,160 @@ class_item: class_name | class_max_global | class_max_local | class_max_ident | - class_sendq | + class_sendq | class_recvq | + class_min_idle | + class_max_idle | + class_flags | error ';' ; -class_name: NAME '=' QSTRING ';' -{ - if (conf_parser_ctx.pass == 1) - { - MyFree(yy_class_name); - DupString(yy_class_name, yylval.string); - } -}; - -class_name_t: QSTRING +class_name: NAME '=' QSTRING ';' { if (conf_parser_ctx.pass == 1) - { - MyFree(yy_class_name); - DupString(yy_class_name, yylval.string); - } + strlcpy(block_state.class.buf, yylval.string, sizeof(block_state.class.buf)); }; class_ping_time: PING_TIME '=' timespec ';' { if (conf_parser_ctx.pass == 1) - PingFreq(yy_class) = $3; -}; - -class_ping_warning: PING_WARNING '=' timespec ';' -{ - if (conf_parser_ctx.pass == 1) - PingWarning(yy_class) = $3; + block_state.ping_freq.value = $3; }; class_number_per_ip: NUMBER_PER_IP '=' NUMBER ';' { if (conf_parser_ctx.pass == 1) - MaxPerIp(yy_class) = $3; + block_state.max_perip.value = $3; }; class_connectfreq: CONNECTFREQ '=' timespec ';' { if (conf_parser_ctx.pass == 1) - ConFreq(yy_class) = $3; + block_state.con_freq.value = $3; }; class_max_number: MAX_NUMBER '=' NUMBER ';' { if (conf_parser_ctx.pass == 1) - MaxTotal(yy_class) = $3; + block_state.max_total.value = $3; }; class_max_global: MAX_GLOBAL '=' NUMBER ';' { if (conf_parser_ctx.pass == 1) - MaxGlobal(yy_class) = $3; + block_state.max_global.value = $3; }; class_max_local: MAX_LOCAL '=' NUMBER ';' { if (conf_parser_ctx.pass == 1) - MaxLocal(yy_class) = $3; + block_state.max_local.value = $3; }; class_max_ident: MAX_IDENT '=' NUMBER ';' { if (conf_parser_ctx.pass == 1) - MaxIdent(yy_class) = $3; + block_state.max_ident.value = $3; }; class_sendq: SENDQ '=' sizespec ';' { if (conf_parser_ctx.pass == 1) - MaxSendq(yy_class) = $3; + block_state.max_sendq.value = $3; +}; + +class_recvq: T_RECVQ '=' sizespec ';' +{ + if (conf_parser_ctx.pass == 1) + if ($3 >= CLIENT_FLOOD_MIN && $3 <= CLIENT_FLOOD_MAX) + block_state.max_recvq.value = $3; }; class_cidr_bitlen_ipv4: CIDR_BITLEN_IPV4 '=' NUMBER ';' { if (conf_parser_ctx.pass == 1) - CidrBitlenIPV4(yy_class) = $3; + block_state.cidr_bitlen_ipv4.value = $3 > 32 ? 32 : $3; }; class_cidr_bitlen_ipv6: CIDR_BITLEN_IPV6 '=' NUMBER ';' { if (conf_parser_ctx.pass == 1) - CidrBitlenIPV6(yy_class) = $3; + block_state.cidr_bitlen_ipv6.value = $3 > 128 ? 128 : $3; }; class_number_per_cidr: NUMBER_PER_CIDR '=' NUMBER ';' { if (conf_parser_ctx.pass == 1) - NumberPerCidr(yy_class) = $3; + block_state.number_per_cidr.value = $3; +}; + +class_min_idle: MIN_IDLE '=' timespec ';' +{ + if (conf_parser_ctx.pass != 1) + break; + + block_state.min_idle.value = $3; + block_state.flags.value |= CLASS_FLAGS_FAKE_IDLE; +}; + +class_max_idle: MAX_IDLE '=' timespec ';' +{ + if (conf_parser_ctx.pass != 1) + break; + + block_state.max_idle.value = $3; + block_state.flags.value |= CLASS_FLAGS_FAKE_IDLE; +}; + +class_flags: IRCD_FLAGS +{ + if (conf_parser_ctx.pass == 1) + block_state.flags.value &= CLASS_FLAGS_FAKE_IDLE; +} '=' class_flags_items ';'; + +class_flags_items: class_flags_items ',' class_flags_item | class_flags_item; +class_flags_item: RANDOM_IDLE +{ + if (conf_parser_ctx.pass == 1) + block_state.flags.value |= CLASS_FLAGS_RANDOM_IDLE; +} | HIDE_IDLE_FROM_OPERS +{ + if (conf_parser_ctx.pass == 1) + block_state.flags.value |= CLASS_FLAGS_HIDE_IDLE_FROM_OPERS; }; + /*************************************************************************** * section listen ***************************************************************************/ listen_entry: LISTEN { if (conf_parser_ctx.pass == 2) - { - listener_address = NULL; - listener_flags = 0; - } -} '{' listen_items '}' ';' -{ - if (conf_parser_ctx.pass == 2) - { - MyFree(listener_address); - listener_address = NULL; - } -}; + reset_block_state(); +} '{' listen_items '}' ';'; listen_flags: IRCD_FLAGS { - listener_flags = 0; + block_state.flags.value = 0; } '=' listen_flags_items ';'; listen_flags_items: listen_flags_items ',' listen_flags_item | listen_flags_item; listen_flags_item: T_SSL { if (conf_parser_ctx.pass == 2) - listener_flags |= LISTENER_SSL; + block_state.flags.value |= LISTENER_SSL; } | HIDDEN { if (conf_parser_ctx.pass == 2) - listener_flags |= LISTENER_HIDDEN; + block_state.flags.value |= LISTENER_HIDDEN; } | T_SERVER { if (conf_parser_ctx.pass == 2) - listener_flags |= LISTENER_SERVER; + block_state.flags.value |= LISTENER_SERVER; }; - - listen_items: listen_items listen_item | listen_item; listen_item: listen_port | listen_flags | listen_address | listen_host | error ';'; -listen_port: PORT '=' port_items { listener_flags = 0; } ';'; +listen_port: PORT '=' port_items { block_state.flags.value = 0; } ';'; port_items: port_items ',' port_item | port_item; @@ -1577,15 +1596,15 @@ port_item: NUMBER { if (conf_parser_ctx.pass == 2) { - if ((listener_flags & LISTENER_SSL)) + if (block_state.flags.value & LISTENER_SSL) #ifdef HAVE_LIBCRYPTO if (!ServerInfo.server_ctx) #endif { - yyerror("SSL not available - port closed"); + conf_error_report("SSL not available - port closed"); break; } - add_listener($1, listener_address, listener_flags); + add_listener($1, block_state.addr.buf, block_state.flags.value); } } | NUMBER TWODOTS NUMBER { @@ -1593,36 +1612,30 @@ port_item: NUMBER { int i; - if ((listener_flags & LISTENER_SSL)) + if (block_state.flags.value & LISTENER_SSL) #ifdef HAVE_LIBCRYPTO if (!ServerInfo.server_ctx) #endif { - yyerror("SSL not available - port closed"); + conf_error_report("SSL not available - port closed"); break; } for (i = $1; i <= $3; ++i) - add_listener(i, listener_address, listener_flags); + add_listener(i, block_state.addr.buf, block_state.flags.value); } }; listen_address: IP '=' QSTRING ';' { if (conf_parser_ctx.pass == 2) - { - MyFree(listener_address); - DupString(listener_address, yylval.string); - } + strlcpy(block_state.addr.buf, yylval.string, sizeof(block_state.addr.buf)); }; listen_host: HOST '=' QSTRING ';' { if (conf_parser_ctx.pass == 2) - { - MyFree(listener_address); - DupString(listener_address, yylval.string); - } + strlcpy(block_state.addr.buf, yylval.string, sizeof(block_state.addr.buf)); }; /*************************************************************************** @@ -1631,71 +1644,44 @@ listen_host: HOST '=' QSTRING ';' auth_entry: IRCD_AUTH { if (conf_parser_ctx.pass == 2) - { - yy_conf = make_conf_item(CLIENT_TYPE); - yy_aconf = map_to_conf(yy_conf); - } - else - { - MyFree(class_name); - class_name = NULL; - } + reset_block_state(); } '{' auth_items '}' ';' { - if (conf_parser_ctx.pass == 2) - { - struct CollectItem *yy_tmp = NULL; - dlink_node *ptr = NULL, *next_ptr = NULL; - - if (yy_aconf->user && yy_aconf->host) - { - conf_add_class_to_conf(yy_conf, class_name); - add_conf_by_address(CONF_CLIENT, yy_aconf); - } - else - delete_conf_item(yy_conf); - - /* copy over settings from first struct */ - DLINK_FOREACH_SAFE(ptr, next_ptr, col_conf_list.head) - { - struct AccessItem *new_aconf; - struct ConfItem *new_conf; - - new_conf = make_conf_item(CLIENT_TYPE); - new_aconf = map_to_conf(new_conf); - - yy_tmp = ptr->data; - - assert(yy_tmp->user && yy_tmp->host); + dlink_node *ptr = NULL; - if (yy_aconf->passwd != NULL) - DupString(new_aconf->passwd, yy_aconf->passwd); - if (yy_conf->name != NULL) - DupString(new_conf->name, yy_conf->name); - if (yy_aconf->passwd != NULL) - DupString(new_aconf->passwd, yy_aconf->passwd); + if (conf_parser_ctx.pass != 2) + break; - new_aconf->flags = yy_aconf->flags; - new_aconf->port = yy_aconf->port; + DLINK_FOREACH(ptr, block_state.mask.list.head) + { + struct MaskItem *conf = NULL; + struct split_nuh_item nuh; - DupString(new_aconf->user, yy_tmp->user); - collapse(new_aconf->user); + nuh.nuhmask = ptr->data; + nuh.nickptr = NULL; + nuh.userptr = block_state.user.buf; + nuh.hostptr = block_state.host.buf; + nuh.nicksize = 0; + nuh.usersize = sizeof(block_state.user.buf); + nuh.hostsize = sizeof(block_state.host.buf); + split_nuh(&nuh); - DupString(new_aconf->host, yy_tmp->host); - collapse(new_aconf->host); + conf = conf_make(CONF_CLIENT); + conf->user = xstrdup(block_state.user.buf); + conf->host = xstrdup(block_state.host.buf); + + if (block_state.rpass.buf[0]) + conf->passwd = xstrdup(block_state.rpass.buf); + if (block_state.name.buf[0]) + conf->name = xstrdup(block_state.name.buf); - conf_add_class_to_conf(new_conf, class_name); - add_conf_by_address(CONF_CLIENT, new_aconf); - dlinkDelete(&yy_tmp->node, &col_conf_list); - free_collect_item(yy_tmp); - } + conf->flags = block_state.flags.value; + conf->port = block_state.port.value; - MyFree(class_name); - class_name = NULL; - yy_conf = NULL; - yy_aconf = NULL; + conf_add_class_to_conf(conf, block_state.class.buf); + add_conf_by_address(CONF_CLIENT, conf); } -}; +}; auth_items: auth_items auth_item | auth_item; auth_item: auth_user | auth_passwd | auth_class | auth_flags | @@ -1705,60 +1691,19 @@ auth_item: auth_user | auth_passwd auth_user: USER '=' QSTRING ';' { if (conf_parser_ctx.pass == 2) - { - struct CollectItem *yy_tmp = NULL; - struct split_nuh_item nuh; - - nuh.nuhmask = yylval.string; - nuh.nickptr = NULL; - nuh.userptr = userbuf; - nuh.hostptr = hostbuf; - - nuh.nicksize = 0; - nuh.usersize = sizeof(userbuf); - nuh.hostsize = sizeof(hostbuf); - - split_nuh(&nuh); - - if (yy_aconf->user == NULL) - { - DupString(yy_aconf->user, userbuf); - DupString(yy_aconf->host, hostbuf); - } - else - { - yy_tmp = MyMalloc(sizeof(struct CollectItem)); - - DupString(yy_tmp->user, userbuf); - DupString(yy_tmp->host, hostbuf); - - dlinkAdd(yy_tmp, &yy_tmp->node, &col_conf_list); - } - } + dlinkAdd(xstrdup(yylval.string), make_dlink_node(), &block_state.mask.list); }; -/* XXX - IP/IPV6 tags don't exist anymore - put IP/IPV6 into user. */ - auth_passwd: PASSWORD '=' QSTRING ';' { if (conf_parser_ctx.pass == 2) - { - /* be paranoid */ - if (yy_aconf->passwd != NULL) - memset(yy_aconf->passwd, 0, strlen(yy_aconf->passwd)); - - MyFree(yy_aconf->passwd); - DupString(yy_aconf->passwd, yylval.string); - } + strlcpy(block_state.rpass.buf, yylval.string, sizeof(block_state.rpass.buf)); }; auth_class: CLASS '=' QSTRING ';' { if (conf_parser_ctx.pass == 2) - { - MyFree(class_name); - DupString(class_name, yylval.string); - } + strlcpy(block_state.class.buf, yylval.string, sizeof(block_state.class.buf)); }; auth_encrypted: ENCRYPTED '=' TBOOL ';' @@ -1766,122 +1711,91 @@ auth_encrypted: ENCRYPTED '=' TBOOL ';' if (conf_parser_ctx.pass == 2) { if (yylval.number) - SetConfEncrypted(yy_aconf); + block_state.flags.value |= CONF_FLAGS_ENCRYPTED; else - ClearConfEncrypted(yy_aconf); + block_state.flags.value &= ~CONF_FLAGS_ENCRYPTED; } }; auth_flags: IRCD_FLAGS { + if (conf_parser_ctx.pass == 2) + block_state.flags.value &= (CONF_FLAGS_ENCRYPTED | CONF_FLAGS_SPOOF_IP); } '=' auth_flags_items ';'; auth_flags_items: auth_flags_items ',' auth_flags_item | auth_flags_item; -auth_flags_item: NOT { not_atom = 1; } auth_flags_item_atom - | { not_atom = 0; } auth_flags_item_atom; - -auth_flags_item_atom: SPOOF_NOTICE +auth_flags_item: SPOOF_NOTICE { if (conf_parser_ctx.pass == 2) - { - if (not_atom) yy_aconf->flags &= ~CONF_FLAGS_SPOOF_NOTICE; - else yy_aconf->flags |= CONF_FLAGS_SPOOF_NOTICE; - } + block_state.flags.value |= CONF_FLAGS_SPOOF_NOTICE; } | EXCEED_LIMIT { if (conf_parser_ctx.pass == 2) - { - if (not_atom) yy_aconf->flags &= ~CONF_FLAGS_NOLIMIT; - else yy_aconf->flags |= CONF_FLAGS_NOLIMIT; - } + block_state.flags.value |= CONF_FLAGS_NOLIMIT; } | KLINE_EXEMPT { if (conf_parser_ctx.pass == 2) - { - if (not_atom) yy_aconf->flags &= ~CONF_FLAGS_EXEMPTKLINE; - else yy_aconf->flags |= CONF_FLAGS_EXEMPTKLINE; - } + block_state.flags.value |= CONF_FLAGS_EXEMPTKLINE; } | NEED_IDENT { if (conf_parser_ctx.pass == 2) - { - if (not_atom) yy_aconf->flags &= ~CONF_FLAGS_NEED_IDENTD; - else yy_aconf->flags |= CONF_FLAGS_NEED_IDENTD; - } + block_state.flags.value |= CONF_FLAGS_NEED_IDENTD; } | CAN_FLOOD { if (conf_parser_ctx.pass == 2) - { - if (not_atom) yy_aconf->flags &= ~CONF_FLAGS_CAN_FLOOD; - else yy_aconf->flags |= CONF_FLAGS_CAN_FLOOD; - } + block_state.flags.value |= CONF_FLAGS_CAN_FLOOD; } | NO_TILDE { if (conf_parser_ctx.pass == 2) - { - if (not_atom) yy_aconf->flags &= ~CONF_FLAGS_NO_TILDE; - else yy_aconf->flags |= CONF_FLAGS_NO_TILDE; - } + block_state.flags.value |= CONF_FLAGS_NO_TILDE; } | GLINE_EXEMPT { if (conf_parser_ctx.pass == 2) - { - if (not_atom) yy_aconf->flags &= ~CONF_FLAGS_EXEMPTGLINE; - else yy_aconf->flags |= CONF_FLAGS_EXEMPTGLINE; - } + block_state.flags.value |= CONF_FLAGS_EXEMPTGLINE; } | RESV_EXEMPT { if (conf_parser_ctx.pass == 2) - { - if (not_atom) yy_aconf->flags &= ~CONF_FLAGS_EXEMPTRESV; - else yy_aconf->flags |= CONF_FLAGS_EXEMPTRESV; - } + block_state.flags.value |= CONF_FLAGS_EXEMPTRESV; +} | T_WEBIRC +{ + if (conf_parser_ctx.pass == 2) + block_state.flags.value |= CONF_FLAGS_WEBIRC; } | NEED_PASSWORD { if (conf_parser_ctx.pass == 2) - { - if (not_atom) yy_aconf->flags &= ~CONF_FLAGS_NEED_PASSWORD; - else yy_aconf->flags |= CONF_FLAGS_NEED_PASSWORD; - } + block_state.flags.value |= CONF_FLAGS_NEED_PASSWORD; }; -/* XXX - need check for illegal hostnames here */ -auth_spoof: SPOOF '=' QSTRING ';' +auth_spoof: SPOOF '=' QSTRING ';' { - if (conf_parser_ctx.pass == 2) - { - MyFree(yy_conf->name); + if (conf_parser_ctx.pass != 2) + break; - if (strlen(yylval.string) < HOSTLEN) - { - DupString(yy_conf->name, yylval.string); - yy_aconf->flags |= CONF_FLAGS_SPOOF_IP; - } - else - { - ilog(L_ERROR, "Spoofs must be less than %d..ignoring it", HOSTLEN); - yy_conf->name = NULL; - } + if (strlen(yylval.string) <= HOSTLEN && valid_hostname(yylval.string)) + { + strlcpy(block_state.name.buf, yylval.string, sizeof(block_state.name.buf)); + block_state.flags.value |= CONF_FLAGS_SPOOF_IP; } + else + ilog(LOG_TYPE_IRCD, "Spoof either is too long or contains invalid characters. Ignoring it."); }; auth_redir_serv: REDIRSERV '=' QSTRING ';' { - if (conf_parser_ctx.pass == 2) - { - yy_aconf->flags |= CONF_FLAGS_REDIR; - MyFree(yy_conf->name); - DupString(yy_conf->name, yylval.string); - } + if (conf_parser_ctx.pass != 2) + break; + + strlcpy(block_state.name.buf, yylval.string, sizeof(block_state.name.buf)); + block_state.flags.value |= CONF_FLAGS_REDIR; }; auth_redir_port: REDIRPORT '=' NUMBER ';' { - if (conf_parser_ctx.pass == 2) - { - yy_aconf->flags |= CONF_FLAGS_REDIR; - yy_aconf->port = $3; - } + if (conf_parser_ctx.pass != 2) + break; + + block_state.flags.value |= CONF_FLAGS_REDIR; + block_state.port.value = $3; }; @@ -1890,57 +1804,41 @@ auth_redir_port: REDIRPORT '=' NUMBER '; ***************************************************************************/ resv_entry: RESV { - if (conf_parser_ctx.pass == 2) - { - MyFree(resv_reason); - resv_reason = NULL; - } + if (conf_parser_ctx.pass != 2) + break; + + reset_block_state(); + strlcpy(block_state.rpass.buf, CONF_NOREASON, sizeof(block_state.rpass.buf)); } '{' resv_items '}' ';' { - if (conf_parser_ctx.pass == 2) - { - MyFree(resv_reason); - resv_reason = NULL; - } + if (conf_parser_ctx.pass != 2) + break; + + create_resv(block_state.name.buf, block_state.rpass.buf, &block_state.mask.list); }; resv_items: resv_items resv_item | resv_item; -resv_item: resv_creason | resv_channel | resv_nick | error ';' ; +resv_item: resv_mask | resv_reason | resv_exempt | error ';' ; -resv_creason: REASON '=' QSTRING ';' +resv_mask: MASK '=' QSTRING ';' { if (conf_parser_ctx.pass == 2) - { - MyFree(resv_reason); - DupString(resv_reason, yylval.string); - } + strlcpy(block_state.name.buf, yylval.string, sizeof(block_state.name.buf)); }; -resv_channel: CHANNEL '=' QSTRING ';' +resv_reason: REASON '=' QSTRING ';' { if (conf_parser_ctx.pass == 2) - { - if (IsChanPrefix(*yylval.string)) - { - char def_reason[] = "No reason"; - - create_channel_resv(yylval.string, resv_reason != NULL ? resv_reason : def_reason, 1); - } - } - /* ignore it for now.. but we really should make a warning if - * its an erroneous name --fl_ */ + strlcpy(block_state.rpass.buf, yylval.string, sizeof(block_state.rpass.buf)); }; -resv_nick: NICK '=' QSTRING ';' +resv_exempt: EXEMPT '=' QSTRING ';' { if (conf_parser_ctx.pass == 2) - { - char def_reason[] = "No reason"; - - create_nick_resv(yylval.string, resv_reason != NULL ? resv_reason : def_reason, 1); - } + dlinkAdd(xstrdup(yylval.string), make_dlink_node(), &block_state.mask.list); }; + /*************************************************************************** * section service ***************************************************************************/ @@ -1951,13 +1849,13 @@ service_item: service_name | error; service_name: NAME '=' QSTRING ';' { - if (conf_parser_ctx.pass == 2) + if (conf_parser_ctx.pass != 2) + break; + + if (valid_servname(yylval.string)) { - if (valid_servname(yylval.string)) - { - yy_conf = make_conf_item(SERVICE_TYPE); - DupString(yy_conf->name, yylval.string); - } + struct MaskItem *conf = conf_make(CONF_SERVICE); + conf->name = xstrdup(yylval.string); } }; @@ -1966,18 +1864,27 @@ service_name: NAME '=' QSTRING ';' ***************************************************************************/ shared_entry: T_SHARED { - if (conf_parser_ctx.pass == 2) - { - yy_conf = make_conf_item(ULINE_TYPE); - yy_match_item = map_to_conf(yy_conf); - yy_match_item->action = SHARED_ALL; - } + if (conf_parser_ctx.pass != 2) + break; + + reset_block_state(); + + strlcpy(block_state.name.buf, "*", sizeof(block_state.name.buf)); + strlcpy(block_state.user.buf, "*", sizeof(block_state.user.buf)); + strlcpy(block_state.host.buf, "*", sizeof(block_state.host.buf)); + block_state.flags.value = SHARED_ALL; } '{' shared_items '}' ';' { - if (conf_parser_ctx.pass == 2) - { - yy_conf = NULL; - } + struct MaskItem *conf = NULL; + + if (conf_parser_ctx.pass != 2) + break; + + conf = conf_make(CONF_ULINE); + conf->flags = block_state.flags.value; + conf->name = xstrdup(block_state.name.buf); + conf->user = xstrdup(block_state.user.buf); + conf->host = xstrdup(block_state.host.buf); }; shared_items: shared_items shared_item | shared_item; @@ -1986,10 +1893,7 @@ shared_item: shared_name | shared_user shared_name: NAME '=' QSTRING ';' { if (conf_parser_ctx.pass == 2) - { - MyFree(yy_conf->name); - DupString(yy_conf->name, yylval.string); - } + strlcpy(block_state.name.buf, yylval.string, sizeof(block_state.name.buf)); }; shared_user: USER '=' QSTRING ';' @@ -2000,71 +1904,64 @@ shared_user: USER '=' QSTRING ';' nuh.nuhmask = yylval.string; nuh.nickptr = NULL; - nuh.userptr = userbuf; - nuh.hostptr = hostbuf; + nuh.userptr = block_state.user.buf; + nuh.hostptr = block_state.host.buf; nuh.nicksize = 0; - nuh.usersize = sizeof(userbuf); - nuh.hostsize = sizeof(hostbuf); + nuh.usersize = sizeof(block_state.user.buf); + nuh.hostsize = sizeof(block_state.host.buf); split_nuh(&nuh); - - DupString(yy_match_item->user, userbuf); - DupString(yy_match_item->host, hostbuf); } }; shared_type: TYPE { if (conf_parser_ctx.pass == 2) - yy_match_item->action = 0; + block_state.flags.value = 0; } '=' shared_types ';' ; shared_types: shared_types ',' shared_type_item | shared_type_item; shared_type_item: KLINE { if (conf_parser_ctx.pass == 2) - yy_match_item->action |= SHARED_KLINE; -} | TKLINE + block_state.flags.value |= SHARED_KLINE; +} | UNKLINE { if (conf_parser_ctx.pass == 2) - yy_match_item->action |= SHARED_TKLINE; -} | UNKLINE + block_state.flags.value |= SHARED_UNKLINE; +} | T_DLINE { if (conf_parser_ctx.pass == 2) - yy_match_item->action |= SHARED_UNKLINE; -} | XLINE + block_state.flags.value |= SHARED_DLINE; +} | T_UNDLINE { if (conf_parser_ctx.pass == 2) - yy_match_item->action |= SHARED_XLINE; -} | TXLINE + block_state.flags.value |= SHARED_UNDLINE; +} | XLINE { if (conf_parser_ctx.pass == 2) - yy_match_item->action |= SHARED_TXLINE; + block_state.flags.value |= SHARED_XLINE; } | T_UNXLINE { if (conf_parser_ctx.pass == 2) - yy_match_item->action |= SHARED_UNXLINE; + block_state.flags.value |= SHARED_UNXLINE; } | RESV { if (conf_parser_ctx.pass == 2) - yy_match_item->action |= SHARED_RESV; -} | TRESV -{ - if (conf_parser_ctx.pass == 2) - yy_match_item->action |= SHARED_TRESV; + block_state.flags.value |= SHARED_RESV; } | T_UNRESV { if (conf_parser_ctx.pass == 2) - yy_match_item->action |= SHARED_UNRESV; + block_state.flags.value |= SHARED_UNRESV; } | T_LOCOPS { if (conf_parser_ctx.pass == 2) - yy_match_item->action |= SHARED_LOCOPS; + block_state.flags.value |= SHARED_LOCOPS; } | T_ALL { if (conf_parser_ctx.pass == 2) - yy_match_item->action = SHARED_ALL; + block_state.flags.value = SHARED_ALL; }; /*************************************************************************** @@ -2072,19 +1969,23 @@ shared_type_item: KLINE ***************************************************************************/ cluster_entry: T_CLUSTER { - if (conf_parser_ctx.pass == 2) - { - yy_conf = make_conf_item(CLUSTER_TYPE); - yy_conf->flags = SHARED_ALL; - } + if (conf_parser_ctx.pass != 2) + break; + + reset_block_state(); + + strlcpy(block_state.name.buf, "*", sizeof(block_state.name.buf)); + block_state.flags.value = SHARED_ALL; } '{' cluster_items '}' ';' { - if (conf_parser_ctx.pass == 2) - { - if (yy_conf->name == NULL) - DupString(yy_conf->name, "*"); - yy_conf = NULL; - } + struct MaskItem *conf = NULL; + + if (conf_parser_ctx.pass != 2) + break; + + conf = conf_make(CONF_CLUSTER); + conf->flags = block_state.flags.value; + conf->name = xstrdup(block_state.name.buf); }; cluster_items: cluster_items cluster_item | cluster_item; @@ -2093,423 +1994,224 @@ cluster_item: cluster_name | cluster_typ cluster_name: NAME '=' QSTRING ';' { if (conf_parser_ctx.pass == 2) - DupString(yy_conf->name, yylval.string); + strlcpy(block_state.name.buf, yylval.string, sizeof(block_state.name.buf)); }; cluster_type: TYPE { if (conf_parser_ctx.pass == 2) - yy_conf->flags = 0; + block_state.flags.value = 0; } '=' cluster_types ';' ; cluster_types: cluster_types ',' cluster_type_item | cluster_type_item; cluster_type_item: KLINE { if (conf_parser_ctx.pass == 2) - yy_conf->flags |= SHARED_KLINE; -} | TKLINE + block_state.flags.value |= SHARED_KLINE; +} | UNKLINE { if (conf_parser_ctx.pass == 2) - yy_conf->flags |= SHARED_TKLINE; -} | UNKLINE + block_state.flags.value |= SHARED_UNKLINE; +} | T_DLINE { if (conf_parser_ctx.pass == 2) - yy_conf->flags |= SHARED_UNKLINE; -} | XLINE + block_state.flags.value |= SHARED_DLINE; +} | T_UNDLINE { if (conf_parser_ctx.pass == 2) - yy_conf->flags |= SHARED_XLINE; -} | TXLINE + block_state.flags.value |= SHARED_UNDLINE; +} | XLINE { if (conf_parser_ctx.pass == 2) - yy_conf->flags |= SHARED_TXLINE; + block_state.flags.value |= SHARED_XLINE; } | T_UNXLINE { if (conf_parser_ctx.pass == 2) - yy_conf->flags |= SHARED_UNXLINE; + block_state.flags.value |= SHARED_UNXLINE; } | RESV { if (conf_parser_ctx.pass == 2) - yy_conf->flags |= SHARED_RESV; -} | TRESV -{ - if (conf_parser_ctx.pass == 2) - yy_conf->flags |= SHARED_TRESV; + block_state.flags.value |= SHARED_RESV; } | T_UNRESV { if (conf_parser_ctx.pass == 2) - yy_conf->flags |= SHARED_UNRESV; + block_state.flags.value |= SHARED_UNRESV; } | T_LOCOPS { if (conf_parser_ctx.pass == 2) - yy_conf->flags |= SHARED_LOCOPS; + block_state.flags.value |= SHARED_LOCOPS; } | T_ALL { if (conf_parser_ctx.pass == 2) - yy_conf->flags = SHARED_ALL; + block_state.flags.value = SHARED_ALL; }; /*************************************************************************** * section connect ***************************************************************************/ -connect_entry: CONNECT +connect_entry: CONNECT { - if (conf_parser_ctx.pass == 2) - { - yy_conf = make_conf_item(SERVER_TYPE); - yy_aconf = (struct AccessItem *)map_to_conf(yy_conf); - yy_aconf->passwd = NULL; - /* defaults */ - yy_aconf->port = PORTNUM; - if (ConfigFileEntry.burst_away) - yy_aconf->flags = CONF_FLAGS_BURST_AWAY; - } - else - { - MyFree(class_name); - class_name = NULL; - } -} connect_name_b '{' connect_items '}' ';' + if (conf_parser_ctx.pass != 2) + break; + + reset_block_state(); + block_state.aftype.value = AF_INET; + block_state.port.value = PORTNUM; +} '{' connect_items '}' ';' { - if (conf_parser_ctx.pass == 2) - { - struct CollectItem *yy_hconf=NULL; - struct CollectItem *yy_lconf=NULL; - dlink_node *ptr; - dlink_node *next_ptr; -#ifdef HAVE_LIBCRYPTO - if (yy_aconf->host && - ((yy_aconf->passwd && yy_aconf->spasswd) || - (yy_aconf->rsa_public_key && IsConfCryptLink(yy_aconf)))) -#else /* !HAVE_LIBCRYPTO */ - if (yy_aconf->host && !IsConfCryptLink(yy_aconf) && - yy_aconf->passwd && yy_aconf->spasswd) -#endif /* !HAVE_LIBCRYPTO */ - { - if (conf_add_server(yy_conf, class_name) == -1) - { - delete_conf_item(yy_conf); - yy_conf = NULL; - yy_aconf = NULL; - } - } - else - { - /* Even if yy_conf ->name is NULL - * should still unhook any hub/leaf confs still pending - */ - unhook_hub_leaf_confs(); - - if (yy_conf->name != NULL) - { -#ifndef HAVE_LIBCRYPTO - if (IsConfCryptLink(yy_aconf)) - yyerror("Ignoring connect block -- no OpenSSL support"); -#else - if (IsConfCryptLink(yy_aconf) && !yy_aconf->rsa_public_key) - yyerror("Ignoring connect block -- missing key"); -#endif - if (yy_aconf->host == NULL) - yyerror("Ignoring connect block -- missing host"); - else if (!IsConfCryptLink(yy_aconf) && - (!yy_aconf->passwd || !yy_aconf->spasswd)) - yyerror("Ignoring connect block -- missing password"); - } - - - /* XXX - * This fixes a try_connections() core (caused by invalid class_ptr - * pointers) reported by metalrock. That's an ugly fix, but there - * is currently no better way. The entire config subsystem needs an - * rewrite ASAP. make_conf_item() shouldn't really add things onto - * a doubly linked list immediately without any sanity checks! -Michael - */ - delete_conf_item(yy_conf); - - yy_aconf = NULL; - yy_conf = NULL; - } - - /* - * yy_conf is still pointing at the server that is having - * a connect block built for it. This means, y_aconf->name - * points to the actual irc name this server will be known as. - * Now this new server has a set or even just one hub_mask (or leaf_mask) - * given in the link list at yy_hconf. Fill in the HUB confs - * from this link list now. - */ - DLINK_FOREACH_SAFE(ptr, next_ptr, hub_conf_list.head) - { - struct ConfItem *new_hub_conf; - struct MatchItem *match_item; + struct MaskItem *conf = NULL; + struct addrinfo hints, *res; - yy_hconf = ptr->data; + if (conf_parser_ctx.pass != 2) + break; - /* yy_conf == NULL is a fatal error for this connect block! */ - if ((yy_conf != NULL) && (yy_conf->name != NULL)) - { - new_hub_conf = make_conf_item(HUB_TYPE); - match_item = (struct MatchItem *)map_to_conf(new_hub_conf); - DupString(new_hub_conf->name, yy_conf->name); - if (yy_hconf->user != NULL) - DupString(match_item->user, yy_hconf->user); - else - DupString(match_item->user, "*"); - if (yy_hconf->host != NULL) - DupString(match_item->host, yy_hconf->host); - else - DupString(match_item->host, "*"); - } - dlinkDelete(&yy_hconf->node, &hub_conf_list); - free_collect_item(yy_hconf); - } + if (!block_state.name.buf[0] || + !block_state.host.buf[0]) + break; - /* Ditto for the LEAF confs */ + if (!block_state.rpass.buf[0] || + !block_state.spass.buf[0]) + break; - DLINK_FOREACH_SAFE(ptr, next_ptr, leaf_conf_list.head) - { - struct ConfItem *new_leaf_conf; - struct MatchItem *match_item; + if (has_wildcards(block_state.name.buf) || + has_wildcards(block_state.host.buf)) + break; - yy_lconf = ptr->data; + conf = conf_make(CONF_SERVER); + conf->port = block_state.port.value; + conf->flags = block_state.flags.value; + conf->aftype = block_state.aftype.value; + conf->host = xstrdup(block_state.host.buf); + conf->name = xstrdup(block_state.name.buf); + conf->passwd = xstrdup(block_state.rpass.buf); + conf->spasswd = xstrdup(block_state.spass.buf); - if ((yy_conf != NULL) && (yy_conf->name != NULL)) - { - new_leaf_conf = make_conf_item(LEAF_TYPE); - match_item = (struct MatchItem *)map_to_conf(new_leaf_conf); - DupString(new_leaf_conf->name, yy_conf->name); - if (yy_lconf->user != NULL) - DupString(match_item->user, yy_lconf->user); - else - DupString(match_item->user, "*"); - if (yy_lconf->host != NULL) - DupString(match_item->host, yy_lconf->host); - else - DupString(match_item->host, "*"); - } - dlinkDelete(&yy_lconf->node, &leaf_conf_list); - free_collect_item(yy_lconf); - } - MyFree(class_name); - class_name = NULL; - yy_conf = NULL; - yy_aconf = NULL; + if (block_state.cert.buf[0]) + conf->certfp = xstrdup(block_state.cert.buf); + + if (block_state.ciph.buf[0]) + conf->cipher_list = xstrdup(block_state.ciph.buf); + + dlinkMoveList(&block_state.leaf.list, &conf->leaf_list); + dlinkMoveList(&block_state.hub.list, &conf->hub_list); + + if (block_state.bind.buf[0]) + { + memset(&hints, 0, sizeof(hints)); + + hints.ai_family = AF_UNSPEC; + hints.ai_socktype = SOCK_STREAM; + hints.ai_flags = AI_PASSIVE | AI_NUMERICHOST; + + if (getaddrinfo(block_state.bind.buf, NULL, &hints, &res)) + ilog(LOG_TYPE_IRCD, "Invalid netmask for server vhost(%s)", block_state.bind.buf); + else + { + assert(res != NULL); + + memcpy(&conf->bind, res->ai_addr, res->ai_addrlen); + conf->bind.ss.ss_family = res->ai_family; + conf->bind.ss_len = res->ai_addrlen; + freeaddrinfo(res); + } } + + conf_add_class_to_conf(conf, block_state.class.buf); + lookup_confhost(conf); }; -connect_name_b: | connect_name_t; connect_items: connect_items connect_item | connect_item; connect_item: connect_name | connect_host | connect_vhost | connect_send_password | connect_accept_password | - connect_aftype | connect_port | + connect_ssl_certificate_fingerprint | + connect_aftype | connect_port | connect_ssl_cipher_list | connect_flags | connect_hub_mask | connect_leaf_mask | connect_class | connect_encrypted | - connect_rsa_public_key_file | connect_cipher_preference | error ';' ; connect_name: NAME '=' QSTRING ';' { if (conf_parser_ctx.pass == 2) - { - if (yy_conf->name != NULL) - yyerror("Multiple connect name entry"); - - MyFree(yy_conf->name); - DupString(yy_conf->name, yylval.string); - } + strlcpy(block_state.name.buf, yylval.string, sizeof(block_state.name.buf)); }; -connect_name_t: QSTRING +connect_host: HOST '=' QSTRING ';' { if (conf_parser_ctx.pass == 2) - { - if (yy_conf->name != NULL) - yyerror("Multiple connect name entry"); - - MyFree(yy_conf->name); - DupString(yy_conf->name, yylval.string); - } + strlcpy(block_state.host.buf, yylval.string, sizeof(block_state.host.buf)); }; -connect_host: HOST '=' QSTRING ';' +connect_vhost: VHOST '=' QSTRING ';' { if (conf_parser_ctx.pass == 2) - { - MyFree(yy_aconf->host); - DupString(yy_aconf->host, yylval.string); - } + strlcpy(block_state.bind.buf, yylval.string, sizeof(block_state.bind.buf)); }; -connect_vhost: VHOST '=' QSTRING ';' +connect_send_password: SEND_PASSWORD '=' QSTRING ';' { - if (conf_parser_ctx.pass == 2) - { - struct addrinfo hints, *res; - - memset(&hints, 0, sizeof(hints)); - - hints.ai_family = AF_UNSPEC; - hints.ai_socktype = SOCK_STREAM; - hints.ai_flags = AI_PASSIVE | AI_NUMERICHOST; - - if (getaddrinfo(yylval.string, NULL, &hints, &res)) - ilog(L_ERROR, "Invalid netmask for server vhost(%s)", yylval.string); - else - { - assert(res != NULL); + if (conf_parser_ctx.pass != 2) + break; - memcpy(&yy_aconf->my_ipnum, res->ai_addr, res->ai_addrlen); - yy_aconf->my_ipnum.ss.ss_family = res->ai_family; - yy_aconf->my_ipnum.ss_len = res->ai_addrlen; - freeaddrinfo(res); - } - } + if ($3[0] == ':') + conf_error_report("Server passwords cannot begin with a colon"); + else if (strchr($3, ' ') != NULL) + conf_error_report("Server passwords cannot contain spaces"); + else + strlcpy(block_state.spass.buf, yylval.string, sizeof(block_state.spass.buf)); }; - -connect_send_password: SEND_PASSWORD '=' QSTRING ';' + +connect_accept_password: ACCEPT_PASSWORD '=' QSTRING ';' { - if (conf_parser_ctx.pass == 2) - { - if ($3[0] == ':') - yyerror("Server passwords cannot begin with a colon"); - else if (strchr($3, ' ') != NULL) - yyerror("Server passwords cannot contain spaces"); - else { - if (yy_aconf->spasswd != NULL) - memset(yy_aconf->spasswd, 0, strlen(yy_aconf->spasswd)); + if (conf_parser_ctx.pass != 2) + break; - MyFree(yy_aconf->spasswd); - DupString(yy_aconf->spasswd, yylval.string); - } - } + if ($3[0] == ':') + conf_error_report("Server passwords cannot begin with a colon"); + else if (strchr($3, ' ') != NULL) + conf_error_report("Server passwords cannot contain spaces"); + else + strlcpy(block_state.rpass.buf, yylval.string, sizeof(block_state.rpass.buf)); }; -connect_accept_password: ACCEPT_PASSWORD '=' QSTRING ';' +connect_ssl_certificate_fingerprint: SSL_CERTIFICATE_FINGERPRINT '=' QSTRING ';' { if (conf_parser_ctx.pass == 2) - { - if ($3[0] == ':') - yyerror("Server passwords cannot begin with a colon"); - else if (strchr($3, ' ') != NULL) - yyerror("Server passwords cannot contain spaces"); - else { - if (yy_aconf->passwd != NULL) - memset(yy_aconf->passwd, 0, strlen(yy_aconf->passwd)); - - MyFree(yy_aconf->passwd); - DupString(yy_aconf->passwd, yylval.string); - } - } + strlcpy(block_state.cert.buf, yylval.string, sizeof(block_state.cert.buf)); }; connect_port: PORT '=' NUMBER ';' { if (conf_parser_ctx.pass == 2) - yy_aconf->port = $3; + block_state.port.value = $3; }; connect_aftype: AFTYPE '=' T_IPV4 ';' { if (conf_parser_ctx.pass == 2) - yy_aconf->aftype = AF_INET; + block_state.aftype.value = AF_INET; } | AFTYPE '=' T_IPV6 ';' { #ifdef IPV6 if (conf_parser_ctx.pass == 2) - yy_aconf->aftype = AF_INET6; + block_state.aftype.value = AF_INET6; #endif }; connect_flags: IRCD_FLAGS { + block_state.flags.value &= CONF_FLAGS_ENCRYPTED; } '=' connect_flags_items ';'; connect_flags_items: connect_flags_items ',' connect_flags_item | connect_flags_item; -connect_flags_item: NOT { not_atom = 1; } connect_flags_item_atom - | { not_atom = 0; } connect_flags_item_atom; - -connect_flags_item_atom: COMPRESSED +connect_flags_item: AUTOCONN { if (conf_parser_ctx.pass == 2) -#ifndef HAVE_LIBZ - yyerror("Ignoring flags = compressed; -- no zlib support"); -#else - { - if (not_atom)ClearConfCompressed(yy_aconf); - else SetConfCompressed(yy_aconf); - } -#endif -} | CRYPTLINK -{ - if (conf_parser_ctx.pass == 2) - { - if (not_atom)ClearConfCryptLink(yy_aconf); - else SetConfCryptLink(yy_aconf); - } -} | AUTOCONN -{ - if (conf_parser_ctx.pass == 2) - { - if (not_atom)ClearConfAllowAutoConn(yy_aconf); - else SetConfAllowAutoConn(yy_aconf); - } -} | BURST_AWAY + block_state.flags.value |= CONF_FLAGS_ALLOW_AUTO_CONN; +} | T_SSL { if (conf_parser_ctx.pass == 2) - { - if (not_atom)ClearConfAwayBurst(yy_aconf); - else SetConfAwayBurst(yy_aconf); - } -} | TOPICBURST -{ - if (conf_parser_ctx.pass == 2) - { - if (not_atom)ClearConfTopicBurst(yy_aconf); - else SetConfTopicBurst(yy_aconf); - } -} -; - -connect_rsa_public_key_file: RSA_PUBLIC_KEY_FILE '=' QSTRING ';' -{ -#ifdef HAVE_LIBCRYPTO - if (conf_parser_ctx.pass == 2) - { - BIO *file; - - if (yy_aconf->rsa_public_key != NULL) - { - RSA_free(yy_aconf->rsa_public_key); - yy_aconf->rsa_public_key = NULL; - } - - if (yy_aconf->rsa_public_key_file != NULL) - { - MyFree(yy_aconf->rsa_public_key_file); - yy_aconf->rsa_public_key_file = NULL; - } - - DupString(yy_aconf->rsa_public_key_file, yylval.string); - - if ((file = BIO_new_file(yylval.string, "r")) == NULL) - { - yyerror("Ignoring rsa_public_key_file -- file doesn't exist"); - break; - } - - yy_aconf->rsa_public_key = (RSA *)PEM_read_bio_RSA_PUBKEY(file, NULL, 0, NULL); - - if (yy_aconf->rsa_public_key == NULL) - { - yyerror("Ignoring rsa_public_key_file -- Key invalid; check key syntax."); - break; - } - - BIO_set_close(file, BIO_CLOSE); - BIO_free(file); - } -#endif /* HAVE_LIBCRYPTO */ + block_state.flags.value |= CONF_FLAGS_SSL; }; connect_encrypted: ENCRYPTED '=' TBOOL ';' @@ -2517,209 +2219,129 @@ connect_encrypted: ENCRYPTED '=' TBOOL ' if (conf_parser_ctx.pass == 2) { if (yylval.number) - yy_aconf->flags |= CONF_FLAGS_ENCRYPTED; + block_state.flags.value |= CONF_FLAGS_ENCRYPTED; else - yy_aconf->flags &= ~CONF_FLAGS_ENCRYPTED; + block_state.flags.value &= ~CONF_FLAGS_ENCRYPTED; } }; -connect_hub_mask: HUB_MASK '=' QSTRING ';' +connect_hub_mask: HUB_MASK '=' QSTRING ';' { if (conf_parser_ctx.pass == 2) - { - struct CollectItem *yy_tmp; - - yy_tmp = (struct CollectItem *)MyMalloc(sizeof(struct CollectItem)); - DupString(yy_tmp->host, yylval.string); - DupString(yy_tmp->user, "*"); - dlinkAdd(yy_tmp, &yy_tmp->node, &hub_conf_list); - } + dlinkAdd(xstrdup(yylval.string), make_dlink_node(), &block_state.hub.list); }; -connect_leaf_mask: LEAF_MASK '=' QSTRING ';' +connect_leaf_mask: LEAF_MASK '=' QSTRING ';' { if (conf_parser_ctx.pass == 2) - { - struct CollectItem *yy_tmp; - - yy_tmp = (struct CollectItem *)MyMalloc(sizeof(struct CollectItem)); - DupString(yy_tmp->host, yylval.string); - DupString(yy_tmp->user, "*"); - dlinkAdd(yy_tmp, &yy_tmp->node, &leaf_conf_list); - } + dlinkAdd(xstrdup(yylval.string), make_dlink_node(), &block_state.leaf.list); }; connect_class: CLASS '=' QSTRING ';' { if (conf_parser_ctx.pass == 2) - { - MyFree(class_name); - DupString(class_name, yylval.string); - } + strlcpy(block_state.class.buf, yylval.string, sizeof(block_state.class.buf)); }; -connect_cipher_preference: CIPHER_PREFERENCE '=' QSTRING ';' +connect_ssl_cipher_list: T_SSL_CIPHER_LIST '=' QSTRING ';' { #ifdef HAVE_LIBCRYPTO if (conf_parser_ctx.pass == 2) - { - struct EncCapability *ecap; - const char *cipher_name; - int found = 0; - - yy_aconf->cipher_preference = NULL; - cipher_name = yylval.string; - - for (ecap = CipherTable; ecap->name; ecap++) - { - if ((irccmp(ecap->name, cipher_name) == 0) && - (ecap->cap & CAP_ENC_MASK)) - { - yy_aconf->cipher_preference = ecap; - found = 1; - break; - } - } - - if (!found) - yyerror("Invalid cipher"); - } + strlcpy(block_state.ciph.buf, yylval.string, sizeof(block_state.ciph.buf)); #else if (conf_parser_ctx.pass == 2) - yyerror("Ignoring cipher_preference -- no OpenSSL support"); + conf_error_report("Ignoring connect::ciphers -- no OpenSSL support"); #endif }; + /*************************************************************************** * section kill ***************************************************************************/ kill_entry: KILL { if (conf_parser_ctx.pass == 2) - { - userbuf[0] = hostbuf[0] = reasonbuf[0] = '\0'; - regex_ban = 0; - } + reset_block_state(); } '{' kill_items '}' ';' { - if (conf_parser_ctx.pass == 2) - { - if (userbuf[0] && hostbuf[0]) - { - if (regex_ban) - { -#ifdef HAVE_LIBPCRE - void *exp_user = NULL; - void *exp_host = NULL; - const char *errptr = NULL; - - if (!(exp_user = ircd_pcre_compile(userbuf, &errptr)) || - !(exp_host = ircd_pcre_compile(hostbuf, &errptr))) - { - ilog(L_ERROR, "Failed to add regular expression based K-Line: %s", - errptr); - break; - } - - yy_aconf = map_to_conf(make_conf_item(RKLINE_TYPE)); - yy_aconf->regexuser = exp_user; - yy_aconf->regexhost = exp_host; - - DupString(yy_aconf->user, userbuf); - DupString(yy_aconf->host, hostbuf); - - if (reasonbuf[0]) - DupString(yy_aconf->reason, reasonbuf); - else - DupString(yy_aconf->reason, "No reason"); -#else - ilog(L_ERROR, "Failed to add regular expression based K-Line: no PCRE support"); - break; -#endif - } - else - { - yy_aconf = map_to_conf(make_conf_item(KLINE_TYPE)); + struct MaskItem *conf = NULL; - DupString(yy_aconf->user, userbuf); - DupString(yy_aconf->host, hostbuf); + if (conf_parser_ctx.pass != 2) + break; - if (reasonbuf[0]) - DupString(yy_aconf->reason, reasonbuf); - else - DupString(yy_aconf->reason, "No reason"); - add_conf_by_address(CONF_KILL, yy_aconf); - } - } + if (!block_state.user.buf[0] || + !block_state.host.buf[0]) + break; - yy_aconf = NULL; - } -}; + conf = conf_make(CONF_KLINE); + conf->user = xstrdup(block_state.user.buf); + conf->host = xstrdup(block_state.host.buf); -kill_type: TYPE -{ -} '=' kill_type_items ';'; - -kill_type_items: kill_type_items ',' kill_type_item | kill_type_item; -kill_type_item: REGEX_T -{ - if (conf_parser_ctx.pass == 2) - regex_ban = 1; + if (block_state.rpass.buf[0]) + conf->reason = xstrdup(block_state.rpass.buf); + else + conf->reason = xstrdup(CONF_NOREASON); + add_conf_by_address(CONF_KLINE, conf); }; kill_items: kill_items kill_item | kill_item; -kill_item: kill_user | kill_reason | kill_type | error; +kill_item: kill_user | kill_reason | error; kill_user: USER '=' QSTRING ';' { + if (conf_parser_ctx.pass == 2) { struct split_nuh_item nuh; nuh.nuhmask = yylval.string; nuh.nickptr = NULL; - nuh.userptr = userbuf; - nuh.hostptr = hostbuf; + nuh.userptr = block_state.user.buf; + nuh.hostptr = block_state.host.buf; nuh.nicksize = 0; - nuh.usersize = sizeof(userbuf); - nuh.hostsize = sizeof(hostbuf); + nuh.usersize = sizeof(block_state.user.buf); + nuh.hostsize = sizeof(block_state.host.buf); split_nuh(&nuh); } }; -kill_reason: REASON '=' QSTRING ';' +kill_reason: REASON '=' QSTRING ';' { if (conf_parser_ctx.pass == 2) - strlcpy(reasonbuf, yylval.string, sizeof(reasonbuf)); + strlcpy(block_state.rpass.buf, yylval.string, sizeof(block_state.rpass.buf)); }; /*************************************************************************** * section deny ***************************************************************************/ -deny_entry: DENY +deny_entry: DENY { if (conf_parser_ctx.pass == 2) - hostbuf[0] = reasonbuf[0] = '\0'; + reset_block_state(); } '{' deny_items '}' ';' { - if (conf_parser_ctx.pass == 2) + struct MaskItem *conf = NULL; + + if (conf_parser_ctx.pass != 2) + break; + + if (!block_state.addr.buf[0]) + break; + + if (parse_netmask(block_state.addr.buf, NULL, NULL) != HM_HOST) { - if (hostbuf[0] && parse_netmask(hostbuf, NULL, NULL) != HM_HOST) - { - yy_aconf = map_to_conf(make_conf_item(DLINE_TYPE)); - DupString(yy_aconf->host, hostbuf); + conf = conf_make(CONF_DLINE); + conf->host = xstrdup(block_state.addr.buf); - if (reasonbuf[0]) - DupString(yy_aconf->reason, reasonbuf); - else - DupString(yy_aconf->reason, "No reason"); - add_conf_by_address(CONF_DLINE, yy_aconf); - yy_aconf = NULL; - } + if (block_state.rpass.buf[0]) + conf->reason = xstrdup(block_state.rpass.buf); + else + conf->reason = xstrdup(CONF_NOREASON); + add_conf_by_address(CONF_DLINE, conf); } -}; +}; deny_items: deny_items deny_item | deny_item; deny_item: deny_ip | deny_reason | error; @@ -2727,13 +2349,13 @@ deny_item: deny_ip | deny_reason | deny_ip: IP '=' QSTRING ';' { if (conf_parser_ctx.pass == 2) - strlcpy(hostbuf, yylval.string, sizeof(hostbuf)); + strlcpy(block_state.addr.buf, yylval.string, sizeof(block_state.addr.buf)); }; -deny_reason: REASON '=' QSTRING ';' +deny_reason: REASON '=' QSTRING ';' { if (conf_parser_ctx.pass == 2) - strlcpy(reasonbuf, yylval.string, sizeof(reasonbuf)); + strlcpy(block_state.rpass.buf, yylval.string, sizeof(block_state.rpass.buf)); }; /*************************************************************************** @@ -2750,11 +2372,10 @@ exempt_ip: IP '=' QSTRING ';' { if (yylval.string[0] && parse_netmask(yylval.string, NULL, NULL) != HM_HOST) { - yy_aconf = map_to_conf(make_conf_item(EXEMPTDLINE_TYPE)); - DupString(yy_aconf->host, yylval.string); + struct MaskItem *conf = conf_make(CONF_EXEMPT); + conf->host = xstrdup(yylval.string); - add_conf_by_address(CONF_EXEMPTDLINE, yy_aconf); - yy_aconf = NULL; + add_conf_by_address(CONF_EXEMPT, conf); } } }; @@ -2765,74 +2386,39 @@ exempt_ip: IP '=' QSTRING ';' gecos_entry: GECOS { if (conf_parser_ctx.pass == 2) - { - regex_ban = 0; - reasonbuf[0] = gecos_name[0] = '\0'; - } + reset_block_state(); } '{' gecos_items '}' ';' { - if (conf_parser_ctx.pass == 2) - { - if (gecos_name[0]) - { - if (regex_ban) - { -#ifdef HAVE_LIBPCRE - void *exp_p = NULL; - const char *errptr = NULL; - - if (!(exp_p = ircd_pcre_compile(gecos_name, &errptr))) - { - ilog(L_ERROR, "Failed to add regular expression based X-Line: %s", - errptr); - break; - } - - yy_conf = make_conf_item(RXLINE_TYPE); - yy_conf->regexpname = exp_p; -#else - ilog(L_ERROR, "Failed to add regular expression based X-Line: no PCRE support"); - break; -#endif - } - else - yy_conf = make_conf_item(XLINE_TYPE); + struct MaskItem *conf = NULL; - yy_match_item = map_to_conf(yy_conf); - DupString(yy_conf->name, gecos_name); + if (conf_parser_ctx.pass != 2) + break; - if (reasonbuf[0]) - DupString(yy_match_item->reason, reasonbuf); - else - DupString(yy_match_item->reason, "No reason"); - } - } -}; + if (!block_state.name.buf[0]) + break; -gecos_flags: TYPE -{ -} '=' gecos_flags_items ';'; + conf = conf_make(CONF_XLINE); + conf->name = xstrdup(block_state.name.buf); -gecos_flags_items: gecos_flags_items ',' gecos_flags_item | gecos_flags_item; -gecos_flags_item: REGEX_T -{ - if (conf_parser_ctx.pass == 2) - regex_ban = 1; + if (block_state.rpass.buf[0]) + conf->reason = xstrdup(block_state.rpass.buf); + else + conf->reason = xstrdup(CONF_NOREASON); }; gecos_items: gecos_items gecos_item | gecos_item; -gecos_item: gecos_name | gecos_reason | gecos_flags | error; +gecos_item: gecos_name | gecos_reason | error; -gecos_name: NAME '=' QSTRING ';' +gecos_name: NAME '=' QSTRING ';' { if (conf_parser_ctx.pass == 2) - strlcpy(gecos_name, yylval.string, sizeof(gecos_name)); + strlcpy(block_state.name.buf, yylval.string, sizeof(block_state.name.buf)); }; -gecos_reason: REASON '=' QSTRING ';' +gecos_reason: REASON '=' QSTRING ';' { if (conf_parser_ctx.pass == 2) - strlcpy(reasonbuf, yylval.string, sizeof(reasonbuf)); + strlcpy(block_state.rpass.buf, yylval.string, sizeof(block_state.rpass.buf)); }; /*************************************************************************** @@ -2847,30 +2433,30 @@ general_item: general_hide_spoof_i general_max_nick_time | general_max_nick_changes | general_max_accept | general_anti_spam_exit_message_time | general_ts_warn_delta | general_ts_max_delta | - general_kill_chase_time_limit | general_kline_with_reason | - general_kline_reason | general_invisible_on_connect | + general_kill_chase_time_limit | + general_invisible_on_connect | general_warn_no_nline | general_dots_in_ident | general_stats_o_oper_only | general_stats_k_oper_only | general_pace_wait | general_stats_i_oper_only | general_pace_wait_simple | general_stats_P_oper_only | + general_stats_u_oper_only | general_short_motd | general_no_oper_flood | general_true_no_oper_flood | general_oper_pass_resv | - general_message_locale | general_oper_only_umodes | general_max_targets | general_use_egd | general_egdpool_path | general_oper_umodes | general_caller_id_wait | general_opers_bypass_callerid | general_default_floodcount | general_min_nonwildcard | general_min_nonwildcard_simple | - general_servlink_path | general_disable_remote_commands | - general_default_cipher_preference | - general_compression_level | general_client_flood | general_throttle_time | general_havent_read_conf | general_ping_cookie | - general_disable_auth | general_burst_away | - general_tkline_expire_notices | general_gline_min_cidr | - general_gline_min_cidr6 | general_use_whois_actually | - general_reject_hold_time | general_stats_e_disabled | + general_disable_auth | + general_tkline_expire_notices | general_gline_enable | + general_gline_duration | general_gline_request_duration | + general_gline_min_cidr | + general_gline_min_cidr6 | + general_stats_e_disabled | general_max_watch | general_services_name | + general_cycle_on_host_change | error; @@ -2879,29 +2465,38 @@ general_max_watch: MAX_WATCH '=' NUMBER ConfigFileEntry.max_watch = $3; }; -general_gline_min_cidr: GLINE_MIN_CIDR '=' NUMBER ';' +general_cycle_on_host_change: CYCLE_ON_HOST_CHANGE '=' TBOOL ';' { - ConfigFileEntry.gline_min_cidr = $3; + if (conf_parser_ctx.pass == 2) + ConfigFileEntry.cycle_on_host_change = yylval.number; }; -general_gline_min_cidr6: GLINE_MIN_CIDR6 '=' NUMBER ';' +general_gline_enable: GLINE_ENABLE '=' TBOOL ';' { - ConfigFileEntry.gline_min_cidr6 = $3; + if (conf_parser_ctx.pass == 2) + ConfigFileEntry.glines = yylval.number; }; -general_burst_away: BURST_AWAY '=' TBOOL ';' +general_gline_duration: GLINE_DURATION '=' timespec ';' { - ConfigFileEntry.burst_away = yylval.number; + if (conf_parser_ctx.pass == 2) + ConfigFileEntry.gline_time = $3; }; -general_use_whois_actually: USE_WHOIS_ACTUALLY '=' TBOOL ';' +general_gline_request_duration: GLINE_REQUEST_DURATION '=' timespec ';' { - ConfigFileEntry.use_whois_actually = yylval.number; + if (conf_parser_ctx.pass == 2) + ConfigFileEntry.gline_request_time = $3; }; -general_reject_hold_time: TREJECT_HOLD_TIME '=' timespec ';' +general_gline_min_cidr: GLINE_MIN_CIDR '=' NUMBER ';' { - GlobalSetOptions.rejecttime = yylval.number; + ConfigFileEntry.gline_min_cidr = $3; +}; + +general_gline_min_cidr6: GLINE_MIN_CIDR6 '=' NUMBER ';' +{ + ConfigFileEntry.gline_min_cidr6 = $3; }; general_tkline_expire_notices: TKLINE_EXPIRE_NOTICES '=' TBOOL ';' @@ -2924,11 +2519,6 @@ general_ignore_bogus_ts: IGNORE_BOGUS_TS ConfigFileEntry.ignore_bogus_ts = yylval.number; }; -general_disable_remote_commands: DISABLE_REMOTE_COMMANDS '=' TBOOL ';' -{ - ConfigFileEntry.disable_remote = yylval.number; -}; - general_failed_oper_notice: FAILED_OPER_NOTICE '=' TBOOL ';' { ConfigFileEntry.failed_oper_notice = yylval.number; @@ -2941,7 +2531,7 @@ general_anti_nick_flood: ANTI_NICK_FLOOD general_max_nick_time: MAX_NICK_TIME '=' timespec ';' { - ConfigFileEntry.max_nick_time = $3; + ConfigFileEntry.max_nick_time = $3; }; general_max_nick_changes: MAX_NICK_CHANGES '=' NUMBER ';' @@ -2974,27 +2564,13 @@ general_havent_read_conf: HAVENT_READ_CO { if (($3 > 0) && conf_parser_ctx.pass == 1) { - ilog(L_CRIT, "You haven't read your config file properly."); - ilog(L_CRIT, "There is a line in the example conf that will kill your server if not removed."); - ilog(L_CRIT, "Consider actually reading/editing the conf file, and removing this line."); + ilog(LOG_TYPE_IRCD, "You haven't read your config file properly."); + ilog(LOG_TYPE_IRCD, "There is a line in the example conf that will kill your server if not removed."); + ilog(LOG_TYPE_IRCD, "Consider actually reading/editing the conf file, and removing this line."); exit(0); } }; -general_kline_with_reason: KLINE_WITH_REASON '=' TBOOL ';' -{ - ConfigFileEntry.kline_with_reason = yylval.number; -}; - -general_kline_reason: KLINE_REASON '=' QSTRING ';' -{ - if (conf_parser_ctx.pass == 2) - { - MyFree(ConfigFileEntry.kline_reason); - DupString(ConfigFileEntry.kline_reason, yylval.string); - } -}; - general_invisible_on_connect: INVISIBLE_ON_CONNECT '=' TBOOL ';' { ConfigFileEntry.invisible_on_connect = yylval.number; @@ -3020,6 +2596,11 @@ general_stats_P_oper_only: STATS_P_OPER_ ConfigFileEntry.stats_P_oper_only = yylval.number; }; +general_stats_u_oper_only: STATS_U_OPER_ONLY '=' TBOOL ';' +{ + ConfigFileEntry.stats_u_oper_only = yylval.number; +}; + general_stats_k_oper_only: STATS_K_OPER_ONLY '=' TBOOL ';' { ConfigFileEntry.stats_k_oper_only = 2 * yylval.number; @@ -3060,7 +2641,7 @@ general_short_motd: SHORT_MOTD '=' TBOOL { ConfigFileEntry.short_motd = yylval.number; }; - + general_no_oper_flood: NO_OPER_FLOOD '=' TBOOL ';' { ConfigFileEntry.no_oper_flood = yylval.number; @@ -3076,17 +2657,6 @@ general_oper_pass_resv: OPER_PASS_RESV ' ConfigFileEntry.oper_pass_resv = yylval.number; }; -general_message_locale: MESSAGE_LOCALE '=' QSTRING ';' -{ - if (conf_parser_ctx.pass == 2) - { - if (strlen(yylval.string) > LOCALE_LENGTH-2) - yylval.string[LOCALE_LENGTH-1] = '\0'; - - set_locale(yylval.string); - } -}; - general_dots_in_ident: DOTS_IN_IDENT '=' NUMBER ';' { ConfigFileEntry.dots_in_ident = $3; @@ -3097,65 +2667,6 @@ general_max_targets: MAX_TARGETS '=' NUM ConfigFileEntry.max_targets = $3; }; -general_servlink_path: SERVLINK_PATH '=' QSTRING ';' -{ - if (conf_parser_ctx.pass == 2) - { - MyFree(ConfigFileEntry.servlink_path); - DupString(ConfigFileEntry.servlink_path, yylval.string); - } -}; - -general_default_cipher_preference: DEFAULT_CIPHER_PREFERENCE '=' QSTRING ';' -{ -#ifdef HAVE_LIBCRYPTO - if (conf_parser_ctx.pass == 2) - { - struct EncCapability *ecap; - const char *cipher_name; - int found = 0; - - ConfigFileEntry.default_cipher_preference = NULL; - cipher_name = yylval.string; - - for (ecap = CipherTable; ecap->name; ecap++) - { - if ((irccmp(ecap->name, cipher_name) == 0) && - (ecap->cap & CAP_ENC_MASK)) - { - ConfigFileEntry.default_cipher_preference = ecap; - found = 1; - break; - } - } - - if (!found) - yyerror("Invalid cipher"); - } -#else - if (conf_parser_ctx.pass == 2) - yyerror("Ignoring default_cipher_preference -- no OpenSSL support"); -#endif -}; - -general_compression_level: COMPRESSION_LEVEL '=' NUMBER ';' -{ - if (conf_parser_ctx.pass == 2) - { - ConfigFileEntry.compression_level = $3; -#ifndef HAVE_LIBZ - yyerror("Ignoring compression_level -- no zlib support"); -#else - if ((ConfigFileEntry.compression_level < 1) || - (ConfigFileEntry.compression_level > 9)) - { - yyerror("Ignoring invalid compression_level, using default"); - ConfigFileEntry.compression_level = 0; - } -#endif - } -}; - general_use_egd: USE_EGD '=' TBOOL ';' { ConfigFileEntry.use_egd = yylval.number; @@ -3166,7 +2677,7 @@ general_egdpool_path: EGDPOOL_PATH '=' Q if (conf_parser_ctx.pass == 2) { MyFree(ConfigFileEntry.egdpool_path); - DupString(ConfigFileEntry.egdpool_path, yylval.string); + ConfigFileEntry.egdpool_path = xstrdup(yylval.string); } }; @@ -3175,7 +2686,7 @@ general_services_name: T_SERVICES_NAME ' if (conf_parser_ctx.pass == 2 && valid_servname(yylval.string)) { MyFree(ConfigFileEntry.service_name); - DupString(ConfigFileEntry.service_name, yylval.string); + ConfigFileEntry.service_name = xstrdup(yylval.string); } }; @@ -3191,7 +2702,7 @@ general_disable_auth: DISABLE_AUTH '=' T general_throttle_time: THROTTLE_TIME '=' timespec ';' { - ConfigFileEntry.throttle_time = yylval.number; + ConfigFileEntry.throttle_time = $3; }; general_oper_umodes: OPER_UMODES @@ -3206,9 +2717,6 @@ umode_oitem: T_BOTS } | T_CCONN { ConfigFileEntry.oper_umodes |= UMODE_CCONN; -} | T_CCONN_FULL -{ - ConfigFileEntry.oper_umodes |= UMODE_CCONN_FULL; } | T_DEAF { ConfigFileEntry.oper_umodes |= UMODE_DEAF; @@ -3218,6 +2726,9 @@ umode_oitem: T_BOTS } | T_FULL { ConfigFileEntry.oper_umodes |= UMODE_FULL; +} | HIDDEN +{ + ConfigFileEntry.oper_umodes |= UMODE_HIDDEN; } | T_SKILL { ConfigFileEntry.oper_umodes |= UMODE_SKILL; @@ -3257,23 +2768,26 @@ umode_oitem: T_BOTS } | T_LOCOPS { ConfigFileEntry.oper_umodes |= UMODE_LOCOPS; +} | T_NONONREG +{ + ConfigFileEntry.oper_umodes |= UMODE_REGONLY; +} | T_FARCONNECT +{ + ConfigFileEntry.oper_umodes |= UMODE_FARCONNECT; }; -general_oper_only_umodes: OPER_ONLY_UMODES +general_oper_only_umodes: OPER_ONLY_UMODES { ConfigFileEntry.oper_only_umodes = 0; } '=' umode_items ';' ; umode_items: umode_items ',' umode_item | umode_item; -umode_item: T_BOTS +umode_item: T_BOTS { ConfigFileEntry.oper_only_umodes |= UMODE_BOTS; } | T_CCONN { ConfigFileEntry.oper_only_umodes |= UMODE_CCONN; -} | T_CCONN_FULL -{ - ConfigFileEntry.oper_only_umodes |= UMODE_CCONN_FULL; } | T_DEAF { ConfigFileEntry.oper_only_umodes |= UMODE_DEAF; @@ -3281,11 +2795,14 @@ umode_item: T_BOTS { ConfigFileEntry.oper_only_umodes |= UMODE_DEBUG; } | T_FULL -{ +{ ConfigFileEntry.oper_only_umodes |= UMODE_FULL; } | T_SKILL { ConfigFileEntry.oper_only_umodes |= UMODE_SKILL; +} | HIDDEN +{ + ConfigFileEntry.oper_only_umodes |= UMODE_HIDDEN; } | T_NCHANGE { ConfigFileEntry.oper_only_umodes |= UMODE_NCHANGE; @@ -3322,6 +2839,12 @@ umode_item: T_BOTS } | T_LOCOPS { ConfigFileEntry.oper_only_umodes |= UMODE_LOCOPS; +} | T_NONONREG +{ + ConfigFileEntry.oper_only_umodes |= UMODE_REGONLY; +} | T_FARCONNECT +{ + ConfigFileEntry.oper_only_umodes |= UMODE_FARCONNECT; }; general_min_nonwildcard: MIN_NONWILDCARD '=' NUMBER ';' @@ -3339,179 +2862,6 @@ general_default_floodcount: DEFAULT_FLOO ConfigFileEntry.default_floodcount = $3; }; -general_client_flood: T_CLIENT_FLOOD '=' sizespec ';' -{ - ConfigFileEntry.client_flood = $3; -}; - - -/*************************************************************************** - * section glines - ***************************************************************************/ -gline_entry: GLINES -{ - if (conf_parser_ctx.pass == 2) - { - yy_conf = make_conf_item(GDENY_TYPE); - yy_aconf = map_to_conf(yy_conf); - } -} '{' gline_items '}' ';' -{ - if (conf_parser_ctx.pass == 2) - { - /* - * since we re-allocate yy_conf/yy_aconf after the end of action=, at the - * end we will have one extra, so we should free it. - */ - if (yy_conf->name == NULL || yy_aconf->user == NULL) - { - delete_conf_item(yy_conf); - yy_conf = NULL; - yy_aconf = NULL; - } - } -}; - -gline_items: gline_items gline_item | gline_item; -gline_item: gline_enable | - gline_duration | - gline_logging | - gline_user | - gline_server | - gline_action | - error; - -gline_enable: ENABLE '=' TBOOL ';' -{ - if (conf_parser_ctx.pass == 2) - ConfigFileEntry.glines = yylval.number; -}; - -gline_duration: DURATION '=' timespec ';' -{ - if (conf_parser_ctx.pass == 2) - ConfigFileEntry.gline_time = $3; -}; - -gline_logging: LOGGING -{ - if (conf_parser_ctx.pass == 2) - ConfigFileEntry.gline_logging = 0; -} '=' gline_logging_types ';'; -gline_logging_types: gline_logging_types ',' gline_logging_type_item | gline_logging_type_item; -gline_logging_type_item: T_REJECT -{ - if (conf_parser_ctx.pass == 2) - ConfigFileEntry.gline_logging |= GDENY_REJECT; -} | T_BLOCK -{ - if (conf_parser_ctx.pass == 2) - ConfigFileEntry.gline_logging |= GDENY_BLOCK; -}; - -gline_user: USER '=' QSTRING ';' -{ - if (conf_parser_ctx.pass == 2) - { - struct split_nuh_item nuh; - - nuh.nuhmask = yylval.string; - nuh.nickptr = NULL; - nuh.userptr = userbuf; - nuh.hostptr = hostbuf; - - nuh.nicksize = 0; - nuh.usersize = sizeof(userbuf); - nuh.hostsize = sizeof(hostbuf); - - split_nuh(&nuh); - - if (yy_aconf->user == NULL) - { - DupString(yy_aconf->user, userbuf); - DupString(yy_aconf->host, hostbuf); - } - else - { - struct CollectItem *yy_tmp = MyMalloc(sizeof(struct CollectItem)); - - DupString(yy_tmp->user, userbuf); - DupString(yy_tmp->host, hostbuf); - - dlinkAdd(yy_tmp, &yy_tmp->node, &col_conf_list); - } - } -}; - -gline_server: NAME '=' QSTRING ';' -{ - if (conf_parser_ctx.pass == 2) - { - MyFree(yy_conf->name); - DupString(yy_conf->name, yylval.string); - } -}; - -gline_action: ACTION -{ - if (conf_parser_ctx.pass == 2) - yy_aconf->flags = 0; -} '=' gdeny_types ';' -{ - if (conf_parser_ctx.pass == 2) - { - struct CollectItem *yy_tmp = NULL; - dlink_node *ptr, *next_ptr; - - DLINK_FOREACH_SAFE(ptr, next_ptr, col_conf_list.head) - { - struct AccessItem *new_aconf; - struct ConfItem *new_conf; - - yy_tmp = ptr->data; - new_conf = make_conf_item(GDENY_TYPE); - new_aconf = map_to_conf(new_conf); - - new_aconf->flags = yy_aconf->flags; - - if (yy_conf->name != NULL) - DupString(new_conf->name, yy_conf->name); - else - DupString(new_conf->name, "*"); - if (yy_aconf->user != NULL) - DupString(new_aconf->user, yy_tmp->user); - else - DupString(new_aconf->user, "*"); - if (yy_aconf->host != NULL) - DupString(new_aconf->host, yy_tmp->host); - else - DupString(new_aconf->host, "*"); - - dlinkDelete(&yy_tmp->node, &col_conf_list); - } - - /* - * In case someone has fed us with more than one action= after user/name - * which would leak memory -Michael - */ - if (yy_conf->name == NULL || yy_aconf->user == NULL) - delete_conf_item(yy_conf); - - yy_conf = make_conf_item(GDENY_TYPE); - yy_aconf = map_to_conf(yy_conf); - } -}; - -gdeny_types: gdeny_types ',' gdeny_type_item | gdeny_type_item; -gdeny_type_item: T_REJECT -{ - if (conf_parser_ctx.pass == 2) - yy_aconf->flags |= GDENY_REJECT; -} | T_BLOCK -{ - if (conf_parser_ctx.pass == 2) - yy_aconf->flags |= GDENY_BLOCK; -}; /*************************************************************************** * section channel @@ -3520,14 +2870,13 @@ channel_entry: CHANNEL '{' channel_items '}' ';'; channel_items: channel_items channel_item | channel_item; -channel_item: channel_disable_local_channels | channel_use_except | - channel_use_invex | channel_use_knock | - channel_max_bans | channel_knock_delay | - channel_knock_delay_channel | channel_max_chans_per_user | - channel_quiet_on_ban | channel_default_split_user_count | +channel_item: channel_max_bans | + channel_knock_delay | channel_knock_delay_channel | + channel_max_chans_per_user | channel_max_chans_per_oper | + channel_default_split_user_count | channel_default_split_server_count | - channel_no_create_on_split | channel_restrict_channels | - channel_no_join_on_split | channel_burst_topicwho | + channel_no_create_on_split | + channel_no_join_on_split | channel_jflood_count | channel_jflood_time | channel_disable_fake_channels | error; @@ -3536,31 +2885,6 @@ channel_disable_fake_channels: DISABLE_F ConfigChannel.disable_fake_channels = yylval.number; }; -channel_restrict_channels: RESTRICT_CHANNELS '=' TBOOL ';' -{ - ConfigChannel.restrict_channels = yylval.number; -}; - -channel_disable_local_channels: DISABLE_LOCAL_CHANNELS '=' TBOOL ';' -{ - ConfigChannel.disable_local_channels = yylval.number; -}; - -channel_use_except: USE_EXCEPT '=' TBOOL ';' -{ - ConfigChannel.use_except = yylval.number; -}; - -channel_use_invex: USE_INVEX '=' TBOOL ';' -{ - ConfigChannel.use_invex = yylval.number; -}; - -channel_use_knock: USE_KNOCK '=' TBOOL ';' -{ - ConfigChannel.use_knock = yylval.number; -}; - channel_knock_delay: KNOCK_DELAY '=' timespec ';' { ConfigChannel.knock_delay = $3; @@ -3576,9 +2900,9 @@ channel_max_chans_per_user: MAX_CHANS_PE ConfigChannel.max_chans_per_user = $3; }; -channel_quiet_on_ban: QUIET_ON_BAN '=' TBOOL ';' +channel_max_chans_per_oper: MAX_CHANS_PER_OPER '=' NUMBER ';' { - ConfigChannel.quiet_on_ban = yylval.number; + ConfigChannel.max_chans_per_oper = $3; }; channel_max_bans: MAX_BANS '=' NUMBER ';' @@ -3606,11 +2930,6 @@ channel_no_join_on_split: NO_JOIN_ON_SPL ConfigChannel.no_join_on_split = yylval.number; }; -channel_burst_topicwho: BURST_TOPICWHO '=' TBOOL ';' -{ - ConfigChannel.burst_topicwho = yylval.number; -}; - channel_jflood_count: JOIN_FLOOD_COUNT '=' NUMBER ';' { GlobalSetOptions.joinfloodcount = yylval.number; @@ -3618,7 +2937,7 @@ channel_jflood_count: JOIN_FLOOD_COUNT ' channel_jflood_time: JOIN_FLOOD_TIME '=' timespec ';' { - GlobalSetOptions.joinfloodtime = yylval.number; + GlobalSetOptions.joinfloodtime = $3; }; /*************************************************************************** @@ -3628,9 +2947,10 @@ serverhide_entry: SERVERHIDE '{' serverhide_items '}' ';'; serverhide_items: serverhide_items serverhide_item | serverhide_item; -serverhide_item: serverhide_flatten_links | serverhide_hide_servers | +serverhide_item: serverhide_flatten_links | serverhide_disable_remote_commands | + serverhide_hide_servers | + serverhide_hide_services | serverhide_links_delay | - serverhide_disable_hidden | serverhide_hidden | serverhide_hidden_name | serverhide_hide_server_ips | error; @@ -3641,18 +2961,30 @@ serverhide_flatten_links: FLATTEN_LINKS ConfigServerHide.flatten_links = yylval.number; }; +serverhide_disable_remote_commands: DISABLE_REMOTE_COMMANDS '=' TBOOL ';' +{ + if (conf_parser_ctx.pass == 2) + ConfigServerHide.disable_remote_commands = yylval.number; +}; + serverhide_hide_servers: HIDE_SERVERS '=' TBOOL ';' { if (conf_parser_ctx.pass == 2) ConfigServerHide.hide_servers = yylval.number; }; +serverhide_hide_services: HIDE_SERVICES '=' TBOOL ';' +{ + if (conf_parser_ctx.pass == 2) + ConfigServerHide.hide_services = yylval.number; +}; + serverhide_hidden_name: HIDDEN_NAME '=' QSTRING ';' { if (conf_parser_ctx.pass == 2) { MyFree(ConfigServerHide.hidden_name); - DupString(ConfigServerHide.hidden_name, yylval.string); + ConfigServerHide.hidden_name = xstrdup(yylval.string); } }; @@ -3676,12 +3008,6 @@ serverhide_hidden: HIDDEN '=' TBOOL ';' ConfigServerHide.hidden = yylval.number; }; -serverhide_disable_hidden: DISABLE_HIDDEN '=' TBOOL ';' -{ - if (conf_parser_ctx.pass == 2) - ConfigServerHide.disable_hidden = yylval.number; -}; - serverhide_hide_server_ips: HIDE_SERVER_IPS '=' TBOOL ';' { if (conf_parser_ctx.pass == 2)