AmendHub

Download:

jcs

/

subtext

/

amendments

/

561

telnet: Don't lookup location of the trusted proxy, look it up later

Once we get the REMOTE_ADDR NEWENV, do the lookup then and update
the session log.

jcs made amendment 561 about 1 year ago
--- telnet.c Thu Nov 9 15:47:33 2023 +++ telnet.c Tue Nov 21 22:16:13 2023 @@ -333,7 +333,7 @@ telnet_idle(void) node->id); } - if (db->ipdb) + if (db->ipdb && !node->from_trusted_proxy) loc = ipdb_lookup(db->ipdb, node->ip); logger_printf("[%s] New telnet connection from %s%s%s%s%s", @@ -610,7 +610,8 @@ telnet_input(struct session *session) char k[sizeof(node->iac_sb)], v[sizeof(node->iac_sb)]; unsigned char l = 0; bool inv = false; - + char *loc = NULL; + k[0] = v[0] = '\0'; /* \40\0\0USER\1blah\0DISPLAY\1... */ @@ -619,8 +620,7 @@ telnet_input(struct session *session) node->iac_sb[j] == 0 || node->iac_sb[j] == 3) { v[l] = '\0'; if (l) { - session_logf_buffered(session, - "NEWENV \"%s\" = \"%s\"", k, v); + loc = NULL; if (node->from_trusted_proxy && strcmp(k, "REMOTE_ADDR") == 0) { @@ -629,7 +629,27 @@ telnet_input(struct session *session) sizeof(node->ip_s)); node->session->log.ip_address = node->ip; + + if (db->ipdb && + (loc = ipdb_lookup(db->ipdb, + node->ip))) { + strlcpy(node->session->location, + loc, + sizeof(node->session->location)); + strlcpy(node->session->log.location, + loc, + sizeof(node->session->log.location)); + } } + + session_logf_buffered(session, + "NEWENV \"%s\" = \"%s\"%s%s%s", k, v, + loc ? " (" : "", + loc ? loc : "", + loc ? ")" : ""); + + if (loc) + xfree(&loc); } l = 0; inv = false;