From 336021a9c06a91accf70c0c5ceb6719b54ab748a Mon Sep 17 00:00:00 2001 From: "Todd C. Miller" Date: Mon, 12 Nov 2012 05:36:43 -0500 Subject: [PATCH] Fix compilation on systems w/o setlocale() --- plugins/sudoers/locale.c | 26 ++++++++++++++++++++------ plugins/sudoers/logging.h | 6 +++--- plugins/sudoers/sudoers.h | 2 +- 3 files changed, 24 insertions(+), 10 deletions(-) diff --git a/plugins/sudoers/locale.c b/plugins/sudoers/locale.c index 964afd4ee..d2727720e 100644 --- a/plugins/sudoers/locale.c +++ b/plugins/sudoers/locale.c @@ -35,8 +35,6 @@ #include "sudoers.h" -#ifdef HAVE_SETLOCALE - static int current_locale = SUDOERS_LOCALE_USER; int @@ -45,7 +43,14 @@ sudoers_getlocale(void) return current_locale; } -int +/* + * Set locale to user or sudoers value. + * Returns true on success and false on failure, + * If prevlocale is non-NULL it will be filled in with the + * old SUDOERS_LOCALE_* value. + */ +#ifdef HAVE_SETLOCALE +bool sudoers_setlocale(int newlocale, int *prevlocale) { char *res = NULL; @@ -75,12 +80,21 @@ sudoers_setlocale(int newlocale, int *prevlocale) } break; } - return res ? 1 : 0; + return res ? true : false; } #else -int +bool sudoers_setlocale(int newlocale, int *prevlocale) { - return 1; + switch (newlocale) { + case SUDOERS_LOCALE_USER: + case SUDOERS_LOCALE_SUDOERS: + if (prevlocale) + *prevlocale = current_locale; + current_locale = newlocale; + return true; + default: + return false; + } } #endif /* HAVE_SETLOCALE */ diff --git a/plugins/sudoers/logging.h b/plugins/sudoers/logging.h index 290839a10..f89a1ed26 100644 --- a/plugins/sudoers/logging.h +++ b/plugins/sudoers/logging.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 1999-2005, 2009-2010 + * Copyright (c) 1999-2005, 2009-2012 * Todd C. Miller * * Permission to use, copy, modify, and distribute this software for any @@ -58,6 +58,8 @@ */ #define LOG_INDENT " " +bool sudoers_setlocale(int newlocale, int *prevlocale); +int sudoers_getlocale(void); void audit_success(char *exec_args[]); void audit_failure(char *exec_args[], char const *const fmt, ...); void log_allowed(int status); @@ -67,7 +69,5 @@ void log_failure(int status, int flags); void log_error(int flags, const char *fmt, ...) __printflike(2, 3); void log_fatal(int flags, const char *fmt, ...) __printflike(2, 3) __attribute__((__noreturn__)); void writeln_wrap(FILE *fp, char *line, size_t len, size_t maxlen); -int sudoers_setlocale(int newlocale, int *prevlocale); -int sudoers_getlocale(void); #endif /* _LOGGING_H */ diff --git a/plugins/sudoers/sudoers.h b/plugins/sudoers/sudoers.h index 430e2a035..f51928b55 100644 --- a/plugins/sudoers/sudoers.h +++ b/plugins/sudoers/sudoers.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 1993-1996, 1998-2005, 2007-2011 + * Copyright (c) 1993-1996, 1998-2005, 2007-2012 * Todd C. Miller * * Permission to use, copy, modify, and distribute this software for any