diff options
author | Todd C. Miller <Todd.Miller@sudo.ws> | 2023-04-16 15:45:19 -0600 |
---|---|---|
committer | Todd C. Miller <Todd.Miller@sudo.ws> | 2023-04-16 15:45:19 -0600 |
commit | 8c9bdeb4ab003fe30e7a981412511997c02f75b5 (patch) | |
tree | 15cab213352de9d6c6504a6eec8d7de83331eb0a | |
parent | a96a7bb7d416bf5e2e42ae3089afae9569873b9c (diff) | |
download | sudo-8c9bdeb4ab003fe30e7a981412511997c02f75b5.tar.gz |
Add an fd argument to sudo_get_ttysize() instead of always using stderr.
For sudoreplay we open /dev/tty, so use that instead of stderr when
determining the terminal size.
-rw-r--r-- | include/sudo_util.h | 5 | ||||
-rw-r--r-- | lib/util/ttysize.c | 14 | ||||
-rw-r--r-- | lib/util/util.exp.in | 1 | ||||
-rw-r--r-- | plugins/sudoers/sudoreplay.c | 2 | ||||
-rw-r--r-- | src/parse_args.c | 4 | ||||
-rw-r--r-- | src/sudo.c | 2 |
6 files changed, 18 insertions, 10 deletions
diff --git a/include/sudo_util.h b/include/sudo_util.h index 045fb02cd..e6ab20c45 100644 --- a/include/sudo_util.h +++ b/include/sudo_util.h @@ -1,7 +1,7 @@ /* * SPDX-License-Identifier: ISC * - * Copyright (c) 2013-2022 Todd C. Miller <Todd.Miller@sudo.ws> + * Copyright (c) 2013-2023 Todd C. Miller <Todd.Miller@sudo.ws> * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above @@ -336,7 +336,8 @@ sudo_dso_public char *sudo_ttyname_dev_v1(dev_t tdev, char *name, size_t namelen /* ttysize.c */ sudo_dso_public void sudo_get_ttysize_v1(int *rowp, int *colp); -#define sudo_get_ttysize(_a, _b) sudo_get_ttysize_v1((_a), (_b)) +sudo_dso_public void sudo_get_ttysize_v2(int fd, int *rowp, int *colp); +#define sudo_get_ttysize(_a, _b, _c) sudo_get_ttysize_v2((_a), (_b), (_c)) /* uuid.c */ sudo_dso_public void sudo_uuid_create_v1(unsigned char uuid_out[16]); diff --git a/lib/util/ttysize.c b/lib/util/ttysize.c index c14e3a85d..d72f96eb9 100644 --- a/lib/util/ttysize.c +++ b/lib/util/ttysize.c @@ -1,7 +1,7 @@ /* * SPDX-License-Identifier: ISC * - * Copyright (c) 2010-2012, 2014-2015 Todd C. Miller <Todd.Miller@sudo.ws> + * Copyright (c) 2010-2012, 2014-2015, 2023 Todd C. Miller <Todd.Miller@sudo.ws> * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above @@ -34,12 +34,12 @@ #include "sudo_util.h" static int -get_ttysize_ioctl(int *rowp, int *colp) +get_ttysize_ioctl(int fd, int *rowp, int *colp) { struct winsize wsize; debug_decl(get_ttysize_ioctl, SUDO_DEBUG_UTIL); - if (isatty(STDERR_FILENO) && ioctl(STDERR_FILENO, TIOCGWINSZ, &wsize) == 0) { + if (isatty(fd) && ioctl(fd, TIOCGWINSZ, &wsize) == 0) { if (wsize.ws_row != 0 && wsize.ws_col != 0) { *rowp = wsize.ws_row; *colp = wsize.ws_col; @@ -52,9 +52,15 @@ get_ttysize_ioctl(int *rowp, int *colp) void sudo_get_ttysize_v1(int *rowp, int *colp) { + sudo_get_ttysize_v2(STDERR_FILENO, rowp, colp); +} + +void +sudo_get_ttysize_v2(int fd, int *rowp, int *colp) +{ debug_decl(sudo_get_ttysize, SUDO_DEBUG_UTIL); - if (get_ttysize_ioctl(rowp, colp) == -1) { + if (get_ttysize_ioctl(fd, rowp, colp) == -1) { char *p; /* Fall back on $LINES and $COLUMNS. */ diff --git a/lib/util/util.exp.in b/lib/util/util.exp.in index 484753ab0..47e776c0d 100644 --- a/lib/util/util.exp.in +++ b/lib/util/util.exp.in @@ -83,6 +83,7 @@ sudo_gai_vfatal_nodebug_v1 sudo_gai_vwarn_nodebug_v1 sudo_gai_warn_nodebug_v1 sudo_get_ttysize_v1 +sudo_get_ttysize_v2 sudo_getgrouplist2_v1 sudo_gethostname_v1 sudo_gettime_awake_v1 diff --git a/plugins/sudoers/sudoreplay.c b/plugins/sudoers/sudoreplay.c index 0f068f05c..965074c4f 100644 --- a/plugins/sudoers/sudoreplay.c +++ b/plugins/sudoers/sudoreplay.c @@ -660,7 +660,7 @@ setup_terminal(struct eventlog *evlog, bool interactive, bool resize) if (!terminal_can_resize) { /* either not xterm or not interactive */ - sudo_get_ttysize(&terminal_lines, &terminal_cols); + sudo_get_ttysize(ttyfd, &terminal_lines, &terminal_cols); } if (evlog->lines == terminal_lines && evlog->columns == terminal_cols) { diff --git a/src/parse_args.c b/src/parse_args.c index 437ecad3f..303004b46 100644 --- a/src/parse_args.c +++ b/src/parse_args.c @@ -755,7 +755,7 @@ usage(void) { int rows, cols; - sudo_get_ttysize(&rows, &cols); + sudo_get_ttysize(STDERR_FILENO, &rows, &cols); display_usage(usage_err, cols); exit(EXIT_FAILURE); } @@ -796,7 +796,7 @@ help(void) int rows, cols; debug_decl(help, SUDO_DEBUG_ARGS); - sudo_get_ttysize(&rows, &cols); + sudo_get_ttysize(STDERR_FILENO, &rows, &cols); sudo_lbuf_init(&lbuf, usage_out, indent, NULL, cols); if (strcmp(pname, "sudoedit") == 0) { sudoedit = true; diff --git a/src/sudo.c b/src/sudo.c index 285ce7f6d..b55859165 100644 --- a/src/sudo.c +++ b/src/sudo.c @@ -623,7 +623,7 @@ get_user_info(struct user_details *ud) goto oom; ud->host = info[i] + sizeof("host=") - 1; - sudo_get_ttysize(&ud->ts_rows, &ud->ts_cols); + sudo_get_ttysize(STDERR_FILENO, &ud->ts_rows, &ud->ts_cols); if (asprintf(&info[++i], "lines=%d", ud->ts_rows) == -1) goto oom; if (asprintf(&info[++i], "cols=%d", ud->ts_cols) == -1) |