From: Todd C. Miller Date: Sun, 25 Nov 2012 14:33:58 +0000 (-0500) Subject: Call gettext() in sudoerserror() in the user's locale and pass the untranslated strin... X-Git-Tag: SUDO_1_8_7~1^2~320 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=15c69e0e3f19cdbb25d2d017188c14ade5b7a50e;p=sudo Call gettext() in sudoerserror() in the user's locale and pass the untranslated string to it. --- diff --git a/Makefile.in b/Makefile.in index bcc940d4f..52bb66c68 100644 --- a/Makefile.in +++ b/Makefile.in @@ -180,10 +180,11 @@ update-pot: case "$$domain" in \ sudo) tmpfiles=; cfiles="src/*c common/*c compat/*c";; \ sudoers) \ + echo "syntax error" > confstr.sh; \ sed -n -e 's/^badpass_message="/gettext "/p' \ -e 's/^passprompt="/gettext "/p' \ -e 's/^mailsub="/gettext "/p' configure.in \ - > confstr.sh; \ + >> confstr.sh; \ tmpfiles=confstr.sh; \ cfiles="plugins/sudoers/*.c plugins/sudoers/auth/*.c";; \ *) echo unknown domain $$domain; continue;; \ diff --git a/plugins/sudoers/alias.c b/plugins/sudoers/alias.c index eb95039f2..1079bf2a8 100644 --- a/plugins/sudoers/alias.c +++ b/plugins/sudoers/alias.c @@ -122,7 +122,7 @@ alias_add(char *name, int type, struct member *members) /* a->seqno = 0; */ list2tq(&a->members, members); if (rbinsert(aliases, a)) { - snprintf(errbuf, sizeof(errbuf), _("Alias `%s' already defined"), name); + snprintf(errbuf, sizeof(errbuf), N_("Alias `%s' already defined"), name); alias_free(a); debug_return_str(errbuf); } diff --git a/plugins/sudoers/gram.c b/plugins/sudoers/gram.c index 665ad6d0c..70b2e002a 100644 --- a/plugins/sudoers/gram.c +++ b/plugins/sudoers/gram.c @@ -147,9 +147,30 @@ sudoerserror(const char *s) if (sudoers_warnings && s != NULL) { LEXTRACE("<*> "); #ifndef TRACELEXER - /* XXX 's' will be in sudoers locale, not user's */ - if (trace_print == NULL || trace_print == sudoers_trace_print) - warningx(N_(">>> %s: %s near line %d <<<"), sudoers, s, sudolineno); + if (trace_print == NULL || trace_print == sudoers_trace_print) { + int oldlocale; + const char fmt[] = ">>> %s: %s near line %d <<<\n"; + + /* Warnings are displayed in the user's locale. */ + sudoers_setlocale(SUDOERS_LOCALE_USER, &oldlocale); + if (sudo_conv != NULL) { + struct sudo_conv_message msg; + struct sudo_conv_reply repl; + char *str; + + easprintf(&str, _(fmt), sudoers, _(s), sudolineno); + + memset(&msg, 0, sizeof(repl)); + memset(&repl, 0, sizeof(repl)); + msg.msg_type = SUDO_CONV_ERROR_MSG; + msg.msg = str; + sudo_conv(1, &msg, &repl); + efree(str); + } else { + fprintf(stderr, _(fmt), sudoers, _(s), sudolineno); + } + sudoers_setlocale(oldlocale, NULL); + } #endif } parse_error = true; diff --git a/plugins/sudoers/gram.y b/plugins/sudoers/gram.y index 7b11ab075..8140c4e97 100644 --- a/plugins/sudoers/gram.y +++ b/plugins/sudoers/gram.y @@ -109,9 +109,30 @@ sudoerserror(const char *s) if (sudoers_warnings && s != NULL) { LEXTRACE("<*> "); #ifndef TRACELEXER - /* XXX 's' will be in sudoers locale, not user's */ - if (trace_print == NULL || trace_print == sudoers_trace_print) - warningx(N_(">>> %s: %s near line %d <<<"), sudoers, s, sudolineno); + if (trace_print == NULL || trace_print == sudoers_trace_print) { + int oldlocale; + const char fmt[] = ">>> %s: %s near line %d <<<\n"; + + /* Warnings are displayed in the user's locale. */ + sudoers_setlocale(SUDOERS_LOCALE_USER, &oldlocale); + if (sudo_conv != NULL) { + struct sudo_conv_message msg; + struct sudo_conv_reply repl; + char *str; + + easprintf(&str, _(fmt), sudoers, _(s), sudolineno); + + memset(&msg, 0, sizeof(repl)); + memset(&repl, 0, sizeof(repl)); + msg.msg_type = SUDO_CONV_ERROR_MSG; + msg.msg = str; + sudo_conv(1, &msg, &repl); + efree(str); + } else { + fprintf(stderr, _(fmt), sudoers, _(s), sudolineno); + } + sudoers_setlocale(oldlocale, NULL); + } #endif } parse_error = true; diff --git a/plugins/sudoers/toke.c b/plugins/sudoers/toke.c index b0d83b99f..2b3f74ebe 100644 --- a/plugins/sudoers/toke.c +++ b/plugins/sudoers/toke.c @@ -3411,13 +3411,8 @@ switch_dir(struct include_stack *stack, char *dirpath) if (!(dir = opendir(dirpath))) { if (errno != ENOENT) { - char *errbuf; - if (asprintf(&errbuf, _("%s: %s"), dirpath, strerror(errno)) != -1) { - sudoerserror(errbuf); - free(errbuf); - } else { - sudoerserror(strerror(errno)); - } + warning("%s", dirpath); + sudoerserror(NULL); } goto done; } @@ -3539,14 +3534,15 @@ _push_include(char *path, bool isdir) /* push current state onto stack */ if (idepth >= istacksize) { if (idepth > MAX_SUDOERS_DEPTH) { - sudoerserror(_("too many levels of includes")); + sudoerserror(N_("too many levels of includes")); debug_return_bool(false); } istacksize += SUDOERS_STACK_INCREMENT; istack = (struct include_stack *) realloc(istack, sizeof(*istack) * istacksize); if (istack == NULL) { - sudoerserror(strerror(errno)); + warning(NULL); + sudoerserror(NULL); debug_return_bool(false); } } @@ -3697,7 +3693,8 @@ parse_include(char *base) len += (int)(ep - cp); path = pp = malloc(len + dirlen + 1); if (path == NULL) { - sudoerserror(strerror(errno)); + warning(NULL); + sudoerserror(NULL); debug_return_str(NULL); } if (dirlen) { diff --git a/plugins/sudoers/toke.l b/plugins/sudoers/toke.l index 96ca82692..ab81e7e21 100644 --- a/plugins/sudoers/toke.l +++ b/plugins/sudoers/toke.l @@ -689,13 +689,8 @@ switch_dir(struct include_stack *stack, char *dirpath) if (!(dir = opendir(dirpath))) { if (errno != ENOENT) { - char *errbuf; - if (asprintf(&errbuf, _("%s: %s"), dirpath, strerror(errno)) != -1) { - sudoerserror(errbuf); - free(errbuf); - } else { - sudoerserror(strerror(errno)); - } + warning("%s", dirpath); + sudoerserror(NULL); } goto done; } @@ -817,14 +812,15 @@ _push_include(char *path, bool isdir) /* push current state onto stack */ if (idepth >= istacksize) { if (idepth > MAX_SUDOERS_DEPTH) { - sudoerserror(_("too many levels of includes")); + sudoerserror(N_("too many levels of includes")); debug_return_bool(false); } istacksize += SUDOERS_STACK_INCREMENT; istack = (struct include_stack *) realloc(istack, sizeof(*istack) * istacksize); if (istack == NULL) { - sudoerserror(strerror(errno)); + warning(NULL); + sudoerserror(NULL); debug_return_bool(false); } } @@ -975,7 +971,8 @@ parse_include(char *base) len += (int)(ep - cp); path = pp = malloc(len + dirlen + 1); if (path == NULL) { - sudoerserror(strerror(errno)); + warning(NULL); + sudoerserror(NULL); debug_return_str(NULL); } if (dirlen) { diff --git a/plugins/sudoers/toke_util.c b/plugins/sudoers/toke_util.c index 0417eb047..b747b66e9 100644 --- a/plugins/sudoers/toke_util.c +++ b/plugins/sudoers/toke_util.c @@ -111,7 +111,8 @@ fill_txt(const char *src, int len, int olen) dst = olen ? realloc(sudoerslval.string, olen + len + 1) : malloc(len + 1); if (dst == NULL) { - sudoerserror(strerror(errno)); + warning(NULL); + sudoerserror(NULL); debug_return_bool(false); } sudoerslval.string = dst; @@ -165,7 +166,8 @@ fill_cmnd(const char *src, int len) dst = sudoerslval.command.cmnd = (char *) malloc(len + 1); if (sudoerslval.command.cmnd == NULL) { - sudoerserror(strerror(errno)); + warning(NULL); + sudoerserror(NULL); debug_return_bool(false); } @@ -205,7 +207,8 @@ fill_args(const char *s, int len, int addspace) (char *) malloc(arg_size); if (p == NULL) { efree(sudoerslval.command.args); - sudoerserror(strerror(errno)); + warning(NULL); + sudoerserror(NULL); debug_return_bool(false); } else sudoerslval.command.args = p; @@ -216,7 +219,8 @@ fill_args(const char *s, int len, int addspace) if (addspace) *p++ = ' '; if (strlcpy(p, s, arg_size - (p - sudoerslval.command.args)) != len) { - sudoerserror(_("fill_args: buffer overflow")); /* paranoia */ + warningx(N_("fill_args: buffer overflow")); /* paranoia */ + sudoerserror(NULL); debug_return_bool(false); } arg_len = new_len;