Commit 7b29a54b authored by rswindell's avatar rswindell
Browse files

Overhaul of temp directory usage:

No more temp files in data or data/temp.
ctrl_dir/../temp (e.g. sbbs/temp) is the new default temp dir.
Each server has its own separately configurable temp dir.
BBS events (e.g. QWK packet processing) now have their own exclusive-use
temp dir (e.g. sbbs/temp/event).
All server threads will attempt to create and verify the validity of their temp dir.
System temp dir is only the default global temp dir for Unix (i.e. /tmp), since
the Windows default temp dir (e.g. C:\DOCUME~1\Rob\LOCALS~1\Temp) is not
particularly friendly or attractive.
parent 083c8640
......@@ -702,7 +702,8 @@ int main(int argc, char **argv)
fprintf(stderr,"!ERROR loading configuration files: %s\n",error);
exit(1);
}
prep_dir(scfg.data_dir, scfg.temp_dir, sizeof(scfg.temp_dir));
SAFECOPY(scfg.temp_dir,"../temp");
prep_dir(scfg.ctrl_dir, scfg.temp_dir, sizeof(scfg.temp_dir));
if(!(scfg.sys_misc&SM_LOCAL_TZ))
putenv("TZ=UTC0");
......
......@@ -168,7 +168,8 @@ int main(int argc, char **argv)
fprintf(stderr,"!ERROR loading configuration files: %s\n",error);
exit(1);
}
prep_dir(scfg.data_dir, scfg.temp_dir, sizeof(scfg.temp_dir));
SAFECOPY(scfg.temp_dir,"../temp");
prep_dir(scfg.ctrl_dir, scfg.temp_dir, sizeof(scfg.temp_dir));
if(!(scfg.sys_misc&SM_LOCAL_TZ))
putenv("TZ=UTC0");
......
......@@ -94,7 +94,6 @@ static DWORD thread_count=0;
static time_t uptime=0;
static DWORD served=0;
static BOOL terminate_server=FALSE;
static char local_hostname[128];
static char revision[16];
static char *text[TOTAL_TEXT];
static link_list_t recycle_semfiles;
......@@ -2267,7 +2266,7 @@ static BOOL badlogin(SOCKET sock, ulong* login_attempts)
static char* ftp_tmpfname(char* str, SOCKET sock)
{
safe_snprintf(str,MAX_PATH,"%sSBBS_FTP.%s.%u.tx",scfg.temp_dir,local_hostname,sock);
safe_snprintf(str,MAX_PATH,"%sSBBS_FTP.%u.%u.tx",scfg.temp_dir,getpid(),sock);
return(str);
}
......@@ -4555,8 +4554,6 @@ void DLLCALL ftp_server(void* arg)
status("Initializing");
gethostname(local_hostname,sizeof(local_hostname));
memset(&scfg, 0, sizeof(scfg));
lprintf(LOG_INFO,"Synchronet FTP Server Revision %s%s"
......@@ -4616,8 +4613,8 @@ void DLLCALL ftp_server(void* arg)
if(startup->temp_dir[0])
SAFECOPY(scfg.temp_dir,startup->temp_dir);
else
prep_dir(scfg.data_dir, scfg.temp_dir, sizeof(scfg.temp_dir));
backslash(scfg.temp_dir);
SAFECOPY(scfg.temp_dir,"../temp");
prep_dir(scfg.ctrl_dir, scfg.temp_dir, sizeof(scfg.temp_dir));
MKDIR(scfg.temp_dir);
lprintf(LOG_DEBUG,"Temporary file directory: %s", scfg.temp_dir);
if(!isdir(scfg.temp_dir)) {
......
......@@ -889,7 +889,8 @@ int main(int argc, char **argv, char** environ)
fprintf(errfp,"!ERROR loading configuration files: %s\n",error);
bail(1);
}
prep_dir(scfg.data_dir, scfg.temp_dir, sizeof(scfg.temp_dir));
SAFECOPY(scfg.temp_dir,"../temp");
prep_dir(scfg.ctrl_dir, scfg.temp_dir, sizeof(scfg.temp_dir));
if(host_name==NULL)
host_name=scfg.sys_inetaddr;
......
......@@ -1999,7 +1999,7 @@ static void smtp_thread(void* arg)
rand(); /* throw-away first result */
SAFEPRINTF3(session_id,"%x%x%lx",socket,rand(),clock());
SAFEPRINTF2(rcptlst_fname,"%sSMTP.%s.lst", scfg.data_dir, session_id);
SAFEPRINTF2(rcptlst_fname,"%sSBBS_SMTP.%s.lst", scfg.temp_dir, session_id);
rcptlst=fopen(rcptlst_fname,"w+");
if(rcptlst==NULL) {
lprintf(LOG_ERR,"%04d !SMTP ERROR %d creating recipient list: %s"
......@@ -2126,7 +2126,7 @@ static void smtp_thread(void* arg)
/* External Mail Processing here */
msg_handled=FALSE;
if(mailproc_count) {
SAFEPRINTF2(proc_err_fname,"%sSMTP.%s.err", scfg.data_dir, session_id);
SAFEPRINTF2(proc_err_fname,"%sSBBS_SMTP.%s.err", scfg.temp_dir, session_id);
remove(proc_err_fname);
for(i=0;i<mailproc_count;i++) {
......@@ -3197,7 +3197,7 @@ static void smtp_thread(void* arg)
if(!(startup->options&MAIL_OPT_DEBUG_RX_BODY))
unlink(msgtxt_fname);
}
SAFEPRINTF2(msgtxt_fname,"%sSMTP.%s.msg", scfg.data_dir, session_id);
SAFEPRINTF2(msgtxt_fname,"%sSBBS_SMTP.%s.msg", scfg.temp_dir, session_id);
if((msgtxt=fopen(msgtxt_fname,"w+b"))==NULL) {
lprintf(LOG_ERR,"%04d !SMTP ERROR %d opening %s"
,socket, errno, msgtxt_fname);
......@@ -4047,6 +4047,19 @@ void DLLCALL mail_server(void* arg)
return;
}
if(startup->temp_dir[0])
SAFECOPY(scfg.temp_dir,startup->temp_dir);
else
SAFECOPY(scfg.temp_dir,"../temp");
prep_dir(scfg.ctrl_dir, scfg.temp_dir, sizeof(scfg.temp_dir));
MKDIR(scfg.temp_dir);
lprintf(LOG_DEBUG,"Temporary file directory: %s", scfg.temp_dir);
if(!isdir(scfg.temp_dir)) {
lprintf(LOG_ERR,"!Invalid temp directory: %s", scfg.temp_dir);
cleanup(1);
return;
}
/* Parse the mailproc[.host].ini */
mailproc_list=NULL;
mailproc_count=0;
......
......@@ -75,8 +75,11 @@ typedef struct {
BOOL (*seteuid)(BOOL user);
BOOL (*setuid)(BOOL force);
/* Strings */
/* Paths */
char ctrl_dir[128];
char temp_dir[128];
/* Strings */
char dns_server[128];
char default_user[128];
char dnsbl_tag[32]; // Tag to add to blacklisted subject
......
......@@ -2209,7 +2209,7 @@ sbbs_t::sbbs_t(ushort node_num, DWORD addr, char* name, SOCKET sd,
strcpy(nodestr,name);
lprintf(LOG_DEBUG,"%s constructor using socket %d (settings=%lx)"
, nodestr, sd, global_cfg->node_misc);
,nodestr, sd, global_cfg->node_misc);
startup = ::startup; // Convert from global to class member
......@@ -2226,10 +2226,16 @@ sbbs_t::sbbs_t(ushort node_num, DWORD addr, char* name, SOCKET sd,
SAFECOPY(cfg.temp_dir,"../temp");
prep_dir(cfg.ctrl_dir, cfg.temp_dir, sizeof(cfg.temp_dir));
md(cfg.temp_dir);
SAFEPRINTF2(path,"%sevent%u",cfg.temp_dir,startup->first_node);
backslash(path);
SAFECOPY(cfg.temp_dir,path);
if(sd==INVALID_SOCKET) { /* events thread */
if(startup->first_node==1)
SAFEPRINTF(path,"%sevent",cfg.temp_dir);
else
SAFEPRINTF2(path,"%sevent%u",cfg.temp_dir,startup->first_node);
backslash(path);
SAFECOPY(cfg.temp_dir,path);
}
}
lprintf(LOG_DEBUG,"%s temporary file directory: %s", nodestr, cfg.temp_dir);
terminated = false;
event_thread_running = false;
......
......@@ -110,6 +110,10 @@ static void read_ini_globals(FILE* fp, global_startup_t* global)
}
p=iniReadString(fp,section,strTempDirectory,nulstr,value);
#if defined(__unix__)
if(*p==0)
p=_PATH_TMP; /* Good idea to use "/tmp" on Unix */
#endif
if(*p) {
SAFECOPY(global->temp_dir,value);
backslash(global->temp_dir);
......@@ -148,7 +152,6 @@ void sbbs_read_ini(
,services_startup_t* services
)
{
const char* p;
const char* section;
const char* default_term_ansi;
const char* default_dosemu_path;
......@@ -165,6 +168,7 @@ void sbbs_read_ini(
if(global->ctrl_dir[0]) {
if(bbs!=NULL) SAFECOPY(bbs->ctrl_dir,global->ctrl_dir);
if(ftp!=NULL) SAFECOPY(ftp->ctrl_dir,global->ctrl_dir);
if(web!=NULL) SAFECOPY(web->ctrl_dir,global->ctrl_dir);
if(mail!=NULL) SAFECOPY(mail->ctrl_dir,global->ctrl_dir);
if(services!=NULL) SAFECOPY(services->ctrl_dir,global->ctrl_dir);
}
......@@ -172,6 +176,8 @@ void sbbs_read_ini(
if(bbs!=NULL) SAFECOPY(bbs->temp_dir,global->temp_dir);
if(ftp!=NULL) SAFECOPY(ftp->temp_dir,global->temp_dir);
if(web!=NULL) SAFECOPY(web->temp_dir,global->temp_dir);
if(mail!=NULL) SAFECOPY(mail->temp_dir,global->temp_dir);
if(services!=NULL) SAFECOPY(services->temp_dir,global->temp_dir);
}
/***********************************************************************/
......@@ -223,6 +229,9 @@ void sbbs_read_ini(
SAFECOPY(bbs->host_name
,iniReadString(fp,section,strHostName,global->host_name,value));
SAFECOPY(bbs->temp_dir
,iniReadString(fp,section,strTempDirectory,bbs->temp_dir,value));
/* Set default terminal type to "stock" termcap closest to "ansi-bbs" */
#if defined(__FreeBSD__)
default_term_ansi="cons25";
......@@ -352,6 +361,9 @@ void sbbs_read_ini(
SAFECOPY(mail->host_name
,iniReadString(fp,section,strHostName,global->host_name,value));
SAFECOPY(mail->temp_dir
,iniReadString(fp,section,strTempDirectory,mail->temp_dir,value));
SAFECOPY(mail->relay_server
,iniReadString(fp,section,"RelayServer",mail->relay_server,value));
SAFECOPY(mail->relay_user
......@@ -422,6 +434,9 @@ void sbbs_read_ini(
SAFECOPY(services->host_name
,iniReadString(fp,section,strHostName,global->host_name,value));
SAFECOPY(services->temp_dir
,iniReadString(fp,section,strTempDirectory,services->temp_dir,value));
SAFECOPY(services->answer_sound
,iniReadString(fp,section,"AnswerSound",nulstr,value));
SAFECOPY(services->hangup_sound
......@@ -471,6 +486,9 @@ void sbbs_read_ini(
SAFECOPY(web->host_name
,iniReadString(fp,section,strHostName,global->host_name,value));
SAFECOPY(web->temp_dir
,iniReadString(fp,section,strTempDirectory,web->temp_dir,value));
SAFECOPY(web->root_dir
,iniReadString(fp,section,"RootDirectory",WEB_DEFAULT_ROOT_DIR,value));
SAFECOPY(web->error_dir
......@@ -496,13 +514,6 @@ void sbbs_read_ini(
web->max_cgi_inactivity
=iniReadShortInt(fp,section,"MaxCgiInactivity",120); /* seconds */
if(web->temp_dir[0])
p=web->temp_dir;
else
p=_PATH_TMP;
SAFECOPY(web->temp_dir
,iniReadString(fp,section,strTempDirectory,p,value));
web->log_mask
=iniReadBitField(fp,section,strLogMask,log_mask_bits,global->log_mask);
web->options
......@@ -694,6 +705,11 @@ BOOL sbbs_write_ini(
else if(!iniSetString(lp,section,strHostName,bbs->host_name,&style))
break;
if(stricmp(bbs->temp_dir,global->temp_dir)==0)
iniRemoveKey(lp,section,strTempDirectory);
else if(!iniSetString(lp,section,strTempDirectory,bbs->temp_dir,&style))
break;
if(!iniSetString(lp,section,"ExternalTermANSI",bbs->xtrn_term_ansi,&style))
break;
if(!iniSetString(lp,section,"ExternalTermDumb",bbs->xtrn_term_dumb,&style))
......@@ -768,6 +784,11 @@ BOOL sbbs_write_ini(
else if(!iniSetString(lp,section,strHostName,ftp->host_name,&style))
break;
if(stricmp(ftp->temp_dir,global->temp_dir)==0)
iniRemoveKey(lp,section,strTempDirectory);
else if(!iniSetString(lp,section,strTempDirectory,ftp->temp_dir,&style))
break;
if(!iniSetString(lp,section,"IndexFileName",ftp->index_file_name,&style))
break;
if(!iniSetString(lp,section,"HtmlIndexFile",ftp->html_index_file,&style))
......@@ -845,6 +866,11 @@ BOOL sbbs_write_ini(
else if(!iniSetString(lp,section,strHostName,mail->host_name,&style))
break;
if(stricmp(mail->temp_dir,global->temp_dir)==0)
iniRemoveKey(lp,section,strTempDirectory);
else if(!iniSetString(lp,section,strTempDirectory,mail->temp_dir,&style))
break;
if(!iniSetString(lp,section,"RelayServer",mail->relay_server,&style))
break;
if(!iniSetString(lp,section,"RelayUsername",mail->relay_user,&style))
......@@ -949,6 +975,11 @@ BOOL sbbs_write_ini(
else if(!iniSetString(lp,section,strHostName,services->host_name,&style))
break;
if(stricmp(services->temp_dir,global->temp_dir)==0)
iniRemoveKey(lp,section,strTempDirectory);
else if(!iniSetString(lp,section,strTempDirectory,services->temp_dir,&style))
break;
if(!iniSetString(lp,section,"AnswerSound",services->answer_sound,&style))
break;
if(!iniSetString(lp,section,"HangupSound",services->hangup_sound,&style))
......@@ -1029,6 +1060,11 @@ BOOL sbbs_write_ini(
else if(!iniSetString(lp,section,strHostName,web->host_name,&style))
break;
if(stricmp(web->temp_dir,global->temp_dir)==0)
iniRemoveKey(lp,section,strTempDirectory);
else if(!iniSetString(lp,section,strTempDirectory,web->temp_dir,&style))
break;
if(!iniSetString(lp,section,"RootDirectory",web->root_dir,&style))
break;
if(!iniSetString(lp,section,"ErrorDirectory",web->error_dir,&style))
......@@ -1049,9 +1085,6 @@ BOOL sbbs_write_ini(
if(!iniSetShortInt(lp,section,"MaxCgiInactivity",web->max_cgi_inactivity,&style))
break;
if(!iniSetString(lp,section,"TempDirectory",web->temp_dir,&style))
break;
if(!iniSetBitField(lp,section,strOptions,web_options,web->options,&style))
break;
......
......@@ -1644,13 +1644,18 @@ void DLLCALL services_thread(void* arg)
return;
}
#if 0 /* ToDo */
if(startup->temp_dir[0]) {
if(startup->temp_dir[0])
SAFECOPY(scfg.temp_dir,startup->temp_dir);
backslash(scfg.temp_dir);
} else
#endif
prep_dir(scfg.data_dir, scfg.temp_dir, sizeof(scfg.temp_dir));
else
SAFECOPY(scfg.temp_dir,"../temp");
prep_dir(scfg.ctrl_dir, scfg.temp_dir, sizeof(scfg.temp_dir));
MKDIR(scfg.temp_dir);
lprintf(LOG_DEBUG,"Temporary file directory: %s", scfg.temp_dir);
if(!isdir(scfg.temp_dir)) {
lprintf(LOG_ERR,"!Invalid temp directory: %s", scfg.temp_dir);
cleanup(1);
return;
}
if(startup->host_name[0]==0)
SAFECOPY(startup->host_name,scfg.sys_inetaddr);
......
......@@ -69,6 +69,7 @@ typedef struct {
/* Paths */
char ctrl_dir[128];
char temp_dir[128];
char answer_sound[128];
char hangup_sound[128];
......
......@@ -2726,7 +2726,7 @@ static BOOL exec_ssjs(http_session_t* session, char *script) {
char str[MAX_REQUEST_LINE+1];
int i;
sprintf(path,"%sSBBS_SSJS.%d.html",temp_dir,session->socket);
sprintf(path,"%sSBBS_SSJS.%u.%u.html",temp_dir,getpid(),session->socket);
if((session->req.fp=fopen(path,"wb"))==NULL) {
lprintf(LOG_ERR,"%04d !ERROR %d opening/creating %s", session->socket, errno, path);
return(FALSE);
......@@ -2811,7 +2811,7 @@ static void respond(http_session_t * session)
return;
}
sprintf(session->req.physical_path
,"%sSBBS_SSJS.%d.html",temp_dir,session->socket);
,"%sSBBS_SSJS.%u.%u.html",temp_dir,getpid(),session->socket);
}
session->req.mime_type=get_mime_type(strrchr(session->req.physical_path,'.'));
......@@ -3217,8 +3217,11 @@ void DLLCALL web_server(void* arg)
/* Copy html directories */
SAFECOPY(root_dir,startup->root_dir);
SAFECOPY(error_dir,startup->error_dir);
SAFECOPY(temp_dir,startup->temp_dir);
SAFECOPY(cgi_dir,startup->cgi_dir);
if(startup->temp_dir[0])
SAFECOPY(temp_dir,startup->temp_dir);
else
SAFECOPY(temp_dir,"../temp");
/* Change to absolute path */
prep_dir(startup->ctrl_dir, root_dir, sizeof(root_dir));
......@@ -3229,8 +3232,6 @@ void DLLCALL web_server(void* arg)
/* Trim off trailing slash/backslash */
if(IS_PATH_DELIM(*(p=lastchar(root_dir)))) *p=0;
backslash(temp_dir); /* Add trailing slash/backslash if missing */
memset(&scfg, 0, sizeof(scfg));
lprintf(LOG_INFO,"%s Revision %s%s"
......@@ -3259,16 +3260,6 @@ void DLLCALL web_server(void* arg)
if(chdir(startup->ctrl_dir)!=0)
lprintf(LOG_ERR,"!ERROR %d changing directory to: %s", errno, startup->ctrl_dir);
lprintf(LOG_DEBUG,"Root HTML directory: %s", root_dir);
lprintf(LOG_DEBUG,"Error HTML directory: %s", error_dir);
lprintf(LOG_DEBUG,"Temporary file directory: %s", temp_dir);
MKDIR(temp_dir);
if(!isdir(temp_dir)) {
lprintf(LOG_ERR,"!Invalid temp directory: %s", temp_dir);
cleanup(1);
return;
}
/* Initial configuration and load from CNF files */
SAFECOPY(scfg.ctrl_dir,startup->ctrl_dir);
lprintf(LOG_INFO,"Loading configuration files from %s", scfg.ctrl_dir);
......@@ -3282,6 +3273,19 @@ void DLLCALL web_server(void* arg)
}
scfg_reloaded=TRUE;
lprintf(LOG_DEBUG,"Temporary file directory: %s", temp_dir);
MKDIR(temp_dir);
if(!isdir(temp_dir)) {
lprintf(LOG_ERR,"!Invalid temp directory: %s", temp_dir);
cleanup(1);
return;
}
lprintf(LOG_DEBUG,"Root directory: %s", root_dir);
lprintf(LOG_DEBUG,"Error directory: %s", error_dir);
#if defined(__unix__)
lprintf(LOG_DEBUG,"CGI directory: %s", cgi_dir);
#endif
iniFileName(path,sizeof(path),scfg.ctrl_dir,"mime_types.ini");
if(!read_mime_types(path)) {
cleanup(1);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment