get_password.c
上传用户:romrleung
上传日期:2022-05-23
资源大小:18897k
文件大小:5k
- /* Copyright (C) 2000 MySQL AB
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2 of the License, or
- (at your option) any later version.
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
- /*
- ** Ask for a password from tty
- ** This is an own file to avoid conflicts with curses
- */
- #include <my_global.h>
- #include <my_sys.h>
- #include "mysql.h"
- #include <m_string.h>
- #include <m_ctype.h>
- #if defined(HAVE_BROKEN_GETPASS) && !defined(HAVE_GETPASSPHRASE)
- #undef HAVE_GETPASS
- #endif
- #ifdef HAVE_GETPASS
- #ifdef HAVE_PWD_H
- #include <pwd.h>
- #endif /* HAVE_PWD_H */
- #else /* ! HAVE_GETPASS */
- #ifndef __WIN__
- #include <sys/ioctl.h>
- #ifdef HAVE_TERMIOS_H /* For tty-password */
- #include <termios.h>
- #define TERMIO struct termios
- #else
- #ifdef HAVE_TERMIO_H /* For tty-password */
- #include <termio.h>
- #define TERMIO struct termio
- #else
- #include <sgtty.h>
- #define TERMIO struct sgttyb
- #endif
- #endif
- #ifdef alpha_linux_port
- #include <asm/ioctls.h> /* QQ; Fix this in configure */
- #include <asm/termiobits.h>
- #endif
- #else
- #include <conio.h>
- #endif /* __WIN__ */
- #endif /* HAVE_GETPASS */
- #ifdef HAVE_GETPASSPHRASE /* For Solaris */
- #define getpass(A) getpassphrase(A)
- #endif
- #ifdef __WIN__
- /* were just going to fake it here and get input from
- the keyboard */
- char *get_tty_password(char *opt_message)
- {
- char to[80];
- char *pos=to,*end=to+sizeof(to)-1;
- int i=0;
- DBUG_ENTER("get_tty_password");
- _cputs(opt_message ? opt_message : "Enter password: ");
- for (;;)
- {
- char tmp;
- tmp=_getch();
- if (tmp == 'b' || (int) tmp == 127)
- {
- if (pos != to)
- {
- _cputs("b b");
- pos--;
- continue;
- }
- }
- if (tmp == 'n' || tmp == 'r' || tmp == 3)
- break;
- if (iscntrl(tmp) || pos == end)
- continue;
- _cputs("*");
- *(pos++) = tmp;
- }
- while (pos != to && isspace(pos[-1]) == ' ')
- pos--; /* Allow dummy space at end */
- *pos=0;
- _cputs("n");
- DBUG_RETURN(my_strdup(to,MYF(MY_FAE)));
- }
- #else
- #ifndef HAVE_GETPASS
- /*
- ** Can't use fgets, because readline will get confused
- ** length is max number of chars in to, not counting