Skip to content

Commit 77f209e

Browse files
committed
sudo_term_raw: change the isig argument into a flags field
There are current two flags: SUDO_TERM_ISIG (enable terminal signals) and SUDO_TERM_OFLAG (preserve output flags). --HG-- branch : 1.9
1 parent 24cc3f4 commit 77f209e

3 files changed

Lines changed: 16 additions & 6 deletions

File tree

include/sudo_util.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -317,13 +317,15 @@ sudo_dso_public int sudo_strtomode_v1(const char *cp, const char **errstr);
317317
extern int (*sudo_printf)(int msg_type, const char *fmt, ...);
318318

319319
/* term.c */
320+
#define SUDO_TERM_ISIG 0x01U
321+
#define SUDO_TERM_OFLAG 0x02U
320322
sudo_dso_public bool sudo_term_cbreak_v1(int fd);
321323
#define sudo_term_cbreak(_a) sudo_term_cbreak_v1((_a))
322324
sudo_dso_public bool sudo_term_copy_v1(int src, int dst);
323325
#define sudo_term_copy(_a, _b) sudo_term_copy_v1((_a), (_b))
324326
sudo_dso_public bool sudo_term_noecho_v1(int fd);
325327
#define sudo_term_noecho(_a) sudo_term_noecho_v1((_a))
326-
sudo_dso_public bool sudo_term_raw_v1(int fd, int isig);
328+
sudo_dso_public bool sudo_term_raw_v1(int fd, unsigned int flags);
327329
#define sudo_term_raw(_a, _b) sudo_term_raw_v1((_a), (_b))
328330
sudo_dso_public bool sudo_term_restore_v1(int fd, bool flush);
329331
#define sudo_term_restore(_a, _b) sudo_term_restore_v1((_a), (_b))

lib/util/term.c

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -178,22 +178,30 @@ sudo_term_noecho_v1(int fd)
178178
}
179179

180180
/*
181-
* Set terminal to raw mode with optional terminal signals.
181+
* Set terminal to raw mode as modified by flags.
182182
* Returns true on success or false on failure.
183183
*/
184184
bool
185-
sudo_term_raw_v1(int fd, int isig)
185+
sudo_term_raw_v1(int fd, unsigned int flags)
186186
{
187187
struct termios term;
188+
tcflag_t oflag;
188189
debug_decl(sudo_term_raw, SUDO_DEBUG_UTIL);
189190

190191
if (!changed && tcgetattr(fd, &oterm) != 0)
191192
debug_return_bool(false);
192193
(void) memcpy(&term, &oterm, sizeof(term));
193-
/* Set terminal to raw mode but optionally enable terminal signals. */
194+
/*
195+
* Set terminal to raw mode but optionally enable terminal signals
196+
* and/or preserve output flags.
197+
*/
198+
if (ISSET(flags, SUDO_TERM_OFLAG))
199+
oflag = term.c_oflag;
194200
cfmakeraw(&term);
195-
if (isig)
201+
if (ISSET(flags, SUDO_TERM_ISIG))
196202
SET(term.c_lflag, ISIG);
203+
if (ISSET(flags, SUDO_TERM_OFLAG))
204+
term.c_oflag = oflag;
197205
if (tcsetattr_nobg(fd, TCSASOFT|TCSADRAIN, &term) == 0) {
198206
changed = 1;
199207
debug_return_bool(true);

plugins/sudoers/sudoreplay.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -629,7 +629,7 @@ setup_terminal(struct eventlog *evlog, bool interactive, bool resize)
629629
/* Open fd for /dev/tty and set to raw mode. */
630630
if (interactive) {
631631
ttyfd = open(_PATH_TTY, O_RDWR);
632-
while (!sudo_term_raw(ttyfd, 1)) {
632+
while (!sudo_term_raw(ttyfd, SUDO_TERM_ISIG)) {
633633
if (errno != EINTR)
634634
sudo_fatal("%s", U_("unable to set tty to raw mode"));
635635
kill(getpid(), SIGTTOU);

0 commit comments

Comments
 (0)