]> granicus.if.org Git - sudo/commitdiff
Call gettext() in sudoerserror() in the user's locale and pass the untranslated strin...
authorTodd C. Miller <Todd.Miller@courtesan.com>
Sun, 25 Nov 2012 14:33:58 +0000 (09:33 -0500)
committerTodd C. Miller <Todd.Miller@courtesan.com>
Sun, 25 Nov 2012 14:33:58 +0000 (09:33 -0500)
Makefile.in
plugins/sudoers/alias.c
plugins/sudoers/gram.c
plugins/sudoers/gram.y
plugins/sudoers/toke.c
plugins/sudoers/toke.l
plugins/sudoers/toke_util.c

index bcc940d4fdc02f98acb14fa4db13abbff011145f..52bb66c68076a176f92e407a68f24304f11f0d11 100644 (file)
@@ -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;; \
index eb95039f2ed5058b50645ecf8db77fddb39d0c54..1079bf2a897f0f258685f1edd7fa7b212a0a1f68 100644 (file)
@@ -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);
     }
index 665ad6d0c989150b2dbc606c75c4ccf734fe9129..70b2e002a45d18268fcd9d44693afbf9e0d35f30 100644 (file)
@@ -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;
index 7b11ab07562f2cd382d5b4104114c2ef78e3f21f..8140c4e97ce00afecbfc875302e0857fc55fd75b 100644 (file)
@@ -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;
index b0d83b99f26c31c72acab0b3e8f94e81e1608350..2b3f74ebedf16204f048675225c626c31e1b791a 100644 (file)
@@ -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) {
index 96ca8269228cf7f7eadf9e435756929718f7c99b..ab81e7e21f6469808b3f3514086a67b01a7aa1c1 100644 (file)
@@ -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) {
index 0417eb047f973619e9ea44e002be3c43677b9eca..b747b66e9a707945b678557ac22a1d0aecbb13eb 100644 (file)
@@ -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;