From e87ffcd7e13a7a017f995622580f830934807efe Mon Sep 17 00:00:00 2001 From: Vladimir Dubrovin <3proxy@3proxy.ru> Date: Fri, 23 Oct 2026 11:47:23 +0300 Subject: [PATCH] Logs: no ODBC user and password in messages about a log A log string is shown only up to its first comma, where an ODBC string goes on with the user and the password: in the message on a log which failed, and in the errors on a log or -l which cannot be opened. Co-Authored-By: Claude Opus 5.5 --- src/conf.c | 4 +++- src/log.c | 11 ++++++++++- src/mainconf.c | 3 ++- src/proxy.h | 1 + 4 files changed, 16 insertions(+), 3 deletions(-) diff --git a/src/conf.c b/src/conf.c index 17a28b0..7811d14 100644 --- a/src/conf.c +++ b/src/conf.c @@ -388,7 +388,9 @@ static int h_log(int argc, unsigned char ** argv){ /* the same log as before is not opened again */ lg = logget((argc > 1)? argv[1] : (unsigned char *)"", rotation); if(!lg){ - perror((argc > 1)? (char *)argv[1] : "log"); + fprintf(stderr, "Unable to open log %.*s: %s, line %d\n", + (int)logselen((argc > 1)? argv[1] : (unsigned char *)""), + (argc > 1)? (char *)argv[1] : "", strerror(errno), linenum); return 1; } if(conf->stacksize < lg->type->stacksize) conf->stacksize = lg->type->stacksize; diff --git a/src/log.c b/src/log.c index 446ee4b..a58006b 100644 --- a/src/log.c +++ b/src/log.c @@ -808,6 +808,14 @@ static void logfallback(struct logger *lg, struct clientparam *param, const unsi logput(to); } +/* The part of a log string fit to be shown: up to a comma, an ODBC string + going on with the user and the password, and at most 200 bytes. */ +size_t logselen(const unsigned char *selector){ + size_t len = strcspn((char *)selector, ","); + + return len > 200? 200 : len; +} + static void logwrite(struct logger *lg, struct clientparam *param, const unsigned char *buf, int len){ int res = 0, failed, report = 0; time_t t; @@ -838,7 +846,8 @@ static void logwrite(struct logger *lg, struct clientparam *param, const unsigne if(report){ unsigned char msg[300]; - sprintf((char *)msg, "Log %.200s failed, its lines go to the error log", lg->selector); + /* up to a comma: an ODBC string goes on with user and password */ + sprintf((char *)msg, "Log %.*s failed, its lines go to the error log", (int)logselen(lg->selector), lg->selector); logerror(msg); } } diff --git a/src/mainconf.c b/src/mainconf.c index a99fddd..3dc1ea6 100644 --- a/src/mainconf.c +++ b/src/mainconf.c @@ -322,7 +322,8 @@ static int srvprepare(struct srvstart *s, int argc, char **argv){ /* the same log the log command, or another service, opened is shared with it */ if(!(lg = logget((unsigned char *)argv[i] + 2, NONE))){ - perror(argv[i] + 2); + fprintf(stderr, "Unable to open log %.*s: %s\n", + (int)logselen((unsigned char *)argv[i] + 2), argv[i] + 2, strerror(errno)); return 1; } logput(srv->logger); diff --git a/src/proxy.h b/src/proxy.h index 79277ab..8acc4a8 100644 --- a/src/proxy.h +++ b/src/proxy.h @@ -352,6 +352,7 @@ void logput(struct logger *lg); void logcommit(struct extparam *c); void logerrset(struct logger *lg); void logstdclose(void); +size_t logselen(const unsigned char *selector); void logtick(time_t t); void logfinish(void); int timechanged (time_t oldtime, time_t newtime, ROTATION lt);