2 * Copyright (c) 1996, 1998-2005, 2007-2009
3 * Todd C. Miller <Todd.Miller@courtesan.com>
5 * Permission to use, copy, modify, and distribute this software for any
6 * purpose with or without fee is hereby granted, provided that the above
7 * copyright notice and this permission notice appear in all copies.
9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 * Sponsored in part by the Defense Advanced Research Projects
18 * Agency (DARPA) and Air Force Research Laboratory, Air Force
19 * Materiel Command, USAF, under agreement number F39502-99-1-0512.
23 * Lock the sudoers file for safe editing (ala vipw) and check for parse errors.
34 #include <sys/types.h>
35 #include <sys/param.h>
37 #include <sys/socket.h>
40 # include <sys/file.h>
51 #endif /* STDC_HEADERS */
55 # ifdef HAVE_STRINGS_H
58 #endif /* HAVE_STRING_H */
61 #endif /* HAVE_UNISTD_H */
68 #include <netinet/in.h>
69 #include <arpa/inet.h>
71 #if TIME_WITH_SYS_TIME
80 # include <emul/timespec.h>
84 #include "interfaces.h"
90 __unused static const char rcsid[] = "$Sudo: visudo.c,v 1.234 2009/05/25 12:02:42 millert Exp $";
100 struct sudoersfile *next;
104 * Function prototypes
106 static RETSIGTYPE quit __P((int));
107 static char *get_args __P((char *));
108 static char *get_editor __P((char **));
109 static void get_hostname __P((void));
110 static char whatnow __P((void));
111 static int check_aliases __P((int, int));
112 static int check_syntax __P((char *, int, int));
113 static int edit_sudoers __P((struct sudoersfile *, char *, char *, int));
114 static int install_sudoers __P((struct sudoersfile *, int));
115 static int print_unused __P((void *, void *));
116 static int reparse_sudoers __P((char *, char *, int, int));
117 static int run_command __P((char *, char **));
118 static void print_undefined __P((char *name, int, int, int));
119 static void setup_signals __P((void));
120 static void usage __P((void)) __attribute__((__noreturn__));
122 extern void yyerror __P((const char *));
123 extern void yyrestart __P((FILE *));
126 * External globals exported by the parser
128 extern struct rbtree *aliases;
130 extern char *sudoers, *errorfile;
131 extern int errorlineno, parse_error;
142 struct interface *interfaces;
143 struct sudo_user sudo_user;
144 struct passwd *list_pw;
145 static struct sudoerslist {
146 struct sudoersfile *first, *last;
148 static struct rbtree *alias_freelist;
155 struct sudoersfile *sp;
156 char *args, *editor, *sudoers_path;
157 int ch, checkonly, quiet, strict, oldperms;
158 #if defined(SUDO_DEVEL) && defined(__OpenBSD__)
159 extern char *malloc_options;
160 malloc_options = "AFGJPR";
164 if ((Argc = argc) < 1)
170 checkonly = oldperms = quiet = strict = FALSE;
171 sudoers_path = _PATH_SUDOERS;
172 while ((ch = getopt(argc, argv, "Vcf:sq")) != -1) {
175 (void) printf("%s version %s\n", getprogname(), PACKAGE_VERSION);
178 checkonly++; /* check mode */
181 sudoers_path = optarg; /* sudoers file path */
185 strict++; /* strict mode */
188 quiet++; /* quiet mode */
202 /* Mock up a fake sudo_user struct. */
204 if ((sudo_user.pw = sudo_getpwuid(getuid())) == NULL)
205 errorx(1, "you don't exist in the passwd database");
208 /* Setup defaults data structures. */
212 exit(check_syntax(sudoers_path, quiet, strict));
215 * Parse the existing sudoers file(s) in quiet mode to highlight any
216 * existing errors and to pull in editor and env_editor conf values.
218 if ((yyin = open_sudoers(sudoers_path, TRUE, NULL)) == NULL) {
219 error(1, "%s", sudoers_path);
221 init_parser(sudoers_path, 0);
223 (void) update_defaults(SETDEF_GENERIC|SETDEF_HOST|SETDEF_USER);
225 editor = get_editor(&args);
227 /* Install signal handlers to clean up temp files if we are killed. */
230 /* Edit the sudoers file(s) */
231 tq_foreach_fwd(&sudoerslist, sp) {
234 if (sp != tq_first(&sudoerslist)) {
235 printf("press return to edit %s: ", sp->path);
236 while ((ch = getchar()) != EOF && ch != '\n')
239 edit_sudoers(sp, editor, args, -1);
242 /* Check edited files for a parse error and re-edit any that fail. */
243 reparse_sudoers(editor, args, strict, quiet);
245 /* Install the sudoers temp files. */
246 tq_foreach_fwd(&sudoerslist, sp) {
248 (void) unlink(sp->tpath);
250 (void) install_sudoers(sp, oldperms);
257 * Edit each sudoers file.
258 * Returns TRUE on success, else FALSE.
261 edit_sudoers(sp, editor, args, lineno)
262 struct sudoersfile *sp;
266 int tfd; /* sudoers temp file descriptor */
267 int modified; /* was the file modified? */
268 int ac; /* argument count */
269 char **av; /* argument vector for run_command */
270 char *cp; /* scratch char pointer */
271 char buf[PATH_MAX*2]; /* buffer used for copying files */
272 char linestr[64]; /* string version of lineno */
273 struct timespec ts1, ts2; /* time before and after edit */
274 struct timespec orig_mtim; /* starting mtime of sudoers file */
275 off_t orig_size; /* starting size of sudoers file */
276 ssize_t nread; /* number of bytes read */
277 struct stat sb; /* stat buffer */
280 if (fstat(sp->fd, &sb) == -1)
282 if (stat(sp->path, &sb) == -1)
284 error(1, "can't stat %s", sp->path);
285 orig_size = sb.st_size;
286 orig_mtim.tv_sec = mtim_getsec(sb);
287 orig_mtim.tv_nsec = mtim_getnsec(sb);
289 /* Create the temp file if needed and set timestamp. */
290 if (sp->tpath == NULL) {
291 easprintf(&sp->tpath, "%s.tmp", sp->path);
292 tfd = open(sp->tpath, O_WRONLY | O_CREAT | O_TRUNC, 0600);
294 error(1, "%s", sp->tpath);
296 /* Copy sp->path -> sp->tpath and reset the mtime. */
297 if (orig_size != 0) {
298 (void) lseek(sp->fd, (off_t)0, SEEK_SET);
299 while ((nread = read(sp->fd, buf, sizeof(buf))) > 0)
300 if (write(tfd, buf, nread) != nread)
301 error(1, "write error");
303 /* Add missing newline at EOF if needed. */
304 if (nread > 0 && buf[nread - 1] != '\n') {
311 (void) touch(-1, sp->tpath, &orig_mtim);
313 /* Find the length of the argument vector */
314 ac = 3 + (lineno > 0);
319 for (wasblank = FALSE, cp = args; *cp; cp++) {
320 if (isblank((unsigned char) *cp))
329 /* Build up argument vector for the command */
330 av = emalloc2(ac, sizeof(char *));
331 if ((av[0] = strrchr(editor, '/')) != NULL)
337 (void) snprintf(linestr, sizeof(linestr), "+%d", lineno);
341 for ((cp = strtok(args, " \t")); cp; (cp = strtok(NULL, " \t")))
344 av[ac++] = sp->tpath;
349 * We cannot check the editor's exit value against 0 since
350 * XPG4 specifies that vi's exit value is a function of the
351 * number of errors during editing (?!?!).
354 if (run_command(editor, av) != -1) {
359 if (stat(sp->tpath, &sb) < 0) {
360 warningx("cannot stat temporary file (%s), %s unchanged",
361 sp->tpath, sp->path);
364 if (sb.st_size == 0 && orig_size != 0) {
365 warningx("zero length temporary file (%s), %s unchanged",
366 sp->tpath, sp->path);
371 warningx("editor (%s) failed, %s unchanged", editor, sp->path);
375 /* Set modified bit if use changed the file. */
377 if (orig_size == sb.st_size &&
378 orig_mtim.tv_sec == mtim_getsec(sb) &&
379 orig_mtim.tv_nsec == mtim_getnsec(sb)) {
381 * If mtime and size match but the user spent no measurable
382 * time in the editor we can't tell if the file was changed.
384 #ifdef HAVE_TIMESPECSUB2
385 timespecsub(&ts1, &ts2);
387 timespecsub(&ts1, &ts2, &ts2);
389 if (timespecisset(&ts2))
394 * If modified in this edit session, mark as modified.
397 sp->modified = modified;
399 warningx("%s unchanged", sp->tpath);
405 * Parse sudoers after editing and re-edit any ones that caused a parse error.
406 * Returns TRUE on success, else FALSE.
409 reparse_sudoers(editor, args, strict, quiet)
413 struct sudoersfile *sp, *last;
418 * Parse the edited sudoers files and do sanity checking
421 sp = tq_first(&sudoerslist);
422 last = tq_last(&sudoerslist);
423 fp = fopen(sp->tpath, "r+");
425 errorx(1, "can't re-open temporary file (%s), %s unchanged.",
426 sp->tpath, sp->path);
428 /* Clean slate for each parse */
430 init_parser(sp->path, quiet);
432 /* Parse the sudoers temp file */
434 if (yyparse() && parse_error != TRUE) {
435 warningx("unabled to parse temporary file (%s), unknown error",
440 if (check_aliases(strict, quiet) != 0)
444 * Got an error, prompt the user for what to do now
448 case 'Q' : parse_error = FALSE; /* ignore parse error */
450 case 'x' : cleanup(0);
456 /* Edit file with the parse error */
457 tq_foreach_fwd(&sudoerslist, sp) {
458 if (errorfile == NULL || strcmp(sp->path, errorfile) == 0) {
459 edit_sudoers(sp, editor, args, errorlineno);
464 errorx(1, "internal error, can't find %s in list!", sudoers);
467 /* If any new #include directives were added, edit them too. */
468 for (sp = last->next; sp != NULL; sp = sp->next) {
469 printf("press return to edit %s: ", sp->path);
470 while ((ch = getchar()) != EOF && ch != '\n')
472 edit_sudoers(sp, editor, args, errorlineno);
474 } while (parse_error);
480 * Set the owner and mode on a sudoers temp file and
481 * move it into place. Returns TRUE on success, else FALSE.
484 install_sudoers(sp, oldperms)
485 struct sudoersfile *sp;
491 * Change mode and ownership of temp file so when
492 * we move it to sp->path things are kosher.
495 /* Use perms of the existing file. */
497 if (fstat(sp->fd, &sb) == -1)
499 if (stat(sp->path, &sb) == -1)
501 error(1, "can't stat %s", sp->path);
502 (void) chown(sp->tpath, sb.st_uid, sb.st_gid);
503 (void) chmod(sp->tpath, sb.st_mode & 0777);
505 if (chown(sp->tpath, SUDOERS_UID, SUDOERS_GID) != 0) {
506 warning("unable to set (uid, gid) of %s to (%d, %d)",
507 sp->tpath, SUDOERS_UID, SUDOERS_GID);
510 if (chmod(sp->tpath, SUDOERS_MODE) != 0) {
511 warning("unable to change mode of %s to 0%o", sp->tpath,
518 * Now that sp->tpath is sane (parses ok) it needs to be
519 * rename(2)'d to sp->path. If the rename(2) fails we try using
520 * mv(1) in case sp->tpath and sp->path are on different file systems.
522 if (rename(sp->tpath, sp->path) == 0) {
526 if (errno == EXDEV) {
528 warningx("%s and %s not on the same file system, using mv to rename",
529 sp->tpath, sp->path);
531 /* Build up argument vector for the command */
532 if ((av[0] = strrchr(_PATH_MV, '/')) != NULL)
541 if (run_command(_PATH_MV, av)) {
542 warningx("command failed: '%s %s %s', %s unchanged",
543 _PATH_MV, sp->tpath, sp->path, sp->path);
544 (void) unlink(sp->tpath);
552 warning("error renaming %s, %s unchanged", sp->tpath, sp->path);
553 (void) unlink(sp->tpath);
597 const struct passwd *pw;
599 return (pw->pw_passwd);
603 * Assuming a parse error occurred, prompt the user for what they want
604 * to do now. Returns the first letter of their choice.
612 (void) fputs("What now? ", stdout);
614 for (c = choice; c != '\n' && c != EOF;)
626 (void) puts("Options are:");
627 (void) puts(" (e)dit sudoers file again");
628 (void) puts(" e(x)it without saving changes to sudoers file");
629 (void) puts(" (Q)uit and save changes to sudoers file (DANGER!)\n");
635 * Install signal handlers for visudo.
643 * Setup signal handlers to cleanup nicely.
645 zero_bytes(&sa, sizeof(sa));
646 sigemptyset(&sa.sa_mask);
647 sa.sa_flags = SA_RESTART;
648 sa.sa_handler = quit;
649 (void) sigaction(SIGTERM, &sa, NULL);
650 (void) sigaction(SIGHUP, &sa, NULL);
651 (void) sigaction(SIGINT, &sa, NULL);
652 (void) sigaction(SIGQUIT, &sa, NULL);
656 run_command(path, argv)
663 switch (pid = fork()) {
665 error(1, "unable to run %s", path);
666 break; /* NOTREACHED */
670 closefrom(STDERR_FILENO + 1);
672 warning("unable to run %s", path);
674 break; /* NOTREACHED */
679 rv = sudo_waitpid(pid, &status, 0);
683 } while (rv == -1 && errno == EINTR);
685 if (rv == -1 || !WIFEXITED(status))
687 return(WEXITSTATUS(status));
691 check_syntax(sudoers_path, quiet, strict)
699 if ((yyin = fopen(sudoers_path, "r")) == NULL) {
701 warning("unable to open %s", sudoers_path);
704 init_parser(sudoers_path, quiet);
705 if (yyparse() && parse_error != TRUE) {
707 warningx("failed to parse %s file, unknown error", sudoers_path);
711 if (check_aliases(strict, quiet) != 0)
717 (void) printf("parse error in %s near line %d\n", errorfile,
720 (void) printf("%s: parsed OK\n", sudoers_path);
722 /* Check mode and owner in strict mode. */
724 if (strict && fstat(fileno(yyin), &sb) == 0)
726 if (strict && stat(sudoers_path, &sb) == 0)
729 if (sb.st_uid != SUDOERS_UID || sb.st_gid != SUDOERS_GID) {
732 fprintf(stderr, "%s: wrong owner (uid, gid) should be (%d, %d)\n",
733 sudoers_path, SUDOERS_UID, SUDOERS_GID);
736 if ((sb.st_mode & 07777) != SUDOERS_MODE) {
739 fprintf(stderr, "%s: bad permissions, should be mode 0%o\n",
740 sudoers_path, SUDOERS_MODE);
749 * Used to open (and lock) the initial sudoers file and to also open
750 * any subsequent files #included via a callback from the parser.
753 open_sudoers(path, doedit, keepopen)
758 struct sudoersfile *entry;
761 /* Check for existing entry */
762 tq_foreach_fwd(&sudoerslist, entry) {
763 if (strcmp(path, entry->path) == 0)
767 entry = emalloc(sizeof(*entry));
768 entry->path = estrdup(path);
771 entry->fd = open(entry->path, O_RDWR | O_CREAT, SUDOERS_MODE);
774 entry->doedit = doedit;
775 if (entry->fd == -1) {
776 warning("%s", entry->path);
780 if (!lock_file(entry->fd, SUDO_TLOCK))
781 errorx(1, "%s busy, try again later", entry->path);
782 if ((fp = fdopen(entry->fd, "r")) == NULL)
783 error(1, "%s", entry->path);
784 /* XXX - macro here? */
785 if (sudoerslist.last == NULL)
786 sudoerslist.first = sudoerslist.last = entry;
788 sudoerslist.last->next = entry;
789 sudoerslist.last = entry;
792 /* Already exists, open .tmp version if there is one. */
793 if (entry->tpath != NULL) {
794 if ((fp = fopen(entry->tpath, "r")) == NULL)
795 error(1, "%s", entry->tpath);
797 if ((fp = fdopen(entry->fd, "r")) == NULL)
798 error(1, "%s", entry->path);
802 if (keepopen != NULL)
811 char *Editor, *EditorArgs, *EditorPath, *UserEditor, *UserEditorArgs;
814 * Check VISUAL and EDITOR environment variables to see which editor
815 * the user wants to use (we may not end up using it though).
816 * If the path is not fully-qualified, make it so and check that
817 * the specified executable actually exists.
819 UserEditorArgs = NULL;
820 if ((UserEditor = getenv("VISUAL")) == NULL || *UserEditor == '\0')
821 UserEditor = getenv("EDITOR");
822 if (UserEditor && *UserEditor == '\0')
824 else if (UserEditor) {
825 UserEditorArgs = get_args(UserEditor);
826 if (find_path(UserEditor, &Editor, NULL, getenv("PATH")) == FOUND) {
829 if (def_env_editor) {
830 /* If we are honoring $EDITOR this is a fatal error. */
831 errorx(1, "specified editor (%s) doesn't exist!", UserEditor);
833 /* Otherwise, just ignore $EDITOR. */
840 * See if we can use the user's choice of editors either because
841 * we allow any $EDITOR or because $EDITOR is in the allowable list.
843 Editor = EditorArgs = EditorPath = NULL;
844 if (def_env_editor && UserEditor) {
846 EditorArgs = UserEditorArgs;
847 } else if (UserEditor) {
848 struct stat editor_sb;
849 struct stat user_editor_sb;
850 char *base, *userbase;
852 if (stat(UserEditor, &user_editor_sb) != 0) {
853 /* Should never happen since we already checked above. */
854 error(1, "unable to stat editor (%s)", UserEditor);
856 EditorPath = estrdup(def_editor);
857 Editor = strtok(EditorPath, ":");
859 EditorArgs = get_args(Editor);
861 * Both Editor and UserEditor should be fully qualified but
864 if ((base = strrchr(Editor, '/')) == NULL)
866 if ((userbase = strrchr(UserEditor, '/')) == NULL) {
873 * We compare the basenames first and then use stat to match
876 if (strcmp(base, userbase) == 0) {
877 if (stat(Editor, &editor_sb) == 0 && S_ISREG(editor_sb.st_mode)
878 && (editor_sb.st_mode & 0000111) &&
879 editor_sb.st_dev == user_editor_sb.st_dev &&
880 editor_sb.st_ino == user_editor_sb.st_ino)
883 } while ((Editor = strtok(NULL, ":")));
887 * Can't use $EDITOR, try each element of def_editor until we
888 * find one that exists, is regular, and is executable.
890 if (Editor == NULL || *Editor == '\0') {
892 EditorPath = estrdup(def_editor);
893 Editor = strtok(EditorPath, ":");
895 EditorArgs = get_args(Editor);
896 if (sudo_goodpath(Editor, NULL))
898 } while ((Editor = strtok(NULL, ":")));
900 /* Bleah, none of the editors existed! */
901 if (Editor == NULL || *Editor == '\0')
902 errorx(1, "no editor found (editor path = %s)", def_editor);
909 * Split out any command line arguments and return them.
918 while (*args && !isblank((unsigned char) *args))
922 while (*args && isblank((unsigned char) *args))
925 return(*args ? args : NULL);
929 * Look up the hostname and set user_host and user_shost.
934 char *p, thost[MAXHOSTNAMELEN + 1];
936 if (gethostname(thost, sizeof(thost)) != 0) {
937 user_host = user_shost = "localhost";
940 thost[sizeof(thost) - 1] = '\0';
941 user_host = estrdup(thost);
943 if ((p = strchr(user_host, '.'))) {
945 user_shost = estrdup(user_host);
948 user_shost = user_host;
953 alias_remove_recursive(name, type)
960 if ((a = alias_find(name, type)) != NULL) {
961 tq_foreach_fwd(&a->members, m) {
962 if (m->type == ALIAS) {
963 alias_remove_recursive(m->name, type);
968 a = alias_remove(name, type);
970 rbinsert(alias_freelist, a);
974 * Iterate through the sudoers datastructures looking for undefined
975 * aliases or unused aliases.
978 check_aliases(strict, quiet)
983 struct member *m, *binding;
984 struct privilege *priv;
987 int atype, error = 0;
989 alias_freelist = rbcreate(alias_compare);
992 tq_foreach_fwd(&userspecs, us) {
993 tq_foreach_fwd(&us->users, m) {
994 if (m->type == ALIAS) {
996 if (alias_find(m->name, USERALIAS) == NULL) {
997 print_undefined(m->name, USERALIAS, strict, quiet);
1002 tq_foreach_fwd(&us->privileges, priv) {
1003 tq_foreach_fwd(&priv->hostlist, m) {
1004 if (m->type == ALIAS) {
1006 if (alias_find(m->name, HOSTALIAS) == NULL) {
1007 print_undefined(m->name, HOSTALIAS, strict, quiet);
1012 tq_foreach_fwd(&priv->cmndlist, cs) {
1013 tq_foreach_fwd(&cs->runasuserlist, m) {
1014 if (m->type == ALIAS) {
1016 if (alias_find(m->name, RUNASALIAS) == NULL) {
1017 print_undefined(m->name, RUNASALIAS, strict, quiet);
1022 if ((m = cs->cmnd)->type == ALIAS) {
1024 if (alias_find(m->name, CMNDALIAS) == NULL) {
1025 print_undefined(m->name, CMNDALIAS, strict, quiet);
1033 /* Reverse check (destructive) */
1034 tq_foreach_fwd(&userspecs, us) {
1035 tq_foreach_fwd(&us->users, m) {
1036 if (m->type == ALIAS) {
1037 (void) alias_remove_recursive(m->name, USERALIAS);
1040 tq_foreach_fwd(&us->privileges, priv) {
1041 tq_foreach_fwd(&priv->hostlist, m) {
1042 if (m->type == ALIAS)
1043 (void) alias_remove_recursive(m->name, HOSTALIAS);
1045 tq_foreach_fwd(&priv->cmndlist, cs) {
1046 tq_foreach_fwd(&cs->runasuserlist, m) {
1047 if (m->type == ALIAS)
1048 (void) alias_remove_recursive(m->name, RUNASALIAS);
1050 if ((m = cs->cmnd)->type == ALIAS)
1051 (void) alias_remove_recursive(m->name, CMNDALIAS);
1055 tq_foreach_fwd(&defaults, d) {
1063 case DEFAULTS_RUNAS:
1070 continue; /* not an alias */
1072 tq_foreach_fwd(&d->binding, binding) {
1073 for (m = binding; m != NULL; m = m->next) {
1074 if (m->type == ALIAS)
1075 (void) alias_remove_recursive(m->name, atype);
1079 rbdestroy(alias_freelist, alias_free);
1081 /* If all aliases were referenced we will have an empty tree. */
1085 alias_apply(print_unused, strict ? "Error" : "Warning");
1087 return (strict ? 1 : 0);
1091 print_undefined(name, type, strict, quiet)
1098 warningx("%s: %s_Alias `%s' referenced but not defined",
1099 strict ? "Error" : "Warning",
1100 type == HOSTALIAS ? "Host" : type == CMNDALIAS ? "Cmnd" :
1101 type == USERALIAS ? "User" : type == RUNASALIAS ? "Runas" :
1107 print_unused(v1, v2)
1111 struct alias *a = (struct alias *)v1;
1112 char *prefix = (char *)v2;
1114 warningx("%s: unused %s_Alias %s", prefix,
1115 a->type == HOSTALIAS ? "Host" : a->type == CMNDALIAS ? "Cmnd" :
1116 a->type == USERALIAS ? "User" : a->type == RUNASALIAS ? "Runas" :
1117 "Unknown", a->name);
1122 * Unlink any sudoers temp files that remain.
1128 struct sudoersfile *sp;
1130 tq_foreach_fwd(&sudoerslist, sp) {
1131 if (sp->tpath != NULL)
1132 (void) unlink(sp->tpath);
1141 * Unlink sudoers temp files (if any) and exit.
1148 #define emsg " exiting due to signal.\n"
1149 write(STDERR_FILENO, getprogname(), strlen(getprogname()));
1150 write(STDERR_FILENO, emsg, sizeof(emsg) - 1);
1157 (void) fprintf(stderr, "usage: %s [-c] [-q] [-s] [-V] [-f sudoers]\n",