diff --git a/Makefile.windows b/Makefile.windows index f2c4a7716..0eeced771 100644 --- a/Makefile.windows +++ b/Makefile.windows @@ -326,6 +326,7 @@ DLL_FILES=\ src/modules/pass.dll \ src/modules/pingpong.dll \ src/modules/plaintext-policy.dll \ + src/modules/portinfo.dll \ src/modules/protoctl.dll \ src/modules/quit.dll \ src/modules/real-quit-reason.dll \ @@ -1116,6 +1117,9 @@ src/modules/pingpong.dll: src/modules/pingpong.c $(INCLUDES) src/modules/plaintext-policy.dll: src/modules/plaintext-policy.c $(INCLUDES) $(CC) $(MODCFLAGS) src/modules/plaintext-policy.c /Fesrc/modules/ /Fosrc/modules/ /Fdsrc/modules/plaintext-policy.pdb $(MODLFLAGS) +src/modules/portinfo.dll: src/modules/portinfo.c $(INCLUDES) + $(CC) $(MODCFLAGS) src/modules/portinfo.c /Fesrc/modules/ /Fosrc/modules/ /Fdsrc/modules/portinfo.pdb $(MODLFLAGS) + src/modules/protoctl.dll: src/modules/protoctl.c $(INCLUDES) $(CC) $(MODCFLAGS) src/modules/protoctl.c /Fesrc/modules/ /Fosrc/modules/ /Fdsrc/modules/protoctl.pdb $(MODLFLAGS) diff --git a/doc/conf/modules.default.conf b/doc/conf/modules.default.conf index 49ffab4db..dca19ce10 100644 --- a/doc/conf/modules.default.conf +++ b/doc/conf/modules.default.conf @@ -300,6 +300,7 @@ loadmodule "spamreport"; /* Spam reporting to a blacklist */ loadmodule "crule"; /* Rules in spamfilter::rule and deny link::rule */ loadmodule "maxperip"; /* allow::maxperip restrictions */ loadmodule "utf8functions"; /* Various UTF8 helper functions */ +loadmodule "portinfo"; /* storing local_port and server_port of users */ loadmodule "geoip_classic"; @if module-loaded("geoip_classic") diff --git a/include/h.h b/include/h.h index ecea77ae9..582084f0e 100644 --- a/include/h.h +++ b/include/h.h @@ -381,6 +381,10 @@ extern const char *pretty_date(time_t t); extern time_t server_time_to_unix_time(const char *tbuf); extern time_t rfc2616_time_to_unix_time(const char *tbuf); extern const char *rfc2616_time(time_t clock); +extern int get_server_port(Client *client); +extern int get_client_port(Client *client); +extern void set_client_port(Client *client, int port); +extern void set_server_port(Client *client, int port); extern void initstats(); extern const char *check_string(const char *); extern char *make_nick_user_host(const char *, const char *, const char *); diff --git a/include/struct.h b/include/struct.h index 9a18ed7e6..b8567c069 100644 --- a/include/struct.h +++ b/include/struct.h @@ -1540,7 +1540,6 @@ struct LocalClient { int identbufcnt; /**< Counter for 'ident' reading code */ struct hostent *hostp; /**< Host record for this client (used by DNS code) */ char sockhost[HOSTLEN + 1]; /**< Hostname from the socket */ - u_short port; /**< Remote TCP port of client */ FloodCounter flood[MAXFLOODOPTIONS]; RPCClient *rpc; /**< RPC Client, or NULL */ Tag *tags; /**< Tags from spamfilter */ diff --git a/src/ircd.c b/src/ircd.c index 7ee5ba290..e25609148 100644 --- a/src/ircd.c +++ b/src/ircd.c @@ -848,7 +848,6 @@ int InitUnrealIRCd(int argc, char *argv[]) if (loop.boot_function) loop.boot_function(); open_debugfile(); - me.local->port = 6667; /* pointless? */ applymeblock(); #ifdef HAVE_SYSLOG openlog("ircd", LOG_PID | LOG_NDELAY, LOG_DAEMON); @@ -1003,7 +1002,6 @@ static void open_debugfile(void) client = make_client(NULL, NULL); client->local->fd = 2; SetLog(client); - client->local->port = debuglevel; client->flags = 0; strlcpy(client->local->sockhost, me.local->sockhost, sizeof client->local->sockhost); diff --git a/src/json.c b/src/json.c index 2c753c3d5..e51b2bcc3 100644 --- a/src/json.c +++ b/src/json.c @@ -209,6 +209,7 @@ void json_expand_client(json_t *j, const char *key, Client *client, int detail) json_t *child; json_t *user = NULL; time_t ts; + int i; if (key) { @@ -286,10 +287,10 @@ void json_expand_client(json_t *j, const char *key, Client *client, int detail) return; } - if (client->local && client->local->listener) - json_object_set_new(child, "server_port", json_integer(client->local->listener->port)); - if (client->local && client->local->port) - json_object_set_new(child, "client_port", json_integer(client->local->port)); + if ((i = get_server_port(client))) + json_object_set_new(child, "server_port", json_integer(i)); + if ((i = get_client_port(client))) + json_object_set_new(child, "client_port", json_integer(i)); if ((ts = get_creationtime(client))) json_object_set_new(child, "connected_since", json_timestamp(ts)); if (client->local && client->local->idle_since) diff --git a/src/misc.c b/src/misc.c index 6187f4f8a..5f46079ec 100644 --- a/src/misc.c +++ b/src/misc.c @@ -273,6 +273,45 @@ const char *myctime(time_t value) return buf; } +/** Return the server port the client connected to (e.g. 6697) */ +int get_server_port(Client *client) +{ + ModData *m; + + if (MyConnect(client) && client->local->listener) + return client->local->listener->port; + + m = moddata_client_get_raw(client, "server_port"); + if (!m) + return 0; + return m->i; +} + +/** Return the client-side port (e.g. 60123) for the 'client' connection. + * Note: don't confuse this with the server-side port (e.g. 6697). + */ +int get_client_port(Client *client) +{ + ModData *m = moddata_client_get_raw(client, "local_port"); + if (!m) + return 0; + return m->i; +} + +void set_client_port(Client *client, int port) +{ + char buf[32]; + snprintf(buf, sizeof(buf), "%d", port); + moddata_client_set(client, "local_port", buf); +} + +void set_server_port(Client *client, int port) +{ + char buf[32]; + snprintf(buf, sizeof(buf), "%d", port); + moddata_client_set(client, "server_port", buf); +} + /* ** get_client_name ** Return the name of the client for various tracking and @@ -304,13 +343,13 @@ const char *get_client_name(Client *client, int showip) if (MyConnect(client)) { if (showip) - ircsnprintf(nbuf, sizeof(nbuf), "%s[%s@%s.%u]", + { + ircsnprintf(nbuf, sizeof(nbuf), "%s[%s@%s.%d]", client->name, IsIdentSuccess(client) ? client->ident : "", client->ip ? client->ip : "???", - (unsigned int)client->local->port); - else - { + get_client_port(client)); + } else { if (mycmp(client->name, client->local->sockhost)) ircsnprintf(nbuf, sizeof(nbuf), "%s[%s]", client->name, client->local->sockhost); diff --git a/src/modules/Makefile.in b/src/modules/Makefile.in index 7ac34cabf..1d15c0f86 100644 --- a/src/modules/Makefile.in +++ b/src/modules/Makefile.in @@ -77,7 +77,7 @@ MODULES= \ typing-indicator.so channel-context.so \ ident_lookup.so history.so chathistory.so \ targetfloodprot.so clienttagdeny.so watch-backend.so \ - monitor.so slog.so tls_cipher.so operinfo.so creationtime.so \ + monitor.so slog.so tls_cipher.so operinfo.so creationtime.so portinfo.so \ unreal_server_compat.so \ extended-monitor.so geoip_csv.so \ geoip_base.so extjwt.so tline.so \ diff --git a/src/modules/central-blocklist.c b/src/modules/central-blocklist.c index 4e3216881..7d16f2469 100644 --- a/src/modules/central-blocklist.c +++ b/src/modules/central-blocklist.c @@ -570,6 +570,7 @@ void cbl_add_client_info(Client *client) json_t *cbl = CBL(client)->handshake; json_t *child = json_object(); const char *str; + int i; json_object_set_new(cbl, "client", child); @@ -607,10 +608,10 @@ void cbl_add_client_info(Client *client) json_object_set_new(child, "details", json_string_unreal(client->name)); } - if (client->local && client->local->listener) - json_object_set_new(child, "server_port", json_integer(client->local->listener->port)); - if (client->local && client->local->port) - json_object_set_new(child, "client_port", json_integer(client->local->port)); + if ((i = get_server_port(client))) + json_object_set_new(child, "server_port", json_integer(i)); + if ((i = get_client_port(client))) + json_object_set_new(child, "client_port", json_integer(i)); if (client->user) { diff --git a/src/modules/ident_lookup.c b/src/modules/ident_lookup.c index e713620e0..6c45668c1 100644 --- a/src/modules/ident_lookup.c +++ b/src/modules/ident_lookup.c @@ -144,8 +144,8 @@ static void ident_lookup_send(int fd, int revents, void *data) Client *client = data; ircsnprintf(authbuf, sizeof(authbuf), "%d , %d\r\n", - client->local->port, - client->local->listener->port); + get_client_port(client), + get_server_port(client)); if (WRITE_SOCK(client->local->authfd, authbuf, strlen(authbuf)) != strlen(authbuf)) { diff --git a/src/modules/trace.c b/src/modules/trace.c index 1df322ac6..028cbd2cb 100644 --- a/src/modules/trace.c +++ b/src/modules/trace.c @@ -201,7 +201,7 @@ CMD_FUNC(cmd_trace) break; case CLIENT_STATUS_LOG: - sendnumeric(client, RPL_TRACELOG, LOGFILE, acptr->local->port); + sendnumeric(client, RPL_TRACELOG, LOGFILE, 0); cnt++; break; diff --git a/src/socket.c b/src/socket.c index cfbb98278..156eae6ed 100644 --- a/src/socket.c +++ b/src/socket.c @@ -891,7 +891,8 @@ refuse_client: set_sockhost(client, ip); if (!set_client_ip(client, ip)) abort(); // would mean getpeerip() or spoof_ip is bad, which is impossible. - client->local->port = port; + set_client_port(client, port); + set_server_port(client, client->local->listener->port); client->local->fd = fd; /* Tag loopback connections */