Reduce name space pollution in libsudo_util.so

This commit is contained in:
Todd C. Miller
2014-06-26 16:21:19 -06:00
parent 9b3c19cc36
commit d36846a699
8 changed files with 47 additions and 46 deletions

View File

@@ -163,13 +163,13 @@ __dso_public void initprogname(const char *);
__dso_public int sudo_setgroups(int ngids, const GETGROUPS_T *gids); __dso_public int sudo_setgroups(int ngids, const GETGROUPS_T *gids);
/* term.c */ /* term.c */
__dso_public bool term_cbreak(int); __dso_public bool sudo_term_cbreak(int);
__dso_public bool term_copy(int, int); __dso_public bool sudo_term_copy(int, int);
__dso_public bool term_noecho(int); __dso_public bool sudo_term_noecho(int);
__dso_public bool term_raw(int, int); __dso_public bool sudo_term_raw(int, int);
__dso_public bool term_restore(int, bool); __dso_public bool sudo_term_restore(int, bool);
/* ttysize.c */ /* ttysize.c */
__dso_public void get_ttysize(int *rowp, int *colp); __dso_public void sudo_get_ttysize(int *rowp, int *colp);
#endif /* _SUDO_UTIL_H */ #endif /* _SUDO_UTIL_H */

View File

@@ -69,15 +69,16 @@ static struct termios term, oterm;
static int changed; static int changed;
/* tgetpass() needs to know the erase and kill chars for cbreak mode. */ /* tgetpass() needs to know the erase and kill chars for cbreak mode. */
__dso_public int term_erase; __dso_public int sudo_term_erase;
__dso_public int term_kill; __dso_public int sudo_term_kill;
static volatile sig_atomic_t got_sigttou; static volatile sig_atomic_t got_sigttou;
/* /*
* SIGTTOU signal handler for term_restore that just sets a flag. * SIGTTOU signal handler for term_restore that just sets a flag.
*/ */
static void sigttou(int signo) static void
sigttou(int signo)
{ {
got_sigttou = 1; got_sigttou = 1;
} }
@@ -116,7 +117,7 @@ tcsetattr_nobg(int fd, int flags, struct termios *tp)
* Returns true on success or false on failure. * Returns true on success or false on failure.
*/ */
bool bool
term_restore(int fd, bool flush) sudo_term_restore(int fd, bool flush)
{ {
debug_decl(term_restore, SUDO_DEBUG_UTIL) debug_decl(term_restore, SUDO_DEBUG_UTIL)
@@ -134,7 +135,7 @@ term_restore(int fd, bool flush)
* Returns true on success or false on failure. * Returns true on success or false on failure.
*/ */
bool bool
term_noecho(int fd) sudo_term_noecho(int fd)
{ {
debug_decl(term_noecho, SUDO_DEBUG_UTIL) debug_decl(term_noecho, SUDO_DEBUG_UTIL)
@@ -163,7 +164,7 @@ again:
* Returns true on success or false on failure. * Returns true on success or false on failure.
*/ */
bool bool
term_raw(int fd, int isig) sudo_term_raw(int fd, int isig)
{ {
struct termios term; struct termios term;
debug_decl(term_raw, SUDO_DEBUG_UTIL) debug_decl(term_raw, SUDO_DEBUG_UTIL)
@@ -197,7 +198,7 @@ again:
* Returns true on success or false on failure. * Returns true on success or false on failure.
*/ */
bool bool
term_cbreak(int fd) sudo_term_cbreak(int fd)
{ {
debug_decl(term_cbreak, SUDO_DEBUG_UTIL) debug_decl(term_cbreak, SUDO_DEBUG_UTIL)
@@ -216,8 +217,8 @@ again:
term.c_cc[VSTATUS] = _POSIX_VDISABLE; term.c_cc[VSTATUS] = _POSIX_VDISABLE;
#endif #endif
if (tcsetattr_nobg(fd, TCSADRAIN|TCSASOFT, &term) == 0) { if (tcsetattr_nobg(fd, TCSADRAIN|TCSASOFT, &term) == 0) {
term_erase = term.c_cc[VERASE]; sudo_term_erase = term.c_cc[VERASE];
term_kill = term.c_cc[VKILL]; sudo_term_kill = term.c_cc[VKILL];
changed = 1; changed = 1;
debug_return_bool(true); debug_return_bool(true);
} }
@@ -234,7 +235,7 @@ again:
* Returns true on success or false on failure. * Returns true on success or false on failure.
*/ */
bool bool
term_copy(int src, int dst) sudo_term_copy(int src, int dst)
{ {
struct termios tt; struct termios tt;
debug_decl(term_copy, SUDO_DEBUG_UTIL) debug_decl(term_copy, SUDO_DEBUG_UTIL)

View File

@@ -71,9 +71,9 @@ get_ttysize_ioctl(int *rowp, int *colp)
#endif /* TIOCGWINSZ */ #endif /* TIOCGWINSZ */
void void
get_ttysize(int *rowp, int *colp) sudo_get_ttysize(int *rowp, int *colp)
{ {
debug_decl(fork_cmnd, SUDO_DEBUG_EXEC) debug_decl(sudo_get_ttysize, SUDO_DEBUG_EXEC)
if (get_ttysize_ioctl(rowp, colp) == -1) { if (get_ttysize_ioctl(rowp, colp) == -1) {
char *p; char *p;

View File

@@ -40,7 +40,6 @@ fatal_callback_deregister
fatal_callback_register fatal_callback_register
fatal_nodebug fatal_nodebug
fatalx_nodebug fatalx_nodebug
get_ttysize
getprogname getprogname
initprogname initprogname
isblank isblank
@@ -99,6 +98,7 @@ sudo_fnmatch
sudo_freeaddrinfo sudo_freeaddrinfo
sudo_futimes sudo_futimes
sudo_gai_strerror sudo_gai_strerror
sudo_get_ttysize
sudo_getaddrinfo sudo_getaddrinfo
sudo_getcwd sudo_getcwd
sudo_getgrouplist sudo_getgrouplist
@@ -132,16 +132,16 @@ sudo_strlcat
sudo_strlcpy sudo_strlcpy
sudo_strsignal sudo_strsignal
sudo_strtonum sudo_strtonum
sudo_term_cbreak
sudo_term_copy
sudo_term_erase
sudo_term_kill
sudo_term_noecho
sudo_term_raw
sudo_term_restore
sudo_utimes sudo_utimes
sudo_vasprintf sudo_vasprintf
sudo_vsnprintf sudo_vsnprintf
term_cbreak
term_copy
term_erase
term_kill
term_noecho
term_raw
term_restore
vfatal_nodebug vfatal_nodebug
vfatalx_nodebug vfatalx_nodebug
vwarning_nodebug vwarning_nodebug

View File

@@ -352,7 +352,7 @@ main(int argc, char *argv[])
printf(_("Replaying sudo session: %s\n"), li->cmd); printf(_("Replaying sudo session: %s\n"), li->cmd);
/* Make sure the terminal is large enough. */ /* Make sure the terminal is large enough. */
get_ttysize(&rows, &cols); sudo_get_ttysize(&rows, &cols);
if (li->rows != 0 && li->cols != 0) { if (li->rows != 0 && li->cols != 0) {
if (li->rows > rows) { if (li->rows > rows) {
printf(_("Warning: your terminal is too small to properly replay the log.\n")); printf(_("Warning: your terminal is too small to properly replay the log.\n"));
@@ -367,7 +367,7 @@ main(int argc, char *argv[])
/* Replay session corresponding to io_log_files[]. */ /* Replay session corresponding to io_log_files[]. */
replay_session(max_wait, decimal); replay_session(max_wait, decimal);
term_restore(STDIN_FILENO, 1); sudo_term_restore(STDIN_FILENO, 1);
done: done:
sudo_debug_exit_int(__func__, __FILE__, __LINE__, sudo_debug_subsys, exitcode); sudo_debug_exit_int(__func__, __FILE__, __LINE__, sudo_debug_subsys, exitcode);
exit(exitcode); exit(exitcode);
@@ -410,7 +410,7 @@ replay_session(const double max_wait, const char *decimal)
idx = fcntl(STDIN_FILENO, F_GETFL, 0); idx = fcntl(STDIN_FILENO, F_GETFL, 0);
if (idx != -1) if (idx != -1)
(void) fcntl(STDIN_FILENO, F_SETFL, idx | O_NONBLOCK); (void) fcntl(STDIN_FILENO, F_SETFL, idx | O_NONBLOCK);
if (!term_raw(STDIN_FILENO, 1)) if (!sudo_term_raw(STDIN_FILENO, 1))
fatal(U_("unable to set tty to raw mode")); fatal(U_("unable to set tty to raw mode"));
} }
@@ -1260,7 +1260,7 @@ help(void)
static void static void
sudoreplay_cleanup(void) sudoreplay_cleanup(void)
{ {
term_restore(STDIN_FILENO, 0); sudo_term_restore(STDIN_FILENO, 0);
} }
/* /*
@@ -1270,6 +1270,6 @@ sudoreplay_cleanup(void)
static void static void
sudoreplay_handler(int signo) sudoreplay_handler(int signo)
{ {
term_restore(STDIN_FILENO, 0); sudo_term_restore(STDIN_FILENO, 0);
kill(getpid(), signo); kill(getpid(), signo);
} }

View File

@@ -116,7 +116,7 @@ pty_cleanup(void)
debug_decl(cleanup, SUDO_DEBUG_EXEC); debug_decl(cleanup, SUDO_DEBUG_EXEC);
if (!TAILQ_EMPTY(&io_plugins) && io_fds[SFD_USERTTY] != -1) if (!TAILQ_EMPTY(&io_plugins) && io_fds[SFD_USERTTY] != -1)
term_restore(io_fds[SFD_USERTTY], 0); sudo_term_restore(io_fds[SFD_USERTTY], 0);
#ifdef HAVE_SELINUX #ifdef HAVE_SELINUX
selinux_restore_tty(); selinux_restore_tty();
#endif #endif
@@ -328,7 +328,7 @@ check_foreground(void)
if (io_fds[SFD_USERTTY] != -1) { if (io_fds[SFD_USERTTY] != -1) {
foreground = tcgetpgrp(io_fds[SFD_USERTTY]) == ppgrp; foreground = tcgetpgrp(io_fds[SFD_USERTTY]) == ppgrp;
if (foreground && !tty_initialized) { if (foreground && !tty_initialized) {
if (term_copy(io_fds[SFD_USERTTY], io_fds[SFD_SLAVE])) { if (sudo_term_copy(io_fds[SFD_USERTTY], io_fds[SFD_SLAVE])) {
tty_initialized = true; tty_initialized = true;
sync_ttysize(io_fds[SFD_USERTTY], io_fds[SFD_SLAVE]); sync_ttysize(io_fds[SFD_USERTTY], io_fds[SFD_SLAVE]);
} }
@@ -363,7 +363,7 @@ suspend_parent(int signo)
if (foreground) { if (foreground) {
if (ttymode != TERM_RAW) { if (ttymode != TERM_RAW) {
do { do {
n = term_raw(io_fds[SFD_USERTTY], 0); n = sudo_term_raw(io_fds[SFD_USERTTY], 0);
} while (!n && errno == EINTR); } while (!n && errno == EINTR);
ttymode = TERM_RAW; ttymode = TERM_RAW;
} }
@@ -378,7 +378,7 @@ suspend_parent(int signo)
/* Restore original tty mode before suspending. */ /* Restore original tty mode before suspending. */
if (ttymode != TERM_COOKED) if (ttymode != TERM_COOKED)
term_restore(io_fds[SFD_USERTTY], 0); sudo_term_restore(io_fds[SFD_USERTTY], 0);
if (sig2str(signo, signame) == -1) if (sig2str(signo, signame) == -1)
snprintf(signame, sizeof(signame), "%d", signo); snprintf(signame, sizeof(signame), "%d", signo);
@@ -413,7 +413,7 @@ suspend_parent(int signo)
if (foreground) { if (foreground) {
/* Foreground process, set tty to raw mode. */ /* Foreground process, set tty to raw mode. */
do { do {
n = term_raw(io_fds[SFD_USERTTY], 0); n = sudo_term_raw(io_fds[SFD_USERTTY], 0);
} while (!n && errno == EINTR); } while (!n && errno == EINTR);
ttymode = TERM_RAW; ttymode = TERM_RAW;
} else { } else {
@@ -727,7 +727,7 @@ fork_pty(struct command_details *details, int sv[], sigset_t *omask)
if (foreground) { if (foreground) {
/* Copy terminal attrs from user tty -> pty slave. */ /* Copy terminal attrs from user tty -> pty slave. */
if (term_copy(io_fds[SFD_USERTTY], io_fds[SFD_SLAVE])) { if (sudo_term_copy(io_fds[SFD_USERTTY], io_fds[SFD_SLAVE])) {
tty_initialized = true; tty_initialized = true;
sync_ttysize(io_fds[SFD_USERTTY], io_fds[SFD_SLAVE]); sync_ttysize(io_fds[SFD_USERTTY], io_fds[SFD_SLAVE]);
} }
@@ -736,7 +736,7 @@ fork_pty(struct command_details *details, int sv[], sigset_t *omask)
if (!pipeline && !ISSET(details->flags, CD_EXEC_BG)) { if (!pipeline && !ISSET(details->flags, CD_EXEC_BG)) {
ttymode = TERM_RAW; ttymode = TERM_RAW;
do { do {
n = term_raw(io_fds[SFD_USERTTY], 0); n = sudo_term_raw(io_fds[SFD_USERTTY], 0);
} while (!n && errno == EINTR); } while (!n && errno == EINTR);
if (!n) if (!n)
fatal(U_("unable to set terminal to raw mode")); fatal(U_("unable to set terminal to raw mode"));
@@ -823,7 +823,7 @@ pty_close(struct command_status *cstat)
/* Restore terminal settings. */ /* Restore terminal settings. */
if (io_fds[SFD_USERTTY] != -1) if (io_fds[SFD_USERTTY] != -1)
term_restore(io_fds[SFD_USERTTY], 0); sudo_term_restore(io_fds[SFD_USERTTY], 0);
/* If child was signalled, write the reason to stdout like the shell. */ /* If child was signalled, write the reason to stdout like the shell. */
if (cstat->type == CMD_WSTATUS && WIFSIGNALED(cstat->val)) { if (cstat->type == CMD_WSTATUS && WIFSIGNALED(cstat->val)) {

View File

@@ -513,7 +513,7 @@ get_user_info(struct user_details *ud)
fatal(NULL); fatal(NULL);
ud->host = user_info[i] + sizeof("host=") - 1; ud->host = user_info[i] + sizeof("host=") - 1;
get_ttysize(&ud->ts_lines, &ud->ts_cols); sudo_get_ttysize(&ud->ts_lines, &ud->ts_cols);
easprintf(&user_info[++i], "lines=%d", ud->ts_lines); easprintf(&user_info[++i], "lines=%d", ud->ts_lines);
easprintf(&user_info[++i], "cols=%d", ud->ts_cols); easprintf(&user_info[++i], "cols=%d", ud->ts_cols);

View File

@@ -119,9 +119,9 @@ restart:
*/ */
if (!ISSET(flags, TGP_ECHO)) { if (!ISSET(flags, TGP_ECHO)) {
if (ISSET(flags, TGP_MASK)) if (ISSET(flags, TGP_MASK))
neednl = term_cbreak(input); neednl = sudo_term_cbreak(input);
else else
neednl = term_noecho(input); neednl = sudo_term_noecho(input);
} }
/* /*
@@ -164,7 +164,7 @@ restart:
restore: restore:
/* Restore old tty settings and signals. */ /* Restore old tty settings and signals. */
if (!ISSET(flags, TGP_ECHO)) if (!ISSET(flags, TGP_ECHO))
term_restore(input, 1); sudo_term_restore(input, 1);
(void) sigaction(SIGALRM, &savealrm, NULL); (void) sigaction(SIGALRM, &savealrm, NULL);
(void) sigaction(SIGINT, &saveint, NULL); (void) sigaction(SIGINT, &saveint, NULL);
(void) sigaction(SIGHUP, &savehup, NULL); (void) sigaction(SIGHUP, &savehup, NULL);
@@ -261,7 +261,7 @@ sudo_askpass(const char *askpass, const char *prompt)
debug_return_str_masked(pass); debug_return_str_masked(pass);
} }
extern int term_erase, term_kill; extern int sudo_term_erase, sudo_term_kill;
static char * static char *
getln(int fd, char *buf, size_t bufsiz, int feedback) getln(int fd, char *buf, size_t bufsiz, int feedback)
@@ -282,7 +282,7 @@ getln(int fd, char *buf, size_t bufsiz, int feedback)
if (nr != 1 || c == '\n' || c == '\r') if (nr != 1 || c == '\n' || c == '\r')
break; break;
if (feedback) { if (feedback) {
if (c == term_kill) { if (c == sudo_term_kill) {
while (cp > buf) { while (cp > buf) {
if (write(fd, "\b \b", 3) == -1) if (write(fd, "\b \b", 3) == -1)
break; break;
@@ -290,7 +290,7 @@ getln(int fd, char *buf, size_t bufsiz, int feedback)
} }
left = bufsiz; left = bufsiz;
continue; continue;
} else if (c == term_erase) { } else if (c == sudo_term_erase) {
if (cp > buf) { if (cp > buf) {
if (write(fd, "\b \b", 3) == -1) if (write(fd, "\b \b", 3) == -1)
break; break;