Synchronet now requires the libarchive development package (e.g. libarchive-dev on Debian-based Linux distros, libarchive.org for more info) to build successfully.

Commit aeb002a3 authored by rswindell's avatar rswindell

prep_dir() no longer assumes the target path buffer is LEN_DIR (64) bytes

or longer, uses a passed 'buflen' parameter to determine the truncation point.
parent d857616e
......@@ -695,7 +695,7 @@ 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);
prep_dir(scfg.data_dir, scfg.temp_dir, sizeof(scfg.temp_dir));
if(!(scfg.sys_misc&SM_LOCAL_TZ))
putenv("TZ=UTC0");
......
......@@ -184,7 +184,7 @@ 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);
prep_dir(scfg.data_dir, scfg.temp_dir, sizeof(scfg.temp_dir));
if(!(scfg.sys_misc&SM_LOCAL_TZ))
putenv("TZ=UTC0");
......
......@@ -4488,7 +4488,7 @@ void DLLCALL ftp_server(void* arg)
uptime=time(NULL); /* this must be done *after* setting the timezone */
/* Use DATA/TEMP for temp dir - should ch'd to be FTP/HOST specific */
prep_dir(scfg.data_dir, scfg.temp_dir);
prep_dir(scfg.data_dir, scfg.temp_dir, sizeof(scfg.temp_dir));
if(!startup->max_clients) {
startup->max_clients=scfg.sys_nodes;
......
......@@ -72,10 +72,10 @@ BOOL DLLCALL load_cfg(scfg_t* cfg, char* text[], BOOL prep, char* error)
if(prep)
for(i=0;i<cfg->sys_nodes;i++)
prep_dir(cfg->ctrl_dir, cfg->node_path[i]);
prep_dir(cfg->ctrl_dir, cfg->node_path[i], sizeof(cfg->node_path[i]));
SAFECOPY(cfg->node_dir,cfg->node_path[cfg->node_num-1]);
prep_dir(cfg->ctrl_dir, cfg->node_dir);
prep_dir(cfg->ctrl_dir, cfg->node_dir, sizeof(cfg->node_dir));
if(read_node_cfg(cfg, error)==FALSE)
return(FALSE);
if(read_msgs_cfg(cfg, error)==FALSE)
......@@ -140,13 +140,13 @@ void prep_cfg(scfg_t* cfg)
#endif
/* Fix-up paths */
prep_dir(cfg->ctrl_dir, cfg->data_dir);
prep_dir(cfg->ctrl_dir, cfg->exec_dir);
prep_dir(cfg->ctrl_dir, cfg->text_dir);
prep_dir(cfg->ctrl_dir, cfg->data_dir, sizeof(cfg->data_dir));
prep_dir(cfg->ctrl_dir, cfg->exec_dir, sizeof(cfg->exec_dir));
prep_dir(cfg->ctrl_dir, cfg->text_dir, sizeof(cfg->text_dir));
prep_dir(cfg->ctrl_dir, cfg->netmail_dir);
prep_dir(cfg->ctrl_dir, cfg->echomail_dir);
prep_dir(cfg->ctrl_dir, cfg->fidofile_dir);
prep_dir(cfg->ctrl_dir, cfg->netmail_dir, sizeof(cfg->netmail_dir));
prep_dir(cfg->ctrl_dir, cfg->echomail_dir, sizeof(cfg->echomail_dir));
prep_dir(cfg->ctrl_dir, cfg->fidofile_dir, sizeof(cfg->fidofile_dir));
prep_path(cfg->netmail_sem);
prep_path(cfg->echomail_sem);
......@@ -169,7 +169,7 @@ void prep_cfg(scfg_t* cfg)
#endif
if(!cfg->sub[i]->data_dir[0]) /* no data storage path specified */
sprintf(cfg->sub[i]->data_dir,"%ssubs",cfg->data_dir);
prep_dir(cfg->ctrl_dir, cfg->sub[i]->data_dir);
prep_dir(cfg->ctrl_dir, cfg->sub[i]->data_dir, sizeof(cfg->sub[i]->data_dir));
/* default QWKnet tagline */
if(!cfg->sub[i]->tagline[0])
......@@ -186,7 +186,7 @@ void prep_cfg(scfg_t* cfg)
for(i=0;i<cfg->total_libs;i++) {
if(cfg->lib[i]->parent_path[0])
prep_dir(cfg->ctrl_dir, cfg->lib[i]->parent_path);
prep_dir(cfg->ctrl_dir, cfg->lib[i]->parent_path, sizeof(cfg->lib[i]->parent_path));
}
for(i=0;i<cfg->total_dirs;i++) {
......@@ -196,14 +196,14 @@ void prep_cfg(scfg_t* cfg)
if(!cfg->dir[i]->data_dir[0]) /* no data storage path specified */
sprintf(cfg->dir[i]->data_dir,"%sdirs",cfg->data_dir);
prep_dir(cfg->ctrl_dir, cfg->dir[i]->data_dir);
prep_dir(cfg->ctrl_dir, cfg->dir[i]->data_dir, sizeof(cfg->dir[i]->data_dir));
if(!cfg->dir[i]->path[0]) /* no file storage path specified */
sprintf(cfg->dir[i]->path,"%sdirs/%s/",cfg->data_dir,cfg->dir[i]->code);
else if(cfg->lib[cfg->dir[i]->lib]->parent_path[0])
prep_dir(cfg->lib[cfg->dir[i]->lib]->parent_path, cfg->dir[i]->path);
prep_dir(cfg->lib[cfg->dir[i]->lib]->parent_path, cfg->dir[i]->path, sizeof(cfg->dir[i]->path));
else
prep_dir(cfg->ctrl_dir, cfg->dir[i]->path);
prep_dir(cfg->ctrl_dir, cfg->dir[i]->path, sizeof(cfg->dir[i]->path));
prep_path(cfg->dir[i]->upload_sem);
}
......@@ -222,13 +222,13 @@ void prep_cfg(scfg_t* cfg)
strlwr(cfg->xtrnsec[i]->code); /* temporary Unix-compatibility hack */
#endif
for(i=0;i<cfg->total_xtrns;i++) {
prep_dir(cfg->ctrl_dir, cfg->xtrn[i]->path);
prep_dir(cfg->ctrl_dir, cfg->xtrn[i]->path, sizeof(cfg->xtrn[i]->path));
}
for(i=0;i<cfg->total_events;i++) {
#ifdef __unix__
strlwr(cfg->event[i]->code); /* temporary Unix-compatibility hack */
#endif
prep_dir(cfg->ctrl_dir, cfg->event[i]->dir);
prep_dir(cfg->ctrl_dir, cfg->event[i]->dir, sizeof(cfg->event[i]->dir));
}
cfg->prepped=TRUE; /* data prepared for run-time, DO NOT SAVE TO DISK! */
......@@ -443,7 +443,7 @@ static void free_attr_cfg(scfg_t* cfg)
cfg->total_colors=0;
}
char* DLLCALL prep_dir(char* base, char* path)
char* DLLCALL prep_dir(char* base, char* path, size_t buflen)
{
#ifdef __unix__
char *p;
......@@ -471,10 +471,10 @@ char* DLLCALL prep_dir(char* base, char* path)
backslashcolon(str);
strcat(str,"."); // Change C: to C:. and C:\SBBS\ to C:\SBBS\.
FULLPATH(abspath,str,LEN_DIR+1); // Change C:\SBBS\NODE1\..\EXEC to C:\SBBS\EXEC
FULLPATH(abspath,str,buflen); // Change C:\SBBS\NODE1\..\EXEC to C:\SBBS\EXEC
backslash(abspath);
sprintf(path,"%.*s",LEN_DIR,abspath);
sprintf(path,"%.*s",(int)(buflen-1),abspath);
return(path);
}
......
......@@ -1252,7 +1252,7 @@ void event_thread(void* arg)
memcpy(&sbbs->cfg,&scfg,sizeof(scfg_t));
// sprintf(sbbs->cfg.temp_dir, "temp/%08lX", sbbs_random(INT_MAX));
prep_dir(sbbs->cfg.data_dir, sbbs->cfg.temp_dir);
prep_dir(sbbs->cfg.data_dir, sbbs->cfg.temp_dir, sizeof(sbbs->cfg.temp_dir));
// Read TIME.DAB
sprintf(str,"%stime.dab",sbbs->cfg.ctrl_dir);
......@@ -1838,10 +1838,10 @@ sbbs_t::sbbs_t(ushort node_num, DWORD addr, char* name, SOCKET sd,
cfg.node_num=node_num;
if(node_num>0) {
strcpy(cfg.node_dir, cfg.node_path[node_num-1]);
prep_dir(cfg.node_dir, cfg.temp_dir);
prep_dir(cfg.node_dir, cfg.temp_dir, sizeof(cfg.temp_dir));
} else {
// sprintf(cfg.temp_dir, "temp/%08lX", sbbs_random(INT_MAX));
prep_dir(cfg.data_dir, cfg.temp_dir);
prep_dir(cfg.data_dir, cfg.temp_dir, sizeof(cfg.temp_dir));
}
terminated = false;
......
......@@ -817,7 +817,7 @@ extern "C" {
DLLEXPORT void DLLCALL refresh_cfg(scfg_t* cfg);
/* scfglib1.c */
DLLEXPORT char * DLLCALL prep_dir(char* base, char* dir);
DLLEXPORT char * DLLCALL prep_dir(char* base, char* dir, size_t buflen);
/* logfile.cpp */
DLLEXPORT BOOL DLLCALL hacklog(scfg_t* cfg, char* prot, char* user, char* text
......
......@@ -348,18 +348,6 @@ BOOL read_file_cfg(scfg_t* cfg, char* error)
get_str(cfg->dir[i]->data_dir,instream);
#if 0 /* default data dir stuff */
fread(str,LEN_DIR+1,1,instream); /* substitute data dir */
offset+=LEN_DIR+1;
if(str[0]) {
prep_dir(cfg->ctrl_dir, str);
if((cfg->dir[i]->data_dir=(char *)MALLOC(strlen(str)+1))==NULL)
return allocerr(instream,error,offset,fname,strlen(str)+1);
strcpy(cfg->dir[i]->data_dir,str);
} else
cfg->dir[i]->data_dir=cfg->data_dir_dirs;
#endif
get_str(cfg->dir[i]->arstr,instream);
get_str(cfg->dir[i]->ul_arstr,instream);
get_str(cfg->dir[i]->dl_arstr,instream);
......
......@@ -144,7 +144,7 @@ BOOL DLLCALL write_node_cfg(scfg_t* cfg, int backup_level)
return(FALSE);
sprintf(str,cfg->node_path[cfg->node_num-1]);
prep_dir(cfg->ctrl_dir,str);
prep_dir(cfg->ctrl_dir,str,sizeof(str));
md(str);
strcat(str,"node.cnf");
backup(str, backup_level, TRUE);
......@@ -477,7 +477,7 @@ BOOL DLLCALL write_msgs_cfg(scfg_t* cfg, int backup_level)
sprintf(smb.file,"%ssubs",cfg->data_dir);
else
sprintf(smb.file,"%s",cfg->sub[i]->data_dir);
prep_dir(cfg->ctrl_dir,smb.file);
prep_dir(cfg->ctrl_dir,smb.file,sizeof(smb.file));
strcat(smb.file,cfg->sub[i]->code);
if(smb_open(&smb)!=0) {
/* errormsg(WHERE,ERR_OPEN,smb.file,x); */
......@@ -609,7 +609,7 @@ BOOL DLLCALL write_msgs_cfg(scfg_t* cfg, int backup_level)
if(!no_msghdr) {
strcpy(dir,cfg->data_dir);
prep_dir(cfg->ctrl_dir,dir);
prep_dir(cfg->ctrl_dir,dir,sizeof(dir));
sprintf(smb.file,"%smail",dir);
if(smb_open(&smb)!=0) {
return(FALSE);
......@@ -820,13 +820,13 @@ BOOL DLLCALL write_file_cfg(scfg_t* cfg, int backup_level)
sprintf(path,"%sdirs/%s/",cfg->data_dir,cfg->dir[i]->code);
else if(cfg->lib[cfg->dir[i]->lib]->parent_path[0]) {
SAFECOPY(path,cfg->lib[cfg->dir[i]->lib]->parent_path);
prep_dir(cfg->ctrl_dir,path);
prep_dir(cfg->ctrl_dir,path,sizeof(path));
md(path);
backslash(path);
strcat(path,cfg->dir[i]->path);
}
else
prep_dir(cfg->ctrl_dir, path);
prep_dir(cfg->ctrl_dir, path,sizeof(path));
md(path);
}
#endif
......
......@@ -2094,8 +2094,8 @@ void DLLCALL web_server(void* arg)
SAFECOPY(error_dir,startup->error_dir);
/* Change to absolute path */
prep_dir(startup->ctrl_dir, root_dir);
prep_dir(startup->ctrl_dir, error_dir);
prep_dir(startup->ctrl_dir, root_dir, sizeof(root_dir));
prep_dir(startup->ctrl_dir, error_dir, sizeof(error_dir));
/* Trim off trailing slash/backslash */
if(*(p=lastchar(root_dir))==BACKSLASH) *p=0;
......
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