Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
sudo-project
GitHub Repository: sudo-project/sudo
Path: blob/main/include/sudo_iolog.h
1532 views
1
/*
2
* SPDX-License-Identifier: ISC
3
*
4
* Copyright (c) 2009-2022 Todd C. Miller <[email protected]>
5
*
6
* Permission to use, copy, modify, and distribute this software for any
7
* purpose with or without fee is hereby granted, provided that the above
8
* copyright notice and this permission notice appear in all copies.
9
*
10
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17
*/
18
19
#ifndef SUDO_IOLOG_H
20
#define SUDO_IOLOG_H
21
22
#include <sys/types.h> /* for gid_t, mode_t, size_t, ssize_t, uid_t */
23
24
#ifdef HAVE_ZLIB_H
25
# include <zlib.h> /* for gzFile */
26
#endif
27
28
/* Default maximum session ID */
29
#define SESSID_MAX 2176782336U
30
31
/* Default value for "iolog_file" */
32
#define IOLOG_FILE "%{seq}"
33
34
/*
35
* I/O log event types as stored as the first field in the timing file.
36
* Changing existing values will result in incompatible I/O log files.
37
*/
38
#define IO_EVENT_STDIN 0
39
#define IO_EVENT_STDOUT 1
40
#define IO_EVENT_STDERR 2
41
#define IO_EVENT_TTYIN 3
42
#define IO_EVENT_TTYOUT 4
43
#define IO_EVENT_WINSIZE 5
44
#define IO_EVENT_TTYOUT_1_8_7 6
45
#define IO_EVENT_SUSPEND 7
46
#define IO_EVENT_COUNT 8
47
48
/*
49
* Indexes into iolog_files[] array.
50
* These must match the IO_EVENT_ defines above.
51
* TODO: eliminate use of IOFD_* and IO_EVENT_* as indexes in favor of
52
* a struct containing iolog_file *s for each (and names too?).
53
*/
54
#define IOFD_STDIN 0
55
#define IOFD_STDOUT 1
56
#define IOFD_STDERR 2
57
#define IOFD_TTYIN 3
58
#define IOFD_TTYOUT 4
59
#define IOFD_TIMING 5
60
#define IOFD_MAX 6
61
62
/*
63
* Default password prompt regex.
64
*/
65
#define PASSPROMPT_REGEX "[Pp]assword[: ]*"
66
67
struct timing_closure {
68
struct timespec delay;
69
const char *decimal;
70
struct iolog_file *iol;
71
int event;
72
union {
73
struct {
74
int lines;
75
int cols;
76
} winsize;
77
size_t nbytes;
78
int signo;
79
} u;
80
};
81
82
struct iolog_file {
83
bool enabled;
84
bool compressed;
85
bool locked;
86
bool writable;
87
union {
88
FILE *f;
89
#ifdef HAVE_ZLIB_H
90
gzFile g;
91
#endif
92
void *v;
93
} fd;
94
};
95
96
struct iolog_path_escape {
97
const char *name;
98
size_t (*copy_fn)(char * restrict, size_t, void * restrict );
99
};
100
101
/* host_port.c */
102
bool iolog_parse_host_port(char *str, char **hostp, char **portp, bool *tlsp, const char *defport, const char *defport_tls);
103
104
/* iolog_path.c */
105
bool expand_iolog_path(const char *inpath, char *path, size_t pathlen, const struct iolog_path_escape *escapes, void *closure);
106
size_t strlcpy_no_slash(char * restrict dst, const char * restrict src, size_t size);
107
108
/* iolog_util.c */
109
bool iolog_parse_timing(const char *line, struct timing_closure *timing);
110
char *iolog_parse_delay(const char *cp, struct timespec *delay, const char *decimal_point);
111
int iolog_read_timing_record(struct iolog_file *iol, struct timing_closure *timing);
112
struct eventlog *iolog_parse_loginfo(int dfd, const char *iolog_dir);
113
bool iolog_parse_loginfo_json(FILE *fp, const char *iolog_dir, struct eventlog *evlog);
114
bool iolog_parse_loginfo_legacy(FILE *fp, const char *iolog_dir, struct eventlog *evlog);
115
void iolog_adjust_delay(struct timespec *delay, struct timespec *max_delay, double scale_factor);
116
117
/* iolog_fileio.c */
118
struct passwd;
119
struct group;
120
bool iolog_close(struct iolog_file *iol, const char **errstr);
121
bool iolog_eof(struct iolog_file *iol);
122
bool iolog_mkdtemp(char *path);
123
bool iolog_mkpath(char *path);
124
bool iolog_nextid(const char *iolog_dir, char sessid[7]);
125
bool iolog_open(struct iolog_file *iol, int dfd, int iofd, const char *mode);
126
bool iolog_write_info_file(int dfd, struct eventlog *evlog);
127
char *iolog_gets(struct iolog_file *iol, char *buf, int bufsize, const char **errsttr);
128
const char *iolog_fd_to_name(int iofd);
129
int iolog_openat(int fdf, const char *path, int flags);
130
off_t iolog_seek(struct iolog_file *iol, off_t offset, int whence);
131
ssize_t iolog_read(struct iolog_file *iol, void *buf, size_t nbytes, const char **errstr);
132
ssize_t iolog_write(struct iolog_file *iol, const void *buf, size_t len, const char **errstr);
133
void iolog_clearerr(struct iolog_file *iol);
134
bool iolog_flush(struct iolog_file *iol, const char **errstr);
135
void iolog_rewind(struct iolog_file *iol);
136
unsigned int iolog_get_maxseq(void);
137
uid_t iolog_get_uid(void);
138
gid_t iolog_get_gid(void);
139
mode_t iolog_get_file_mode(void);
140
mode_t iolog_get_dir_mode(void);
141
bool iolog_get_compress(void);
142
bool iolog_get_flush(void);
143
void iolog_set_compress(bool);
144
void iolog_set_defaults(void);
145
void iolog_set_flush(bool);
146
void iolog_set_gid(gid_t gid);
147
void iolog_set_maxseq(unsigned int maxval);
148
void iolog_set_mode(mode_t mode);
149
void iolog_set_owner(uid_t uid, uid_t gid);
150
bool iolog_swapids(bool restore);
151
bool iolog_mkdirs(const char *path);
152
153
/* iolog_filter.c */
154
void *iolog_pwfilt_alloc(void);
155
bool iolog_pwfilt_add(void *handle, const char *pattern);
156
void iolog_pwfilt_free(void *handle);
157
bool iolog_pwfilt_remove(void *handle, const char *pattern);
158
bool iolog_pwfilt_run(void *handle, int event, const char *buf, size_t len, char **newbuf);
159
160
#endif /* SUDO_IOLOG_H */
161
162