diff --git a/include/sudo_iolog.h b/include/sudo_iolog.h index 2846584a1..8363dfa2d 100644 --- a/include/sudo_iolog.h +++ b/include/sudo_iolog.h @@ -109,9 +109,10 @@ char *expand_iolog_path(const char *prefix, const char *dir, const char *file, 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 free_iolog_info(struct iolog_info *li); void adjust_delay(struct timespec *delay, struct timespec *max_delay, double scale_factor); +void free_iolog_info(struct iolog_info *li); /* iolog_fileio.c */ struct passwd; diff --git a/lib/iolog/iolog_util.c b/lib/iolog/iolog_util.c index d031459b3..7a9265626 100644 --- a/lib/iolog/iolog_util.c +++ b/lib/iolog/iolog_util.c @@ -362,6 +362,36 @@ bad: debug_return_bool(false); } +/* + * Read the next record from the timing file. + * Return 0 on success, 1 on EOF and -1 on error. + */ +int +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) + + /* Read next record from timing file. */ + if (iolog_gets(iol, line, sizeof(line), &errstr) == NULL) { + /* EOF or error reading timing file, we are done. */ + if (iolog_eof(iol)) + debug_return_int(1); + sudo_warnx(U_("error reading timing file: %s"), errstr); + debug_return_int(-1); + } + + /* Parse timing file record. */ + line[strcspn(line, "\n")] = '\0'; + if (!parse_timing(line, timing)) { + sudo_warnx(U_("invalid timing file line: %s"), line); + debug_return_int(-1); + } + + debug_return_int(0); +} + void free_iolog_info(struct iolog_info *li) { diff --git a/logsrvd/iolog_writer.c b/logsrvd/iolog_writer.c index ef45ea1f9..ccbbc5319 100644 --- a/logsrvd/iolog_writer.c +++ b/logsrvd/iolog_writer.c @@ -617,38 +617,6 @@ iolog_init(AcceptMessage *msg, struct connection_closure *closure) debug_return_bool(true); } -/* - * Read the next record from the timing file. - * Return 0 on success, 1 on EOF and -1 on error. - */ -static int -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) - - /* Read next record from timing file. */ - if (iolog_gets(iol, line, sizeof(line), &errstr) == NULL) { - /* EOF or error reading timing file, we are done. */ - if (iolog_eof(iol)) - debug_return_int(1); /* EOF */ - sudo_debug_printf(SUDO_DEBUG_ERROR|SUDO_DEBUG_LINENO, - "error reading timing file: %s", errstr); - debug_return_int(-1); - } - - /* Parse timing file record. */ - line[strcspn(line, "\n")] = '\0'; - if (!parse_timing(line, timing)) { - sudo_debug_printf(SUDO_DEBUG_ERROR|SUDO_DEBUG_LINENO|SUDO_DEBUG_ERRNO, - "invalid timing file line: %s", line); - debug_return_int(-1); - } - - debug_return_int(0); -} - /* * Copy len bytes from src to dst. */ diff --git a/logsrvd/sendlog.c b/logsrvd/sendlog.c index f3b97eb34..35e62663f 100644 --- a/logsrvd/sendlog.c +++ b/logsrvd/sendlog.c @@ -166,37 +166,6 @@ client_closure_free(struct client_closure *closure) debug_return; } -/* - * Read the next record from the timing file. - * Return 0 on success, 1 on EOF and -1 on error. - * TODO: share with logsrvd - */ -int -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) - - /* Read next record from timing file. */ - if (iolog_gets(iol, line, sizeof(line), &errstr) == NULL) { - /* EOF or error reading timing file, we are done. */ - if (iolog_eof(iol)) - debug_return_int(1); - sudo_warnx(U_("error reading timing file: %s"), errstr); - debug_return_int(-1); - } - - /* Parse timing file record. */ - line[strcspn(line, "\n")] = '\0'; - if (!parse_timing(line, timing)) { - sudo_warnx(U_("invalid timing file line: %s"), line); - debug_return_int(-1); - } - - debug_return_int(0); -} - /* * Read the next I/O buffer as described by closure->timing. */ diff --git a/plugins/sudoers/sudoreplay.c b/plugins/sudoers/sudoreplay.c index 4dd9f0a1d..6b3f0f3c5 100644 --- a/plugins/sudoers/sudoreplay.c +++ b/plugins/sudoers/sudoreplay.c @@ -727,29 +727,16 @@ restore_terminal_size(void) * Read the next record from the timing file and schedule a delay * event with the specified timeout. * Return 0 on success, 1 on EOF and -1 on error. - * XXX - duplicated in sendlog */ static int -read_timing_record(struct replay_closure *closure) +get_timing_record(struct replay_closure *closure) { struct timing_closure *timing = &closure->timing; - char line[LINE_MAX]; - const char *errstr; - debug_decl(read_timing_record, SUDO_DEBUG_UTIL) + int ret; + debug_decl(get_timing_record, SUDO_DEBUG_UTIL) - /* Read next record from timing file. */ - if (iolog_gets(&iolog_files[IOFD_TIMING], line, sizeof(line), &errstr) == NULL) { - /* EOF or error reading timing file, we are done. */ - if (iolog_eof(&iolog_files[IOFD_TIMING])) - debug_return_int(1); - sudo_fatalx(U_("error reading timing file: %s"), errstr); - debug_return_int(-1); - } - - /* Parse timing file record. */ - line[strcspn(line, "\n")] = '\0'; - if (!parse_timing(line, timing)) - sudo_fatalx(U_("invalid timing file line: %s"), line); + if ((ret = read_timing_record(&iolog_files[IOFD_TIMING], timing)) != 0) + debug_return_int(ret); /* Record number bytes to read. */ if (timing->event != IO_EVENT_WINSIZE && @@ -780,7 +767,7 @@ next_timing_record(struct replay_closure *closure) debug_decl(next_timing_record, SUDO_DEBUG_UTIL) again: - switch (read_timing_record(closure)) { + switch (get_timing_record(closure)) { case 0: /* success */ if (closure->timing.event == IO_EVENT_SUSPEND && @@ -1030,7 +1017,7 @@ replay_session(int iolog_dir_fd, const char *iolog_dir, /* Allocate the delay closure and read the first timing record. */ closure = replay_closure_alloc(iolog_dir_fd, iolog_dir, max_delay, decimal, interactive, suspend_wait); - if (read_timing_record(closure) != 0) { + if (get_timing_record(closure) != 0) { ret = 1; goto done; } @@ -1121,7 +1108,7 @@ write_output(int fd, int what, void *v) if (iobuf->off == iobuf->len) { /* Write complete, go to next timing entry if possible. */ - switch (read_timing_record(closure)) { + switch (get_timing_record(closure)) { case 0: /* success */ break;