--- sbbs/src/sbbs3/sbbs_ini.c 2018/04/24 16:41:23 1.1.1.1 +++ sbbs/src/sbbs3/sbbs_ini.c 2018/04/24 16:42:39 1.1.1.2 @@ -2,13 +2,13 @@ /* Synchronet initialization (.ini) file routines */ -/* $Id: sbbs_ini.c,v 1.1.1.1 2018/04/24 16:41:23 root Exp $ */ +/* $Id: sbbs_ini.c,v 1.1.1.2 2018/04/24 16:42:39 root Exp $ */ /**************************************************************************** * @format.tab-size 4 (Plain Text/Source Code File Header) * * @format.use-tabs true (see http://www.synchro.net/ptsc_hdr.html) * * * - * Copyright 2006 Rob Swindell - http://www.synchro.net/copyright.html * + * Copyright 2011 Rob Swindell - http://www.synchro.net/copyright.html * * * * This program is free software; you can redistribute it and/or * * modify it under the terms of the GNU General Public License * @@ -59,57 +59,49 @@ static const char* strBindRetryDelay="Bi static const char* strAnswerSound="AnswerSound"; static const char* strHangupSound="HangupSound"; static const char* strHackAttemptSound="HackAttemptSound"; +static const char* strLoginAttemptDelay="LoginAttemptDelay"; +static const char* strLoginAttemptThrottle="LoginAttemptThrottle"; +static const char* strLoginAttemptHackThreshold="LoginAttemptHackThreshold"; +static const char* strLoginAttemptFilterThreshold="LoginAttemptFilterThreshold"; static const char* strJavaScriptMaxBytes ="JavaScriptMaxBytes"; static const char* strJavaScriptContextStack ="JavaScriptContextStack"; static const char* strJavaScriptThreadStack ="JavaScriptThreadStack"; static const char* strJavaScriptBranchLimit ="JavaScriptBranchLimit"; static const char* strJavaScriptGcInterval ="JavaScriptGcInterval"; static const char* strJavaScriptYieldInterval ="JavaScriptYieldInterval"; +static const char* strJavaScriptLoadPath ="JavaScriptLoadPath"; static const char* strSemFileCheckFrequency ="SemFileCheckFrequency"; -#define DEFAULT_LOG_LEVEL LOG_DEBUG -#define DEFAULT_MAX_MSG_SIZE (10*1024*1024) /* 10MB */ -#define DEFAULT_BIND_RETRY_COUNT 2 -#define DEFAULT_BIND_RETRY_DELAY 15 +#define DEFAULT_LOG_LEVEL LOG_DEBUG +#define DEFAULT_MAX_MSG_SIZE (20*1024*1024) /* 20MB */ +#define DEFAULT_MAX_MSGS_WAITING 100 +#define DEFAULT_CONNECT_TIMEOUT 30 /* seconds */ +#define DEFAULT_BIND_RETRY_COUNT 2 +#define DEFAULT_BIND_RETRY_DELAY 15 +#define DEFAULT_LOGIN_ATTEMPT_DELAY 5000 /* milliseconds */ +#define DEFAULT_LOGIN_ATTEMPT_THROTTLE 1000 /* milliseconds */ +#define DEFAULT_LOGIN_ATTEMPT_HACKLOG 10 /* write to hack.log after this many consecutive unique attempts */ +#define DEFAULT_LOGIN_ATTEMPT_FILTER 0 /* filter client IP address after this many consecutive unique attempts */ void sbbs_get_ini_fname(char* ini_file, char* ctrl_dir, char* pHostName) { - char host_name[128]; - char path[MAX_PATH+1]; - char* p; - - if(pHostName!=NULL) - SAFECOPY(host_name,pHostName); - else { -#if defined(_WINSOCKAPI_) - WSADATA WSAData; - WSAStartup(MAKEWORD(1,1), &WSAData); /* req'd for gethostname */ -#endif - gethostname(host_name,sizeof(host_name)-1); -#if defined(_WINSOCKAPI_) - WSACleanup(); -#endif - } - SAFECOPY(path,ctrl_dir); - backslash(path); - sprintf(ini_file,"%s%s.ini",path,host_name); - if(fexistcase(ini_file)) - return; - if((p=strchr(host_name,'.'))!=NULL) { - *p=0; - sprintf(ini_file,"%s%s.ini",path,host_name); - if(fexistcase(ini_file)) - return; - } + /* pHostName is no longer used since iniFileName calls gethostname() itself */ + +#if defined(_WINSOCKAPI_) + WSADATA WSAData; + WSAStartup(MAKEWORD(1,1), &WSAData); /* req'd for gethostname */ +#endif + #if defined(__unix__) && defined(PREFIX) sprintf(ini_file,PREFIX"/etc/sbbs.ini"); if(fexistcase(ini_file)) return; #endif iniFileName(ini_file,MAX_PATH,ctrl_dir,"sbbs.ini"); - if(fexistcase(ini_file)) - return; - iniFileName(ini_file,MAX_PATH,ctrl_dir,"startup.ini"); + +#if defined(_WINSOCKAPI_) + WSACleanup(); +#endif } static void sbbs_fix_js_settings(js_startup_t* js) @@ -125,13 +117,23 @@ void sbbs_get_js_settings( ,js_startup_t* js ,js_startup_t* defaults) { - js->max_bytes = iniGetInteger(list,section,strJavaScriptMaxBytes ,defaults->max_bytes); - js->cx_stack = iniGetInteger(list,section,strJavaScriptContextStack ,defaults->cx_stack); - js->thread_stack = iniGetInteger(list,section,strJavaScriptThreadStack ,defaults->thread_stack); + char value[INI_MAX_VALUE_LEN]; + char* p; + + js->max_bytes = (ulong)iniGetBytes(list,section,strJavaScriptMaxBytes ,/* unit: */1,defaults->max_bytes); + js->cx_stack = (ulong)iniGetBytes(list,section,strJavaScriptContextStack ,/* unit: */1,defaults->cx_stack); + js->thread_stack = (ulong)iniGetBytes(list,section,strJavaScriptThreadStack ,/* unit: */1,defaults->thread_stack); js->branch_limit = iniGetInteger(list,section,strJavaScriptBranchLimit ,defaults->branch_limit); js->gc_interval = iniGetInteger(list,section,strJavaScriptGcInterval ,defaults->gc_interval); js->yield_interval = iniGetInteger(list,section,strJavaScriptYieldInterval ,defaults->yield_interval); + /* Get JavaScriptLoadPath, use default is key is missing, use blank if key value is blank */ + if((p=iniGetExistingString(list, section, strJavaScriptLoadPath, nulstr, value)) == NULL) { + if(defaults!=js) + SAFECOPY(js->load_path, defaults->load_path); + } else + SAFECOPY(js->load_path, p); + sbbs_fix_js_settings(js); } @@ -150,7 +152,9 @@ BOOL sbbs_set_js_settings( ,JAVASCRIPT_BRANCH_LIMIT ,JAVASCRIPT_GC_INTERVAL ,JAVASCRIPT_YIELD_INTERVAL + ,JAVASCRIPT_LOAD_PATH }; + SAFECOPY(global_defaults.load_path, JAVASCRIPT_LOAD_PATH); if(defaults==NULL) defaults=&global_defaults; @@ -160,17 +164,17 @@ BOOL sbbs_set_js_settings( if(js->max_bytes==defaults->max_bytes) iniRemoveValue(lp,section,strJavaScriptMaxBytes); else - failure|=iniSetInteger(lp,section,strJavaScriptMaxBytes,js->max_bytes,style)==NULL; + failure|=iniSetBytes(lp,section,strJavaScriptMaxBytes,/*unit: */1, js->max_bytes,style)==NULL; if(js->cx_stack==defaults->cx_stack) iniRemoveValue(lp,section,strJavaScriptContextStack); else - failure|=iniSetInteger(lp,section,strJavaScriptContextStack,js->cx_stack,style)==NULL; + failure|=iniSetBytes(lp,section,strJavaScriptContextStack,/*unit: */1,js->cx_stack,style)==NULL; if(js->thread_stack==defaults->thread_stack) iniRemoveValue(lp,section,strJavaScriptThreadStack); else - failure|=iniSetInteger(lp,section,strJavaScriptThreadStack,js->thread_stack,style)==NULL; + failure|=iniSetBytes(lp,section,strJavaScriptThreadStack,/*unit: */1,js->thread_stack,style)==NULL; if(js->branch_limit==defaults->branch_limit) iniRemoveValue(lp,section,strJavaScriptBranchLimit); @@ -187,6 +191,11 @@ BOOL sbbs_set_js_settings( else failure|=iniSetInteger(lp,section,strJavaScriptYieldInterval,js->yield_interval,style)==NULL; + if(strcmp(js->load_path,defaults->load_path)==0) + iniRemoveKey(lp,section,strJavaScriptLoadPath); + else + failure|=iniSetString(lp,section,strJavaScriptLoadPath,js->load_path,style)==NULL; + return(!failure); } @@ -221,6 +230,10 @@ static void get_ini_globals(str_list_t l global->log_level=iniGetLogLevel(list,section,strLogLevel,DEFAULT_LOG_LEVEL); global->bind_retry_count=iniGetInteger(list,section,strBindRetryCount,DEFAULT_BIND_RETRY_COUNT); global->bind_retry_delay=iniGetInteger(list,section,strBindRetryDelay,DEFAULT_BIND_RETRY_DELAY); + global->login_attempt_delay=iniGetInteger(list,section,strLoginAttemptDelay,DEFAULT_LOGIN_ATTEMPT_DELAY); + global->login_attempt_throttle=iniGetInteger(list,section,strLoginAttemptThrottle,DEFAULT_LOGIN_ATTEMPT_THROTTLE); + global->login_attempt_hack_threshold=iniGetInteger(list,section,strLoginAttemptHackThreshold,DEFAULT_LOGIN_ATTEMPT_HACKLOG); + global->login_attempt_filter_threshold=iniGetInteger(list,section,strLoginAttemptFilterThreshold,DEFAULT_LOGIN_ATTEMPT_FILTER); /* Setup default values here */ global->js.max_bytes = JAVASCRIPT_MAX_BYTES; @@ -229,6 +242,7 @@ static void get_ini_globals(str_list_t l global->js.branch_limit = JAVASCRIPT_BRANCH_LIMIT; global->js.gc_interval = JAVASCRIPT_GC_INTERVAL; global->js.yield_interval = JAVASCRIPT_YIELD_INTERVAL; + SAFECOPY(global->js.load_path, JAVASCRIPT_LOAD_PATH); /* Read .ini values here */ sbbs_get_js_settings(list, section, &global->js, &global->js); @@ -338,7 +352,7 @@ void sbbs_read_ini( ,iniGetString(list,section,"ExternalTermDumb","dumb",value)); #if defined(__FreeBSD__) - default_dosemu_path="/usr/bin/doscmd"; + default_dosemu_path="/usr/local/bin/doscmd"; #else default_dosemu_path="/usr/bin/dosemu.bin"; #endif @@ -359,6 +373,10 @@ void sbbs_read_ini( bbs->bind_retry_count=iniGetInteger(list,section,strBindRetryCount,global->bind_retry_count); bbs->bind_retry_delay=iniGetInteger(list,section,strBindRetryDelay,global->bind_retry_delay); + bbs->login_attempt_delay=iniGetInteger(list,section,strLoginAttemptDelay,global->login_attempt_delay); + bbs->login_attempt_throttle=iniGetInteger(list,section,strLoginAttemptThrottle,global->login_attempt_throttle); + bbs->login_attempt_hack_threshold=iniGetInteger(list,section,strLoginAttemptHackThreshold,global->login_attempt_hack_threshold); + bbs->login_attempt_filter_threshold=iniGetInteger(list,section,strLoginAttemptFilterThreshold,global->login_attempt_filter_threshold); } /***********************************************************************/ @@ -422,6 +440,10 @@ void sbbs_read_ini( ftp->bind_retry_count=iniGetInteger(list,section,strBindRetryCount,global->bind_retry_count); ftp->bind_retry_delay=iniGetInteger(list,section,strBindRetryDelay,global->bind_retry_delay); + ftp->login_attempt_delay=iniGetInteger(list,section,strLoginAttemptDelay,global->login_attempt_delay); + ftp->login_attempt_throttle=iniGetInteger(list,section,strLoginAttemptThrottle,global->login_attempt_throttle); + ftp->login_attempt_hack_threshold=iniGetInteger(list,section,strLoginAttemptHackThreshold,global->login_attempt_hack_threshold); + ftp->login_attempt_filter_threshold=iniGetInteger(list,section,strLoginAttemptFilterThreshold,global->login_attempt_filter_threshold); } /***********************************************************************/ @@ -436,6 +458,8 @@ void sbbs_read_ini( =iniGetIpAddress(list,section,strInterface,global->interface_addr); mail->smtp_port =iniGetShortInt(list,section,"SMTPPort",IPPORT_SMTP); + mail->submission_port + =iniGetShortInt(list,section,"SubmissionPort",IPPORT_SUBMISSION); mail->pop3_port =iniGetShortInt(list,section,"POP3Port",IPPORT_POP3); mail->relay_port @@ -456,6 +480,10 @@ void sbbs_read_ini( =iniGetShortInt(list,section,"MaxRecipients",100); mail->max_msg_size =iniGetInteger(list,section,"MaxMsgSize",DEFAULT_MAX_MSG_SIZE); + mail->max_msgs_waiting + =iniGetInteger(list,section,"MaxMsgsWaiting",DEFAULT_MAX_MSGS_WAITING); + mail->connect_timeout + =iniGetInteger(list,section,"ConnectTimeout",DEFAULT_CONNECT_TIMEOUT); SAFECOPY(mail->host_name ,iniGetString(list,section,strHostName,global->host_name,value)); @@ -502,6 +530,10 @@ void sbbs_read_ini( mail->bind_retry_count=iniGetInteger(list,section,strBindRetryCount,global->bind_retry_count); mail->bind_retry_delay=iniGetInteger(list,section,strBindRetryDelay,global->bind_retry_delay); + mail->login_attempt_delay=iniGetInteger(list,section,strLoginAttemptDelay,global->login_attempt_delay); + mail->login_attempt_throttle=iniGetInteger(list,section,strLoginAttemptThrottle,global->login_attempt_throttle); + mail->login_attempt_hack_threshold=iniGetInteger(list,section,strLoginAttemptHackThreshold,global->login_attempt_hack_threshold); + mail->login_attempt_filter_threshold=iniGetInteger(list,section,strLoginAttemptFilterThreshold,global->login_attempt_filter_threshold); } /***********************************************************************/ @@ -540,6 +572,10 @@ void sbbs_read_ini( services->bind_retry_count=iniGetInteger(list,section,strBindRetryCount,global->bind_retry_count); services->bind_retry_delay=iniGetInteger(list,section,strBindRetryDelay,global->bind_retry_delay); + services->login_attempt_delay=iniGetInteger(list,section,strLoginAttemptDelay,global->login_attempt_delay); + services->login_attempt_throttle=iniGetInteger(list,section,strLoginAttemptThrottle,global->login_attempt_throttle); + services->login_attempt_hack_threshold=iniGetInteger(list,section,strLoginAttemptHackThreshold,global->login_attempt_hack_threshold); + services->login_attempt_filter_threshold=iniGetInteger(list,section,strLoginAttemptFilterThreshold,global->login_attempt_filter_threshold); } /***********************************************************************/ @@ -576,6 +612,8 @@ void sbbs_read_ini( ,iniGetString(list,section,"ErrorDirectory",WEB_DEFAULT_ERROR_DIR,value)); SAFECOPY(web->cgi_dir ,iniGetString(list,section,"CGIDirectory",WEB_DEFAULT_CGI_DIR,value)); + SAFECOPY(web->default_auth_list + ,iniGetString(list,section,"Authentication",WEB_DEFAULT_AUTH_LIST,value)); SAFECOPY(web->logfile_base ,iniGetString(list,section,"HttpLogFile",nulstr,value)); @@ -623,6 +661,10 @@ void sbbs_read_ini( web->bind_retry_count=iniGetInteger(list,section,strBindRetryCount,global->bind_retry_count); web->bind_retry_delay=iniGetInteger(list,section,strBindRetryDelay,global->bind_retry_delay); + web->login_attempt_delay=iniGetInteger(list,section,strLoginAttemptDelay,global->login_attempt_delay); + web->login_attempt_throttle=iniGetInteger(list,section,strLoginAttemptThrottle,global->login_attempt_throttle); + web->login_attempt_hack_threshold=iniGetInteger(list,section,strLoginAttemptHackThreshold,global->login_attempt_hack_threshold); + web->login_attempt_filter_threshold=iniGetInteger(list,section,strLoginAttemptFilterThreshold,global->login_attempt_filter_threshold); } iniFreeStringList(list); @@ -671,42 +713,18 @@ BOOL sbbs_write_ini( if(global!=&global_buf) { section = "Global"; - if(global->ctrl_dir[0]==0) - iniRemoveKey(lp,section,strCtrlDirectory); - else - iniSetString(lp,section,strCtrlDirectory,global->ctrl_dir,&style); - - if(global->temp_dir[0]==0) - iniRemoveKey(lp,section,strTempDirectory); - else - iniSetString(lp,section,strTempDirectory,global->temp_dir,&style); - - if(global->host_name[0]==0) - iniRemoveKey(lp,section,strHostName); - else - iniSetString(lp,section,strHostName,global->host_name,&style); - - if(global->sem_chk_freq==0) - iniRemoveKey(lp,section,strSemFileCheckFrequency); - else - iniSetShortInt(lp,section,strSemFileCheckFrequency,global->sem_chk_freq,&style); - if(global->interface_addr==INADDR_ANY) - iniRemoveKey(lp,section,strInterface); - else - iniSetIpAddress(lp,section,strInterface,global->interface_addr,&style); - if(global->log_level==DEFAULT_LOG_LEVEL) - iniRemoveKey(lp,section,strLogLevel); - else - iniSetLogLevel(lp,section,strLogLevel,global->log_level,&style); - - if(global->bind_retry_count==DEFAULT_BIND_RETRY_COUNT) - iniRemoveKey(lp,section,strBindRetryCount); - else - iniSetInteger(lp,section,strBindRetryCount,global->bind_retry_count,&style); - if(global->bind_retry_delay==DEFAULT_BIND_RETRY_DELAY) - iniRemoveKey(lp,section,strBindRetryDelay); - else - iniSetInteger(lp,section,strBindRetryDelay,global->bind_retry_delay,&style); + iniSetString(lp,section,strCtrlDirectory,global->ctrl_dir,&style); + iniSetString(lp,section,strTempDirectory,global->temp_dir,&style); + iniSetString(lp,section,strHostName,global->host_name,&style); + iniSetShortInt(lp,section,strSemFileCheckFrequency,global->sem_chk_freq,&style); + iniSetIpAddress(lp,section,strInterface,global->interface_addr,&style); + iniSetLogLevel(lp,section,strLogLevel,global->log_level,&style); + iniSetInteger(lp,section,strBindRetryCount,global->bind_retry_count,&style); + iniSetInteger(lp,section,strBindRetryDelay,global->bind_retry_delay,&style); + iniSetInteger(lp,section,strLoginAttemptDelay,global->login_attempt_delay,&style); + iniSetInteger(lp,section,strLoginAttemptThrottle,global->login_attempt_throttle,&style); + iniSetInteger(lp,section,strLoginAttemptHackThreshold,global->login_attempt_hack_threshold,&style); + iniSetInteger(lp,section,strLoginAttemptFilterThreshold,global->login_attempt_filter_threshold,&style); /* JavaScript operating parameters */ if(!sbbs_set_js_settings(lp,section,&global->js,NULL,&style)) @@ -926,6 +944,10 @@ BOOL sbbs_write_ini( break; if(!iniSetInteger(lp,section,"MaxMsgSize",mail->max_msg_size,&style)) break; + if(!iniSetInteger(lp,section,"MaxMsgsWaiting",mail->max_msgs_waiting,&style)) + break; + if(!iniSetInteger(lp,section,"ConnectTimeout",mail->connect_timeout,&style)) + break; if(strcmp(mail->host_name,global->host_name)==0 || strcmp(bbs->host_name,cfg->sys_inetaddr)==0) @@ -1090,6 +1112,8 @@ BOOL sbbs_write_ini( break; if(!iniSetString(lp,section,"CGIDirectory",web->cgi_dir,&style)) break; + if(!iniSetString(lp,section,"Authentication",web->default_auth_list,&style)) + break; if(!iniSetString(lp,section,"HttpLogFile",web->logfile_base,&style)) break;