if userpwd is "username:", this now implies a blank password while only

"username" will cause libcurl to prompt for password. Bryan Kemp noticed.

test case 136 is added for this
This commit is contained in:
Daniel Stenberg 2003-01-09 16:47:09 +00:00
parent 2ede47b8c8
commit 9a2de6e6ee
2 changed files with 13 additions and 5 deletions

View file

@ -2526,14 +2526,17 @@ static CURLcode CreateConnection(struct SessionHandle *data,
/* the name is given, get user+password */ /* the name is given, get user+password */
sscanf(data->set.userpwd, "%127[^:]:%127[^\n]", sscanf(data->set.userpwd, "%127[^:]:%127[^\n]",
data->state.user, data->state.passwd); data->state.user, data->state.passwd);
if(strchr(data->set.userpwd, ':'))
/* a colon means the password was given, even if blank */
data->state.passwdgiven = TRUE;
} }
else else
/* no name given, get the password only */ /* no name given, starts with a colon, get the password only */
sscanf(data->set.userpwd+1, "%127[^\n]", data->state.passwd); sscanf(data->set.userpwd+1, "%127[^\n]", data->state.passwd);
} }
if (data->set.use_netrc != CURL_NETRC_IGNORED && if (data->set.use_netrc != CURL_NETRC_IGNORED &&
data->state.passwd[0] == '\0' ) { /* need passwd */ !data->state.passwdgiven) { /* need passwd */
if(Curl_parsenetrc(conn->hostname, if(Curl_parsenetrc(conn->hostname,
data->state.user, data->state.user,
data->state.passwd)) { data->state.passwd)) {
@ -2544,8 +2547,7 @@ static CURLcode CreateConnection(struct SessionHandle *data,
} }
/* if we have a user but no password, ask for one */ /* if we have a user but no password, ask for one */
if(conn->bits.user_passwd && if(conn->bits.user_passwd && !data->state.passwdgiven ) {
!data->state.passwd[0] ) {
if(data->set.fpasswd(data->set.passwd_client, if(data->set.fpasswd(data->set.passwd_client,
"password:", data->state.passwd, "password:", data->state.passwd,
sizeof(data->state.passwd))) sizeof(data->state.passwd)))
@ -2556,9 +2558,12 @@ static CURLcode CreateConnection(struct SessionHandle *data,
/* If our protocol needs a password and we have none, use the defaults */ /* If our protocol needs a password and we have none, use the defaults */
if ( (conn->protocol & (PROT_FTP|PROT_HTTP)) && if ( (conn->protocol & (PROT_FTP|PROT_HTTP)) &&
!conn->bits.user_passwd) { !conn->bits.user_passwd &&
!data->state.passwdgiven) {
strcpy(data->state.user, CURL_DEFAULT_USER); strcpy(data->state.user, CURL_DEFAULT_USER);
strcpy(data->state.passwd, CURL_DEFAULT_PASSWORD); strcpy(data->state.passwd, CURL_DEFAULT_PASSWORD);
/* This is the default password, so DON'T set conn->bits.user_passwd */ /* This is the default password, so DON'T set conn->bits.user_passwd */
} }

View file

@ -570,6 +570,9 @@ struct UrlState {
char proxyuser[MAX_CURL_USER_LENGTH]; char proxyuser[MAX_CURL_USER_LENGTH];
char proxypasswd[MAX_CURL_PASSWORD_LENGTH]; char proxypasswd[MAX_CURL_PASSWORD_LENGTH];
bool passwdgiven; /* set TRUE if an application-provided password has been
set */
struct timeval keeps_speed; /* for the progress meter really */ struct timeval keeps_speed; /* for the progress meter really */
/* 'connects' will be an allocated array with pointers. If the pointer is /* 'connects' will be an allocated array with pointers. If the pointer is