jcs
/subtext
/amendments
/511
telnet: Do ipdb lookup on connect, log location and store in session
jcs made amendment 511 about 1 year ago
--- telnet.c Mon May 1 15:14:45 2023
+++ telnet.c Wed Jun 14 23:02:09 2023
@@ -292,7 +292,9 @@ telnet_idle(void)
case ConnectionStateSYNSent:
/* TODO: enforce our own timeout on these? */
break;
- case ConnectionStateEstablished:
+ case ConnectionStateEstablished: {
+ char *loc = NULL;
+
/* start up a new socket for listening */
telnet_listener_node = NULL;
@@ -306,8 +308,12 @@ telnet_idle(void)
node->id);
}
- logger_printf("[%s] New telnet connection from %s%s",
+ if (db->ipdb)
+ loc = ipdb_lookup(db->ipdb, node->ip);
+
+ logger_printf("[%s] New telnet connection from %s%s%s%s%s",
node->name, node->ip_s,
+ (loc ? " (" : ""), (loc ? loc : ""), (loc ? ") " : ""),
node->from_trusted_proxy ? " (via trusted proxy)" : "");
node->state = TELNET_PB_STATE_CONNECTED;
@@ -321,6 +327,8 @@ telnet_idle(void)
_TCPRelease(&node->listen_pb, node->stream, nil,
nil, false);
node->state = TELNET_PB_STATE_UNUSED;
+ if (loc)
+ xfree(&loc);
goto next_node;
}
node->session->cookie = (void *)node;
@@ -329,7 +337,15 @@ telnet_idle(void)
node->session->log.ip_address = telnet_status_pb.remoteHost;
if (node->from_trusted_proxy)
node->session->can_nomodem = true;
+ if (loc) {
+ strlcpy(node->session->location, loc,
+ sizeof(node->session->location));
+ strlcpy(node->session->log.location, loc,
+ sizeof(node->session->log.location));
+ xfree(&loc);
+ }
break;
+ }
default:
if (telnet_status_pb.remoteHost == 0)
long2ip(node->listen_pb.csParam.open.remoteHost,