Commit dee21ed6 authored by Rob Swindell's avatar Rob Swindell 💬

Fix observed race-condition resulting in the HOSTNAME @-code being blank.

Eliminate the hack in each server where it will over-write startup host_name
(with the configured Internet email address), if it's blank. This hack was
subject to a race condition where the parent app (e.g. sbbsctrl.exe) would
clear or re-initialize the host_name after the sever threads had initialized.
Instead, just use a function which will return either the startup->host_name
or (fallback to) scfg.inet_addr.
parent b5f1c4af
Pipeline #74 passed with stage
in 10 minutes and 45 seconds
......@@ -505,7 +505,7 @@ const char* sbbs_t::atcode(char* sp, char* str, size_t maxlen, long* pmode, bool
return(cfg.sys_inetaddr);
if(!strcmp(sp,"HOSTNAME"))
return(startup->host_name);
return server_host_name();
if(!strcmp(sp,"FIDOADDR")) {
if(cfg.total_faddrs)
......
......@@ -117,7 +117,7 @@ bool sbbs_t::bulkmail(uchar *ar)
memset(&smb,0,sizeof(smb));
smb.subnum=INVALID_SUB; /* mail database */
i=savemsg(&cfg, &smb, &msg, &client, startup->host_name, msgbuf, /* remsg: */NULL);
i=savemsg(&cfg, &smb, &msg, &client, server_host_name(), msgbuf, /* remsg: */NULL);
free(msgbuf);
if(i!=0) {
smb_close(&smb);
......
......@@ -303,7 +303,7 @@ bool sbbs_t::email(int usernumber, const char *top, const char *subj, long mode,
/* Security logging */
msg_client_hfields(&msg,&client);
smb_hfield_str(&msg,SENDERSERVER,startup->host_name);
smb_hfield_str(&msg,SENDERSERVER,server_host_name());
smb_hfield_str(&msg,SUBJECT,title);
......
......@@ -201,6 +201,11 @@ static BOOL winsock_startup(void)
#endif
static char* server_host_name(void)
{
return startup->host_name[0] ? startup->host_name : scfg.sys_inetaddr;
}
static void status(char* str)
{
if(startup!=NULL && startup->status!=NULL)
......@@ -593,7 +598,7 @@ js_initcx(JSRuntime* runtime, SOCKET sock, JSObject** glob, JSObject** ftp, js_c
break;
lprintf(LOG_DEBUG,"%04d JavaScript: Initializing System object",sock);
if(js_CreateSystemObject(js_cx, *glob, &scfg, uptime, startup->host_name, SOCKLIB_DESC)==NULL)
if(js_CreateSystemObject(js_cx, *glob, &scfg, uptime, server_host_name(), SOCKLIB_DESC)==NULL)
break;
if((*ftp=JS_DefineObject(js_cx, *glob, "ftp", NULL
......@@ -3124,7 +3129,7 @@ static void ctrl_thread(void* arg)
mswait(login_attempts*startup->login_attempt.throttle);
}
sockprintf(sock,sess,"220-%s (%s)",scfg.sys_name, startup->host_name);
sockprintf(sock,sess,"220-%s (%s)",scfg.sys_name, server_host_name());
sockprintf(sock,sess," Synchronet FTP Server %s-%s Ready"
,revision,PLATFORM_DESC);
sprintf(str,"%sftplogin.txt",scfg.text_dir);
......@@ -3850,7 +3855,7 @@ static void ctrl_thread(void* arg)
ip_addr=0;
/* TODO: IPv6 this here lookup */
if(startup->options&FTP_OPT_LOOKUP_PASV_IP
&& (host=gethostbyname(startup->host_name))!=NULL)
&& (host=gethostbyname(server_host_name()))!=NULL)
ip_addr=ntohl(*((ulong*)host->h_addr_list[0]));
if(ip_addr==0 && (ip_addr=startup->pasv_ip_addr.s_addr)==0)
ip_addr=ntohl(pasv_addr.in.sin_addr.s_addr);
......@@ -6107,9 +6112,6 @@ void DLLCALL ftp_server(void* arg)
break;
}
if(startup->host_name[0]==0)
SAFECOPY(startup->host_name,scfg.sys_inetaddr);
if((t=checktime())!=0) { /* Check binary time */
lprintf(LOG_ERR,"!TIME PROBLEM (%ld)",t);
}
......
......@@ -237,6 +237,11 @@ static BOOL winsock_startup(void)
#endif
static char* server_host_name(void)
{
return startup->host_name[0] ? startup->host_name : scfg.sys_inetaddr;
}
static void update_clients(void)
{
if(startup!=NULL && startup->clients!=NULL)
......@@ -1143,7 +1148,7 @@ static void pop3_thread(void* arg)
srand((unsigned int)(time(NULL) ^ (time_t)GetCurrentThreadId())); /* seed random number generator */
rand(); /* throw-away first result */
safe_snprintf(challenge,sizeof(challenge),"<%x%x%lx%lx@%.128s>"
,rand(),socket,(ulong)time(NULL),(ulong)clock(),startup->host_name);
,rand(),socket,(ulong)time(NULL),(ulong)clock(), server_host_name());
sockprintf(socket,client.protocol,session,"+OK Synchronet %s Server %s-%s Ready %s"
,client.protocol, revision,PLATFORM_DESC,challenge);
......@@ -2231,7 +2236,7 @@ js_mailproc(SOCKET sock, client_t* client, user_t* user, struct mailproc* mailpr
if(*js_glob==NULL) {
/* Global Objects (including system, js, client, Socket, MsgBase, File, User, etc. */
if(!js_CreateCommonObjects(*js_cx, &scfg, &scfg, NULL
,uptime, startup->host_name, SOCKLIB_DESC /* system */
,uptime, server_host_name(), SOCKLIB_DESC /* system */
,&js_callback /* js */
,&startup->js
,client, sock, -1 /* client */
......@@ -3181,7 +3186,7 @@ static void smtp_thread(void* arg)
/* SMTP session active: */
sockprintf(socket,client.protocol,session,"220 %s Synchronet %s Server %s-%s Ready"
,startup->host_name, client.protocol, revision, PLATFORM_DESC);
,server_host_name(), client.protocol, revision, PLATFORM_DESC);
while(1) {
rd = sockreadline(socket, client.protocol, session, buf, sizeof(buf));
if(rd<0)
......@@ -3712,7 +3717,7 @@ static void smtp_thread(void* arg)
smb_hfield_str(&msg, RECIPIENT, rcpt_name);
smb.subnum=subnum;
if((i=savemsg(&scfg, &smb, &msg, &client, startup->host_name, msgbuf, /* remsg: */NULL))!=SMB_SUCCESS) {
if((i=savemsg(&scfg, &smb, &msg, &client, server_host_name(), msgbuf, /* remsg: */NULL))!=SMB_SUCCESS) {
lprintf(LOG_WARNING,"%04d %s !ERROR %d (%s) posting message to %s (%s)"
,socket, client.protocol, i, smb.last_error, scfg.sub[subnum]->sname, smb.file);
sockprintf(socket,client.protocol,session, "452 ERROR %d (%s) posting message"
......@@ -3818,7 +3823,7 @@ static void smtp_thread(void* arg)
/* E-mail */
smb.subnum=INVALID_SUB;
/* creates message data, but no header or index records (since msg.to==NULL) */
i=savemsg(&scfg, &smb, &msg, &client, startup->host_name, msgbuf, /* remsg: */NULL);
i=savemsg(&scfg, &smb, &msg, &client, server_host_name(), msgbuf, /* remsg: */NULL);
if(smb_countattachments(&smb, &msg, msgbuf) > 0)
msg.hdr.auxattr |= MSG_MIMEATTACH;
msg.hdr.netattr |= MSG_KILLSENT;
......@@ -3877,7 +3882,7 @@ static void smtp_thread(void* arg)
,host_name,hello_name
,smtp.client_addr.addr.sa_family==AF_INET6?"IPv6: ":""
,host_ip
,startup->host_name
,server_host_name()
,server_addr.addr.sa_family==AF_INET6?"IPv6: ":""
,server_ip
,server_name
......@@ -4068,7 +4073,7 @@ static void smtp_thread(void* arg)
p=buf+4;
SKIP_WHITESPACE(p);
SAFECOPY(hello_name,p);
sockprintf(socket,client.protocol,session,"250 %s",startup->host_name);
sockprintf(socket,client.protocol,session,"250 %s",server_host_name());
esmtp=FALSE;
state=SMTP_STATE_HELO;
cmd=SMTP_CMD_NONE;
......@@ -4080,7 +4085,7 @@ static void smtp_thread(void* arg)
p=buf+4;
SKIP_WHITESPACE(p);
SAFECOPY(hello_name,p);
sockprintf(socket,client.protocol,session,"250-%s",startup->host_name);
sockprintf(socket,client.protocol,session,"250-%s",server_host_name());
sockprintf(socket,client.protocol,session,"250-AUTH PLAIN LOGIN CRAM-MD5");
sockprintf(socket,client.protocol,session,"250-SEND");
sockprintf(socket,client.protocol,session,"250-SOML");
......@@ -4209,7 +4214,7 @@ static void smtp_thread(void* arg)
}
if(!stricmp(buf,"AUTH CRAM-MD5")) {
safe_snprintf(challenge,sizeof(challenge),"<%x%x%lx%lx@%s>"
,rand(),socket,(ulong)time(NULL),(ulong)clock(),startup->host_name);
,rand(),socket,(ulong)time(NULL),(ulong)clock(),server_host_name());
#if 0
lprintf(LOG_DEBUG,"%04d SMTP CRAM-MD5 challenge: %s"
,socket,challenge);
......@@ -4300,7 +4305,7 @@ static void smtp_thread(void* arg)
continue;
}
if(!stricmp(buf,"QUIT")) {
sockprintf(socket,client.protocol,session,"221 %s Service closing transmission channel",startup->host_name);
sockprintf(socket,client.protocol,session,"221 %s Service closing transmission channel",server_host_name());
break;
}
if(!stricmp(buf,"NOOP")) {
......@@ -5104,7 +5109,7 @@ BOOL bounce(SOCKET sock, smb_t* smb, smbmsg_t* msg, char* err, BOOL immediate)
else
attempts[0]=0;
SAFEPRINTF2(str,"%s reporting delivery failure of message %s"
,startup->host_name, attempts);
,server_host_name(), attempts);
smb_hfield_str(&newmsg, SMB_COMMENT, str);
SAFEPRINTF2(str,"from %s to %s\r\n"
,msg->from
......@@ -5294,7 +5299,7 @@ static SOCKET sendmail_negotiate(CRYPT_SESSION *session, smb_t *smb, smbmsg_t *m
return INVALID_SOCKET;
}
sockprintf(sock, "SEND", *session,"EHLO %s",startup->host_name);
sockprintf(sock, "SEND", *session,"EHLO %s",server_host_name());
switch (sockgetrsp_opt(sock, "SEND", *session,"250", "STARTTLS", buf, sizeof(buf))) {
case -1:
if(startup->options&MAIL_OPT_RELAY_TX
......@@ -5305,7 +5310,7 @@ static SOCKET sendmail_negotiate(CRYPT_SESSION *session, smb_t *smb, smbmsg_t *m
mail_close_socket(&sock, session);
return INVALID_SOCKET;
}
sockprintf(sock, "SEND", *session,"HELO %s",startup->host_name);
sockprintf(sock, "SEND", *session,"HELO %s",server_host_name());
if(!sockgetrsp(sock, "SEND", *session,"250",buf,sizeof(buf))) {
SAFEPRINTF3(err,badrsp_err,server,buf,"250");
remove_msg_intransit(smb,msg);
......@@ -5371,7 +5376,7 @@ static SOCKET sendmail_negotiate(CRYPT_SESSION *session, smb_t *smb, smbmsg_t *m
continue;
}
}
sockprintf(sock,prot,*session,"EHLO %s",startup->host_name);
sockprintf(sock,prot,*session,"EHLO %s",server_host_name());
if(!sockgetrsp(sock, prot, *session,"250",buf,sizeof(buf))) {
SAFEPRINTF3(err,badrsp_err,server,buf,"220");
lprintf(LOG_INFO, "%04d SEND/TLS %s", sock, err);
......@@ -6128,9 +6133,6 @@ void DLLCALL mail_server(void* arg)
iniCloseFile(fp);
}
if(startup->host_name[0]==0)
SAFECOPY(startup->host_name,scfg.sys_inetaddr);
if((t=checktime())!=0) { /* Check binary time */
lprintf(LOG_ERR,"!TIME PROBLEM (%ld)",t);
}
......
......@@ -1284,7 +1284,7 @@ JSContext* sbbs_t::js_init(JSRuntime** runtime, JSObject** glob, const char* des
/* Global Objects (including system, js, client, Socket, MsgBase, File, User, etc. */
if(!js_CreateCommonObjects(js_cx, &scfg, &cfg, js_global_functions
,uptime, startup->host_name, SOCKLIB_DESC /* system */
,uptime, server_host_name(), SOCKLIB_DESC /* system */
,&js_callback /* js */
,&startup->js
,&client, client_socket, -1 /* client */
......@@ -3077,7 +3077,7 @@ void event_thread(void* arg)
&& (now_tm.tm_hour*60)+now_tm.tm_min>=sbbs->cfg.event[i]->time
&& (now_tm.tm_mday!=tm.tm_mday || now_tm.tm_mon!=tm.tm_mon)))
&& sbbs->cfg.event[i]->days&(1<<now_tm.tm_wday)
&& (sbbs->cfg.event[i]->mdays==0
&& (sbbs->cfg.event[i]->mdays < 2
|| sbbs->cfg.event[i]->mdays&(1<<now_tm.tm_mday))
&& (sbbs->cfg.event[i]->months==0
|| sbbs->cfg.event[i]->months&(1<<now_tm.tm_mon))))
......@@ -5095,9 +5095,6 @@ void DLLCALL bbs_thread(void* arg)
return;
}
if(startup->host_name[0]==0)
SAFECOPY(startup->host_name,scfg.sys_inetaddr);
if((t=checktime())!=0) { /* Check binary time */
lprintf(LOG_ERR,"!TIME PROBLEM (%ld)",t);
}
......
......@@ -311,7 +311,7 @@ bool sbbs_t::netmail(const char *into, const char *title, long mode, smb_t* resm
smb_t smb;
memset(&smb, 0, sizeof(smb));
smb.subnum = INVALID_SUB;
int result = savemsg(&cfg, &smb, &msg, &client, startup->host_name, buf, remsg);
int result = savemsg(&cfg, &smb, &msg, &client, server_host_name(), buf, remsg);
free(buf);
smb_close(&smb);
smb_freemsgmem(&msg);
......@@ -1120,13 +1120,13 @@ bool sbbs_t::inetmail(const char *into, const char *subj, long mode, smb_t* resm
/* Security logging */
msg_client_hfields(&msg,&client);
smb_hfield_str(&msg,SENDERSERVER,startup->host_name);
smb_hfield_str(&msg,SENDERSERVER, server_host_name());
smb_hfield_str(&msg,SUBJECT,title);
editor_info_to_msg(&msg, editor, charset);
i = savemsg(&cfg, &smb, &msg, &client, startup->host_name, msgbuf, remsg);
i = savemsg(&cfg, &smb, &msg, &client, server_host_name(), msgbuf, remsg);
free(msgbuf);
if(i!=SMB_SUCCESS) {
......@@ -1396,7 +1396,7 @@ bool sbbs_t::qnetmail(const char *into, const char *subj, long mode, smb_t* resm
/* Security logging */
msg_client_hfields(&msg,&client);
smb_hfield_str(&msg,SENDERSERVER,startup->host_name);
smb_hfield_str(&msg,SENDERSERVER, server_host_name());
smb_hfield_str(&msg,SUBJECT,title);
......
......@@ -297,7 +297,7 @@ bool sbbs_t::postmsg(uint subnum, long wm_mode, smb_t* resmb, smbmsg_t* remsg)
/* Security logging */
msg_client_hfields(&msg,&client);
smb_hfield_str(&msg,SENDERSERVER,startup->host_name);
smb_hfield_str(&msg,SENDERSERVER, server_host_name());
smb_hfield_str(&msg,SUBJECT,title);
......
......@@ -1163,7 +1163,7 @@ int sbbs_t::scanposts(uint subnum, long mode, const char *find)
/* Security logging */
msg_client_hfields(&vote, &client);
smb_hfield_str(&vote, SENDERSERVER, startup->host_name);
smb_hfield_str(&vote, SENDERSERVER, server_host_name());
if((i=votemsg(&cfg, &smb, &vote, notice, text[VoteNoticeFmt])) != SMB_SUCCESS)
errormsg(WHERE,ERR_WRITE,smb.file,i,smb.last_error);
......
......@@ -643,6 +643,7 @@ public:
bool gettimeleft_inside;
/* str.cpp */
char* server_host_name(void);
char* timestr(time_t);
char* datestr(time_t);
char timestr_output[60];
......
......@@ -182,6 +182,11 @@ static BOOL winsock_startup(void)
#endif
static char* server_host_name(void)
{
return startup->host_name[0] ? startup->host_name : scfg.sys_inetaddr;
}
static ulong active_clients(void)
{
ulong i;
......@@ -824,7 +829,7 @@ js_initcx(JSRuntime* js_runtime, SOCKET sock, service_client_t* service_client,
if(!js_CreateUserObjects(js_cx, *glob, &scfg, /*user: */NULL, service_client->client, NULL, service_client->subscan))
break;
if(js_CreateSystemObject(js_cx, *glob, &scfg, uptime, startup->host_name, SOCKLIB_DESC)==NULL)
if(js_CreateSystemObject(js_cx, *glob, &scfg, uptime, server_host_name(), SOCKLIB_DESC)==NULL)
break;
if(service_client->service->js_server_props.version[0]==0) {
......@@ -1840,9 +1845,6 @@ void DLLCALL services_thread(void* arg)
return;
}
if(startup->host_name[0]==0)
SAFECOPY(startup->host_name,scfg.sys_inetaddr);
if((t=checktime())!=0) { /* Check binary time */
lprintf(LOG_ERR,"!TIME PROBLEM (%ld)",t);
}
......
......@@ -1272,3 +1272,8 @@ char* sbbs_t::age_of_posted_item(char* buf, size_t max, time_t t)
safe_snprintf(buf, max, text[AgeOfPostedItem], value, units, past);
return buf;
}
char* sbbs_t::server_host_name(void)
{
return startup->host_name[0] ? startup->host_name : cfg.sys_inetaddr;
}
......@@ -740,6 +740,11 @@ static BOOL winsock_startup(void)
#endif
static char* server_host_name(void)
{
return startup->host_name[0] ? startup->host_name : scfg.sys_inetaddr;
}
static void status(char* str)
{
if(startup!=NULL && startup->status!=NULL)
......@@ -2797,7 +2802,7 @@ static BOOL parse_headers(http_session_t * session)
}
if(content_len)
session->req.post_len = content_len;
add_env(session,"SERVER_NAME",session->req.host[0] ? session->req.host : startup->host_name );
add_env(session,"SERVER_NAME",session->req.host[0] ? session->req.host : server_host_name() );
return TRUE;
}
......@@ -3125,12 +3130,12 @@ static BOOL get_request_headers(http_session_t * session)
}
if(!(session->req.vhost[0])) {
SAFECOPY(session->req.vhost, startup->host_name);
SAFECOPY(session->req.vhost, server_host_name());
/* Lower-case for normalization */
strlwr(session->req.vhost);
}
if(!(session->req.host[0])) {
SAFECOPY(session->req.host, startup->host_name);
SAFECOPY(session->req.host, server_host_name());
/* Lower-case for normalization */
strlwr(session->req.host);
}
......@@ -5764,7 +5769,7 @@ js_initcx(http_session_t *session)
if(!js_CreateCommonObjects(js_cx, &scfg, NULL
,NULL /* global */
,uptime /* system */
,startup->host_name /* system */
,server_host_name() /* system */
,SOCKLIB_DESC /* system */
,&session->js_callback /* js */
,&startup->js /* js */
......@@ -7067,9 +7072,6 @@ void DLLCALL web_server(void* arg)
iniCloseFile(fp);
}
if(startup->host_name[0]==0)
SAFECOPY(startup->host_name,scfg.sys_inetaddr);
if(uptime==0)
uptime=time(NULL); /* this must be done *after* setting the timezone */
......
......@@ -1378,7 +1378,7 @@ void sbbs_t::forwardmail(smbmsg_t *msg, int usernumber)
/* Security logging */
msg_client_hfields(msg,&client);
smb_hfield_str(msg,SENDERSERVER,startup->host_name);
smb_hfield_str(msg,SENDERSERVER, server_host_name());
username(&cfg,usernumber,touser);
smb_hfield_str(msg,RECIPIENT,touser);
......
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