Commit f3e1a080 authored by Rob Swindell's avatar Rob Swindell 💬
Browse files

Sanity-check each sub's FidoNet-style address when loading msgs.cnf

Just in case a sysop deletes/changes their addresses after create subs, find the nearest matching configured system FTN address/AKA and use that.
parent b504538c
......@@ -21,6 +21,7 @@
#include "msg_id.h"
#include "smblib.h"
#include "scfglib.h"
#include "git_branch.h"
#include "git_hash.h"
......@@ -169,7 +170,7 @@ BOOL add_msg_ids(scfg_t* cfg, smb_t* smb, smbmsg_t* msg, smbmsg_t* remsg)
if(smb->subnum == INVALID_SUB && msg->to_net.type == NET_FIDO) {
safe_snprintf(msg_id, sizeof(msg_id)
,"%s %08lx"
,smb_faddrtoa(&cfg->faddr[nearest_sysfaddr(cfg, msg->to_net.addr)], NULL)
,smb_faddrtoa(nearest_sysfaddr(cfg, msg->to_net.addr), NULL)
,msgid_serialno(msg)
);
if(smb_hfield_str(msg, FIDOMSGID, msg_id) != SMB_SUCCESS)
......@@ -249,16 +250,3 @@ char* msg_program_id(char* pid, size_t maxlen)
,__DATE__,compiler);
return pid;
}
uint nearest_sysfaddr(scfg_t* cfg, faddr_t* dest_addr)
{
uint i;
for(i=0; i<cfg->total_faddrs; i++)
if(dest_addr->zone == cfg->faddr[i].zone && dest_addr->net == cfg->faddr[i].net)
return i;
for(i=0; i<cfg->total_faddrs; i++)
if(dest_addr->zone == cfg->faddr[i].zone)
return i;
return 0;
}
......@@ -35,7 +35,6 @@ DLLEXPORT uint32_t get_new_msg_number(smb_t*);
DLLEXPORT BOOL add_msg_ids(scfg_t*, smb_t*, smbmsg_t*, smbmsg_t* remsg);
DLLEXPORT BOOL add_reply_ids(scfg_t*, smb_t*, smbmsg_t*, smbmsg_t* remsg);
DLLEXPORT char* msg_program_id(char* pid, size_t);
DLLEXPORT uint nearest_sysfaddr(scfg_t*, faddr_t* dest_addr);
#ifdef __cplusplus
}
......
......@@ -66,6 +66,8 @@ int getlibnum(scfg_t*, const char* code);
int getsubnum(scfg_t*, const char* code);
int getgrpnum(scfg_t*, const char* code);
faddr_t* nearest_sysfaddr(scfg_t*, faddr_t*);
#ifdef __cplusplus
}
#endif
......
......@@ -532,6 +532,10 @@ BOOL read_msgs_cfg(scfg_t* cfg, char* error, size_t maxerrlen)
for(i=0;i<cfg->total_faddrs;i++)
get_int(cfg->faddr[i],instream);
// Sanity-check each sub's FidoNet-style address
for(i = 0; i < cfg->total_subs; i++)
cfg->sub[i]->faddr = *nearest_sysfaddr(cfg, &cfg->sub[i]->faddr);
get_str(cfg->origline,instream);
get_str(cfg->netmail_sem,instream);
get_str(cfg->echomail_sem,instream);
......@@ -821,3 +825,28 @@ int getgrpnum(scfg_t* cfg, const char* code)
return cfg->sub[i]->grp;
return i;
}
faddr_t* nearest_sysfaddr(scfg_t* cfg, faddr_t* addr)
{
uint i;
if(cfg->total_faddrs <= 0)
return addr;
for(i=0; i < cfg->total_faddrs; i++)
if(memcmp(addr, &cfg->faddr[i], sizeof(*addr)) == 0)
return &cfg->faddr[i];
for(i=0; i < cfg->total_faddrs; i++)
if(addr->zone == cfg->faddr[i].zone
&& addr->net == cfg->faddr[i].net
&& addr->node == cfg->faddr[i].node)
return &cfg->faddr[i];
for(i=0; i < cfg->total_faddrs; i++)
if(addr->zone == cfg->faddr[i].zone
&& addr->net == cfg->faddr[i].net)
return &cfg->faddr[i];
for(i=0; i < cfg->total_faddrs; i++)
if(addr->zone == cfg->faddr[i].zone)
return &cfg->faddr[i];
return &cfg->faddr[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