From 7468018a7d6d236f8c04b63edeffb63772fa4ea3 Mon Sep 17 00:00:00 2001 From: Bram Matthys Date: Sun, 29 Oct 2023 07:02:23 +0100 Subject: [PATCH] Make $client.details follow the ident rules in the handshake too. Post-handshake this was working fine, but before register_user() it was always using nick!user@host, never using the ident and never ~ prefixing. Now it just uses the usual rules that we have, which are: prefixing with a ~ if ident lookups are enabled and failed, and without a ~ prefix if ident lookup succeeded or set::options::identd-check is off. Reported by k4be. --- src/json.c | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/src/json.c b/src/json.c index 9eab4cd80..a253ae093 100644 --- a/src/json.c +++ b/src/json.c @@ -240,7 +240,35 @@ void json_expand_client(json_t *j, const char *key, Client *client, int detail) */ if (client->user) { - snprintf(buf, sizeof(buf), "%s!%s@%s", client->name, client->user->username, client->user->realhost); + if (IsUser(client) || !MyConnect(client)) + { + /* Post-handshake, after register_user(), it is easy: */ + snprintf(buf, sizeof(buf), "%s!%s@%s", client->name, client->user->username, client->user->realhost); + } else + { + /* In the handshake, more possibilities (ident could still be ongoing) + * and more speculative (a later class block may want to ignore ident, + * but we don't know that, so we assume that is not the case). + */ + const char *ident; + char temp[USERLEN+1]; + if (IDENT_CHECK) + { + if (IsIdentSuccess(client)) + { + /* ident succeeded means: use the identd and no ~ prefix */ + ident = client->ident; + } else { + /* ident check failed means ~ prefix */ + snprintf(temp, sizeof(temp), "~%s", client->user->username); + ident = temp; + } + } else { + /* no ident check means no ~ prefix */ + ident = client->user->username; + } + snprintf(buf, sizeof(buf), "%s!%s@%s", client->name, ident, client->user->realhost); + } json_object_set_new(child, "details", json_string_unreal(buf)); } else if (client->ip) { if (*client->name)