23 #include <my_global.h>
29 #if defined(HAVE_BROKEN_GETPASS) && !defined(HAVE_GETPASSPHRASE)
39 #include <sys/ioctl.h>
42 #define TERMIO struct termios
46 #define TERMIO struct termio
49 #define TERMIO struct sgttyb
52 #ifdef alpha_linux_port
53 #include <asm/ioctls.h>
54 #include <asm/termiobits.h>
61 #ifdef HAVE_GETPASSPHRASE
62 #define getpass(A) getpassphrase(A)
67 char *get_tty_password(
const char *opt_message)
70 char *pos=
to,*end=to+
sizeof(
to)-1;
72 DBUG_ENTER(
"get_tty_password");
73 _cputs(opt_message ? opt_message :
"Enter password: ");
78 if (tmp ==
'\b' || (
int) tmp == 127)
87 if (tmp ==
'\n' || tmp ==
'\r' || tmp == 3)
89 if (iscntrl(tmp) || pos == end)
94 while (pos != to && isspace(pos[-1]) ==
' ')
98 DBUG_RETURN(my_strdup(to,MYF(MY_FAE)));
110 static void get_password(
char *to,uint length,
int fd, my_bool echo)
112 char *pos=
to,*end=to+length;
117 if (my_read(fd,&tmp,1,MYF(0)) != 1)
119 if (tmp ==
'\b' || (
int) tmp == 127)
125 fputs(
"\b \b",stdout);
132 if (tmp ==
'\n' || tmp ==
'\r' || tmp == 3)
134 if (iscntrl(tmp) || pos == end)
143 while (pos != to && isspace(pos[-1]) ==
' ')
151 char *get_tty_password(
const char *opt_message)
160 DBUG_ENTER(
"get_tty_password");
163 passbuff = getpass(opt_message ? opt_message :
"Enter password: ");
166 strnmov(buff, passbuff,
sizeof(buff) - 1);
168 memset(passbuff, 0, _PASSWORD_LEN);
171 if (isatty(fileno(stdout)))
173 fputs(opt_message ? opt_message :
"Enter password: ",stdout);
176 #if defined(HAVE_TERMIOS_H)
177 tcgetattr(fileno(stdin), &org);
179 tmp.c_lflag &= ~(ECHO | ISIG | ICANON);
182 tcsetattr(fileno(stdin), TCSADRAIN, &tmp);
183 get_password(buff,
sizeof(buff)-1, fileno(stdin), isatty(fileno(stdout)));
184 tcsetattr(fileno(stdin), TCSADRAIN, &org);
185 #elif defined(HAVE_TERMIO_H)
186 ioctl(fileno(stdin), (
int) TCGETA, &org);
188 tmp.c_lflag &= ~(ECHO | ISIG | ICANON);
191 ioctl(fileno(stdin),(
int) TCSETA, &tmp);
192 get_password(buff,
sizeof(buff)-1,fileno(stdin),isatty(fileno(stdout)));
193 ioctl(fileno(stdin),(
int) TCSETA, &org);
195 gtty(fileno(stdin), &org);
197 tmp.sg_flags &= ~ECHO;
199 stty(fileno(stdin), &tmp);
200 get_password(buff,
sizeof(buff)-1,fileno(stdin),isatty(fileno(stdout)));
201 stty(fileno(stdin), &org);
203 if (isatty(fileno(stdout)))
207 DBUG_RETURN(my_strdup(buff,MYF(MY_FAE)));