mirror of
https://github.com/unrealircd/unrealircd.git
synced 2026-07-09 08:43:13 +02:00
Move/add local_port & server_port to ModData, so remote clients can be tracked.
This is sent over the wire as early moddata, just like "operlogin" and "operclass"
This commit is contained in:
@@ -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)
|
||||
|
||||
|
||||
@@ -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")
|
||||
|
||||
@@ -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 *);
|
||||
|
||||
@@ -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 */
|
||||
|
||||
@@ -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);
|
||||
|
||||
+5
-4
@@ -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)
|
||||
|
||||
+43
-4
@@ -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);
|
||||
|
||||
@@ -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 \
|
||||
|
||||
@@ -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)
|
||||
{
|
||||
|
||||
@@ -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))
|
||||
{
|
||||
|
||||
+1
-1
@@ -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;
|
||||
|
||||
|
||||
+2
-1
@@ -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 */
|
||||
|
||||
Reference in New Issue
Block a user