Commit 2014777c authored by Rob Swindell's avatar Rob Swindell 💬
Browse files

Add option to create drop files in node's temp directory.

Enabling this feature causes the node's temp directory to be cleared before
running the external program and causes the drop file(s) to be created-in and
read back from (when appropriate) the node's temp directory.

Creating drop files in a node's temp directory eliminates the possiblity of
an external program (e.g. door game) accidentally reading the wrong drop
file (e.g. wrong-cased name or a stale file of a different type).

Note: Synchronet/XSDK doors *always* read their drop file (xtrn.dat) from the
node directory, so don't try to use this option with those doors. Only doors
where you can configure the drop file path or specify on the command-line
(e.g. %g for the temp dir or %f for the fullpath of the drop file) should
potentially use this new feature.
parent fc3d3650
Pipeline #271 passed with stage
in 18 minutes and 19 seconds
......@@ -1026,6 +1026,7 @@ public:
bool user_event(user_event_t); /* Executes user event(s) */
char xtrn_access(uint xnum); /* Does useron have access to xtrn? */
void moduserdat(uint xtrnnum);
const char* xtrn_dropdir(const xtrn_t*, char* buf, size_t);
/* logfile.cpp */
void logentry(const char *code,const char *entry);
......
......@@ -415,7 +415,7 @@ typedef enum { /* Values for xtrn_t.event */
#define QUOTEWRAP (1<<21) /* Word-wrap quoted message text */
#define SAVECOLUMNS (1<<22) /* Save/share current terminal width */
#define XTRN_UTF8 (1<<23) /* External program supports UTF-8 */
#define XTRN_JS_CX (1<<24) /* New JavaScript Context */
#define XTRN_TEMP_DIR (1<<24) /* Place drop files in temp dir */
#define XTRN_CONIO (1<<31) /* Intercept Windows Console I/O (Drwy) */
/* Bits in cfg.xtrn_misc */
......
......@@ -1062,7 +1062,7 @@ void xtrn_cfg(uint section)
,cfg.xtrn[i]->misc&REALNAME ? "(R)":nulstr
,dropfile(cfg.xtrn[i]->type,cfg.xtrn[i]->misc));
sprintf(opt[k++],"%-27.27s%s","Place Drop File In"
,cfg.xtrn[i]->misc&STARTUPDIR ? "Start-Up Directory":"Node Directory");
,cfg.xtrn[i]->misc&STARTUPDIR ? "Start-Up Directory":cfg.xtrn[i]->misc&XTRN_TEMP_DIR ? "Temp Directory" : "Node Directory");
sprintf(opt[k++],"Time Options...");
opt[k][0]=0;
uifc.helpbuf=
......@@ -1450,24 +1450,41 @@ void xtrn_cfg(uint section)
}
break;
case 16:
k=0;
k = (cfg.xtrn[i]->misc & STARTUPDIR) ? 1 : (cfg.xtrn[i]->misc & XTRN_TEMP_DIR) ? 2 : 0;
strcpy(opt[0],"Node Directory");
strcpy(opt[1],"Start-up Directory");
opt[2][0]=0;
strcpy(opt[2],"Temporary Directory");
opt[3][0]=0;
uifc.helpbuf=
"`Directory for Drop File:`\n"
"\n"
"You can have the data file created in the current `Node Directory` or the\n"
"`Start-up Directory` (if one is specified).\n"
"You can have the data (drop) file created in the current `Node Directory`,\n"
"current `Temporary Directory`, or the `Start-up Directory` (if specified).\n"
"\n"
"For multi-user doors, you usually will `not` want the drop files placed\n"
"in the start-up directory due to potential conflict with other nodes.\n"
"\n"
"The safest option is the `Temp Directory`, as this directory is unique per\n"
"terminal server node and is automatically cleared-out for each logon.\n"
"\n"
"`Note:`\n"
"Many classic Synchronet (XSDK) doors assume the drop file will be\n"
"located in the `Node Directory`.\n"
;
k=uifc.list(WIN_MID|WIN_SAV,0,0,0,&k,0,"Create Drop File In"
,opt);
if(!k && cfg.xtrn[i]->misc&STARTUPDIR) {
cfg.xtrn[i]->misc&=~STARTUPDIR;
if(!k && (cfg.xtrn[i]->misc&(STARTUPDIR | XTRN_TEMP_DIR)) != 0) {
cfg.xtrn[i]->misc &= ~(STARTUPDIR | XTRN_TEMP_DIR);
uifc.changes=TRUE;
}
else if(k==1 && (cfg.xtrn[i]->misc&(STARTUPDIR | XTRN_TEMP_DIR)) != STARTUPDIR) {
cfg.xtrn[i]->misc &= ~(STARTUPDIR | XTRN_TEMP_DIR);
cfg.xtrn[i]->misc |= STARTUPDIR;
uifc.changes=TRUE;
}
else if(k==1 && !(cfg.xtrn[i]->misc&STARTUPDIR)) {
cfg.xtrn[i]->misc|=STARTUPDIR;
else if(k==2 && (cfg.xtrn[i]->misc&(STARTUPDIR | XTRN_TEMP_DIR)) != XTRN_TEMP_DIR) {
cfg.xtrn[i]->misc &= ~(STARTUPDIR | XTRN_TEMP_DIR);
cfg.xtrn[i]->misc |= XTRN_TEMP_DIR;
uifc.changes=TRUE;
}
break;
......
......@@ -1237,8 +1237,7 @@ void sbbs_t::moduserdat(uint xtrnnum)
sprintf(startup,"%s/",cfg.xtrn[xtrnnum]->path);
if(cfg.xtrn[xtrnnum]->type==XTRN_RBBS || cfg.xtrn[xtrnnum]->type==XTRN_RBBS1) {
sprintf(path,"%sEXITINFO.BBS"
,cfg.xtrn[xtrnnum]->misc&STARTUPDIR ? startup : cfg.node_dir);
SAFEPRINTF(path, "%sEXITINFO.BBS", xtrn_dropdir(cfg.xtrn[xtrnnum], startup, sizeof(startup)));
fexistcase(path);
if((file=nopen(path,O_RDONLY))!=-1) {
lseek(file,361,SEEK_SET);
......@@ -1256,8 +1255,7 @@ void sbbs_t::moduserdat(uint xtrnnum)
return;
}
else if(cfg.xtrn[xtrnnum]->type==XTRN_GAP) {
sprintf(path,"%sDOOR.SYS"
,cfg.xtrn[xtrnnum]->misc&STARTUPDIR ? startup : cfg.node_dir);
SAFEPRINTF(path,"%sDOOR.SYS", xtrn_dropdir(cfg.xtrn[xtrnnum], startup, sizeof(startup)));
fexistcase(path);
if((stream=fopen(path,"rb"))!=NULL) {
for(i=0;i<15;i++) /* skip first 14 lines */
......@@ -1324,8 +1322,7 @@ void sbbs_t::moduserdat(uint xtrnnum)
}
else if(cfg.xtrn[xtrnnum]->type==XTRN_PCBOARD) {
sprintf(path,"%sUSERS.SYS"
,cfg.xtrn[xtrnnum]->misc&STARTUPDIR ? startup : cfg.node_dir);
SAFEPRINTF(path, "%sUSERS.SYS", xtrn_dropdir(cfg.xtrn[xtrnnum], startup, sizeof(startup)));
fexistcase(path);
if((file=nopen(path,O_RDONLY))!=-1) {
lseek(file,39,SEEK_SET);
......@@ -1347,8 +1344,7 @@ void sbbs_t::moduserdat(uint xtrnnum)
return;
}
sprintf(path,"%sMODUSER.DAT"
,cfg.xtrn[xtrnnum]->misc&STARTUPDIR ? startup : cfg.node_dir);
SAFEPRINTF(path,"%sMODUSER.DAT", xtrn_dropdir(cfg.xtrn[xtrnnum], startup, sizeof(startup)));
fexistcase(path);
if((stream=fopen(path,"rb"))!=NULL) { /* File exists */
if(fgets(str,81,stream) && (mod=atol(str))!=0) {
......@@ -1463,6 +1459,20 @@ void sbbs_t::moduserdat(uint xtrnnum)
}
}
const char* sbbs_t::xtrn_dropdir(const xtrn_t* xtrn, char* buf, size_t maxlen)
{
const char* p = cfg.node_dir;
if(xtrn->misc & STARTUPDIR)
p = xtrn->path;
else if(xtrn->misc & XTRN_TEMP_DIR)
p = cfg.temp_dir;
char path[MAX_PATH + 1];
SAFECOPY(path, p);
backslash(path);
strncpy(buf, path, maxlen);
buf[maxlen - 1] = 0;
return buf;
}
/****************************************************************************/
/* This function handles configured external program execution. */
......@@ -1515,10 +1525,10 @@ bool sbbs_t::exec_xtrn(uint xtrnnum)
return(false);
}
SAFECOPY(str,cfg.xtrn[xtrnnum]->path);
backslash(str);
SAFECOPY(path,cfg.xtrn[xtrnnum]->misc&STARTUPDIR ? str : cfg.node_dir);
SAFECOPY(dropdir,cfg.xtrn[xtrnnum]->misc&STARTUPDIR ? str : cfg.node_dir);
if(cfg.xtrn[xtrnnum]->misc & XTRN_TEMP_DIR)
delfiles(cfg.temp_dir, ALLFILES);
xtrn_dropdir(cfg.xtrn[xtrnnum], dropdir, sizeof(dropdir));
SAFECOPY(path, dropdir);
switch(cfg.xtrn[xtrnnum]->type) {
case XTRN_WWIV:
......
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