renamed getpass() to my_getpass() and it is now thread-safe and should

disable passwd-echoing on win32 (supplied by Bjrn Stenberg)
This commit is contained in:
Daniel Stenberg 2000-10-26 10:32:04 +00:00
parent a5b01cf4e8
commit 02037971ed
3 changed files with 32 additions and 23 deletions

View File

@ -45,8 +45,6 @@
# endif # endif
#endif #endif
#define INPUT_BUFFER 128
#ifndef RETSIGTYPE #ifndef RETSIGTYPE
# define RETSIGTYPE void # define RETSIGTYPE void
#endif #endif
@ -70,11 +68,10 @@
# define perror(x) fprintf(stderr, "Error in: %s\n", x) # define perror(x) fprintf(stderr, "Error in: %s\n", x)
#endif #endif
char *getpass(const char *prompt) void my_getpass(const char *prompt, char *buffer, int buflen)
{ {
FILE *infp; FILE *infp;
FILE *outfp; FILE *outfp;
static char buf[INPUT_BUFFER];
RETSIGTYPE (*sigint)(); RETSIGTYPE (*sigint)();
#ifndef __EMX__ #ifndef __EMX__
RETSIGTYPE (*sigtstp)(); RETSIGTYPE (*sigtstp)();
@ -142,8 +139,8 @@ char *getpass(const char *prompt)
fputs(prompt, outfp); fputs(prompt, outfp);
fflush(outfp); fflush(outfp);
bytes_read=read(infd, buf, INPUT_BUFFER); bytes_read=read(infd, buffer, buflen);
buf[bytes_read > 0 ? (bytes_read -1) : 0] = '\0'; buffer[bytes_read > 0 ? (bytes_read -1) : 0] = '\0';
/* print a new line if needed */ /* print a new line if needed */
#ifdef HAVE_TERMIOS_H #ifdef HAVE_TERMIOS_H
@ -157,7 +154,7 @@ char *getpass(const char *prompt)
/* /*
* reset term charectaristics, use TCSAFLUSH incase the * reset term charectaristics, use TCSAFLUSH incase the
* user types more than INPUT_BUFFER * user types more than buflen
*/ */
#ifdef HAVE_TERMIOS_H #ifdef HAVE_TERMIOS_H
if(tcsetattr(outfd, TCSAFLUSH, &orig) != 0) if(tcsetattr(outfd, TCSAFLUSH, &orig) != 0)
@ -179,15 +176,25 @@ char *getpass(const char *prompt)
signal(SIGTSTP, sigtstp); signal(SIGTSTP, sigtstp);
#endif #endif
return(buf);
} }
#else #else /* WIN32 */
#include <stdio.h> #include <stdio.h>
char *getpass(const char *prompt) #include <conio.h>
void my_getpass(const char *prompt, char *buffer, int buflen)
{ {
static char password[80]; int i;
printf(prompt); printf("%s", prompt);
gets(password);
return password; for(i=0; i<buflen; i++) {
buffer[i] = getch();
if ( buffer[i] == '\r' ) {
buffer[i] = 0;
break;
} }
#endif /* don't do anything if WIN32 */ }
/* if user didn't hit ENTER, terminate buffer */
if (i==buflen)
buffer[buflen-1]=0;
}
#endif

View File

@ -1 +1 @@
char *getpass(const char *prompt); void my_getpass(const char *prompt, char* buffer, int buflen );

View File

@ -780,16 +780,16 @@ CURLcode curl_connect(CURL *curl, CURLconnect **in_connect)
if(*data->userpwd != ':') { if(*data->userpwd != ':') {
/* the name is given, get user+password */ /* the name is given, get user+password */
sscanf(data->userpwd, "%127[^:]:%127[^@]", sscanf(data->userpwd, "%127[^:]:%127[^\n]",
data->user, data->passwd); data->user, data->passwd);
} }
else else
/* no name given, get the password only */ /* no name given, get the password only */
sscanf(data->userpwd+1, "%127[^@]", data->passwd); sscanf(data->userpwd+1, "%127[^\n]", data->passwd);
/* check for password, if no ask for one */ /* check for password, if no ask for one */
if( !data->passwd[0] ) { if( !data->passwd[0] ) {
strncpy(data->passwd, getpass("password: "), sizeof(data->passwd)); my_getpass("password:", data->passwd, sizeof(data->passwd));
} }
} }
@ -799,16 +799,18 @@ CURLcode curl_connect(CURL *curl, CURLconnect **in_connect)
if(*data->proxyuserpwd != ':') { if(*data->proxyuserpwd != ':') {
/* the name is given, get user+password */ /* the name is given, get user+password */
sscanf(data->proxyuserpwd, "%127[^:]:%127[^@]", sscanf(data->proxyuserpwd, "%127[^:]:%127[^\n]",
data->proxyuser, data->proxypasswd); data->proxyuser, data->proxypasswd);
} }
else else
/* no name given, get the password only */ /* no name given, get the password only */
sscanf(data->proxyuserpwd+1, "%127[^@]", data->proxypasswd); sscanf(data->proxyuserpwd+1, "%127[^\n]", data->proxypasswd);
/* check for password, if no ask for one */ /* check for password, if no ask for one */
if( !data->proxypasswd[0] ) { if( !data->proxypasswd[0] ) {
strncpy(data->proxypasswd, getpass("proxy password: "), sizeof(data->proxypasswd)); my_getpass("proxy password:",
data->proxypasswd,
sizeof(data->proxypasswd));
} }
} }
@ -1117,7 +1119,7 @@ CURLcode curl_connect(CURL *curl, CURLconnect **in_connect)
/* check for password, if no ask for one */ /* check for password, if no ask for one */
if( !data->passwd[0] ) { if( !data->passwd[0] ) {
strncpy(data->passwd, getpass("password: "), sizeof(data->passwd)); my_getpass("password:",data->passwd,sizeof(data->passwd));
} }
conn->name = ++ptr; conn->name = ++ptr;