MXS-1683: Allow MaxAdmin use without controlling tty

When MaxAdmin would be used without a controlling terminal, it would
refuse to accept passwords from stdin as it could not set the terminal
attributes. This means that executing MaxAdmin commands from other
programs would fail if the process had no controlling terminal.

Turning the error into a warning will allow users to know that terminal
echo is still enabled before they type their passwords.
This commit is contained in:
Markus Mäkelä 2018-02-25 04:24:05 +02:00
parent 8bfb4f231a
commit 73de112ae4
No known key found for this signature in database
GPG Key ID: 72D48FCE664F7B19
2 changed files with 41 additions and 23 deletions

View File

@ -17,6 +17,13 @@ being monitored by the mariadbmon monitor, the current GTID position will be
displayed in the newly added column. If no GTID is available, an empty value is
returned.
### MaxAdmin input from scripts
The failure to set terminal attributes for MaxScale is no longer considered an
error as scripts most often do not have an actual terminal that control the
process. This means that passwords and other commands can be passed to MaxAdmin
without a controlling terminal.
## Dropped Features
## New Features

View File

@ -937,8 +937,7 @@ read_inifile(char **socket,
*/
bool getPassword(char *passwd, size_t len)
{
bool gotten = false;
bool err = false;
struct termios tty_attr;
tcflag_t c_lflag;
@ -948,36 +947,48 @@ bool getPassword(char *passwd, size_t len)
tty_attr.c_lflag &= ~ICANON;
tty_attr.c_lflag &= ~ECHO;
if (tcsetattr(STDIN_FILENO, 0, &tty_attr) == 0)
if (tcsetattr(STDIN_FILENO, 0, &tty_attr) != 0)
{
printf("Password: ");
if (fgets(passwd, len, stdin) == NULL)
{
printf("Failed to read password\n");
}
err = true;
}
}
else
{
err = true;
}
tty_attr.c_lflag = c_lflag;
if (err)
{
fprintf(stderr,
"Warning: Could not configure terminal. Terminal echo is still enabled. This\n"
"means that the password will be visible on the controlling terminal when\n"
"it is written!\n");
}
if (tcsetattr(STDIN_FILENO, 0, &tty_attr) == 0)
{
int i = strlen(passwd);
printf("Password: ");
if (fgets(passwd, len, stdin) == NULL)
{
printf("Failed to read password\n");
}
if (i > 1)
{
passwd[i - 1] = '\0';
}
if (!err)
{
tty_attr.c_lflag = c_lflag;
printf("\n");
gotten = true;
}
if (tcsetattr(STDIN_FILENO, 0, &tty_attr) != 0)
{
err = true;
}
}
if (!gotten)
int i = strlen(passwd);
if (i > 0)
{
fprintf(stderr, "Could not configure terminal.\n");
passwd[i - 1] = '\0';
}
return gotten;
printf("\n");
return *passwd;
}