mirror of
https://github.com/postgres/postgres.git
synced 2025-11-03 09:13:20 +03:00
Add application_name to connection authorized msg
The connection authorized message has quite a bit of useful information in it, but didn't include the application_name (when provided), so let's add that as it can be very useful. Note that at the point where we're emitting the connection authorized message, we haven't processed GUCs, so it's not possible to get this by using log_line_prefix (which pulls from the GUC). There's also something to be said for having this included in the connection authorized message and then not needing to repeat it for every line, as having it in log_line_prefix would do. The GUC cleans the application name to pure-ascii, so do that here too, but pull out the logic for cleaning up a string into its own function in common and re-use it from those places, and check_cluster_name which was doing the same thing. Author: Don Seiler <don@seiler.us> Discussion: https://postgr.es/m/CAHJZqBB_Pxv8HRfoh%2BAB4KxSQQuPVvtYCzMg7woNR3r7dfmopw%40mail.gmail.com
This commit is contained in:
@@ -99,6 +99,7 @@
|
||||
#include "catalog/pg_control.h"
|
||||
#include "common/file_perm.h"
|
||||
#include "common/ip.h"
|
||||
#include "common/string.h"
|
||||
#include "lib/ilist.h"
|
||||
#include "libpq/auth.h"
|
||||
#include "libpq/libpq.h"
|
||||
@@ -2096,6 +2097,21 @@ retry1:
|
||||
pstrdup(nameptr));
|
||||
port->guc_options = lappend(port->guc_options,
|
||||
pstrdup(valptr));
|
||||
|
||||
/*
|
||||
* Copy application_name to port if we come across it. This
|
||||
* is done so we can log the application_name in the
|
||||
* connection authorization message. Note that the GUC would
|
||||
* be used but we haven't gone through GUC setup yet.
|
||||
*/
|
||||
if (strcmp(nameptr, "application_name") == 0)
|
||||
{
|
||||
char *tmp_app_name = pstrdup(valptr);
|
||||
|
||||
pg_clean_ascii(tmp_app_name);
|
||||
|
||||
port->application_name = tmp_app_name;
|
||||
}
|
||||
}
|
||||
offset = valoffset + strlen(valptr) + 1;
|
||||
}
|
||||
|
||||
@@ -249,34 +249,56 @@ PerformAuthentication(Port *port)
|
||||
#ifdef USE_SSL
|
||||
if (port->ssl_in_use)
|
||||
ereport(LOG,
|
||||
(errmsg("replication connection authorized: user=%s SSL enabled (protocol=%s, cipher=%s, bits=%d, compression=%s)",
|
||||
port->user_name,
|
||||
be_tls_get_version(port),
|
||||
be_tls_get_cipher(port),
|
||||
be_tls_get_cipher_bits(port),
|
||||
be_tls_get_compression(port) ? _("on") : _("off"))));
|
||||
(port->application_name != NULL
|
||||
? errmsg("replication connection authorized: user=%s application_name=%s SSL enabled (protocol=%s, cipher=%s, bits=%d, compression=%s)",
|
||||
port->user_name,
|
||||
port->application_name,
|
||||
be_tls_get_version(port),
|
||||
be_tls_get_cipher(port),
|
||||
be_tls_get_cipher_bits(port),
|
||||
be_tls_get_compression(port) ? _("on") : _("off"))
|
||||
: errmsg("replication connection authorized: user=%s SSL enabled (protocol=%s, cipher=%s, bits=%d, compression=%s)",
|
||||
port->user_name,
|
||||
be_tls_get_version(port),
|
||||
be_tls_get_cipher(port),
|
||||
be_tls_get_cipher_bits(port),
|
||||
be_tls_get_compression(port) ? _("on") : _("off"))));
|
||||
else
|
||||
#endif
|
||||
ereport(LOG,
|
||||
(errmsg("replication connection authorized: user=%s",
|
||||
port->user_name)));
|
||||
(port->application_name != NULL
|
||||
? errmsg("replication connection authorized: user=%s application_name=%s",
|
||||
port->user_name,
|
||||
port->application_name)
|
||||
: errmsg("replication connection authorized: user=%s",
|
||||
port->user_name)));
|
||||
}
|
||||
else
|
||||
{
|
||||
#ifdef USE_SSL
|
||||
if (port->ssl_in_use)
|
||||
ereport(LOG,
|
||||
(errmsg("connection authorized: user=%s database=%s SSL enabled (protocol=%s, cipher=%s, bits=%d, compression=%s)",
|
||||
port->user_name, port->database_name,
|
||||
be_tls_get_version(port),
|
||||
be_tls_get_cipher(port),
|
||||
be_tls_get_cipher_bits(port),
|
||||
be_tls_get_compression(port) ? _("on") : _("off"))));
|
||||
(port->application_name != NULL
|
||||
? errmsg("connection authorized: user=%s database=%s application_name=%s SSL enabled (protocol=%s, cipher=%s, bits=%d, compression=%s)",
|
||||
port->user_name, port->database_name, port->application_name,
|
||||
be_tls_get_version(port),
|
||||
be_tls_get_cipher(port),
|
||||
be_tls_get_cipher_bits(port),
|
||||
be_tls_get_compression(port) ? _("on") : _("off"))
|
||||
: errmsg("connection authorized: user=%s database=%s SSL enabled (protocol=%s, cipher=%s, bits=%d, compression=%s)",
|
||||
port->user_name, port->database_name,
|
||||
be_tls_get_version(port),
|
||||
be_tls_get_cipher(port),
|
||||
be_tls_get_cipher_bits(port),
|
||||
be_tls_get_compression(port) ? _("on") : _("off"))));
|
||||
else
|
||||
#endif
|
||||
ereport(LOG,
|
||||
(errmsg("connection authorized: user=%s database=%s",
|
||||
port->user_name, port->database_name)));
|
||||
(port->application_name != NULL
|
||||
? errmsg("connection authorized: user=%s database=%s application_name=%s",
|
||||
port->user_name, port->database_name, port->application_name)
|
||||
: errmsg("connection authorized: user=%s database=%s",
|
||||
port->user_name, port->database_name)));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -41,6 +41,7 @@
|
||||
#include "commands/vacuum.h"
|
||||
#include "commands/variable.h"
|
||||
#include "commands/trigger.h"
|
||||
#include "common/string.h"
|
||||
#include "funcapi.h"
|
||||
#include "jit/jit.h"
|
||||
#include "libpq/auth.h"
|
||||
@@ -10760,13 +10761,7 @@ static bool
|
||||
check_application_name(char **newval, void **extra, GucSource source)
|
||||
{
|
||||
/* Only allow clean ASCII chars in the application name */
|
||||
char *p;
|
||||
|
||||
for (p = *newval; *p; p++)
|
||||
{
|
||||
if (*p < 32 || *p > 126)
|
||||
*p = '?';
|
||||
}
|
||||
pg_clean_ascii(*newval);
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -10782,13 +10777,7 @@ static bool
|
||||
check_cluster_name(char **newval, void **extra, GucSource source)
|
||||
{
|
||||
/* Only allow clean ASCII chars in the cluster name */
|
||||
char *p;
|
||||
|
||||
for (p = *newval; *p; p++)
|
||||
{
|
||||
if (*p < 32 || *p > 126)
|
||||
*p = '?';
|
||||
}
|
||||
pg_clean_ascii(*newval);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user