Mercurial > masqmail
diff src/log.c @ 331:e507c854a63e
Security fix! Correct handling of seteuid() return value
See Debian bug #638002, reported by John Lightsey.
When possible the (already available) set_euidgid() function is used.
Additionally, it is unnecessary to change the identity when writing
into an already open file descriptor.
This should fix the problem.
author | markus schnalke <meillo@marmaro.de> |
---|---|
date | Sat, 27 Aug 2011 16:19:07 +0200 |
parents | f671821d8222 |
children | b27f66555ba8 |
line wrap: on
line diff
--- a/src/log.c Wed Jul 13 10:30:52 2011 +0200 +++ b/src/log.c Sat Aug 27 16:19:07 2011 +0200 @@ -65,8 +65,9 @@ uid_t saved_uid; gid_t saved_gid; - saved_gid = setegid(conf.mail_gid); - saved_uid = seteuid(conf.mail_uid); + if (!conf.run_as_user) { + set_euidgid(conf.mail_uid, conf.mail_gid, &saved_uid, &saved_gid); + } filename = g_strdup_printf("%s/masqmail.log", conf.log_dir); logfile = fopen(filename, "a"); @@ -76,8 +77,9 @@ } g_free(filename); - seteuid(saved_uid); - setegid(saved_gid); + if (!conf.run_as_user) { + set_euidgid(saved_uid, saved_gid, NULL, NULL); + } } #ifdef ENABLE_DEBUG @@ -114,35 +116,26 @@ va_copy(args_copy, args); vfprintf(stdout, fmt, args_copy); va_end(args_copy); - fflush(stdout); /* is this necessary? */ + fflush(stdout); /* in case output ends not with newline */ } pri &= ~LOG_VERBOSE; - if (pri) { - if (conf.use_syslog) - vsyslog(pri, fmt, args); - else { - if (pri <= conf.log_max_pri) { - FILE *file = logfile ? logfile : stderr; - time_t now = time(NULL); - struct tm *t = localtime(&now); - gchar buf[24]; - uid_t saved_uid; - gid_t saved_gid; + if (!pri) { + return; + } + if (conf.use_syslog) + vsyslog(pri, fmt, args); + else if (pri <= conf.log_max_pri) { + FILE *file = logfile ? logfile : stderr; + time_t now = time(NULL); + struct tm *t = localtime(&now); + gchar buf[24]; - saved_gid = setegid(conf.mail_gid); - saved_uid = seteuid(conf.mail_uid); - - strftime(buf, 24, "%Y-%m-%d %H:%M:%S", t); - fprintf(file, "%s [%d] ", buf, getpid()); + strftime(buf, 24, "%Y-%m-%d %H:%M:%S", t); + fprintf(file, "%s [%d] ", buf, getpid()); - vfprintf(file, fmt, args); - fflush(file); - - seteuid(saved_uid); - setegid(saved_gid); - } - } + vfprintf(file, fmt, args); + fflush(file); } }