#ifdef HAVE_UNISTD_H
# include <unistd.h>
#endif /* HAVE_UNISTD_H */
+#ifdef HAVE_SETLOCALE
+# include <locale.h>
+#endif /* HAVE_SETLOCALE */
+#ifdef HAVE_NL_LANGINFO
+# include <langinfo.h>
+#endif /* HAVE_NL_LANGINFO */
#include <pwd.h>
#include <grp.h>
#include <signal.h>
char *p, *tmp, save;
const char *fmt;
+#ifdef HAVE_SETLOCALE
+ const char *old_locale = estrdup(setlocale(LC_ALL, NULL));
+ if (!setlocale(LC_ALL, def_sudoers_locale))
+ setlocale(LC_ALL, "C");
+#endif /* HAVE_SETLOCALE */
+
/*
* Log the full line, breaking into multiple syslog(3) calls if necessary
*/
fmt = FMT_CONTD;
maxlen = MAXSYSLOGLEN - (sizeof(FMT_CONTD) - 6 + strlen(user_name));
}
+
+#ifdef HAVE_SETLOCALE
+ setlocale(LC_ALL, old_locale);
+ efree((void *)old_locale);
+#endif /* HAVE_SETLOCALE */
}
static void
} else {
time_t now;
+#ifdef HAVE_SETLOCALE
+ const char *old_locale = estrdup(setlocale(LC_ALL, NULL));
+ if (!setlocale(LC_ALL, def_sudoers_locale))
+ setlocale(LC_ALL, "C");
+#endif /* HAVE_SETLOCALE */
+
now = time(NULL);
if (def_loglinelen == 0) {
/* Don't pretty-print long log file lines (hard to grep) */
(void) fflush(fp);
(void) lock_file(fileno(fp), SUDO_UNLOCK);
(void) fclose(fp);
+
+#ifdef HAVE_SETLOCALE
+ setlocale(LC_ALL, old_locale);
+ efree((void *)old_locale);
+#endif /* HAVE_SETLOCALE */
}
}
"USER=root",
NULL
};
-#endif
+#endif /* NO_ROOT_MAILER */
/* Just return if mailer is disabled. */
if (!def_mailerpath || !def_mailto)
/* Daemonize - disassociate from session/tty. */
if (setsid() == -1)
warning("setsid");
- (void) chdir("/");
+ if (chdir("/") == -1)
+ warning("chdir(/)");
if ((fd = open(_PATH_DEVNULL, O_RDWR, 0644)) != -1) {
(void) dup2(fd, STDIN_FILENO);
(void) dup2(fd, STDOUT_FILENO);
(void) dup2(fd, STDERR_FILENO);
}
+#ifdef HAVE_SETLOCALE
+ if (!setlocale(LC_ALL, def_sudoers_locale)) {
+ setlocale(LC_ALL, "C");
+ efree(def_sudoers_locale);
+ def_sudoers_locale = estrdup("C");
+ }
+#endif /* HAVE_SETLOCALE */
+
/* Close password, group and other fds so we don't leak. */
sudo_endpwent();
sudo_endgrent();
(void) fputc(*p, mail);
}
+#ifdef HAVE_NL_LANGINFO
+ if (strcmp(def_sudoers_locale, "C") != 0)
+ (void) fprintf(mail, "\nContent-Type: text/plain; charset=\"%s\"\nContent-Transfer-Encoding: 8bit", nl_langinfo(CODESET));
+#endif /* HAVE_NL_LANGINFO */
+
(void) fprintf(mail, "\n\n%s : %s : %s : ", user_host,
get_timestr(time(NULL), def_log_year), user_name);
#ifdef __STDC__
int status;
{
- return(def_mail_always || ISSET(status, VALIDATE_ERROR) ||
+ return def_mail_always || ISSET(status, VALIDATE_ERROR) ||
(def_mail_no_user && ISSET(status, FLAG_NO_USER)) ||
(def_mail_no_host && ISSET(status, FLAG_NO_HOST)) ||
- (def_mail_no_perms && !ISSET(status, VALIDATE_OK)));
+ (def_mail_no_perms && !ISSET(status, VALIDATE_OK));
}
#define LL_TTY_STR "TTY="
}
len += sizeof(LL_ENV_STR) + 2 + evlen;
}
+ /* Note: we log "sudo -l command arg ..." as "list command arg ..." */
len += sizeof(LL_CMND_STR) - 1 + strlen(user_cmnd);
+ if (ISSET(sudo_mode, MODE_CHECK))
+ len += sizeof("list ") - 1;
if (user_args != NULL)
len += strlen(user_args) + 1;
goto toobig;
efree(evstr);
}
- if (strlcat(line, LL_CMND_STR, len) >= len ||
- strlcat(line, user_cmnd, len) >= len)
+ if (strlcat(line, LL_CMND_STR, len) >= len)
+ goto toobig;
+ if (ISSET(sudo_mode, MODE_CHECK) && strlcat(line, "list ", len) >= len)
+ goto toobig;
+ if (strlcat(line, user_cmnd, len) >= len)
goto toobig;
if (user_args != NULL) {
if (strlcat(line, " ", len) >= len ||
goto toobig;
}
- return (line);
+ return line;
toobig:
errorx(1, "internal error: insufficient space for log line");
}