diff --git a/include/sudo_iolog.h b/include/sudo_iolog.h index d4b4c71b3..b49ed29f3 100644 --- a/include/sudo_iolog.h +++ b/include/sudo_iolog.h @@ -106,13 +106,12 @@ struct iolog_path_escape { char *expand_iolog_path(const char *prefix, const char *dir, const char *file, char **slashp, const struct iolog_path_escape *escapes, void *closure); /* iolog_util.c */ -/* XXX - prefix these */ -bool parse_timing(const char *line, struct timing_closure *timing); -char *parse_delay(const char *cp, struct timespec *delay, const char *decimal_point); -int read_timing_record(struct iolog_file *iol, struct timing_closure *timing); -struct iolog_info *parse_logfile(FILE *fp, const char *iolog_dir); -void adjust_delay(struct timespec *delay, struct timespec *max_delay, double scale_factor); -void free_iolog_info(struct iolog_info *li); +bool iolog_parse_timing(const char *line, struct timing_closure *timing); +char *iolog_parse_delay(const char *cp, struct timespec *delay, const char *decimal_point); +int iolog_read_timing_record(struct iolog_file *iol, struct timing_closure *timing); +struct iolog_info *iolog_parse_loginfo(FILE *fp, const char *iolog_dir); +void iolog_adjust_delay(struct timespec *delay, struct timespec *max_delay, double scale_factor); +void iolog_free_loginfo(struct iolog_info *li); /* iolog_fileio.c */ struct passwd; diff --git a/lib/iolog/iolog_util.c b/lib/iolog/iolog_util.c index 7a9265626..daa37736c 100644 --- a/lib/iolog/iolog_util.c +++ b/lib/iolog/iolog_util.c @@ -61,16 +61,16 @@ static int timing_event_adj; struct iolog_info * -parse_logfile(FILE *fp, const char *logfile) +iolog_parse_loginfo(FILE *fp, const char *logfile) { char *buf = NULL, *cp, *ep; const char *errstr; size_t bufsize = 0, cwdsize = 0, cmdsize = 0; struct iolog_info *li = NULL; - debug_decl(parse_logfile, SUDO_DEBUG_UTIL) + debug_decl(iolog_parse_loginfo, SUDO_DEBUG_UTIL) /* - * ID file has three lines: + * Info file has three lines: * 1) a log info line * 2) cwd * 3) command with args @@ -172,16 +172,16 @@ parse_logfile(FILE *fp, const char *logfile) bad: free(buf); - free_iolog_info(li); + iolog_free_loginfo(li); debug_return_ptr(NULL); } void -adjust_delay(struct timespec *delay, struct timespec *max_delay, +iolog_adjust_delay(struct timespec *delay, struct timespec *max_delay, double scale_factor) { double seconds; - debug_decl(adjust_delay, SUDO_DEBUG_UTIL) + debug_decl(iolog_adjust_delay, SUDO_DEBUG_UTIL) if (scale_factor != 1.0) { /* Order is important: we don't want to double the remainder. */ @@ -212,13 +212,14 @@ adjust_delay(struct timespec *delay, struct timespec *max_delay, * in the C locale this may not match the current locale. */ char * -parse_delay(const char *cp, struct timespec *delay, const char *decimal_point) +iolog_parse_delay(const char *cp, struct timespec *delay, + const char *decimal_point) { char numbuf[(((sizeof(long long) * 8) + 2) / 3) + 2]; const char *errstr, *ep; long long llval; size_t len; - debug_decl(parse_delay, SUDO_DEBUG_UTIL) + debug_decl(iolog_parse_delay, SUDO_DEBUG_UTIL) /* Parse seconds (whole number portion). */ for (ep = cp; isdigit((unsigned char)*ep); ep++) @@ -295,11 +296,11 @@ parse_delay(const char *cp, struct timespec *delay, const char *decimal_point) * Returns true on success and false on failure. */ bool -parse_timing(const char *line, struct timing_closure *timing) +iolog_parse_timing(const char *line, struct timing_closure *timing) { unsigned long ulval; char *cp, *ep; - debug_decl(parse_timing, SUDO_DEBUG_UTIL) + debug_decl(iolog_parse_timing, SUDO_DEBUG_UTIL) /* Clear iolog descriptor. */ timing->iol = NULL; @@ -319,7 +320,7 @@ parse_timing(const char *line, struct timing_closure *timing) continue; /* Parse delay, returns the next field or NULL on error. */ - if ((cp = parse_delay(cp, &timing->delay, timing->decimal)) == NULL) + if ((cp = iolog_parse_delay(cp, &timing->delay, timing->decimal)) == NULL) goto bad; switch (timing->event) { @@ -367,11 +368,11 @@ bad: * Return 0 on success, 1 on EOF and -1 on error. */ int -read_timing_record(struct iolog_file *iol, struct timing_closure *timing) +iolog_read_timing_record(struct iolog_file *iol, struct timing_closure *timing) { char line[LINE_MAX]; const char *errstr; - debug_decl(read_timing_record, SUDO_DEBUG_UTIL) + debug_decl(iolog_read_timing_record, SUDO_DEBUG_UTIL) /* Read next record from timing file. */ if (iolog_gets(iol, line, sizeof(line), &errstr) == NULL) { @@ -384,7 +385,7 @@ read_timing_record(struct iolog_file *iol, struct timing_closure *timing) /* Parse timing file record. */ line[strcspn(line, "\n")] = '\0'; - if (!parse_timing(line, timing)) { + if (!iolog_parse_timing(line, timing)) { sudo_warnx(U_("invalid timing file line: %s"), line); debug_return_int(-1); } @@ -393,7 +394,7 @@ read_timing_record(struct iolog_file *iol, struct timing_closure *timing) } void -free_iolog_info(struct iolog_info *li) +iolog_free_loginfo(struct iolog_info *li) { if (li != NULL) { free(li->cwd); diff --git a/lib/iolog/regress/iolog_util/check_iolog_util.c b/lib/iolog/regress/iolog_util/check_iolog_util.c index 6021fa8d9..f72657f5e 100644 --- a/lib/iolog/regress/iolog_util/check_iolog_util.c +++ b/lib/iolog/regress/iolog_util/check_iolog_util.c @@ -53,7 +53,7 @@ static struct parse_delay_test { }; /* - * Test parse_delay() + * Test iolog_parse_delay() */ void test_parse_delay(int *ntests, int *nerrors) @@ -63,7 +63,7 @@ test_parse_delay(int *ntests, int *nerrors) for (i = 0; i < nitems(parse_delay_tests); i++) { struct timespec delay; struct parse_delay_test *test = &parse_delay_tests[i]; - char *cp = parse_delay(test->input, &delay, "."); + char *cp = iolog_parse_delay(test->input, &delay, "."); if (cp == NULL) { sudo_warnx("%s:%u failed to parse delay: %s", __func__, i, test->input); @@ -110,7 +110,7 @@ static struct adjust_delay_test { }; /* - * Test adjust_delay() + * Test iolog_adjust_delay() */ void test_adjust_delay(int *ntests, int *nerrors) @@ -120,8 +120,9 @@ test_adjust_delay(int *ntests, int *nerrors) for (i = 0; i < nitems(adjust_delay_tests); i++) { struct adjust_delay_test *test = &adjust_delay_tests[i]; - adjust_delay(&test->in_delay, sudo_timespecisset(&test->max_delay) ? - &test->max_delay : NULL, test->scale_factor); + iolog_adjust_delay(&test->in_delay, + sudo_timespecisset(&test->max_delay) ? &test->max_delay : NULL, + test->scale_factor); if (!sudo_timespeccmp(&test->in_delay, &test->out_delay, ==)) { sudo_warnx("%s:%u want {%lld, %ld}, got {%lld, %ld}", __func__, i, (long long)test->out_delay.tv_sec, test->out_delay.tv_nsec, diff --git a/logsrvd/iolog_writer.c b/logsrvd/iolog_writer.c index 3ea8d8beb..b10717d60 100644 --- a/logsrvd/iolog_writer.c +++ b/logsrvd/iolog_writer.c @@ -670,7 +670,7 @@ iolog_rewrite(const struct timespec *target, struct connection_closure *closure) /* TODO: use iolog_seekto with a callback? */ for (;;) { /* Read next record from timing file. */ - if (read_timing_record(&closure->iolog_files[IOFD_TIMING], &timing) != 0) + if (iolog_read_timing_record(&closure->iolog_files[IOFD_TIMING], &timing) != 0) goto done; sudo_timespecadd(&timing.delay, &closure->elapsed_time, &closure->elapsed_time); diff --git a/logsrvd/logsrv_util.c b/logsrvd/logsrv_util.c index 4fc9f8a0b..806c5c40a 100644 --- a/logsrvd/logsrv_util.c +++ b/logsrvd/logsrv_util.c @@ -141,7 +141,7 @@ iolog_seekto(int iolog_dir_fd, const char *iolog_path, /* Parse timing file until we reach the target point. */ for (;;) { - if (read_timing_record(&iolog_files[IOFD_TIMING], &timing) != 0) + if (iolog_read_timing_record(&iolog_files[IOFD_TIMING], &timing) != 0) goto bad; sudo_timespecadd(&timing.delay, elapsed_time, elapsed_time); if (timing.event < IOFD_TIMING) { diff --git a/logsrvd/sendlog.c b/logsrvd/sendlog.c index f496741a7..605b0eb4d 100644 --- a/logsrvd/sendlog.c +++ b/logsrvd/sendlog.c @@ -622,7 +622,7 @@ fmt_next_iolog(struct client_closure *closure) /* TODO: fill write buffer with multiple messages */ again: - switch (read_timing_record(&iolog_files[IOFD_TIMING], timing)) { + switch (iolog_read_timing_record(&iolog_files[IOFD_TIMING], timing)) { case 0: /* OK */ break; @@ -1045,7 +1045,7 @@ iolog_seekto(int iolog_dir_fd, const char *iolog_path, /* Parse timing file until we reach the target point. */ for (;;) { - if (read_timing_record(&iolog_files[IOFD_TIMING], &timing) != 0) + if (iolog_read_timing_record(&iolog_files[IOFD_TIMING], &timing) != 0) goto bad; sudo_timespecadd(&timing.delay, elapsed_time, elapsed_time); if (timing.event < IOFD_TIMING) { @@ -1223,7 +1223,7 @@ main(int argc, char *argv[]) sudo_warn("%s/log", iolog_dir); goto bad; } - if ((log_info = parse_logfile(fp, iolog_dir)) == NULL) + if ((log_info = iolog_parse_loginfo(fp, iolog_dir)) == NULL) goto bad; /* Open the I/O log files and seek to restart point if there is one. */ diff --git a/plugins/sudoers/regress/iolog_plugin/check_iolog_plugin.c b/plugins/sudoers/regress/iolog_plugin/check_iolog_plugin.c index 9a336b8b8..bb44b159e 100644 --- a/plugins/sudoers/regress/iolog_plugin/check_iolog_plugin.c +++ b/plugins/sudoers/regress/iolog_plugin/check_iolog_plugin.c @@ -95,7 +95,7 @@ validate_iolog_info(const char *logfile) sudo_warn("%s", logfile); return false; } - info = parse_logfile(fp, logfile); + info = iolog_parse_loginfo(fp, logfile); fclose(fp); if (info == NULL) return false; @@ -146,7 +146,7 @@ validate_iolog_info(const char *logfile) return false; } - free_iolog_info(info); + iolog_free_loginfo(info); return true; } @@ -162,7 +162,7 @@ validate_timing(FILE *fp, int recno, int type, unsigned int p1, unsigned int p2) return false; } buf[strcspn(buf, "\n")] = '\0'; - if (!parse_timing(buf, &timing)) { + if (!iolog_parse_timing(buf, &timing)) { sudo_warnx("invalid timing file line: %s", buf); return false; } diff --git a/plugins/sudoers/sudoreplay.c b/plugins/sudoers/sudoreplay.c index 6b3f0f3c5..bfabe00e9 100644 --- a/plugins/sudoers/sudoreplay.c +++ b/plugins/sudoers/sudoreplay.c @@ -366,7 +366,7 @@ main(int argc, char *argv[]) fd = openat(iolog_dir_fd, "log", O_RDONLY, 0); if (fd == -1 || (fp = fdopen(fd, "r")) == NULL) sudo_fatal(U_("unable to open %s/%s"), iolog_dir, "log"); - if ((li = parse_logfile(fp, iolog_dir)) == NULL) + if ((li = iolog_parse_loginfo(fp, iolog_dir)) == NULL) goto done; fclose(fp); printf(_("Replaying sudo session: %s"), li->cmd); @@ -379,7 +379,7 @@ main(int argc, char *argv[]) putchar('\n'); /* Done with parsed log file. */ - free_iolog_info(li); + iolog_free_loginfo(li); li = NULL; /* Replay session corresponding to iolog_files[]. */ @@ -735,7 +735,7 @@ get_timing_record(struct replay_closure *closure) int ret; debug_decl(get_timing_record, SUDO_DEBUG_UTIL) - if ((ret = read_timing_record(&iolog_files[IOFD_TIMING], timing)) != 0) + if ((ret = iolog_read_timing_record(&iolog_files[IOFD_TIMING], timing)) != 0) debug_return_int(ret); /* Record number bytes to read. */ @@ -748,7 +748,7 @@ get_timing_record(struct replay_closure *closure) } /* Adjust delay using speed factor and max_delay. */ - adjust_delay(&timing->delay, closure->max_delay, speed_factor); + iolog_adjust_delay(&timing->delay, closure->max_delay, speed_factor); /* Schedule the delay event. */ if (sudo_ev_add(closure->evbase, closure->delay_ev, &timing->delay, false) == -1) @@ -1319,7 +1319,7 @@ list_session(char *logfile, regex_t *re, const char *user, const char *tty) sudo_warn("%s", logfile); goto done; } - if ((li = parse_logfile(fp, logfile)) == NULL) + if ((li = iolog_parse_loginfo(fp, logfile)) == NULL) goto done; /* Match on search expression if there is one. */ @@ -1356,7 +1356,7 @@ list_session(char *logfile, regex_t *re, const char *user, const char *tty) done: if (fp != NULL) fclose(fp); - free_iolog_info(li); + iolog_free_loginfo(li); debug_return_int(ret); }