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.
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
* SPDX-License-Identifier: ISC
|
* 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
|
* Permission to use, copy, modify, and distribute this software for any
|
||||||
* purpose with or without fee is hereby granted, provided that the above
|
* 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 */
|
/* ttysize.c */
|
||||||
sudo_dso_public void sudo_get_ttysize_v1(int *rowp, int *colp);
|
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 */
|
/* uuid.c */
|
||||||
sudo_dso_public void sudo_uuid_create_v1(unsigned char uuid_out[16]);
|
sudo_dso_public void sudo_uuid_create_v1(unsigned char uuid_out[16]);
|
||||||
|
@@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
* SPDX-License-Identifier: ISC
|
* 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
|
* Permission to use, copy, modify, and distribute this software for any
|
||||||
* purpose with or without fee is hereby granted, provided that the above
|
* purpose with or without fee is hereby granted, provided that the above
|
||||||
@@ -34,12 +34,12 @@
|
|||||||
#include "sudo_util.h"
|
#include "sudo_util.h"
|
||||||
|
|
||||||
static int
|
static int
|
||||||
get_ttysize_ioctl(int *rowp, int *colp)
|
get_ttysize_ioctl(int fd, int *rowp, int *colp)
|
||||||
{
|
{
|
||||||
struct winsize wsize;
|
struct winsize wsize;
|
||||||
debug_decl(get_ttysize_ioctl, SUDO_DEBUG_UTIL);
|
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) {
|
if (wsize.ws_row != 0 && wsize.ws_col != 0) {
|
||||||
*rowp = wsize.ws_row;
|
*rowp = wsize.ws_row;
|
||||||
*colp = wsize.ws_col;
|
*colp = wsize.ws_col;
|
||||||
@@ -51,10 +51,16 @@ get_ttysize_ioctl(int *rowp, int *colp)
|
|||||||
|
|
||||||
void
|
void
|
||||||
sudo_get_ttysize_v1(int *rowp, int *colp)
|
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);
|
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;
|
char *p;
|
||||||
|
|
||||||
/* Fall back on $LINES and $COLUMNS. */
|
/* Fall back on $LINES and $COLUMNS. */
|
||||||
|
@@ -83,6 +83,7 @@ sudo_gai_vfatal_nodebug_v1
|
|||||||
sudo_gai_vwarn_nodebug_v1
|
sudo_gai_vwarn_nodebug_v1
|
||||||
sudo_gai_warn_nodebug_v1
|
sudo_gai_warn_nodebug_v1
|
||||||
sudo_get_ttysize_v1
|
sudo_get_ttysize_v1
|
||||||
|
sudo_get_ttysize_v2
|
||||||
sudo_getgrouplist2_v1
|
sudo_getgrouplist2_v1
|
||||||
sudo_gethostname_v1
|
sudo_gethostname_v1
|
||||||
sudo_gettime_awake_v1
|
sudo_gettime_awake_v1
|
||||||
|
@@ -660,7 +660,7 @@ setup_terminal(struct eventlog *evlog, bool interactive, bool resize)
|
|||||||
|
|
||||||
if (!terminal_can_resize) {
|
if (!terminal_can_resize) {
|
||||||
/* either not xterm or not interactive */
|
/* 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) {
|
if (evlog->lines == terminal_lines && evlog->columns == terminal_cols) {
|
||||||
|
@@ -755,7 +755,7 @@ usage(void)
|
|||||||
{
|
{
|
||||||
int rows, cols;
|
int rows, cols;
|
||||||
|
|
||||||
sudo_get_ttysize(&rows, &cols);
|
sudo_get_ttysize(STDERR_FILENO, &rows, &cols);
|
||||||
display_usage(usage_err, cols);
|
display_usage(usage_err, cols);
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
@@ -796,7 +796,7 @@ help(void)
|
|||||||
int rows, cols;
|
int rows, cols;
|
||||||
debug_decl(help, SUDO_DEBUG_ARGS);
|
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);
|
sudo_lbuf_init(&lbuf, usage_out, indent, NULL, cols);
|
||||||
if (strcmp(pname, "sudoedit") == 0) {
|
if (strcmp(pname, "sudoedit") == 0) {
|
||||||
sudoedit = true;
|
sudoedit = true;
|
||||||
|
@@ -623,7 +623,7 @@ get_user_info(struct user_details *ud)
|
|||||||
goto oom;
|
goto oom;
|
||||||
ud->host = info[i] + sizeof("host=") - 1;
|
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)
|
if (asprintf(&info[++i], "lines=%d", ud->ts_rows) == -1)
|
||||||
goto oom;
|
goto oom;
|
||||||
if (asprintf(&info[++i], "cols=%d", ud->ts_cols) == -1)
|
if (asprintf(&info[++i], "cols=%d", ud->ts_cols) == -1)
|
||||||
|
Reference in New Issue
Block a user