summaryrefslogtreecommitdiff
path: root/src/sudo_exec.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/sudo_exec.h')
-rw-r--r--src/sudo_exec.h102
1 files changed, 91 insertions, 11 deletions
diff --git a/src/sudo_exec.h b/src/sudo_exec.h
index 2f099a332..a75d6f17f 100644
--- a/src/sudo_exec.h
+++ b/src/sudo_exec.h
@@ -27,6 +27,13 @@
#endif
/*
+ * Linux-specific wait flag used with ptrace(2).
+ */
+#ifndef __WALL
+# define __WALL 0
+#endif
+
+/*
* Some older systems support siginfo but predate SI_USER.
*/
#ifdef SI_USER
@@ -35,8 +42,66 @@
# define USER_SIGNALED(_info) ((_info) != NULL && (_info)->si_code <= 0)
#endif
+/* Values for ttymode. */
+#define TERM_COOKED 0
+#define TERM_RAW 1
+
+struct command_details;
+struct command_status;
+struct sudo_event_base;
+struct stat;
+
+/*
+ * Closure passed to I/O event callbacks.
+ */
+struct exec_closure {
+ struct command_details *details;
+ struct sudo_event_base *evbase;
+ struct sudo_event *backchannel_event;
+ struct sudo_event *fwdchannel_event;
+ struct sudo_event *sigint_event;
+ struct sudo_event *sigquit_event;
+ struct sudo_event *sigtstp_event;
+ struct sudo_event *sigterm_event;
+ struct sudo_event *sighup_event;
+ struct sudo_event *sigalrm_event;
+ struct sudo_event *sigpipe_event;
+ struct sudo_event *sigusr1_event;
+ struct sudo_event *sigusr2_event;
+ struct sudo_event *sigchld_event;
+ struct sudo_event *sigcont_event;
+ struct sudo_event *siginfo_event;
+ struct sudo_event *sigwinch_event;
+ struct command_status *cstat;
+ void *intercept;
+ pid_t monitor_pid;
+ pid_t cmnd_pid;
+ pid_t ppgrp;
+ short rows;
+ short cols;
+};
+
/*
- * Indices into io_fds[] when running a command in a pty.
+ * I/O buffer with associated read/write events and a logging action.
+ * Used to, e.g. pass data from the pty to the user's terminal
+ * and any I/O logging plugins.
+ */
+struct io_buffer;
+typedef bool (*sudo_io_action_t)(const char *, unsigned int, struct io_buffer *);
+struct io_buffer {
+ SLIST_ENTRY(io_buffer) entries;
+ struct exec_closure *ec;
+ struct sudo_event *revent;
+ struct sudo_event *wevent;
+ sudo_io_action_t action;
+ int len; /* buffer length (how much produced) */
+ int off; /* write position (how much already consumed) */
+ char buf[64 * 1024];
+};
+SLIST_HEAD(io_buffer_list, io_buffer);
+
+/*
+ * Indices into io_fds[] when logging I/O.
*/
#define SFD_STDIN 0
#define SFD_STDOUT 1
@@ -45,6 +110,9 @@
#define SFD_FOLLOWER 4
#define SFD_USERTTY 5
+/* Evaluates to true if the event has /dev/tty as its fd. */
+#define USERTTY_EVENT(_ev) (sudo_ev_get_fd((_ev)) == io_fds[SFD_USERTTY])
+
/*
* Special values to indicate whether continuing in foreground or background.
*/
@@ -104,18 +172,11 @@ union sudo_token_un {
# endif /* HAVE_DECL_SECCOMP_MODE_FILTER */
#endif /* _PATH_SUDO_INTERCEPT && __linux__ */
-/*
- * Symbols shared between exec.c, exec_nopty.c, exec_pty.c and exec_monitor.c
- */
-struct command_details;
-struct command_status;
-struct sudo_event_base;
-struct stat;
-
/* exec.c */
void exec_cmnd(struct command_details *details, sigset_t *mask, int intercept_fd, int errfd);
void terminate_command(pid_t pid, bool use_pgrp);
bool sudo_terminated(struct command_status *cstat);
+void free_exec_closure(struct exec_closure *ec);
/* exec_common.c */
int sudo_execve(int fd, const char *path, char *const argv[], char *envp[], int intercept_fd, int flags);
@@ -126,6 +187,24 @@ char **enable_monitor(char *envp[], const char *dso);
void *intercept_setup(int fd, struct sudo_event_base *evbase, struct command_details *details);
void intercept_cleanup(void);
+/* exec_iolog.c */
+bool log_ttyin(const char *buf, unsigned int n, struct io_buffer *iob);
+bool log_stdin(const char *buf, unsigned int n, struct io_buffer *iob);
+bool log_ttyout(const char *buf, unsigned int n, struct io_buffer *iob);
+bool log_stdout(const char *buf, unsigned int n, struct io_buffer *iob);
+bool log_stderr(const char *buf, unsigned int n, struct io_buffer *iob);
+void log_suspend(struct exec_closure *ec, int signo);
+void log_winchange(struct exec_closure *ec, unsigned int rows, unsigned int cols);
+void io_buf_new(int rfd, int wfd, bool (*action)(const char *, unsigned int, struct io_buffer *), void (*read_cb)(int fd, int what, void *v), void (*write_cb)(int fd, int what, void *v), struct exec_closure *ec, struct io_buffer_list *head);
+int safe_close(int fd);
+void ev_free_by_fd(struct sudo_event_base *evbase, int fd);
+void free_io_bufs(void);
+void add_io_events(struct sudo_event_base *evbase);
+void del_io_events(bool nonblocking);
+void init_ttyblock(void);
+extern struct io_buffer_list iobufs;
+extern int ttymode;
+
/* exec_nopty.c */
void exec_nopty(struct command_details *details, struct command_status *cstat);
@@ -144,7 +223,8 @@ bool utmp_login(const char *from_line, const char *to_line, int ttyfd,
bool utmp_logout(const char *line, int status);
/* exec_preload.c */
-char **sudo_preload_dso(char *envp[], const char *dso_file, int intercept_fd);
+char **sudo_preload_dso(char *const envp[], const char *dso_file, int intercept_fd);
+char **sudo_preload_dso_mmap(char *const envp[], const char *dso_file, int intercept_fd);
/* exec_ptrace.c */
bool exec_ptrace_stopped(pid_t pid, int status, void *intercept);
@@ -152,6 +232,6 @@ bool set_exec_filter(void);
int exec_ptrace_seize(pid_t child);
/* suspend_nopty.c */
-void suspend_sudo_nopty(int signo, pid_t ppgrp, pid_t cmnd_pid);
+void suspend_sudo_nopty(struct exec_closure *ec, int signo, pid_t ppgrp, pid_t cmnd_pid);
#endif /* SUDO_EXEC_H */