21
21
** Ask for a password from tty
22
22
** This is an own file to avoid conflicts with curses
24
#include <my_global.h>
24
#include <drizzled/global.h>
25
#include <mysys/my_sys.h>
26
26
#include "drizzle.h"
27
#include <mystrings/m_string.h>
28
#include <mystrings/m_ctype.h>
30
30
#if defined(HAVE_BROKEN_GETPASS) && !defined(HAVE_GETPASSPHRASE)
31
31
#undef HAVE_GETPASS
34
34
#ifdef HAVE_GETPASS
37
#endif /* HAVE_PWD_H */
37
# endif /* HAVE_PWD_H */
38
38
#else /* ! HAVE_GETPASS */
39
#if !defined(__WIN__) && !defined(__NETWARE__)
40
#include <sys/ioctl.h>
41
#ifdef HAVE_TERMIOS_H /* For tty-password */
43
#define TERMIO struct termios
45
#ifdef HAVE_TERMIO_H /* For tty-password */
47
#define TERMIO struct termio
50
#define TERMIO struct sgttyb
53
#ifdef alpha_linux_port
54
#include <asm/ioctls.h> /* QQ; Fix this in configure */
55
#include <asm/termiobits.h>
60
#endif /* __NETWARE__ */
39
# if !defined(__WIN__) && !defined(__NETWARE__)
40
# include <sys/ioctl.h>
41
# ifdef HAVE_TERMIOS_H /* For tty-password */
43
# define TERMIO struct termios
45
# ifdef HAVE_TERMIO_H /* For tty-password */
47
# define TERMIO struct termio
50
# define TERMIO struct sgttyb
53
# ifdef alpha_linux_port
54
# include <asm/ioctls.h> /* QQ; Fix this in configure */
55
# include <asm/termiobits.h>
60
# endif /* ! __NETWARE__ */
61
# endif /* ! __WIN__ AND ! __NETWARE__ */
62
62
#endif /* HAVE_GETPASS */
64
64
#ifdef HAVE_GETPASSPHRASE /* For Solaris */
65
65
#define getpass(A) getpassphrase(A)
68
#if defined( __WIN__) || defined(__NETWARE__)
69
/* were just going to fake it here and get input from the keyboard */
74
#define _getch getcharacter
75
#define _cputs(A) putstring(A)
78
69
char *get_tty_password(const char *opt_message)
158
#endif /* ! HAVE_GETPASS */
149
# endif /* ! HAVE_GETPASS */
161
152
char *get_tty_password(const char *opt_message)
165
#else /* ! HAVE_GETPASS */
156
# else /* ! HAVE_GETPASS */
167
#endif /* HAVE_GETPASS */
158
# endif /* HAVE_GETPASS */
171
162
passbuff = getpass(opt_message ? opt_message : "Enter password: ");
173
164
/* copy the password to buff and clear original (static) buffer */
174
165
strnmov(buff, passbuff, sizeof(buff) - 1);
166
# ifdef _PASSWORD_LEN
176
167
memset(passbuff, 0, _PASSWORD_LEN);
169
# else /* ! HAVE_GETPASS */
179
170
if (isatty(fileno(stdout)))
181
172
fputs(opt_message ? opt_message : "Enter password: ",stdout);
184
#if defined(HAVE_TERMIOS_H)
175
# if defined(HAVE_TERMIOS_H)
185
176
tcgetattr(fileno(stdin), &org);
187
178
tmp.c_lflag &= ~(ECHO | ISIG | ICANON);
190
181
tcsetattr(fileno(stdin), TCSADRAIN, &tmp);
191
182
get_password(buff, sizeof(buff)-1, fileno(stdin), isatty(fileno(stdout)));
192
183
tcsetattr(fileno(stdin), TCSADRAIN, &org);
193
#elif defined(HAVE_TERMIO_H)
184
# elif defined(HAVE_TERMIO_H)
194
185
ioctl(fileno(stdin), (int) TCGETA, &org);
196
187
tmp.c_lflag &= ~(ECHO | ISIG | ICANON);
199
190
ioctl(fileno(stdin),(int) TCSETA, &tmp);
200
191
get_password(buff,sizeof(buff)-1,fileno(stdin),isatty(fileno(stdout)));
201
192
ioctl(fileno(stdin),(int) TCSETA, &org);
203
194
gtty(fileno(stdin), &org);
205
196
tmp.sg_flags &= ~ECHO;
207
198
stty(fileno(stdin), &tmp);
208
199
get_password(buff,sizeof(buff)-1,fileno(stdin),isatty(fileno(stdout)));
209
200
stty(fileno(stdin), &org);
211
202
if (isatty(fileno(stdout)))
212
203
fputc('\n',stdout);
213
#endif /* HAVE_GETPASS */
204
# endif /* HAVE_GETPASS */
215
206
return(my_strdup(buff,MYF(MY_FAE)));