#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 50 of file get_password.c.
Definition at line 121 of file get_password.c.
References my_read, MYF, and pos().
00122 { 00123 char *pos=to,*end=to+length; 00124 00125 for (;;) 00126 { 00127 char tmp; 00128 if (my_read(fd,&tmp,1,MYF(0)) != 1) 00129 break; 00130 if (tmp == '\b' || (int) tmp == 127) 00131 { 00132 if (pos != to) 00133 { 00134 if (echo) 00135 { 00136 fputs("\b \b",stdout); 00137 fflush(stdout); 00138 } 00139 pos--; 00140 continue; 00141 } 00142 } 00143 if (tmp == '\n' || tmp == '\r' || tmp == 3) 00144 break; 00145 if (iscntrl(tmp) || pos == end) 00146 continue; 00147 if (echo) 00148 { 00149 fputc('*',stdout); 00150 fflush(stdout); 00151 } 00152 *(pos++) = tmp; 00153 } 00154 while (pos != to && isspace(pos[-1]) == ' ') 00155 pos--; /* Allow dummy space at end */ 00156 *pos=0; 00157 return; 00158 }
Here is the call graph for this function:

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

1.4.7

