Imported Upstream version 1.8.2
[debian/sudo] / src / parse_args.c
index e9f09e47faeb57f0dadbd4959e8233442061f595..f8aac4b62b9f4b07c6042eec0e0338cb24fdbb0d 100644 (file)
@@ -177,7 +177,7 @@ parse_args(int argc, char **argv, int *nargc, char ***nargv, char ***settingsp,
                    break;
                case 'C':
                    if (atoi(optarg) < 3) {
-                       warningx("the argument to -C must be a number greater than or equal to 3");
+                       warningx(_("the argument to -C must be a number greater than or equal to 3"));
                        usage(1);
                    }
                    sudo_settings[ARG_CLOSEFROM].value = optarg;
@@ -189,7 +189,7 @@ parse_args(int argc, char **argv, int *nargc, char ***nargv, char ***settingsp,
 #endif
                case 'D':
                    if ((debug_level = atoi(optarg)) < 1 || debug_level > 9) {
-                       warningx("the argument to -D must be between 1 and 9 inclusive");
+                       warningx(_("the argument to -D must be between 1 and 9 inclusive"));
                        usage(1);
                    }
                    sudo_settings[ARG_DEBUG_LEVEL].value = optarg;
@@ -270,7 +270,7 @@ parse_args(int argc, char **argv, int *nargc, char ***nargv, char ***settingsp,
                    break;
                case 'U':
                    if ((getpwnam(optarg)) == NULL)
-                       errorx(1, "unknown user: %s", optarg);
+                       errorx(1, _("unknown user: %s"), optarg);
                    list_user = optarg;
                    break;
                case 'u':
@@ -329,11 +329,11 @@ parse_args(int argc, char **argv, int *nargc, char ***nargv, char ***settingsp,
 
     if (ISSET(flags, MODE_LOGIN_SHELL)) {
        if (ISSET(flags, MODE_SHELL)) {
-           warningx("you may not specify both the `-i' and `-s' options");
+           warningx(_("you may not specify both the `-i' and `-s' options"));
            usage(1);
        }
        if (ISSET(flags, MODE_PRESERVE_ENV)) {
-           warningx("you may not specify both the `-i' and `-E' options");
+           warningx(_("you may not specify both the `-i' and `-E' options"));
            usage(1);
        }
        SET(flags, MODE_SHELL);
@@ -343,9 +343,9 @@ parse_args(int argc, char **argv, int *nargc, char ***nargv, char ***settingsp,
     if (mode == MODE_EDIT &&
        (ISSET(flags, MODE_PRESERVE_ENV) || env_add[0] != NULL)) {
        if (ISSET(mode, MODE_PRESERVE_ENV))
-           warningx("the `-E' option is not valid in edit mode");
+           warningx(_("the `-E' option is not valid in edit mode"));
        if (env_add[0] != NULL)
-           warningx("you may not specify environment variables in edit mode");
+           warningx(_("you may not specify environment variables in edit mode"));
        usage(1);
     }
     if ((runas_user != NULL || runas_group != NULL) &&
@@ -353,11 +353,11 @@ parse_args(int argc, char **argv, int *nargc, char ***nargv, char ***settingsp,
        usage(1);
     }
     if (list_user != NULL && mode != MODE_LIST && mode != MODE_CHECK) {
-       warningx("the `-U' option may only be used with the `-l' option");
+       warningx(_("the `-U' option may only be used with the `-l' option"));
        usage(1);
     }
     if (ISSET(tgetpass_flags, TGP_STDIN) && ISSET(tgetpass_flags, TGP_ASKPASS)) {
-       warningx("the `-A' and `-S' options may not be used together");
+       warningx(_("the `-A' and `-S' options may not be used together"));
        usage(1);
     }
     if ((argc == 0 && mode == MODE_EDIT) ||
@@ -385,17 +385,28 @@ parse_args(int argc, char **argv, int *nargc, char ***nargv, char ***settingsp,
            memcpy(av + 1, argv, argc * sizeof(char *));
        } else {
            /* shell -c "command" */
-           char *src, *dst, *end;
+           char *cmnd, *src, *dst;
            size_t cmnd_size = (size_t) (argv[argc - 1] - argv[0]) +
-                   strlen(argv[argc - 1]) + 1;
+               strlen(argv[argc - 1]) + 1;
+
+           cmnd = dst = emalloc2(cmnd_size, 2);
+           for (av = argv; *av != NULL; av++) {
+               for (src = *av; *src != '\0'; src++) {
+                   /* quote potential meta characters */
+                   if (!isalnum((unsigned char)*src) && *src != '_' && *src != '-')
+                       *dst++ = '\\';
+                   *dst++ = *src;
+               }
+               *dst++ = ' ';
+           }
+           if (cmnd != dst)
+               dst--;  /* replace last space with a NUL */
+           *dst = '\0';
+
            ac = 3;
            av = emalloc2(ac + 1, sizeof(char *));
            av[1] = "-c";
-           av[2] = dst = emalloc(cmnd_size);
-           src = argv[0];
-           for (end = src + cmnd_size - 1; src < end; src++, dst++)
-               *dst = *src == '\0' ? ' ' : *src;
-           *dst = '\0';
+           av[2] = cmnd;
        }
        av[0] = (char *)user_details.shell; /* plugin may override shell */
        av[ac] = NULL;
@@ -415,7 +426,7 @@ parse_args(int argc, char **argv, int *nargc, char ***nargv, char ***settingsp,
            settings[j] = fmt_string(sudo_settings[i].name,
                sudo_settings[i].value);
            if (settings[j] == NULL)
-               errorx(1, "unable to allocate memory");
+               errorx(1, _("unable to allocate memory"));
            j++;
        }
     }
@@ -428,7 +439,7 @@ parse_args(int argc, char **argv, int *nargc, char ***nargv, char ***settingsp,
        argv--;
        argv[0] = "sudoedit";
 #else
-       errorx(1, "sudoedit is not supported on this platform");
+       errorx(1, _("sudoedit is not supported on this platform"));
 #endif
     }
 
@@ -485,7 +496,7 @@ usage(int fatal)
     lbuf_init(&lbuf, fatal ? usage_err : usage_out, ulen, NULL,
        user_details.ts_cols);
     for (i = 0; uvec[i] != NULL; i++) {
-       lbuf_append(&lbuf, "usage: ", getprogname(), uvec[i], NULL);
+       lbuf_append(&lbuf, "usage: %s%s", getprogname(), uvec[i]);
        lbuf_print(&lbuf);
     }
     lbuf_destroy(&lbuf);
@@ -499,7 +510,7 @@ usage(int fatal)
 static void
 usage_excl(int fatal)
 {
-    warningx("Only one of the -e, -h, -i, -K, -l, -s, -v or -V options may be specified");
+    warningx(_("Only one of the -e, -h, -i, -K, -l, -s, -v or -V options may be specified"));
     usage(fatal);
 }
 
@@ -512,81 +523,74 @@ help(void)
 
     lbuf_init(&lbuf, usage_out, indent, NULL, user_details.ts_cols);
     if (strcmp(pname, "sudoedit") == 0)
-       lbuf_append(&lbuf, pname,  " - edit files as another user\n\n", NULL);
+       lbuf_append(&lbuf, _("%s - edit files as another user\n\n"), pname);
     else
-       lbuf_append(&lbuf, pname,  " - execute a command as another user\n\n", NULL);
+       lbuf_append(&lbuf, _("%s - execute a command as another user\n\n"), pname);
     lbuf_print(&lbuf);
 
     usage(0);
 
-    lbuf_append(&lbuf, "\nOptions:\n", NULL);
+    lbuf_append(&lbuf, _("\nOptions:\n"));
 #ifdef HAVE_BSD_AUTH_H
-    lbuf_append(&lbuf,
-       "  -A            use helper program for password prompting\n", NULL);
+    lbuf_append(&lbuf, "  -A            %s",
+       _("use helper program for password prompting\n"));
 #endif
-    lbuf_append(&lbuf,
-       "  -a type       use specified BSD authentication type\n", NULL);
-    lbuf_append(&lbuf,
-       "  -b            run command in the background\n", NULL);
-    lbuf_append(&lbuf,
-       "  -C fd         close all file descriptors >= fd\n", NULL);
+    lbuf_append(&lbuf, "  -a type       %s",
+       _("use specified BSD authentication type\n"));
+    lbuf_append(&lbuf, "  -b            %s",
+       _("run command in the background\n"));
+    lbuf_append(&lbuf, "  -C fd         %s",
+       _("close all file descriptors >= fd\n"));
 #ifdef HAVE_LOGIN_CAP_H
-    lbuf_append(&lbuf,
-       "  -c class      run command with specified login class\n", NULL);
+    lbuf_append(&lbuf, "  -c class      %s",
+       _("run command with specified login class\n"));
 #endif
-    lbuf_append(&lbuf,
-       "  -E            preserve user environment when executing command\n",
-       NULL);
-    lbuf_append(&lbuf,
-       "  -e            edit files instead of running a command\n", NULL);
-    lbuf_append(&lbuf,
-       "  -g group      execute command as the specified group\n", NULL);
-    lbuf_append(&lbuf,
-       "  -H            set HOME variable to target user's home dir.\n",
-       NULL);
-    lbuf_append(&lbuf,
-       "  -h            display help message and exit\n", NULL);
-    lbuf_append(&lbuf,
-       "  -i [command]  run a login shell as target user\n", NULL);
-    lbuf_append(&lbuf,
-       "  -K            remove timestamp file completely\n", NULL);
-    lbuf_append(&lbuf,
-       "  -k            invalidate timestamp file\n", NULL);
-    lbuf_append(&lbuf,
-       "  -l[l] command list user's available commands\n", NULL);
-    lbuf_append(&lbuf,
-       "  -n            non-interactive mode, will not prompt user\n", NULL);
-    lbuf_append(&lbuf,
-       "  -P            preserve group vector instead of setting to target's\n",
-       NULL);
-    lbuf_append(&lbuf,
-       "  -p prompt     use specified password prompt\n", NULL);
+    lbuf_append(&lbuf, "  -E            %s",
+       _("preserve user environment when executing command\n"));
+    lbuf_append(&lbuf, "  -e            %s",
+       _("edit files instead of running a command\n"));
+    lbuf_append(&lbuf, "  -g group      %s",
+       _("execute command as the specified group\n"));
+    lbuf_append(&lbuf, "  -H            %s",
+       _("set HOME variable to target user's home dir.\n"));
+    lbuf_append(&lbuf, "  -h            %s",
+       _("display help message and exit\n"));
+    lbuf_append(&lbuf, "  -i [command]  %s",
+       _("run a login shell as target user\n"));
+    lbuf_append(&lbuf, "  -K            %s",
+       _("remove timestamp file completely\n"));
+    lbuf_append(&lbuf, "  -k            %s",
+       _("invalidate timestamp file\n"));
+    lbuf_append(&lbuf, "  -l[l] command %s",
+       _("list user's available commands\n"));
+    lbuf_append(&lbuf, "  -n            %s",
+       _("non-interactive mode, will not prompt user\n"));
+    lbuf_append(&lbuf, "  -P            %s",
+       _("preserve group vector instead of setting to target's\n"));
+    lbuf_append(&lbuf, "  -p prompt     %s",
+       _("use specified password prompt\n"));
 #ifdef HAVE_SELINUX
-    lbuf_append(&lbuf,
-       "  -r role       create SELinux security context with specified role\n",
-       NULL);
+    lbuf_append(&lbuf, "  -r role       %s",
+       _("create SELinux security context with specified role\n"));
 #endif
+    lbuf_append(&lbuf, "  -S            %s",
+       _("read password from standard input\n"));
     lbuf_append(&lbuf,
-       "  -S            read password from standard input\n", NULL);
-    lbuf_append(&lbuf,
-       "  -s [command]  run a shell as target user\n", NULL);
+       "  -s [command]  %s", _("run a shell as target user\n"));
 #ifdef HAVE_SELINUX
-    lbuf_append(&lbuf,
-       "  -t type       create SELinux security context with specified role\n",
-       NULL);
+    lbuf_append(&lbuf, "  -t type       %s",
+       _("create SELinux security context with specified role\n"));
 #endif
-    lbuf_append(&lbuf,
-       "  -U user       when listing, list specified user's privileges\n",
-       NULL);
-    lbuf_append(&lbuf,
-       "  -u user       run command (or edit file) as specified user\n", NULL);
-    lbuf_append(&lbuf,
-       "  -V            display version information and exit\n", NULL);
-    lbuf_append(&lbuf,
-       "  -v            update user's timestamp without running a command\n",
-       NULL);
-    lbuf_append(&lbuf,
-       "  --            stop processing command line arguments\n", NULL);
+    lbuf_append(&lbuf, "  -U user       %s",
+       _("when listing, list specified user's privileges\n"));
+    lbuf_append(&lbuf, "  -u user       %s",
+       _("run command (or edit file) as specified user\n"));
+    lbuf_append(&lbuf, "  -V            %s",
+       _("display version information and exit\n"));
+    lbuf_append(&lbuf, "  -v            %s",
+       _("update user's timestamp without running a command\n"));
+    lbuf_append(&lbuf, "  --            %s",
+       _("stop processing command line arguments\n"));
     lbuf_print(&lbuf);
     lbuf_destroy(&lbuf);
     exit(0);