2 * Copyright (c) 2011 Todd C. Miller <Todd.Miller@courtesan.com>
4 * Permission to use, copy, modify, and distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
19 #include <sys/types.h>
28 #endif /* STDC_HEADERS */
30 # if defined(HAVE_MEMORY_H) && !defined(STDC_HEADERS)
34 #endif /* HAVE_STRING_H */
37 #endif /* HAVE_STRINGS_H */
39 #define SUDO_ERROR_WRAP 0
43 #include "sudo_plugin.h"
45 sudo_conv_t sudo_conv; /* NULL in non-plugin */
47 extern void writeln_wrap(FILE *fp, char *line, size_t len, size_t maxlen);
52 fprintf(stderr, "usage: check_wrap inputfile\n");
57 main(int argc, char *argv[])
61 char *cp, *dash, *line, lines[2][2048];
64 #if !defined(HAVE_GETPROGNAME) && !defined(HAVE___PROGNAME)
65 setprogname(argc > 0 ? argv[0] : "check_wrap");
71 fp = fopen(argv[1], "r");
73 errorx(1, "unable to open %s", argv[1]);
76 * Each test record consists of a log entry on one line and a list of
77 * line lengths to test it with on the next. E.g.
79 * Jun 30 14:49:51 : millert : TTY=ttypn ; PWD=/usr/src/local/millert/hg/sudo/trunk/plugins/sudoers ; USER=root ; TSID=0004LD ; COMMAND=/usr/local/sbin/visudo
82 while ((line = fgets(lines[which], sizeof(lines[which]), fp)) != NULL) {
83 len = strcspn(line, "\n");
86 /* If we read the 2nd line, parse list of line lengths and check. */
88 for (cp = strtok(lines[1], ","); cp != NULL; cp = strtok(NULL, ",")) {
90 /* May be either a number or a range. */
91 len = maxlen = atoi(cp);
92 dash = strchr(cp, '-');
94 maxlen = atoi(dash + 1);
95 while (len <= maxlen) {
96 printf("# word wrap at %d characters\n", (int)len);
97 writeln_wrap(stdout, lines[0], strlen(lines[0]), len);