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

Commits (25)
/* chk_ar.cpp */
/* Synchronet ARS checking routine */
/* $Id: chk_ar.cpp,v 1.32 2020/03/19 18:50:51 rswindell Exp $ */
/****************************************************************************
* @format.tab-size 4 (Plain Text/Source Code File Header) *
* @format.use-tabs true (see http://www.synchro.net/ptsc_hdr.html) *
......@@ -17,21 +13,9 @@
* See the GNU General Public License for more details: gpl.txt or *
* http://www.fsf.org/copyleft/gpl.html *
* *
* Anonymous FTP access to the most recent released source is available at *
* ftp://vert.synchro.net, ftp://cvs.synchro.net and ftp://ftp.synchro.net *
* *
* Anonymous CVS access to the development source and modification history *
* is available at cvs.synchro.net:/cvsroot/sbbs, example: *
* cvs -d :pserver:anonymous@cvs.synchro.net:/cvsroot/sbbs login *
* (just hit return, no password is necessary) *
* cvs -d :pserver:anonymous@cvs.synchro.net:/cvsroot/sbbs checkout src *
* *
* For Synchronet coding style and modification guidelines, see *
* http://www.synchro.net/source.html *
* *
* You are encouraged to submit any modifications (preferably in Unix diff *
* format) via e-mail to mods@synchro.net *
* *
* Note: If this box doesn't appear square, then you need to fix your tabs. *
****************************************************************************/
......@@ -878,7 +862,5 @@ uint sbbs_t::getusrdir(uint dirnum)
int sbbs_t::dir_op(uint dirnum)
{
return(SYSOP || (cfg.dir[dirnum]->op_ar!=NULL && cfg.dir[dirnum]->op_ar[0] && chk_ar(cfg.dir[dirnum]->op_ar,&useron,&client)));
return(SYSOP || (cfg.dir[dirnum]->op_ar[0] && chk_ar(cfg.dir[dirnum]->op_ar,&useron,&client)));
}
......@@ -44,7 +44,7 @@ uint sbbs_t::finduser(const char* instr, bool silent_failure)
if(str2[0] && strcmp(str2,"DELETED USER"))
return(i);
}
strcpy(str,instr);
SAFECOPY(str,instr);
strupr(str);
SAFEPRINTF(str3,"%suser/name.dat",cfg.data_dir);
if(flength(str3)<1L)
......@@ -65,7 +65,7 @@ uint sbbs_t::finduser(const char* instr, bool silent_failure)
str2[c]=0;
if(!c) /* deleted user */
continue;
strcpy(str3,str2);
SAFECOPY(str3,str2);
strupr(str2);
if(pass==1 && !strcmp(str,str2)) {
fclose(stream);
......
......@@ -169,13 +169,11 @@ bool sbbs_t::removefcdt(file_t* f)
&& f->hdr.times_downloaded) /* all downloads */
cdt+=((ulong)((long)f->hdr.times_downloaded
*f->cost*(cfg.dir[f->dir]->dn_pct/100.0))/cur_cps)/60;
if(cdt) {
adjustuserrec(&cfg,u,U_MIN,10,-cdt);
sprintf(str,"%lu minute",cdt);
sprintf(tmp,text[FileRemovedUserMsg]
,f->name,cdt ? str : text[No]);
putsmsg(&cfg,u,tmp);
}
adjustuserrec(&cfg,u,U_MIN,10,-cdt);
sprintf(str,"%lu minute",cdt);
sprintf(tmp,text[FileRemovedUserMsg]
,f->name,cdt ? str : text[No]);
putsmsg(&cfg,u,tmp);
}
else {
if(cfg.dir[f->dir]->misc&DIR_CDTUL)
......@@ -192,12 +190,10 @@ bool sbbs_t::removefcdt(file_t* f)
return false;
cdt = atol(str);
}
if(cdt) {
adjustuserrec(&cfg,u,U_CDT,10,-cdt);
sprintf(tmp,text[FileRemovedUserMsg]
,f->name,cdt ? ultoac(cdt,str) : text[No]);
putsmsg(&cfg,u,tmp);
}
adjustuserrec(&cfg,u,U_CDT,10,-cdt);
sprintf(tmp,text[FileRemovedUserMsg]
,f->name,cdt ? ultoac(cdt,str) : text[No]);
putsmsg(&cfg,u,tmp);
}
adjustuserrec(&cfg,u,U_ULB,10,(long)-f->size);
......
......@@ -719,7 +719,9 @@ long extract_files_from_archive(const char* archive, const char* outdir, const c
long extracted = 0;
char fpath[MAX_PATH + 1];
if(error != NULL && maxerrlen >= 1)
if(error == NULL)
maxerrlen = 0;
if(maxerrlen >= 1)
*error = '\0';
if((ar = archive_read_new()) == NULL) {
safe_snprintf(error, maxerrlen, "archive_read_new returned NULL");
......
......@@ -125,7 +125,7 @@ js_extract(JSContext *cx, uintN argc, jsval *arglist)
JS_ReportError(cx, "Invalid output directory specified (null or undefined)");
else
JSVALUE_TO_MSTRING(cx, argv[0], outdir, NULL);
if(JS_IsExceptionPending(cx)) {
if(JS_IsExceptionPending(cx) || outdir == NULL) {
free(outdir);
return JS_FALSE;
}
......
......@@ -225,6 +225,10 @@ js_sendfile(JSContext *cx, uintN argc, jsval *arglist)
free(fname);
len=filelength(file);
if(len < 1) {
close(file);
return(JS_TRUE);
}
if((buf=malloc((size_t)len))==NULL) {
close(file);
return(JS_TRUE);
......
......@@ -2582,9 +2582,6 @@ JSObject* js_CreateConsoleObject(JSContext* cx, JSObject* parent)
,JSPROP_ENUMERATE|JSPROP_READONLY))==NULL)
return(NULL);
if (obj == NULL)
return NULL;
JS_SetPrivate(cx, obj, sbbs);
/* Create an array of pre-defined colors */
......
......@@ -1561,8 +1561,6 @@ js_cryptcert_get(JSContext *cx, JSObject *obj, jsid id, jsval *vp)
if ((p=(struct js_cryptcert_private_data *)JS_GetPrivate(cx,obj))==NULL) {
return JS_TRUE;
JS_ReportError(cx, getprivate_failure, WHERE);
return JS_FALSE;
}
JS_IdToValue(cx, id, &idval);
......
......@@ -1129,7 +1129,7 @@ JSObject* DLLCALL js_CreateCryptContextClass(JSContext* cx, JSObject* parent)
JS_DeepFreezeObject(cx, algo);
}
mode = JS_DefineObject(cx, constructor, "MODE", NULL, NULL, JSPROP_PERMANENT|JSPROP_ENUMERATE|JSPROP_READONLY);
if(JS_GetProperty(cx, constructor, "MODE", &val) && !JSVAL_NULL_OR_VOID(val)) {
if(mode != NULL && JS_GetProperty(cx, constructor, "MODE", &val) && !JSVAL_NULL_OR_VOID(val)) {
JS_DefineProperty(cx, mode, "None", INT_TO_JSVAL(CRYPT_MODE_NONE), NULL, NULL
, JSPROP_PERMANENT|JSPROP_ENUMERATE|JSPROP_READONLY);
JS_DefineProperty(cx, mode, "ECB", INT_TO_JSVAL(CRYPT_MODE_ECB), NULL, NULL
......
......@@ -329,8 +329,6 @@ js_cryptkeyset_get(JSContext *cx, JSObject *obj, jsid id, jsval *vp)
if ((p=(struct private_data *)JS_GetPrivate(cx,obj))==NULL) {
return JS_TRUE;
JS_ReportError(cx, getprivate_failure, WHERE);
return JS_FALSE;
}
JS_IdToValue(cx, id, &idval);
......
......@@ -1657,11 +1657,11 @@ js_raw_write(JSContext *cx, uintN argc, jsval *arglist)
rc=JS_SUSPENDREQUEST(cx);
if(write(fileno(p->fp),cp,len)==(size_t)len) {
free(cp);
dbprintf(FALSE, p, "wrote %u raw bytes",len);
dbprintf(FALSE, p, "wrote %lu raw bytes",len);
JS_SET_RVAL(cx, arglist, JSVAL_TRUE);
} else {
free(cp);
dbprintf(TRUE, p, "raw write of %u bytes failed",len);
dbprintf(TRUE, p, "raw write of %lu bytes failed",len);
}
JS_RESUMEREQUEST(cx, rc);
......@@ -1754,7 +1754,7 @@ js_write(JSContext *cx, uintN argc, jsval *arglist)
}
free(cp);
}
dbprintf(FALSE, p, "wrote %u bytes",tlen);
dbprintf(FALSE, p, "wrote %lu bytes", (ulong)tlen);
JS_SET_RVAL(cx, arglist, JSVAL_TRUE);
} else {
free(cp);
......
......@@ -468,8 +468,6 @@ js_hash_file(JSContext *cx, uintN argc, jsval *arglist)
SAFECOPY(path, filename);
else {
file.name = filename;
// read index record, if it exists (for altpath)
smb_findfile(&p->smb, filename, &file);
getfilepath(scfg, &file, path);
}
off_t size = flength(path);
......@@ -1535,7 +1533,7 @@ js_filebase_constructor(JSContext *cx, uintN argc, jsval *arglist)
#endif
p->smb.dirnum = getdirnum(scfg, base);
if(p->smb.dirnum >= 0 && p->smb.dirnum < scfg->total_dirs) {
if(p->smb.dirnum < scfg->total_dirs) {
safe_snprintf(p->smb.file, sizeof(p->smb.file), "%s%s"
,scfg->dir[p->smb.dirnum]->data_dir, scfg->dir[p->smb.dirnum]->code);
} else { /* unknown code */
......
......@@ -1140,7 +1140,7 @@ js_send(JSContext *cx, uintN argc, jsval *arglist)
JS_SET_RVAL(cx, arglist, INT_TO_JSVAL(ret));
} else {
p->last_error=ERROR_VALUE;
dbprintf(TRUE, p, "send of %u bytes failed",len);
dbprintf(TRUE, p, "send of %lu bytes failed",len);
}
free(cp);
JS_RESUMEREQUEST(cx, rc);
......@@ -1175,11 +1175,11 @@ js_sendline(JSContext *cx, uintN argc, jsval *arglist)
rc=JS_SUSPENDREQUEST(cx);
if(js_socket_sendsocket(p,cp,len,FALSE)==len && js_socket_sendsocket(p,"\r\n",2,TRUE)==2) {
dbprintf(FALSE, p, "sent %u bytes",len+2);
dbprintf(FALSE, p, "sent %lu bytes",len+2);
JS_SET_RVAL(cx, arglist, JSVAL_TRUE);
} else {
p->last_error=ERROR_VALUE;
dbprintf(TRUE, p, "send of %u bytes failed",len+2);
dbprintf(TRUE, p, "send of %lu bytes failed",len+2);
}
free(cp);
JS_RESUMEREQUEST(cx, rc);
......@@ -1250,15 +1250,15 @@ js_sendto(JSContext *cx, uintN argc, jsval *arglist)
for(cur=res; cur; cur=cur->ai_next) {
inet_addrtop((void *)cur->ai_addr, ip_addr, sizeof(ip_addr));
dbprintf(FALSE, p, "sending %d bytes to %s port %u at %s"
dbprintf(FALSE, p, "sending %lu bytes to %s port %u at %s"
,len, ip_addr, port, p->hostname);
inet_setaddrport((void *)cur->ai_addr, port);
if(sendto(p->sock,cp,len,0 /* flags */,cur->ai_addr,cur->ai_addrlen)==len) {
dbprintf(FALSE, p, "sent %u bytes",len);
dbprintf(FALSE, p, "sent %lu bytes",len);
JS_SET_RVAL(cx, arglist, JSVAL_TRUE);
} else {
p->last_error=ERROR_VALUE;
dbprintf(TRUE, p, "send of %u bytes failed to %s",len, ip_addr);
dbprintf(TRUE, p, "send of %lu bytes failed to %s",len, ip_addr);
}
}
free(cp);
......
......@@ -1708,8 +1708,7 @@ js_new_user(JSContext *cx, uintN argc, jsval *arglist)
if(client->protocol != NULL)
SAFECOPY(user.modem,client->protocol);
SAFECOPY(user.comp,client->host);
if(client->addr != NULL)
SAFECOPY(user.ipaddr,client->addr);
SAFECOPY(user.ipaddr,client->addr);
}
user.sex=' ';
......
......@@ -499,9 +499,6 @@ static JSBool js_set(JSContext *cx, JSObject *obj, jsid id, JSBool strict, jsval
if(!JS_ValueToInt32(cx, *vp, &i))
return JS_FALSE;
switch(tiny) {
case PROP_CHANGES:
uifc->changes=i;
break;
case PROP_MODE:
uifc->mode=i;
break;
......
......@@ -4198,8 +4198,8 @@ void sbbs_t::catsyslog(int crash)
return;
}
}
length=(long)ftell(logfile_fp);
if(length) {
length = ftell(logfile_fp);
if(length > 0) {
if((buf=(char *)malloc(length))==NULL) {
errormsg(WHERE,ERR_ALLOC,str,length);
return;
......
......@@ -174,8 +174,8 @@ void getnodedat(int number, node_t *node, int lockit)
if(count>=(LOOP_NODEDAB/2))
printf("NODE.DAB (node %d) COLLISION (READ) - Count: %d\n"
,number+1, count);
else if(count==LOOP_NODEDAB) {
printf("!Error reading nodefile for node %d\n",number+1);
if(count>=LOOP_NODEDAB) {
printf("!Error %d reading nodefile for node %d\n", errno, number+1);
}
}
......
......@@ -190,7 +190,7 @@ bool sbbs_t::postmsg(uint subnum, long wm_mode, smb_t* resmb, smbmsg_t* remsg)
wm_mode|=WM_ANON;
}
if(cfg.sub[subnum]->mod_ar!=NULL && cfg.sub[subnum]->mod_ar[0] && chk_ar(cfg.sub[subnum]->mod_ar,&useron,&client))
if(cfg.sub[subnum]->mod_ar[0] && chk_ar(cfg.sub[subnum]->mod_ar,&useron,&client))
msgattr|=MSG_MODERATED;
if(cfg.sub[subnum]->misc&SUB_SYSPERM && sub_op(subnum))
......
......@@ -689,6 +689,11 @@ void sbbs_t::qwksetptr(uint subnum, char *buf, int reset)
long l;
uint32_t last;
if(reset && !IS_DIGIT(*buf)) {
getlastmsg(subnum,&(subscan[subnum].ptr),/* time_t* */NULL);
return;
}
if(buf[2]=='/' && buf[5]=='/') { /* date specified */
time_t t=dstrtounix(&cfg,buf);
subscan[subnum].ptr=getmsgnum(subnum,t);
......@@ -697,15 +702,13 @@ void sbbs_t::qwksetptr(uint subnum, char *buf, int reset)
l=atol(buf);
if(l>=0) /* ptr specified */
subscan[subnum].ptr=l;
else if(l) { /* relative ptr specified */
else { /* relative (to last msg) ptr specified */
getlastmsg(subnum,&last,/* time_t* */NULL);
if(-l>(long)last)
subscan[subnum].ptr=0;
else
subscan[subnum].ptr=last+l;
}
else if(reset)
getlastmsg(subnum,&(subscan[subnum].ptr),/* time_t* */NULL);
}
......@@ -774,7 +777,7 @@ void sbbs_t::qwkcfgline(char *buf,uint subnum)
qwksetptr(subnum,str+7,1);
return;
}
}
}
if(!strncmp(str,"RESETALL ",9)) { /* set all ptrs */
for(x=y=0;x<usrgrps;x++)
......
......@@ -1343,7 +1343,7 @@ char *daystr(char days)
str[0]=0;
for(i=0;i<7;i++) {
if(days&(1<<i)) {
strcat(str,wday[i]);
SAFECAT(str,wday[i]);
SAFECAT(str," ");
}
}
......
......@@ -207,7 +207,7 @@ void postmsg(char type, char* to, char* to_number, char* to_address,
/* Read message text from stream (file or stdin) */
msgtxtlen=0;
while(!feof(fp)) {
i=fread(buf,1,sizeof(buf),fp);
i=fread(buf,sizeof(buf),1,fp);
if(i<1)
break;
if((msgtxt = realloc(msgtxt,msgtxtlen+i+1))==NULL) {
......@@ -501,7 +501,7 @@ void listmsgs(ulong start, ulong count)
count=~0;
while(l<count) {
fseek(smb.sid_fp,((start-1L) + l)*idxreclen,SEEK_SET);
if(!fread(&msg.idx,1,sizeof(msg.idx),smb.sid_fp))
if(!fread(&msg.idx,sizeof(msg.idx),1,smb.sid_fp))
break;
i=smb_lockmsghdr(&smb,&msg);
if(i) {
......@@ -573,7 +573,7 @@ void dumpindex(ulong start, ulong count)
count=~0;
while(l<count) {
fseek(smb.sid_fp,((start-1L) + l) * idxreclen,SEEK_SET);
if(!fread(&idx,1,sizeof(idx),smb.sid_fp))
if(!fread(&idx,sizeof(idx),1,smb.sid_fp))
break;
printf("%10"PRIu32" ", idx.number);
switch(smb_msg_type(idx.attr)) {
......@@ -594,7 +594,7 @@ void dumpindex(ulong start, ulong count)
if(smb_msg_type(idx.attr) == SMB_MSG_TYPE_FILE && idxreclen == sizeof(fileidxrec_t)) {
fileidxrec_t fidx;
fseek(smb.sid_fp,((start-1L) + l) * idxreclen,SEEK_SET);
if(!fread(&fidx,1,sizeof(fidx),smb.sid_fp))
if(!fread(&fidx,sizeof(fidx),1,smb.sid_fp))
break;
printf(" %02X %.*s", fidx.hash.flags, (int)sizeof(fidx.name), fidx.name);
}
......@@ -619,7 +619,7 @@ void viewmsgs(ulong start, ulong count, BOOL verbose)
count=~0;
while(l<count) {
fseek(smb.sid_fp,((start-1L) + l) * idxreclen,SEEK_SET);
if(!fread(&msg.idx,1,sizeof(msg.idx),smb.sid_fp))
if(!fread(&msg.idx,sizeof(msg.idx),1,smb.sid_fp))
break;
i=smb_lockmsghdr(&smb,&msg);
if(i) {
......@@ -1002,11 +1002,10 @@ void packmsgs(ulong packable)
fseek(smb.sda_fp,0L,SEEK_SET);
for(l=m=0;l<length;l+=2) {
printf("\r%2lu%% ",l ? (long)(100.0/((float)length/l)) : 0);
/* TODO: Only works on LE (size mismatch) */
i=0;
if(!fread(&i,2,1,smb.sda_fp))
uint16_t val = 0;
if(!fread(&val,sizeof(val),1,smb.sda_fp))
break;
if(!i)
if(val == 0)
m++;
}
......@@ -1143,7 +1142,7 @@ void packmsgs(ulong packable)
for(l=0;l<smb.status.total_msgs;l++) {
fseek(smb.sid_fp, l * idxreclen,SEEK_SET);
printf("%lu of %"PRIu32"\r",l+1,smb.status.total_msgs);
if(!fread(&msg.idx, 1, sizeof(msg.idx), smb.sid_fp))
if(!fread(&msg.idx, sizeof(msg.idx), 1, smb.sid_fp))
break;
if(msg.idx.attr&MSG_DELETE) {
printf("\nDeleted index %lu: msg number %lu\n", l,(ulong) msg.idx.number);
......@@ -1421,7 +1420,7 @@ void readmsgs(ulong start, ulong count)
while(!done) {
if(domsg) {
fseek(smb.sid_fp,msg.idx_offset*idxreclen,SEEK_SET);
if(!fread(&msg.idx,1,sizeof(msg.idx),smb.sid_fp))
if(!fread(&msg.idx,sizeof(msg.idx),1,smb.sid_fp))
break;
i=smb_lockmsghdr(&smb,&msg);
if(i) {
......
......@@ -60,8 +60,7 @@ void sbbs_t::userlist(long mode)
if(!chk_ar(cfg.grp[usrgrp[curgrp]]->ar,&user,/* client: */NULL))
continue;
if(!chk_ar(cfg.sub[usrsub[curgrp][cursub[curgrp]]]->ar,&user,/* client: */NULL)
|| (cfg.sub[usrsub[curgrp][cursub[curgrp]]]->read_ar!=NULL
&& cfg.sub[usrsub[curgrp][cursub[curgrp]]]->read_ar[0]
|| (cfg.sub[usrsub[curgrp][cursub[curgrp]]]->read_ar[0]
&& !chk_ar(cfg.sub[usrsub[curgrp][cursub[curgrp]]]->read_ar,&user,/* client: */NULL)))
continue;
}
......@@ -505,7 +504,7 @@ size_t sbbs_t::gettmplt(char *strout, const char *templt, long mode)
}
c=0;
if(mode&K_EDIT) {
strcpy(str,strout);
SAFECOPY(str,strout);
bputs(str);
c=strlen(str);
}
......@@ -544,7 +543,7 @@ size_t sbbs_t::gettmplt(char *strout, const char *templt, long mode)
attr(LIGHTGRAY);
CRLF;
if(!(sys_status&SS_ABORT))
strcpy(strout,str);
SAFECOPY(strout,str);
return(c);
}
......
......@@ -191,7 +191,7 @@ void sbbs_t::telnet_gate(char* destaddr, ulong mode, char* client_user_name, cha
rd=getstr((char*)buf,sizeof(buf)-1,l);
if(!rd)
continue;
strcat((char*)buf,crlf);
SAFECAT((char*)buf,crlf);
rd+=2;
gotline=true;
}
......