RPM, tests, pointlist indexing and nlookup-ing, lint fixes #4

Merged
zx merged 15 commits from zx into master 2025-04-21 10:27:16 +03:00
25 changed files with 184 additions and 131 deletions
Showing only changes of commit ff329a7602 - Show all commits

View File

@ -259,11 +259,15 @@ int main(int argc, char *argv[], char *envp[])
mainenv[0] = NULL;
i=0;
while (envp[i]) {
mainenv[i] = malloc(strlen(envp[i])+2);
strcpy(mainenv[i], envp[i]);
mainenv[++i] = NULL;
DEB((D_FREE, "Program ENV: %s\n", mainenv[(i-1)]));
if ( envp[0] ) {
while (envp[i]) {
mainenv[i] = malloc(strlen(envp[i])+2);
if ( mainenv[i] ) {
strcpy(mainenv[i], envp[i]);
mainenv[++i] = NULL;
DEB((D_FREE, "Program ENV: %s\n", mainenv[(i-1)]));
}
}
}
memset(&opts, '\0', sizeof(s_bforce_opts));

View File

@ -662,7 +662,7 @@ static int proc_domain(s_domain *dest, char *value)
if( p_path[strlen(p_path)-1] == DIRSEPCHR )
dest->path = xstrcpy(p_path);
else
dest->path = string_concat(p_path, DIRSEPSTR, NULL);
dest->path = string_concat(p_path, DIRSEPSTR, '\0');
return(PROC_RC_OK);
}
else
@ -751,7 +751,7 @@ static int proc_path(s_string *dest, char *value)
if( value[strlen(value)-1] == DIRSEPCHR )
dest->str = xstrcpy(value);
else
dest->str = string_concat(value, DIRSEPSTR, NULL);
dest->str = string_concat(value, DIRSEPSTR, '\0');
return(PROC_RC_OK);
}
@ -1004,7 +1004,7 @@ static int proc_filebox(s_filebox *dest, char *value)
if( p_path[strlen(p_path)-1] == DIRSEPCHR )
dest->path = xstrcpy(p_path);
else
dest->path = string_concat(p_path, DIRSEPSTR, NULL);
dest->path = string_concat(p_path, DIRSEPSTR, '\0');
dest->flavor = flavor;
return rc;
}

View File

