diff --git a/Documentation/Release-Notes/MaxScale-2.2.3-Release-Notes.md b/Documentation/Release-Notes/MaxScale-2.2.3-Release-Notes.md index cf1f85e50..c7c1d4f58 100644 --- a/Documentation/Release-Notes/MaxScale-2.2.3-Release-Notes.md +++ b/Documentation/Release-Notes/MaxScale-2.2.3-Release-Notes.md @@ -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 diff --git a/client/maxadmin.c b/client/maxadmin.c index 9ef3a33ce..486f3bbce 100644 --- a/client/maxadmin.c +++ b/client/maxadmin.c @@ -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; }