2 * Copyright (c) 2011-2013 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 */
42 #define SUDO_ERROR_WRAP 0
48 struct sudo_user sudo_user;
49 struct passwd *list_pw;
51 static char sessid[7];
53 __dso_public int main(int argc, char *argv[]);
58 fprintf(stderr, "usage: check_iolog_path datafile\n");
63 do_check(char *dir_in, char *file_in, char *tdir_out, char *tfile_out)
66 char dir_out[4096], file_out[4096];
72 * Expand any strftime(3) escapes
73 * XXX - want to pass timeptr to expand_iolog_path
76 timeptr = localtime(&now);
77 strftime(dir_out, sizeof(dir_out), tdir_out, timeptr);
78 strftime(file_out, sizeof(file_out), tfile_out, timeptr);
80 path = expand_iolog_path(NULL, dir_in, file_in, &slash);
82 if (strcmp(path, dir_out) != 0) {
83 warningx("%s: expected %s, got %s", dir_in, dir_out, path);
86 if (strcmp(slash + 1, file_out) != 0) {
87 warningx("%s: expected %s, got %s", file_in, file_out, slash + 1);
97 main(int argc, char *argv[])
99 struct passwd pw, rpw;
103 char *file_in = NULL, *file_out = NULL;
104 char *dir_in = NULL, *dir_out = NULL;
109 #if !defined(HAVE_GETPROGNAME) && !defined(HAVE___PROGNAME)
110 setprogname(argc > 0 ? argv[0] : "check_iolog_path");
116 fp = fopen(argv[1], "r");
118 fatalx("unable to open %s", argv[1]);
120 memset(&pw, 0, sizeof(pw));
121 memset(&rpw, 0, sizeof(rpw));
123 sudo_user._runas_pw = &rpw;
126 * Input consists of 12 lines:
132 * hostname [short form]
135 * file [with escapes]
140 while (fgets(line, sizeof(line), fp) != NULL) {
141 len = strcspn(line, "\n");
146 strlcpy(sessid, line, sizeof(sessid));
149 if (user_name != NULL)
151 user_name = strdup(line);
154 user_gid = atoi(line);
157 if (runas_pw->pw_name != NULL)
158 free(runas_pw->pw_name);
159 runas_pw->pw_name = strdup(line);
162 runas_pw->pw_gid = atoi(line);
165 user_shost = strdup(line);
168 user_base = strdup(line);
171 dir_in = strdup(line);
174 file_in = strdup(line);
177 dir_out = strdup(line);
180 file_out = strdup(line);
183 errors += do_check(dir_in, file_in, dir_out, file_out);
187 fatalx("internal error, invalid state %d", state);
189 state = (state + 1) % MAX_STATE;
193 printf("iolog_path: %d test%s run, %d errors, %d%% success rate\n",
194 tests, tests == 1 ? "" : "s", errors,
195 (tests - errors) * 100 / tests);
201 void io_nextid(char *iolog_dir, char *fallback, char id[7])
203 memcpy(id, sessid, sizeof(sessid));