The world's most popular open source database
#include <my_global.h>#include <my_sys.h>#include "mysql.h"#include <m_string.h>#include <m_ctype.h>#include <sys/ioctl.h>#include <sgtty.h>Include dependency graph for get_password.c:

Go to the source code of this file.
Defines | |
| #define | TERMIO struct sgttyb |
Functions | |
| static void | get_password (char *to, uint length, int fd, bool echo) |
| char * | get_tty_password (const char *opt_message) |
| #define TERMIO struct sgttyb |
Definition at line 111 of file get_password.c.
References my_read, MYF, and pos().
Referenced by Edit_user_cmd::execute(), Add_user_cmd::execute(), Print_password_line_cmd::execute(), and get_tty_password().
00112 { 00113 char *pos=to,*end=to+length; 00114 00115 for (;;) 00116 { 00117 char tmp; 00118 if (my_read(fd,&tmp,1,MYF(0)) != 1) 00119 break; 00120 if (tmp == '\b' || (int) tmp == 127) 00121 { 00122 if (pos != to) 00123 { 00124 if (echo) 00125 { 00126 fputs("\b \b",stderr); 00127 fflush(stderr); 00128 } 00129 pos--; 00130 continue; 00131 } 00132 } 00133 if (tmp == '\n' || tmp == '\r' || tmp == 3) 00134 break; 00135 if (iscntrl(tmp) || pos == end) 00136 continue; 00137 if (echo) 00138 { 00139 fputc('*',stderr); 00140 fflush(stderr); 00141 } 00142 *(pos++) = tmp; 00143 } 00144 while (pos != to && isspace(pos[-1]) == ' ') 00145 pos--; /* Allow dummy space at end */ 00146 *pos=0; 00147 return; 00148 }
Here is the call graph for this function:

Here is the caller graph for this function:

| char* get_tty_password | ( | const char * | opt_message | ) |
Definition at line 153 of file get_password.c.
Referenced by get_one_option(), get_options(), get_password(), main(), and parse_args().
00154 { 00155 #ifdef HAVE_GETPASS 00156 char *passbuff; 00157 #else /* ! HAVE_GETPASS */ 00158 TERMIO org,tmp; 00159 #endif /* HAVE_GETPASS */ 00160 char buff[80]; 00161 00162 DBUG_ENTER("get_tty_password"); 00163 00164 #ifdef HAVE_GETPASS 00165 passbuff = getpass(opt_message ? opt_message : "Enter password: "); 00166 00167 /* copy the password to buff and clear original (static) buffer */ 00168 strnmov(buff, passbuff, sizeof(buff) - 1); 00169 #ifdef _PASSWORD_LEN 00170 memset(passbuff, 0, _PASSWORD_LEN); 00171 #endif 00172 #else 00173 if (isatty(fileno(stderr))) 00174 { 00175 fputs(opt_message ? opt_message : "Enter password: ",stderr); 00176 fflush(stderr); 00177 } 00178 #if defined(HAVE_TERMIOS_H) 00179 tcgetattr(fileno(stdin), &org); 00180 tmp = org; 00181 tmp.c_lflag &= ~(ECHO | ISIG | ICANON); 00182 tmp.c_cc[VMIN] = 1; 00183 tmp.c_cc[VTIME] = 0; 00184 tcsetattr(fileno(stdin), TCSADRAIN, &tmp); 00185 get_password(buff, sizeof(buff)-1, fileno(stdin), isatty(fileno(stderr))); 00186 tcsetattr(fileno(stdin), TCSADRAIN, &org); 00187 #elif defined(HAVE_TERMIO_H) 00188 ioctl(fileno(stdin), (int) TCGETA, &org); 00189 tmp=org; 00190 tmp.c_lflag &= ~(ECHO | ISIG | ICANON); 00191 tmp.c_cc[VMIN] = 1; 00192 tmp.c_cc[VTIME]= 0; 00193 ioctl(fileno(stdin),(int) TCSETA, &tmp); 00194 get_password(buff,sizeof(buff)-1,fileno(stdin),isatty(fileno(stderr))); 00195 ioctl(fileno(stdin),(int) TCSETA, &org); 00196 #else 00197 gtty(fileno(stdin), &org); 00198 tmp=org; 00199 tmp.sg_flags &= ~ECHO; 00200 tmp.sg_flags |= RAW; 00201 stty(fileno(stdin), &tmp); 00202 get_password(buff,sizeof(buff)-1,fileno(stdin),isatty(fileno(stderr))); 00203 stty(fileno(stdin), &org); 00204 #endif 00205 if (isatty(fileno(stderr))) 00206 fputc('\n',stderr); 00207 #endif /* HAVE_GETPASS */ 00208 00209 DBUG_RETURN(my_strdup(buff,MYF(MY_FAE))); 00210 }
Here is the caller graph for this function:

1.4.7

