Commit 60f996f9 authored by rswindell's avatar rswindell
Browse files

Clean up the hostname look-up stuff:

- getnameinfo() was being called with NI_NUMERICHOST in the mail server and
  web server (but nowhere else)
- use a singly-defined macro (STR_NO_HOSTNAME) for the "<no name>" string
  rather than copying it about
- the webserver apparently assumes that session->host_name will always have
  *some* unique value (e.g. the IP address when no hostname is available) - so
  account for that special need <grumble>
parent 5dc77fef
......@@ -3093,15 +3093,11 @@ static void ctrl_thread(void* arg)
lprintf(LOG_INFO,"%04d CTRL connection accepted from: %s port %u"
,sock, host_ip, inet_addrport(&ftp.client_addr));
if(startup->options&FTP_OPT_NO_HOST_LOOKUP)
strcpy(host_name,"<no name>");
else {
if(getnameinfo(&ftp.client_addr.addr, sizeof(ftp.client_addr), host_name, sizeof(host_name), NULL, 0, NI_NAMEREQD)!=0)
strcpy(host_name,"<no name>");
}
if(!(startup->options&FTP_OPT_NO_HOST_LOOKUP))
SAFECOPY(host_name, STR_NO_HOSTNAME);
if(!(startup->options&FTP_OPT_NO_HOST_LOOKUP)) {
getnameinfo(&ftp.client_addr.addr, sizeof(ftp.client_addr), host_name, sizeof(host_name), NULL, 0, NI_NAMEREQD);
lprintf(LOG_INFO,"%04d Hostname: %s", sock, host_name);
}
ulong banned = loginBanned(&scfg, startup->login_attempt_list, sock, host_name, startup->login_attempt, &attempted);
if(banned || trashcan(&scfg,host_ip,"ip")) {
......
......@@ -156,7 +156,7 @@ void sbbs_t::badlogin(char* user, char* passwd, const char* protocol, xp_sockadd
if(addr == NULL)
addr = &client_addr;
SAFECOPY(host_name, "<no name>");
SAFECOPY(host_name, STR_NO_HOSTNAME);
socklen_t addr_len = sizeof(*addr);
SAFEPRINTF(reason,"%s LOGIN", protocol);
count=loginFailure(startup->login_attempt_list, addr, protocol, user, passwd);
......
......@@ -994,12 +994,12 @@ static void pop3_thread(void* arg)
lprintf(LOG_INFO,"%04d %s connection accepted from: %s port %u"
,socket, client.protocol, host_ip, inet_addrport(&pop3.client_addr));
if(getnameinfo(&pop3.client_addr.addr, pop3.client_addr_len, host_name, sizeof(host_name), NULL, 0, (startup->options&MAIL_OPT_NO_HOST_LOOKUP)?NI_NUMERICHOST:0)!=0)
SAFECOPY(host_name, "<no name>");
if(!(startup->options&MAIL_OPT_NO_HOST_LOOKUP) && (startup->options&MAIL_OPT_DEBUG_POP3))
lprintf(LOG_INFO,"%04d %s Hostname: %s", socket, client.protocol, host_name);
SAFECOPY(host_name, STR_NO_HOSTNAME);
if(!(startup->options&MAIL_OPT_NO_HOST_LOOKUP)) {
getnameinfo(&pop3.client_addr.addr, pop3.client_addr_len, host_name, sizeof(host_name), NULL, 0, NI_NAMEREQD);
if(startup->options&MAIL_OPT_DEBUG_POP3)
lprintf(LOG_INFO,"%04d %s Hostname: %s", socket, client.protocol, host_name);
}
if (pop3.tls_port) {
if (get_ssl_cert(&scfg, &estr, &level) == -1) {
if (estr) {
......@@ -2901,12 +2901,11 @@ static void smtp_thread(void* arg)
lprintf(LOG_INFO,"%04d %s Connection accepted on port %u from: %s port %u"
,socket, client.protocol, inet_addrport(&server_addr), host_ip, inet_addrport(&smtp.client_addr));
if(getnameinfo(&smtp.client_addr.addr, smtp.client_addr_len, host_name, sizeof(host_name), NULL, 0, (startup->options&MAIL_OPT_NO_HOST_LOOKUP)?NI_NUMERICHOST:0)!=0)
SAFECOPY(host_name, "<no name>");
if(!(startup->options&MAIL_OPT_NO_HOST_LOOKUP))
SAFECOPY(host_name, STR_NO_HOSTNAME);
if(!(startup->options&MAIL_OPT_NO_HOST_LOOKUP)) {
getnameinfo(&smtp.client_addr.addr, smtp.client_addr_len, host_name, sizeof(host_name), NULL, 0, NI_NAMEREQD);
lprintf(LOG_INFO,"%04d %s Hostname: %s", socket, client.protocol, host_name);
}
protected_uint32_adjust(&active_clients, 1);
update_clients();
......
......@@ -5676,7 +5676,7 @@ NO_SSH:
sbbs->bprintf("\r\n%s\r\n", VERSION_NOTICE);
sbbs->bprintf("%s connection from: %s\r\n", client.protocol, host_ip);
SAFECOPY(host_name, "<no name>");
SAFECOPY(host_name, STR_NO_HOSTNAME);
if(!(startup->options&BBS_OPT_NO_HOST_LOOKUP)) {
sbbs->bprintf("Resolving hostname...");
getnameinfo(&client_addr.addr, client_addr_len, host_name, sizeof(host_name), NULL, 0, NI_NAMEREQD);
......
......@@ -70,6 +70,7 @@
#define UNKNOWN_LOAD_ERROR "Unknown load error - Library mismatch?"
#define STR_UNKNOWN_USER "<unknown user>"
#define STR_NO_HOSTNAME "<no name>"
#define JAVASCRIPT_MAX_BYTES (8*1024*1024)
#define JAVASCRIPT_CONTEXT_STACK (16*1024)
......
......@@ -1002,19 +1002,13 @@ static void js_service_thread(void* arg)
protected_uint32_adjust(&threads_pending_start, -1);
/* Host name lookup and filtering */
if(service->options&BBS_OPT_NO_HOST_LOOKUP
|| startup->options&BBS_OPT_NO_HOST_LOOKUP)
SAFECOPY(host_name, "<no name>");
else {
if(getnameinfo(&service_client.addr.addr, xp_sockaddr_len(&service_client), host_name, sizeof(host_name), NULL, 0, NI_NAMEREQD) != 0)
SAFECOPY(host_name, "<no name>");
}
SAFECOPY(host_name, STR_NO_HOSTNAME);
if(!(service->options&BBS_OPT_NO_HOST_LOOKUP)
&& !(startup->options&BBS_OPT_NO_HOST_LOOKUP)
&& service->log_level >= LOG_INFO) {
lprintf(LOG_INFO,"%04d %s Hostname: %s"
,socket, service->protocol, host_name);
&& !(startup->options&BBS_OPT_NO_HOST_LOOKUP)) {
getnameinfo(&service_client.addr.addr, xp_sockaddr_len(&service_client), host_name, sizeof(host_name), NULL, 0, NI_NAMEREQD);
if(service->log_level >= LOG_INFO)
lprintf(LOG_INFO,"%04d %s Hostname: %s"
,socket, service->protocol, host_name);
}
if(trashcan(&scfg,host_name,"host")) {
......@@ -1390,15 +1384,10 @@ static void native_service_thread(void* arg)
protected_uint32_adjust(&threads_pending_start, -1);
/* Host name lookup and filtering */
if(service->options&BBS_OPT_NO_HOST_LOOKUP
|| startup->options&BBS_OPT_NO_HOST_LOOKUP)
SAFECOPY(host_name, "<no name>");
else
if(getnameinfo(&service_client.addr.addr, xp_sockaddr_len(&service_client), host_name, sizeof(host_name), NULL, 0, NI_NAMEREQD)!=0)
SAFECOPY(host_name, "<no name>");
SAFECOPY(host_name, STR_NO_HOSTNAME);
if(!(service->options&BBS_OPT_NO_HOST_LOOKUP)
&& !(startup->options&BBS_OPT_NO_HOST_LOOKUP)) {
getnameinfo(&service_client.addr.addr, xp_sockaddr_len(&service_client), host_name, sizeof(host_name), NULL, 0, NI_NAMEREQD);
lprintf(LOG_INFO,"%04d %s Hostname: %s"
,socket, service->protocol, host_name);
#if 0 /* gethostbyaddr() is apparently not (always) thread-safe
......
......@@ -6283,19 +6283,18 @@ void http_session_thread(void* arg)
sbbs_srand(); /* Seed random number generator */
if(getnameinfo(&session.addr.addr, session.addr_len, session.host_name, sizeof(session.host_name), NULL, 0, (startup->options&BBS_OPT_NO_HOST_LOOKUP)?NI_NUMERICHOST:0)!=0)
SAFECOPY(session.host_name, session.host_ip);
char host_name[128] = "";
if(!(startup->options&BBS_OPT_NO_HOST_LOOKUP)) {
lprintf(LOG_INFO,"%04d Hostname: %s", session.socket, session.host_name);
getnameinfo(&session.addr.addr, session.addr_len, host_name, sizeof(host_name), NULL, 0, NI_NAMEREQD);
lprintf(LOG_INFO,"%04d Hostname: %s", session.socket, host_name[0] ? host_name : STR_NO_HOSTNAME);
#if 0 /* gethostbyaddr() is apparently not (always) thread-safe
and getnameinfo() doesn't return alias information */
for(i=0;host!=NULL && host->h_aliases!=NULL
&& host->h_aliases[i]!=NULL;i++)
lprintf(LOG_INFO,"%04d HostAlias: %s", session.socket, host->h_aliases[i]);
#endif
if(trashcan(&scfg,session.host_name,"host")) {
lprintf(LOG_NOTICE,"%04d !CLIENT BLOCKED in host.can: %s", session.socket, session.host_name);
if(host_name[0] && trashcan(&scfg, host_name,"host")) {
lprintf(LOG_NOTICE,"%04d !CLIENT BLOCKED in host.can: %s", session.socket, host_name);
close_session_socket(&session);
sem_wait(&session.output_thread_terminated);
sem_destroy(&session.output_thread_terminated);
......@@ -6304,9 +6303,15 @@ void http_session_thread(void* arg)
return;
}
}
if(host_name[0])
SAFECOPY(session.host_name, host_name);
else {
SAFECOPY(session.host_name, session.host_ip);
SAFECOPY(host_name, STR_NO_HOSTNAME);
}
login_attempt_t attempted;
ulong banned = loginBanned(&scfg, startup->login_attempt_list, session.socket, session.host_name, startup->login_attempt, &attempted);
ulong banned = loginBanned(&scfg, startup->login_attempt_list, session.socket, host_name, startup->login_attempt, &attempted);
/* host_ip wasn't defined in http_session_thread */
if(banned || trashcan(&scfg,session.host_ip,"ip")) {
......@@ -6329,7 +6334,7 @@ void http_session_thread(void* arg)
SAFECOPY(session.username,unknown);
SAFECOPY(session.client.addr,session.host_ip);
SAFECOPY(session.client.host,session.host_name);
SAFECOPY(session.client.host, host_name);
session.client.port=inet_addrport(&session.addr);
session.client.time=time32(NULL);
session.client.protocol=session.is_tls ? "HTTPS":"HTTP";
......
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