@ -1035,7 +1035,7 @@ int daemon_run(const char *confname, const char *incname, bool quit)
/*
* Check rescan timer
*/
if( !timer_running(timer_rescan) || timer_expired(timer_rescan) )
if( timer_expired(timer_rescan) )
{
(void)daemon_rescan_sysqueue(&daemon_sys_queue,
daemon_queues);
@ -1045,7 +1045,7 @@ int daemon_run(const char *confname, const char *incname, bool quit)
/*
* Check alive timer
*/
if( !timer_running(timer_alive) || timer_expired(timer_alive) )
if( timer_expired(timer_alive) )
{
daemon_alive_message(&daemon_sys_queue);
timer_set(&timer_alive, DAEMON_ALIVE_TIMER);

View File

@ -955,7 +955,7 @@ yydestruct (char *yymsg,
{
YY_USE (yyvaluep);
if (!yymsg)
yymsg = "Deleting";
yymsg = "Deleting"; // cppcheck_suppress uselessAssignmentPtrArg
YY_SYMBOL_PRINT (yymsg, yykind, yyvaluep, yylocationp);
YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
@ -1067,8 +1067,9 @@ yysetstate:
data in use in that stack, in bytes. This used to be a
conditional around just the two extra args, but that might
be undefined if yyoverflow is a macro. */
yyoverflow (YY_("memory exhausted"),
&yyss1, yysize * YYSIZEOF (*yyssp),
&yyss1, yysize * YYSIZEOF (*yyssp), // cppcheck_suppress syntaxError
&yyvs1, yysize * YYSIZEOF (*yyvsp),
&yyls1, yysize * YYSIZEOF (*yylsp),
&yystacksize);
@ -1088,7 +1089,7 @@ yysetstate:
yy_state_t *yyss1 = yyss;
union yyalloc *yyptr =
YY_CAST (union yyalloc *,
YYSTACK_ALLOC (YY_CAST (YYSIZE_T, YYSTACK_BYTES (yystacksize))));
YYSTACK_ALLOC (YY_CAST (YYSIZE_T, YYSTACK_BYTES (yystacksize)))); // cppcheck_suppress sizeofwithnumericparameter
if (! yyptr)
YYNOMEM;
YYSTACK_RELOCATE (yyss_alloc, yyss);

View File

@ -200,9 +200,18 @@ static void req_proc_ext(s_freq *freq, char *reqname)
char srfname[L_tmpnam+5];
char rspname[L_tmpnam+5];
char *comline = NULL;
char *chunk;
if( tmpnam(srfname) )
chunk = xmalloc(L_tmpnam+1);
if ( chunk )
{
getrandname(chunk, L_tmpnam);
chunk[L_tmpnam]='\0';
strnxcpy(srfname, chunk, L_tmpnam);
free(chunk);
//if( tmpnam(srfname) )
//{
strncpy(rspname, srfname, L_tmpnam+4);
rspname[L_tmpnam+4] = '\0';
strcat(srfname, ".srf");

View File

@ -116,7 +116,7 @@ static pid_t lock_read_pid(const char *lckname)
if( len == sizeof(pid) || sscanf(buf, "%d", &pid) != 1 || pid == 0 )
{
/* We found binary lock file? */
pid = *((int *)buf);
pid = *((u_int *)buf);
#ifndef LOCK_BINARY
log("warning: found binary lock file %s", lckname);
#endif
@ -197,12 +197,15 @@ static int lock_create(const char *lckname, const char *tmpname)
int rc, fd;
int tries;
#ifdef LOCK_BINARY
pid_t pid;
#else
char buf[32];
#endif
ASSERT(lckname != NULL && tmpname != NULL);
if( (fd = open(tmpname, O_CREAT | O_RDWR, 0644)) < 0 )
@ -299,8 +302,7 @@ int port_checklock(const char *lockdir, const s_modemport *modemport)
rc = lock_check(lckname);
if( lckname )
free(lckname);
free(lckname);
return rc;
}
@ -312,20 +314,24 @@ int port_lock(const char *lockdir, const s_modemport *modemport)
{
int rc;
char *lckname;
char *tmpname, *p_tmpname;
char *tmpname, *p_tmpname, *chunk;
if( *lockdir )
tmpname = xstrcpy(lockdir);
else
tmpname = xstrcpy(BFORCE_LOCK_DIR);
tmpname = xstrcat(tmpname, "bfXXXXXX");
//tmpname = xstrcat(tmpname, "bfXXXXXX");
if( (p_tmpname = mktemp(tmpname)) == NULL )
{
logerr("can't generate unique file name from \"%s\"", tmpname);
free(tmpname); return 1;
}
chunk = xmalloc(7);
getrandname(chunk,6);
p_tmpname = string_concat(tmpname, "bf", chunk, '\0');
//if( (p_tmpname = mktemp(tmpname)) == NULL )
//{
// logerr("can't generate unique file name from \"%s\"", tmpname);
// free(tmpname); return 1;
//}
if( (lckname = lock_getname(lockdir, modemport)) == NULL )
{
@ -340,8 +346,7 @@ int port_lock(const char *lockdir, const s_modemport *modemport)
if( tmpname )
free(tmpname);
if( lckname )
free(lckname);
free(lckname);
return rc;
}

View File

@ -144,7 +144,7 @@ int log_close(void)
ASSERT(log_fp);
if( log_fp )
if( log_fp != NULL )
{
rc = fclose(log_fp);
DEB((D_INFO,"Closing log file."));
@ -543,7 +543,7 @@ void debug(unsigned long what, const char *str, ...)
debug_open();
}
if( debug_fp )
if( debug_fp != NULL )
{
fprintf(debug_fp, "%s ", time_string_log(buf, sizeof(buf), 0));
va_start(args, str);

View File

@ -155,8 +155,8 @@ int exec_redirect_descriptor(int desc, const char *fname, int flags)
close(fd);
return -1;
}
//cppcheck-suppress resourceLeak
return 0;
return 0; //cppcheck-suppress resourceLeak
}
int exec_command(s_exec_options *eopt)

View File

@ -46,7 +46,7 @@ char *out_getname_4d(s_faddr addr)
else
sprintf(buf, "%04x%04x.pnt/%08x", addr.net, addr.node, addr.point);
dest = string_concat(p_outbound, buf, NULL);
dest = string_concat(p_outbound, buf, '\0');
}
else
{
@ -55,7 +55,7 @@ char *out_getname_4d(s_faddr addr)
else
sprintf(buf, ".%03x/%04x%04x.pnt/%08x", addr.zone, addr.net, addr.node, addr.point);
dest = string_concat(out_root, out_main, buf, NULL);
dest = string_concat(out_root, out_main, buf, '\0');
}
}
@ -83,7 +83,7 @@ char *out_getname_domain(s_faddr addr)
else
sprintf(buf, "%04x%04x.pnt/%08x", addr.net, addr.node, addr.point);
dest = string_concat(cfptr->d.domain.path, buf, NULL);
dest = string_concat(cfptr->d.domain.path, buf, '\0');
break;
}
}
@ -102,7 +102,7 @@ char *out_getname_amiga(s_faddr addr)
if( p_amigaoutbound && *p_amigaoutbound )
{
sprintf(buf, "%d.%d.%d.%d", addr.zone, addr.net, addr.node, addr.point);
dest = string_concat(p_amigaoutbound, buf, NULL);
dest = string_concat(p_amigaoutbound, buf, '\0');
}
return dest;

