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 <noreply@anthropic.com>
This commit is contained in:
Vladimir Dubrovin 2026-10-23 11:47:23 +03:00
parent d613750b94
commit e87ffcd7e1
4 changed files with 16 additions and 3 deletions

View File

@ -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;

View File

@ -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);
}
}

View File

@ -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);

View File

@ -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);