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 */
45 #define SUDO_ERROR_WRAP 0
51 struct sudo_user sudo_user;
52 struct passwd *list_pw;
53 sudo_conv_t sudo_conv; /* NULL in non-plugin */
55 static char sessid[7];
60 fprintf(stderr, "usage: check_iolog_path datafile\n");
65 do_check(char *dir_in, char *file_in, char *tdir_out, char *tfile_out)
68 char dir_out[4096], file_out[4096];
74 * Expand any strftime(3) escapes
75 * XXX - want to pass timeptr to expand_iolog_path
78 timeptr = localtime(&now);
79 strftime(dir_out, sizeof(dir_out), tdir_out, timeptr);
80 strftime(file_out, sizeof(file_out), tfile_out, timeptr);
82 path = expand_iolog_path(NULL, dir_in, file_in, &slash);
84 if (strcmp(path, dir_out) != 0) {
85 warningx("%s: expected %s, got %s", dir_in, dir_out, path);
88 if (strcmp(slash + 1, file_out) != 0) {
89 warningx("%s: expected %s, got %s", file_in, file_out, slash + 1);
99 main(int argc, char *argv[])
101 struct passwd pw, rpw;
105 char *file_in = NULL, *file_out = NULL;
106 char *dir_in = NULL, *dir_out = NULL;
111 #if !defined(HAVE_GETPROGNAME) && !defined(HAVE___PROGNAME)
112 setprogname(argc > 0 ? argv[0] : "check_iolog_path");
118 fp = fopen(argv[1], "r");
120 errorx(1, "unable to open %s", argv[1]);
122 memset(&pw, 0, sizeof(pw));
123 memset(&rpw, 0, sizeof(rpw));
125 sudo_user._runas_pw = &rpw;
128 * Input consists of 12 lines:
134 * hostname [short form]
137 * file [with escapes]
142 while (fgets(line, sizeof(line), fp) != NULL) {
143 len = strcspn(line, "\n");
148 strlcpy(sessid, line, sizeof(sessid));
151 if (user_name != NULL)
153 user_name = strdup(line);
156 user_gid = atoi(line);
159 if (runas_pw->pw_name != NULL)
160 free(runas_pw->pw_name);
161 runas_pw->pw_name = strdup(line);
164 runas_pw->pw_gid = atoi(line);
167 user_shost = strdup(line);
170 user_base = strdup(line);
173 dir_in = strdup(line);
176 file_in = strdup(line);
179 dir_out = strdup(line);
182 file_out = strdup(line);
185 errors += do_check(dir_in, file_in, dir_out, file_out);
189 errorx(1, "internal error, invalid state %d", state);
191 state = (state + 1) % MAX_STATE;
195 printf("iolog_path: %d test%s run, %d errors, %d%% success rate\n",
196 tests, tests == 1 ? "" : "s", errors,
197 (tests - errors) * 100 / tests);
203 void io_nextid(char *iolog_dir, char id[7])
205 memcpy(id, sessid, sizeof(sessid));