View File

@ -155,7 +155,7 @@ static int out_scan_bso_dir(s_outbound_callback_data *callback,
if( alst || !fa_list )
{
p = string_concat(path, dirent->d_name, "/", NULL);
p = string_concat(path, dirent->d_name, "/", '\0');
out_scan_bso_dir(callback, fa_list, addr, p, 1);
if( p ) { free(p); p = NULL; }
}
@ -178,7 +178,7 @@ static int out_scan_bso_dir(s_outbound_callback_data *callback,
if( alst || !fa_list )
{
callback->path = string_concat(path, dirent->d_name, NULL);
callback->path = string_concat(path, dirent->d_name, '\0');
callback->addr = *addr;
callback->type = OUTB_TYPE_BSO;
callback->flavor = -1;
@ -250,7 +250,7 @@ static int out_scan_bso(s_outbound_callback_data *callback,
if( alst || mailfor == NULL )
{
newpath = string_concat(out_root, dirent->d_name, "/", NULL);
newpath = string_concat(out_root, dirent->d_name, "/", '\0');
out_scan_bso_dir(callback, mailfor, &addr, newpath, 0);
free(newpath);
}
@ -296,7 +296,7 @@ static int out_scan_fbox_dir(s_outbound_callback_data *callback,
while( (dirent = readdir(dir)) )
{
callback->path = string_concat(path, dirent->d_name, NULL);
callback->path = string_concat(path, dirent->d_name, '\0');
if( is_regfile(callback->path) )
{
callback->addr = addr;
@ -340,7 +340,7 @@ static int out_scan_lbox(s_outbound_callback_data *callback,
alst = alst->next );
if( alst )
{
newpath = string_concat(path, dirent->d_name, "/", NULL);
newpath = string_concat(path, dirent->d_name, "/", '\0');
(void)out_scan_fbox_dir(callback, newpath, addr, FLAVOR_HOLD);
free(newpath);
}
@ -348,7 +348,7 @@ static int out_scan_lbox(s_outbound_callback_data *callback,
else
{
/* Scan all fileboxes */
newpath = string_concat(path, dirent->d_name, "/", NULL);
newpath = string_concat(path, dirent->d_name, "/", '\0');
(void)out_scan_fbox_dir(callback, newpath, addr, FLAVOR_HOLD);
free(newpath);
}
@ -424,7 +424,7 @@ static int out_scan_aso(s_outbound_callback_data *callback,
if( alst || !mailfor )
{
callback->path = string_concat(path, dirent->d_name, NULL);
callback->path = string_concat(path, dirent->d_name, '\0');
callback->addr = addr;
callback->type = OUTB_TYPE_ASO;
callback->flavor = -1;

View File

@ -593,7 +593,7 @@ else if (bstate->mode == bmode_transfer) {
case 1: //send M_FILE - M_GET forcibly sets this phase. M_GET must open needed file
DEB((D_24554, "send M_FILE"));
buf[0] = BPMSG_FILE;
*block_length = 1+sprintf(buf+1, "%s %ld %ld 0", bstate->pi->send->net_name,
*block_length = 1+sprintf(buf+1, "%s %zu %lu 0", bstate->pi->send->net_name,
bstate->pi->send->bytes_total, bstate->pi->send->mod_time);
DEB((D_24554, "M_FILE: %s", buf+1));
*block_type = BINKP_BLK_CMD;
@ -823,7 +823,7 @@ case BPMSG_FILE: /* File information */
DEB((D_24554, "no, skipping; TODO: accept it"));
if( bstate->extracmd[0] != (char)-1 ) return 0;
bstate->extracmd[0] = BPMSG_SKIP;
sprintf(bstate->extracmd+1, "%s %ld %ld %ld", recvfi.fn, recvfi.sz, recvfi.tm, recvfi.offs);
sprintf(bstate->extracmd+1, "%s %zu %lu %zu", recvfi.fn, recvfi.sz, recvfi.tm, recvfi.offs);
bstate->extraislast = false;
return 1;
}

View File

@ -1053,7 +1053,7 @@ int p_rx_fopen(s_protinfo *pi, char *fn, size_t sz, time_t tm, mode_t mode)
/*
* Check, there is enough space in our inbound
*/
if (openmode == "a") needed_bytes_total = minfree + pi->recv->bytes_total - pi->recv->bytes_skipped;
if ( strcmp(openmode, "a") == 0 ) needed_bytes_total = minfree + pi->recv->bytes_total - pi->recv->bytes_skipped;
else needed_bytes_total = minfree + pi->recv->bytes_total;
if( minfree > 0 && getfreespace(state.inbound) < needed_bytes_total )

View File

@ -449,8 +449,8 @@ static int sm_rx_waitseq(s_rx_emsidat *d)
static int sm_rx_getdat(s_rx_emsidat *d)
{
int rc = 0;
int pos = 0;
int emsi_len = 0;
u_int pos = 0;
u_int emsi_len = 0;
short unsigned ourcrc;
short unsigned remcrc;
char *emsi_dat = NULL;

View File

@ -65,7 +65,7 @@ static char *add_str(char *source, const char *add)
{
len += 2;
dest = (char *)xrealloc(dest, len);
sprintf(&dest[pos], "\\%02hd", *(unsigned char*)add);
sprintf(&dest[pos], "\\%02hhu", *(unsigned char*)add);
add += 1;
pos += 3;
}
@ -200,38 +200,12 @@ char *emsi_createdat(s_emsi *emsi)
if( emsi->compcodes.NCP ) tmp = add_str(tmp, "NCP,");
} else {
ord = xmalloc(4);
DEB((D_HSHAKE,"Protocol order found: %s", p_order));
ord = strncpy(ord, p_order,3);
ord[3] = '\0';
DEB((D_HSHAKE,"Protocol order chunk: %s", ord));
if ( ord == NULL )
DEB((D_HSHAKE,"EMSI create order error"));
if ( !strcmp(ord,"HYD") )
if ( emsi->compcodes.HYD) tmp = add_str(tmp, "HYD,");
if ( !strcmp(ord,"JAN") )
if ( emsi->compcodes.JAN) tmp = add_str(tmp, "JAN,");
if ( !strcmp(ord,"DZA") )
if ( emsi->compcodes.DZA) tmp = add_str(tmp, "DZA,");
if ( !strcmp(ord,"ZAP") )
if ( emsi->compcodes.ZAP) tmp = add_str(tmp, "ZAP,");
if ( !strcmp(ord,"ZMO") )
if ( emsi->compcodes.ZMO) tmp = add_str(tmp, "ZMO,");
if ( !strcmp(ord,"TZA") )
if ( emsi->compcodes.TZA) tmp = add_str(tmp, "TZA,");
if ( !strcmp(ord,"SLK") )
if ( emsi->compcodes.SLK) tmp = add_str(tmp, "SLK,");
if ( !strcmp(ord,"KER") )
if ( emsi->compcodes.KER) tmp = add_str(tmp, "KER,");
if ( !strcmp(ord,"NCP") )
if ( emsi->compcodes.NCP) tmp = add_str(tmp, "NCP,");
p_order = strchr(p_order, ',');
if ( p_order ) p_order = p_order+1; /* skip ',' */
while ( p_order ) {
if (ord)
{
DEB((D_HSHAKE,"Protocol order found: %s", p_order));
ord = strncpy(ord, p_order,3);
ord[3] = '\0';
DEB((D_HSHAKE,"Protocol order chunk: %s", ord));
if ( ord == NULL )
DEB((D_HSHAKE,"EMSI create order error"));
if ( !strcmp(ord,"HYD") )
if ( emsi->compcodes.HYD) tmp = add_str(tmp, "HYD,");
if ( !strcmp(ord,"JAN") )
@ -251,9 +225,34 @@ char *emsi_createdat(s_emsi *emsi)
if ( !strcmp(ord,"NCP") )
if ( emsi->compcodes.NCP) tmp = add_str(tmp, "NCP,");
p_order = strchr(p_order, ',');
if ( p_order ) p_order = p_order+1; /* skip ',' */
if ( p_order ) p_order = p_order+1; /* skip ',' */
while ( p_order ) {
ord = strncpy(ord, p_order,3);
ord[3] = '\0';
DEB((D_HSHAKE,"Protocol order chunk: %s", ord));
if ( !strcmp(ord,"HYD") )
if ( emsi->compcodes.HYD) tmp = add_str(tmp, "HYD,");
if ( !strcmp(ord,"JAN") )
if ( emsi->compcodes.JAN) tmp = add_str(tmp, "JAN,");
if ( !strcmp(ord,"DZA") )
if ( emsi->compcodes.DZA) tmp = add_str(tmp, "DZA,");
if ( !strcmp(ord,"ZAP") )
if ( emsi->compcodes.ZAP) tmp = add_str(tmp, "ZAP,");
if ( !strcmp(ord,"ZMO") )
if ( emsi->compcodes.ZMO) tmp = add_str(tmp, "ZMO,");
if ( !strcmp(ord,"TZA") )
if ( emsi->compcodes.TZA) tmp = add_str(tmp, "TZA,");
if ( !strcmp(ord,"SLK") )
if ( emsi->compcodes.SLK) tmp = add_str(tmp, "SLK,");
if ( !strcmp(ord,"KER") )
if ( emsi->compcodes.KER) tmp = add_str(tmp, "KER,");
if ( !strcmp(ord,"NCP") )
if ( emsi->compcodes.NCP) tmp = add_str(tmp, "NCP,");
p_order = strchr(p_order, ',');
if ( p_order ) p_order = p_order+1; /* skip ',' */
}
free(ord);
}
free(ord);
}
if( emsi->compcodes.FRQ ) tmp = add_str(tmp, "FRQ,");
@ -452,7 +451,7 @@ char *emsi_createdat(s_emsi *emsi)
static char *get_field(char **str, char from, char to)
{
char *dst, *src, *dest = NULL;
int ch;
u_int ch;
src = *str;
@ -722,7 +721,7 @@ int emsi_parsedat(char *emsi_dat, s_emsi *emsi)
if( (p=get_field(&emsi_dat, '{', '}')) == NULL ) return(1);
if( p && *p )
{
if( sscanf(p, "%08X %08X", &emsi->netmail_size, &emsi->arcmail_size) == 2 )
if( sscanf(p, "%08zX %08zX", &emsi->netmail_size, &emsi->arcmail_size) == 2 )
{
emsi->have_traf = 1;
}
@ -738,7 +737,7 @@ int emsi_parsedat(char *emsi_dat, s_emsi *emsi)
if( (p=get_field(&p, '[', ']')) == NULL ) return(1);
if( p && *p )
{
if( sscanf(p, "%08X", &emsi->files_size) == 1 )
if( sscanf(p, "%08zX", &emsi->files_size) == 1 )
{
emsi->have_moh = 1;
}
@ -781,21 +780,24 @@ int emsi_parsedat(char *emsi_dat, s_emsi *emsi)
/* Parse EMSI TZUTC in fmt (+|-)HHMM */
if( *p ) {
tzc = malloc(2);
DEB((D_HSHAKE, "Got TZUTC=%s for parsing", p));
tzn = sscanf( p, "%1c%02u%02u", tzc, &tzh, &tzm);
tzc[1] = '\0';
if ( tzn == 3) {
DEB((D_HSHAKE, "Got TZC=%s , H=%u, M=%u", tzc, tzh,tzm));
emsi->have_tzutc = 1;
if ( strcmp(tzc, "-") == 0 ) {
emsi->tzutc = -(tzh*60 + tzm);
if (tzc)
{
DEB((D_HSHAKE, "Got TZUTC=%s for parsing", p));
tzn = sscanf( p, "%1c%02u%02u", tzc, &tzh, &tzm);
tzc[1] = '\0';
if ( tzn == 3) {
DEB((D_HSHAKE, "Got TZC=%s , H=%u, M=%u", tzc, tzh,tzm));
emsi->have_tzutc = 1;
if ( strcmp(tzc, "-") == 0 ) {
emsi->tzutc = -(tzh*60 + tzm);
} else {
emsi->tzutc = tzh*60 + tzm;
}
} else {
emsi->tzutc = tzh*60 + tzm;
DEB((D_HSHAKE,"TZUTC value not parsed!"));
}
} else {
DEB((D_HSHAKE,"TZUTC value not parsed!"));
free(tzc);
}
free(tzc);
}
}
else

View File

@ -100,7 +100,8 @@ char *hydra_pkttype_names[] =
"HPKT_EOFACK",
"HPKT_END",
"HPKT_IDLE",
"HPKT_DEVDATA"
"HPKT_DEVDATA",
"HPKT_DEVDACK"
};
char *hydra_char_names[] =
@ -1049,8 +1050,8 @@ static int hydra_parse_init(s_hydrainfo *hi, char *pkt, size_t pktlen)
if( appinf && canopt && desopt && window && prefix )
{
char buf[256];
long txwindow = 0L;
long rxwindow = 0L;
unsigned long txwindow = 0UL;
unsigned long rxwindow = 0UL;
DEB((D_PROT, "hydra: revtime = \"%s\"", time_string_long(buf, sizeof(buf), revtime)));
DEB((D_PROT, "hydra: appinf = \"%s\"", appinf));
@ -1637,7 +1638,7 @@ int hydra_batch(s_hydrainfo *hi, s_protinfo *pi)
char *p;
/* Get file modification time and size */
sscanf(hi->ibuf, "%08lx%08x%*08x%*08x%*08x",
sscanf(hi->ibuf, "%08lx%08zx%*08zx%*08zx%*08zx",
(unsigned long *)&modtime, &filesize);
/* Convert local time -> UTC */

View File

@ -67,7 +67,7 @@ static const char *FrameTypes[] =
"ZCOMMAND",
"ZSTDERR",
"Unused"
#define FRTYPES 22 /* Total number of frame types in this array */
#define FRTYPES 20 /* Total number of frame types in this array */
/* not including psuedo negative entries */
};
#endif

View File

@ -548,7 +548,7 @@ static int zmodem_proc_ZFILE(s_protinfo *pi, char *blkptr, size_t blklen)
fileiptr = blkptr + strlen(blkptr) + 1;
if( fileiptr >= (blkptr + blklen) ||
sscanf(fileiptr, "%d%lo", &filesize, (unsigned long *)&filetime) < 1 )
sscanf(fileiptr, "%zu%lo", &filesize, (unsigned long *)&filetime) < 1 )
{
log("zmodem: got invalid ZFILE packet");
return 1;

View File

@ -47,14 +47,18 @@ static void zmodem_add_empty_packet(s_protinfo *pi)
s_filelist **ptrl;
s_packet pkt;
char tmpname[] = "/tmp/bfXXXXXX";
char *chunk;
char *p_tmpname;
if( (p_tmpname = mktemp(tmpname)) == NULL )
{
logerr("cannot generate temp. file name for packet from \"%s\"", tmpname);
chunk = xmalloc(7);
if (!chunk) {
logerr("cannot generate temp. file name for packet");
return;
}
getrandname(chunk, 6);
p_tmpname = string_concat("/tmp/bf", chunk, '\0');
free(chunk);
memset(&pkt, '\0', sizeof(s_packet));
pkt.dest = state.node.addr;

View File

@ -519,7 +519,7 @@ case CALL_TCPIP_TELNET:
state.session = SESSION_UNKNOWN;
target = xstrcpy("ITN");
break;
defalt:
default:
log("invalid protocol for TCP/IP module");
return BFERR_FATALERROR;
}
@ -536,7 +536,7 @@ defalt:
if ( ! resflg )
{
char *p = string_casestr(pbuf, target);
const char *p = string_casestr(pbuf, target);
if ( p )
{

View File

@ -58,11 +58,11 @@ static char *session_stat_get_stsfile(s_faddr *addr, int linenum)
addr->zone, addr->net,
addr->node, addr->point);
else
sprintf(buf, "%u.%u.%u.%u-%u.sts",
sprintf(buf, "%u.%u.%u.%u-%d.sts",
addr->zone, addr->net,
addr->node, addr->point, linenum);
yield = string_concat(p_stsdir, buf, NULL);
yield = string_concat(p_stsdir, buf, '\0');
}
return yield;

View File

@ -109,6 +109,22 @@ int file_lock_wait(FILE *fp, bool exclusive)
return -1;
}
void getrandname(char * buf, u_int size)
{
srand((unsigned int)time(NULL));
char c;
int i;
for (i = 0; i<size; i++)
{
c = rand();
// Only ASCII 0..9A..Z
while ( (c > 90) || (c < 48) || ( ( c > 57) && ( c < 65 ) ) )
c = rand();
buf[i] = c;
}
buf[size]='\0';
}
bool file_name_issafe(int ch)
{
if( ch == '!' ) return TRUE;
@ -151,12 +167,22 @@ char *file_getname(char *filename)
char *file_gettmp(void)
{
char *tmp = xstrcpy("/tmp/bforce-XXXXXX");
char *res = mktemp(tmp);
if( !res )
free(tmp);
char *chunk = xmalloc(7);
char *res = NULL;
if (chunk)
{
getrandname(chunk,6);
chunk[6] = '\0';
char *tmp = xstrcpy("/tmp/bforce-");
res = string_concat(tmp, chunk, '\0');
if( chunk )
free(chunk);
if( !res )
free(tmp);
}
return res;
}

View File

@ -152,7 +152,13 @@ int plock_link(const char *lockname, const char *tmpname)
int plock_create(const char *lockname)
{
int rc;
char *tmpname, *p;
char *tmpname, *p, *chunk;
chunk = xmalloc(7);
if (!chunk) {
logerr("can't generate unique file name from \"%s\"", tmpname);
DEB((D_FREE, "plock freed"));
return PLOCK_ERROR;
}
ASSERT(lockname != NULL);
@ -166,16 +172,10 @@ int plock_create(const char *lockname)
DEB((D_FREE, "plock freed"));
return PLOCK_ERROR;
}
tmpname = xstrcat(tmpname, "bforce-XXXXXX");
if( (p = mktemp(tmpname)) == NULL )
{
logerr("can't generate unique file name from \"%s\"", tmpname);
DEB((D_FREE, "plock free"));
free(tmpname);
DEB((D_FREE, "plock freed"));
return PLOCK_ERROR;
}
tmpname = xstrcat(tmpname, "bforce-");
getrandname(chunk,6);
p = string_concat(tmpname,chunk,'\0');
if( (rc = plock_write(p)) == PLOCK_OK )
rc = plock_link(lockname, p);

View File

@ -46,10 +46,10 @@ enum day
typedef struct faddr {
bool inetform; /* Is address in domain form? */
int zone; /* -1 value means any?! */
int net;
int node;
int point;
u_int zone; /* -1 value means any?! */
u_int net;
u_int node;
u_int point;
char domain[BF_MAXDOMAIN+1];
} s_faddr;
@ -83,7 +83,7 @@ typedef struct message {
typedef struct packet {
s_faddr orig;
s_faddr dest;
int baud;
u_int baud;
char password[8+1];
s_message *msgs;
int n_msgs;
@ -161,6 +161,7 @@ bool is_regfile(const char *filename);
int directory_create(const char *dirname, mode_t access_mode);
FILE *file_open(const char *path, const char *mode);
int file_close(FILE *stream);
void getrandname(char * buf, u_int size);
/* u_ftn.c */
int ftn_addrparse(s_faddr *addr, const char *s, bool wildcard);

View File

@ -6,7 +6,7 @@ proto_order %PROTO%
#domain schoolnet /var/spool/ftn/schoolnet/ 461
log_file %TESTZONE%/logsA/bf-log
debug_file %TESTZONE%/logsA/bf-debug
debug_level info modem hshake event prot override
debug_level info modem hshake event prot outbound override
nodial_flag %TESTZONE%/etc/nodial
inbound_directory (Protected) %TESTZONE%/inboundA
inbound_directory %TESTZONE%/inbound-unsecureA

View File

@ -6,7 +6,7 @@ proto_order %PROTO%
#domain schoolnet /var/spool/ftn/schoolnet/ 461
log_file %TESTZONE%/logsB/bf-log
debug_file %TESTZONE%/logsB/bf-debug
debug_level info modem hshake event prot override
debug_level info modem hshake event prot outbound override
nodial_flag %TESTZONE%/etc/nodial
inbound_directory (Protected) %TESTZONE%/inboundB
inbound_directory %TESTZONE%/inbound-unsecureB