]> granicus.if.org Git - sudo/blob - plugins/sudoers/iolog.h
d803a15b790d504ae4e9176e6207e2e7fb0d2e80
[sudo] / plugins / sudoers / iolog.h
1 /*
2  * Copyright (c) 2009-2018 Todd C. Miller <Todd.Miller@sudo.ws>
3  *
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.
7  *
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.
15  */
16
17 #ifndef SUDOERS_IOLOG_H
18 #define SUDOERS_IOLOG_H
19
20 #ifdef HAVE_ZLIB_H
21 # include <zlib.h>      /* for gzFile */
22 #endif
23
24 /*
25  * I/O log event types as stored as the first field in the timing file.
26  * Changing existing values will result in incompatible I/O log files.
27  */
28 #define IO_EVENT_STDIN          0
29 #define IO_EVENT_STDOUT         1
30 #define IO_EVENT_STDERR         2
31 #define IO_EVENT_TTYIN          3
32 #define IO_EVENT_TTYOUT         4
33 #define IO_EVENT_WINSIZE        5
34 #define IO_EVENT_TTYOUT_1_8_7   6
35 #define IO_EVENT_SUSPEND        7
36 #define IO_EVENT_COUNT          8
37
38 /* Default maximum session ID */
39 #define SESSID_MAX      2176782336U
40
41 union io_fd {
42     FILE *f;
43 #ifdef HAVE_ZLIB_H
44     gzFile g;
45 #endif
46     void *v;
47 };
48
49 /*
50  * Info present in the I/O log file
51  */
52 struct log_info {
53     char *cwd;
54     char *user;
55     char *runas_user;
56     char *runas_group;
57     char *tty;
58     char *cmd;
59     time_t tstamp;
60     int rows;
61     int cols;
62 };
63
64 struct timing_closure {
65     const char *decimal;
66     struct timespec *max_delay;
67     union io_fd fd;
68     int event;
69     union {
70         struct {
71             int rows;
72             int cols;
73         } winsize;
74         size_t nbytes; // XXX
75         int signo;
76     } u;
77 };
78
79 /* iolog_util.c */
80 bool parse_timing(const char *buf, struct timespec *delay, struct timing_closure *timing);
81 char *parse_delay(const char *cp, struct timespec *delay, const char *decimal_point);
82 struct log_info *parse_logfile(const char *logfile);
83 void free_log_info(struct log_info *li);
84 void adjust_delay(struct timespec *delay, struct timespec *max_delay, double scale_factor);
85
86 #endif /* SUDOERS_IOLOG_H */