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 */
49 struct sudo_user sudo_user;
50 struct passwd *list_pw;
52 static char sessid[7];
57 fprintf(stderr, "usage: check_iolog_path datafile\n");
62 do_check(char *dir_in, char *file_in, char *tdir_out, char *tfile_out)
65 char dir_out[4096], file_out[4096];
71 * Expand any strftime(3) escapes
72 * XXX - want to pass timeptr to expand_iolog_path
75 timeptr = localtime(&now);
76 strftime(dir_out, sizeof(dir_out), tdir_out, timeptr);
77 strftime(file_out, sizeof(file_out), tfile_out, timeptr);
79 path = expand_iolog_path(NULL, dir_in, file_in, &slash);
81 if (strcmp(path, dir_out) != 0) {
82 warningx("%s: expected %s, got %s", dir_in, dir_out, path);
85 if (strcmp(slash + 1, file_out) != 0) {
86 warningx("%s: expected %s, got %s", file_in, file_out, slash + 1);
96 main(int argc, char *argv[])
98 struct passwd pw, rpw;
102 char *file_in = NULL, *file_out = NULL;
103 char *dir_in = NULL, *dir_out = NULL;
111 fp = fopen(argv[1], "r");
113 errorx(1, "unable to open %s", argv[1]);
115 memset(&pw, 0, sizeof(pw));
116 memset(&rpw, 0, sizeof(rpw));
118 sudo_user._runas_pw = &rpw;
121 * Input consists of 12 lines:
127 * hostname [short form]
130 * file [with escapes]
135 while (fgets(line, sizeof(line), fp) != NULL) {
136 len = strcspn(line, "\n");
141 strlcpy(sessid, line, sizeof(sessid));
144 if (user_name != NULL)
146 user_name = strdup(line);
149 user_gid = atoi(line);
152 if (runas_pw->pw_name != NULL)
153 free(runas_pw->pw_name);
154 runas_pw->pw_name = strdup(line);
157 runas_pw->pw_gid = atoi(line);
160 user_shost = strdup(line);
163 user_base = strdup(line);
166 dir_in = strdup(line);
169 file_in = strdup(line);
172 dir_out = strdup(line);
175 file_out = strdup(line);
178 errors += do_check(dir_in, file_in, dir_out, file_out);
182 errorx(1, "internal error, invalid state %d", state);
184 state = (state + 1) % MAX_STATE;
188 printf("iolog_path: %d test%s run, %d errors, %d%% success rate\n",
189 tests, tests == 1 ? "" : "s", errors,
190 (tests - errors) * 100 / tests);
196 void io_nextid(char *iolog_dir, char id[7])
198 memcpy(id, sessid, sizeof(sessid));