From 1749d3ff813407a840d98229509344248c0b7ef7 Mon Sep 17 00:00:00 2001 From: Rob Swindell <rob@synchro.net> Date: Tue, 29 Nov 2022 16:29:51 -0800 Subject: [PATCH] Filter messages in qwk_voting->qwk_vote() No longer applying QWK filters to incoming netmail messages since we would need different criteria for netmail filtering (e.g. don't apply the twitlist.cfg). And I'm not clear that we actually need netmail filtering. Disable the importing of "remaining" VOTING.DAT sections (polls, votes) since this should no longer be necessary for backwards compatibility and appears to the source of errors like: qwk.cpp line 1141 (qwk_vote) writing "/sbbs/data/subs/sync_sys" access=-105 info=smb_addpollclosure thread_back field missing qwk_vote() takes a msg_filters argument, so we'd have to pass that to qwk_handle_remaining_votes() and frankly, it just shouldn't be needed any more, so disabling and logging a warning if there are any "remaining QWK voting.dat sections" after parsing QWK/REP packet (which consumes the sections from the parsed VOTING.DAT file). --- src/sbbs3/qwk.cpp | 35 ++++++++++++++++++++++------------- src/sbbs3/sbbs.h | 12 +++++++++--- src/sbbs3/un_qwk.cpp | 31 ++++++++++++------------------- src/sbbs3/un_rep.cpp | 30 ++++++++++++------------------ 4 files changed, 55 insertions(+), 53 deletions(-) diff --git a/src/sbbs3/qwk.cpp b/src/sbbs3/qwk.cpp index 6612bb2fbd..ae96654954 100644 --- a/src/sbbs3/qwk.cpp +++ b/src/sbbs3/qwk.cpp @@ -957,7 +957,7 @@ uint sbbs_t::resolve_qwkconf(uint n, int hubnum) } bool sbbs_t::qwk_voting(str_list_t* ini, long offset, smb_net_type_t net_type, const char* qnet_id - , uint confnum, int hubnum) + , uint confnum, msg_filters filters, int hubnum) { char* section; char location[128]; @@ -977,7 +977,7 @@ bool sbbs_t::qwk_voting(str_list_t* ini, long offset, smb_net_type_t net_type, c strListFree(§ion_list); return false; } - result = qwk_vote(*ini, section, net_type, qnet_id, confnum, hubnum); + result = qwk_vote(*ini, section, net_type, qnet_id, confnum, filters, hubnum); iniRemoveSection(ini, section); iniRemoveSection(ini, location); strListFree(§ion_list); @@ -989,15 +989,18 @@ void sbbs_t::qwk_handle_remaining_votes(str_list_t* ini, smb_net_type_t net_type str_list_t section_list = iniGetSectionList(*ini, /* prefix: */NULL); for(int i=0; section_list != NULL && section_list[i] != NULL; i++) { + lprintf(LOG_WARNING, "Remaining QWK VOTING.DAT section: %s", section_list[i]); +#if 0 // (problematic) Backwards-compatibility hack that shouldn't be necessary any more if(strnicmp(section_list[i], "poll:", 5) == 0 || strnicmp(section_list[i], "vote:", 5) == 0 || strnicmp(section_list[i], "close:", 6) == 0) qwk_vote(*ini, section_list[i], net_type, qnet_id, /* confnum: */0, hubnum); +#endif } strListFree(§ion_list); } -bool sbbs_t::qwk_vote(str_list_t ini, const char* section, smb_net_type_t net_type, const char* qnet_id, uint confnum, int hubnum) +bool sbbs_t::qwk_vote(str_list_t ini, const char* section, smb_net_type_t net_type, const char* qnet_id, uint confnum, msg_filters filters, int hubnum) { char* p; int result; @@ -1023,10 +1026,6 @@ bool sbbs_t::qwk_vote(str_list_t ini, const char* section, smb_net_type_t net_ty errormsg(WHERE, ERR_CHK, "conference number (voting not allowed)", confnum, section); return false; } - if((result = smb_open_sub(&cfg, &smb, smb.subnum)) != SMB_SUCCESS) { - errormsg(WHERE, ERR_OPEN, smb.file, 0, smb.last_error); - return false; - } smbmsg_t msg; ZERO_VAR(msg); @@ -1076,6 +1075,16 @@ bool sbbs_t::qwk_vote(str_list_t ini, const char* section, smb_net_type_t net_ty while((p=iniGetString(ini,section, smb_hfieldtype(SENDERORG), NULL, NULL)) != NULL) smb_hfield_str(&msg, SENDERORG, p); + if(qwk_msg_filtered(&msg, filters)) { + smb_freemsgmem(&msg); + return false; + } + + if((result = smb_open_sub(&cfg, &smb, smb.subnum)) != SMB_SUCCESS) { + errormsg(WHERE, ERR_OPEN, smb.file, 0, smb.last_error); + return false; + } + if(strnicmp(section, "poll:", 5) == 0) { smb_hfield_str(&msg, RFC822MSGID, section + 5); @@ -1148,7 +1157,7 @@ bool sbbs_t::qwk_vote(str_list_t ini, const char* section, smb_net_type_t net_ty return result == SMB_SUCCESS; } -bool sbbs_t::qwk_msg_filtered(smbmsg_t* msg, str_list_t ip_can, str_list_t host_can, str_list_t subject_can, str_list_t twit_list) +bool sbbs_t::qwk_msg_filtered(smbmsg_t* msg, msg_filters filters) { uint32_t now = time32(NULL); @@ -1160,7 +1169,7 @@ bool sbbs_t::qwk_msg_filtered(smbmsg_t* msg, str_list_t ip_can, str_list_t host_ return true; } - if(findstr_in_list(msg->from_ip,ip_can)) { + if(findstr_in_list(msg->from_ip, filters.ip_can)) { lprintf(LOG_NOTICE,"!Filtering QWK message from %s due to blocked IP: %s" ,msg->from ,msg->from_ip); @@ -1168,21 +1177,21 @@ bool sbbs_t::qwk_msg_filtered(smbmsg_t* msg, str_list_t ip_can, str_list_t host_ } const char* hostname=getHostNameByAddr(msg->from_host); - if(findstr_in_list(hostname,host_can)) { + if(findstr_in_list(hostname, filters.host_can)) { lprintf(LOG_NOTICE,"!Filtering QWK message from %s due to blocked hostname: %s" ,msg->from ,hostname); return true; } - if(findstr_in_list(msg->subj,subject_can)) { + if(findstr_in_list(msg->subj, filters.subject_can)) { lprintf(LOG_NOTICE,"!Filtering QWK message from %s due to filtered subject: %s" ,msg->from ,msg->subj); return true; } - if(findstr_in_list(msg->from,twit_list) || findstr_in_list(msg->to,twit_list)) { + if(findstr_in_list(msg->from, filters.twit_list) || findstr_in_list(msg->to, filters.twit_list)) { lprintf(LOG_NOTICE,"!Filtering QWK message from '%s' to '%s'" ,msg->from ,msg->to); @@ -1193,7 +1202,7 @@ bool sbbs_t::qwk_msg_filtered(smbmsg_t* msg, str_list_t ip_can, str_list_t host_ char fidoaddr[64]; char str[128]; SAFEPRINTF2(str, "%s@%s", msg->from, smb_netaddrstr(&msg->from_net, fidoaddr)); - if(findstr_in_list(str, twit_list)) { + if(findstr_in_list(str, filters.twit_list)) { lprintf(LOG_NOTICE,"!Filtering QWK message from '%s' to '%s'" ,str ,msg->to); diff --git a/src/sbbs3/sbbs.h b/src/sbbs3/sbbs.h index 0f2119dc7d..911ab3953e 100644 --- a/src/sbbs3/sbbs.h +++ b/src/sbbs3/sbbs.h @@ -1134,10 +1134,16 @@ public: void qwkcfgline(char *buf,uint subnum); bool set_qwk_flag(ulong flag); uint resolve_qwkconf(uint confnum, int hubnum=-1); - bool qwk_vote(str_list_t ini, const char* section, smb_net_type_t, const char* qnet_id, uint confnum, int hubnum); - bool qwk_voting(str_list_t* ini, long offset, smb_net_type_t, const char* qnet_id, uint confnum, int hubnum = -1); + struct msg_filters { + str_list_t ip_can; + str_list_t host_can; + str_list_t subject_can; + str_list_t twit_list; + }; + bool qwk_msg_filtered(smbmsg_t* msg, msg_filters); + bool qwk_vote(str_list_t ini, const char* section, smb_net_type_t, const char* qnet_id, uint confnum, msg_filters, int hubnum); + bool qwk_voting(str_list_t* ini, long offset, smb_net_type_t, const char* qnet_id, uint confnum, msg_filters, int hubnum = -1); void qwk_handle_remaining_votes(str_list_t* ini, smb_net_type_t, const char* qnet_id, int hubnum = -1); - bool qwk_msg_filtered(smbmsg_t* msg, str_list_t ip_can, str_list_t host_can, str_list_t subject_can, str_list_t twit_list=NULL); /* pack_qwk.cpp */ bool pack_qwk(char *packet, ulong *msgcnt, bool prepack); diff --git a/src/sbbs3/un_qwk.cpp b/src/sbbs3/un_qwk.cpp index 7218c96144..197cf6aac3 100644 --- a/src/sbbs3/un_qwk.cpp +++ b/src/sbbs3/un_qwk.cpp @@ -62,11 +62,8 @@ bool sbbs_t::unpack_qwk(char *packet,uint hubnum) smbmsg_t msg; str_list_t headers=NULL; str_list_t voting=NULL; - str_list_t ip_can=NULL; - str_list_t host_can=NULL; - str_list_t subject_can=NULL; - str_list_t twit_list=NULL; link_list_t user_list={0}; + msg_filters msg_filters{}; memset(&msg,0,sizeof(msg)); @@ -135,12 +132,12 @@ bool sbbs_t::unpack_qwk(char *packet,uint hubnum) /********************/ lprintf(LOG_INFO,"Importing QWK Network Packet: %s",packet); - ip_can=trashcan_list(&cfg,"ip"); - host_can=trashcan_list(&cfg,"host"); - subject_can=trashcan_list(&cfg,"subject"); + msg_filters.ip_can = trashcan_list(&cfg,"ip"); + msg_filters.host_can = trashcan_list(&cfg,"host"); + msg_filters.subject_can = trashcan_list(&cfg,"subject"); SAFEPRINTF(fname,"%stwitlist.cfg",cfg.ctrl_dir); - twit_list = findstr_list(fname); + msg_filters.twit_list = findstr_list(fname); for(l=QWK_BLOCK_LEN;l<size;l+=blocks*QWK_BLOCK_LEN) { if(terminated) { @@ -166,7 +163,7 @@ bool sbbs_t::unpack_qwk(char *packet,uint hubnum) n=(uint)block[123]|(((uint)block[124])<<8); /* conference number */ if(blocks<2) { if(block[0] == 'V' && blocks == 1 && voting != NULL) { /* VOTING DATA */ - if(!qwk_voting(&voting, l, NET_QWK, cfg.qhub[hubnum]->id, n, hubnum)) { + if(!qwk_voting(&voting, l, NET_QWK, cfg.qhub[hubnum]->id, n, msg_filters, hubnum)) { lprintf(LOG_WARNING, "QWK vote failure, offset %lu in %s", l, packet); errors++; } @@ -184,9 +181,6 @@ bool sbbs_t::unpack_qwk(char *packet,uint hubnum) continue; } - if(qwk_msg_filtered(&msg, ip_can, host_can, subject_can)) - continue; - if(!n) { /* NETMAIL */ lprintf(LOG_INFO,"QWK NetMail from %s to %s", cfg.qhub[hubnum]->id, msg.to); if(!stricmp(msg.to,"NETMAIL")) { /* QWK to FidoNet NetMail */ @@ -279,9 +273,8 @@ bool sbbs_t::unpack_qwk(char *packet,uint hubnum) continue; } - /* TWIT FILTER */ - if(qwk_msg_filtered(&msg, /* ip_can: */NULL, /* host_can: */NULL, /* subject_can: */NULL, twit_list)) - continue; + if(qwk_msg_filtered(&msg, msg_filters)) + continue; if(j!=lastsub) { @@ -367,10 +360,10 @@ bool sbbs_t::unpack_qwk(char *packet,uint hubnum) iniFreeStringList(headers); iniFreeStringList(voting); - strListFree(&ip_can); - strListFree(&host_can); - strListFree(&subject_can); - strListFree(&twit_list); + strListFree(&msg_filters.ip_can); + strListFree(&msg_filters.host_can); + strListFree(&msg_filters.subject_can); + strListFree(&msg_filters.twit_list); listFree(&user_list); delfiles(cfg.temp_dir,"*.NDX"); diff --git a/src/sbbs3/un_rep.cpp b/src/sbbs3/un_rep.cpp index 18dc112284..9eac98f80a 100644 --- a/src/sbbs3/un_rep.cpp +++ b/src/sbbs3/un_rep.cpp @@ -52,11 +52,8 @@ bool sbbs_t::unpack_rep(char* repfile) smbmsg_t msg; str_list_t headers=NULL; str_list_t voting=NULL; - str_list_t ip_can=NULL; - str_list_t host_can=NULL; - str_list_t subject_can=NULL; - str_list_t twit_list=NULL; link_list_t user_list={0}; + msg_filters msg_filters{}; const char* AttemptedToUploadREPpacket="Attempted to upload REP packet"; memset(&msg,0,sizeof(msg)); @@ -167,12 +164,12 @@ bool sbbs_t::unpack_rep(char* repfile) bputs(text[QWKUnpacking]); } - ip_can=trashcan_list(&cfg,"ip"); - host_can=trashcan_list(&cfg,"host"); - subject_can=trashcan_list(&cfg,"subject"); + msg_filters.ip_can = trashcan_list(&cfg,"ip"); + msg_filters.host_can = trashcan_list(&cfg,"host"); + msg_filters.subject_can = trashcan_list(&cfg,"subject"); SAFEPRINTF(fname,"%stwitlist.cfg",cfg.ctrl_dir); - twit_list = findstr_list(fname); + msg_filters.twit_list = findstr_list(fname); now=time(NULL); for(l=QWK_BLOCK_LEN;l<size;l+=blocks*QWK_BLOCK_LEN) { @@ -197,7 +194,7 @@ bool sbbs_t::unpack_rep(char* repfile) long confnum = atol((char *)block+1); if(blocks<2) { if(block[0] == 'V' && blocks == 1 && voting != NULL) { /* VOTING DATA */ - if(!qwk_voting(&voting, l, (useron.rest&FLAG('Q')) ? NET_QWK : NET_NONE, /* QWKnet ID : */useron.alias, confnum)) { + if(!qwk_voting(&voting, l, (useron.rest&FLAG('Q')) ? NET_QWK : NET_NONE, /* QWKnet ID : */useron.alias, confnum, msg_filters)) { lprintf(LOG_WARNING, "QWK vote failure, offset %ld of %s", l, getfname(msg_fname)); errors++; } @@ -217,9 +214,6 @@ bool sbbs_t::unpack_rep(char* repfile) continue; } - if(qwk_msg_filtered(&msg, ip_can, host_can, subject_can)) - continue; - if(confnum == 0) { /* E-mail */ if(msg.from == NULL) bprintf("E-mail to %s: %s\r\n", msg.to, msg.subj); @@ -433,8 +427,8 @@ bool sbbs_t::unpack_rep(char* repfile) } #endif - /* TWIT FILTER */ - if(qwk_msg_filtered(&msg, /* ip_can: */NULL, /* host_can: */NULL, /* subject_can: */NULL, twit_list)) + + if(qwk_msg_filtered(&msg, msg_filters)) continue; if(n!=lastsub) { @@ -522,10 +516,10 @@ bool sbbs_t::unpack_rep(char* repfile) iniFreeStringList(headers); iniFreeStringList(voting); - strListFree(&ip_can); - strListFree(&host_can); - strListFree(&subject_can); - strListFree(&twit_list); + strListFree(&msg_filters.ip_can); + strListFree(&msg_filters.host_can); + strListFree(&msg_filters.subject_can); + strListFree(&msg_filters.twit_list); listFree(&user_list); if(lastsub!=INVALID_SUB) -- GitLab