]> granicus.if.org Git - sudo/commitdiff
Make "sudoreplay -m 0" skip the pauses entirely.
authorTodd C. Miller <Todd.Miller@sudo.ws>
Thu, 8 Mar 2018 14:53:29 +0000 (07:53 -0700)
committerTodd C. Miller <Todd.Miller@sudo.ws>
Thu, 8 Mar 2018 14:53:29 +0000 (07:53 -0700)
doc/sudoreplay.cat
doc/sudoreplay.man.in
doc/sudoreplay.mdoc.in
plugins/sudoers/sudoreplay.c

index b7b89ec5dae122e8da3d3a732b785653ffc459a7..e939626c8933cf1ba87ec1c443d36a82fa2c59c6 100644 (file)
@@ -120,8 +120,8 @@ D\bDE\bES\bSC\bCR\bRI\bIP\bPT\bTI\bIO\bON\bN
                  session includes long pauses.  When the -\b-m\bm option is
                  specified, s\bsu\bud\bdo\bor\bre\bep\bpl\bla\bay\by will limit these pauses to at most
                  _\bm_\ba_\bx_\b__\bw_\ba_\bi_\bt seconds.  The value may be specified as a floating
-                 point number, e.g. _\b2_\b._\b5.  A negative value will eliminate the
-                 pauses entirely.
+                 point number, e.g. _\b2_\b._\b5.  A _\bm_\ba_\bx_\b__\bw_\ba_\bi_\bt of zero or less will
+                 eliminate the pauses entirely.
 
      -\b-n\bn, -\b--\b-n\bno\bon\bn-\b-i\bin\bnt\bte\ber\bra\bac\bct\bti\biv\bve\be
                  Do not prompt for user input or attempt to resize the
index 1c447441d2b75cde47da3104e8ef32957794cf99..5a0e728d7abf6f3069e519f92755770f42cea875 100644 (file)
@@ -240,7 +240,9 @@ will limit these pauses to at most
 seconds.
 The value may be specified as a floating point number, e.g.\&
 \fI2.5\fR.
-A negative value will eliminate the pauses entirely.
+A
+\fImax_wait\fR
+of zero or less will eliminate the pauses entirely.
 .TP 12n
 \fB\-n\fR, \fB\--non-interactive\fR
 Do not prompt for user input or attempt to resize the terminal.
index 49cc6e86e0bac45fecd349b5d70ba3dde326cb6b..e9e530ba3661559a3c4875fecee4b876da29f398 100644 (file)
@@ -220,7 +220,9 @@ will limit these pauses to at most
 seconds.
 The value may be specified as a floating point number, e.g.\&
 .Em 2.5 .
-A negative value will eliminate the pauses entirely.
+A
+.Em max_wait
+of zero or less will eliminate the pauses entirely.
 .It Fl n , -non-interactive
 Do not prompt for user input or attempt to resize the terminal.
 The session is written to the standard output, not directly to
index 0875b4acd584411d67d8fba74dbb6d1319ab9e65..495db68a8836a763c7a7abf899e2571cae139d42 100644 (file)
@@ -101,7 +101,7 @@ struct replay_closure {
     struct sudo_event *sigtstp_ev;
     struct timing_closure {
        const char *decimal;
-       double max_delay;
+       struct timeval *max_delay;
        int idx;
        union {
            struct {
@@ -193,7 +193,7 @@ static struct log_info *parse_logfile(char *logfile);
 static void read_keyboard(int fd, int what, void *v);
 static void free_log_info(struct log_info *li);
 static void help(void) __attribute__((__noreturn__));
-static int replay_session(double max_wait, const char *decimal, bool interactive);
+static int replay_session(struct timeval *max_wait, const char *decimal, bool interactive);
 static void sudoreplay_cleanup(void);
 static void usage(int);
 static void write_output(int fd, int what, void *v);
@@ -225,7 +225,8 @@ main(int argc, char *argv[])
     const char *decimal, *id, *user = NULL, *pattern = NULL, *tty = NULL;
     char *cp, *ep, path[PATH_MAX];
     struct log_info *li;
-    double max_delay = 0;
+    struct timeval max_delay_storage, *max_delay = NULL;
+    double dval;
     debug_decl(main, SUDO_DEBUG_MAIN)
 
 #if defined(SUDO_DEVEL) && defined(__OpenBSD__)
@@ -281,9 +282,17 @@ main(int argc, char *argv[])
            break;
        case 'm':
            errno = 0;
-           max_delay = strtod(optarg, &ep);
+           dval = strtod(optarg, &ep);
            if (*ep != '\0' || errno != 0)
                sudo_fatalx(U_("invalid max wait: %s"), optarg);
+           if (dval <= 0.0) {
+               sudo_timevalclear(&max_delay_storage);
+           } else {
+               max_delay_storage.tv_sec = dval;
+               max_delay_storage.tv_usec =
+                   (dval - max_delay_storage.tv_sec) * 1000000.0;
+           }
+           max_delay = &max_delay_storage;
            break;
        case 'n':
            interactive = false;
@@ -789,15 +798,19 @@ read_timing_record(struct replay_closure *closure)
        closure->iobuf.toread = closure->timing.u.nbytes;
     }
 
-    /* Adjust delay using speed factor and clamp to max_delay */
+    /* Adjust delay using speed factor. */
     delay /= speed_factor;
-    if (closure->timing.max_delay && delay > closure->timing.max_delay)
-       delay = closure->timing.max_delay;
 
     /* Convert delay to a timeval. */
     timeout.tv_sec = delay;
     timeout.tv_usec = (delay - timeout.tv_sec) * 1000000.0;
 
+    /* Clamp timeout to max delay. */
+    if (closure->timing.max_delay != NULL) {
+       if (sudo_timevalcmp(&timeout, closure->timing.max_delay, >))
+           timeout = *closure->timing.max_delay;
+    }
+
     /* Schedule the delay event. */
     if (sudo_ev_add(closure->evbase, closure->delay_ev, &timeout, false) == -1)
        sudo_fatal(U_("unable to add event to queue"));
@@ -940,7 +953,7 @@ signal_cb(int signo, int what, void *v)
 }
 
 static struct replay_closure *
-replay_closure_alloc(double max_delay, const char *decimal, bool interactive)
+replay_closure_alloc(struct timeval *max_delay, const char *decimal, bool interactive)
 {
     struct replay_closure *closure;
     debug_decl(replay_closure_alloc, SUDO_DEBUG_UTIL)
@@ -1021,7 +1034,7 @@ bad:
 }
 
 static int
-replay_session(double max_delay, const char *decimal, bool interactive)
+replay_session(struct timeval *max_delay, const char *decimal, bool interactive)
 {
     struct replay_closure *closure;
     int ret = 0;