1
0
mirror of https://github.com/moparisthebest/curl synced 2024-12-21 23:58:49 -05:00

socks: deduplicate the code for auth request

This commit is contained in:
Kamil Dudka 2017-03-08 12:16:01 +01:00
parent 641072b919
commit cd1c9f0807

View File

@ -375,6 +375,7 @@ CURLcode Curl_SOCKS5(const char *proxy_user,
*/ */
unsigned char socksreq[600]; /* room for large user/pw (255 max each) */ unsigned char socksreq[600]; /* room for large user/pw (255 max each) */
int idx;
ssize_t actualread; ssize_t actualread;
ssize_t written; ssize_t written;
int result; int result;
@ -426,17 +427,17 @@ CURLcode Curl_SOCKS5(const char *proxy_user,
return CURLE_COULDNT_CONNECT; return CURLE_COULDNT_CONNECT;
} }
socksreq[0] = 5; /* version */ idx = 0;
socksreq[idx++] = 5; /* version */
idx++; /* reserve for the number of authentication methods */
socksreq[idx++] = 0; /* no authentication */
#if defined(HAVE_GSSAPI) || defined(USE_WINDOWS_SSPI) #if defined(HAVE_GSSAPI) || defined(USE_WINDOWS_SSPI)
socksreq[1] = (char)(proxy_user ? 3 : 2); /* number of methods (below) */ socksreq[idx++] = 1; /* GSS-API */
socksreq[2] = 0; /* no authentication */
socksreq[3] = 1; /* GSS-API */
socksreq[4] = 2; /* username/password */
#else
socksreq[1] = (char)(proxy_user ? 2 : 1); /* number of methods (below) */
socksreq[2] = 0; /* no authentication */
socksreq[3] = 2; /* username/password */
#endif #endif
if(proxy_user)
socksreq[idx++] = 2; /* username/password */
/* write the number of authentication methods */
socksreq[1] = (unsigned char) (idx - 2);
(void)curlx_nonblock(sock, FALSE); (void)curlx_nonblock(sock, FALSE);