1
0
mirror of https://github.com/moparisthebest/curl synced 2024-11-16 14:35:03 -05:00

ntlm: Pass the Curl_easy structure to the private winbind functions

...rather than the full conndata structure.
This commit is contained in:
Steve Holme 2019-05-08 09:36:51 +01:00
parent c2220ed639
commit b765cb3c81
No known key found for this signature in database
GPG Key ID: 4059CB85CA7E8F19

View File

@ -112,7 +112,7 @@ static void ntlm_wb_cleanup(struct ntlmdata *ntlm)
Curl_safefree(ntlm->response); Curl_safefree(ntlm->response);
} }
static CURLcode ntlm_wb_init(struct connectdata *conn, struct ntlmdata *ntlm, static CURLcode ntlm_wb_init(struct Curl_easy *data, struct ntlmdata *ntlm,
const char *userp) const char *userp)
{ {
curl_socket_t sockfds[2]; curl_socket_t sockfds[2];
@ -127,6 +127,10 @@ static CURLcode ntlm_wb_init(struct connectdata *conn, struct ntlmdata *ntlm,
#endif #endif
char buffer[STRERROR_LEN]; char buffer[STRERROR_LEN];
#if defined(CURL_DISABLE_VERBOSE_STRINGS)
(void) data;
#endif
/* Return if communication with ntlm_auth already set up */ /* Return if communication with ntlm_auth already set up */
if(ntlm->ntlm_auth_hlpr_socket != CURL_SOCKET_BAD || if(ntlm->ntlm_auth_hlpr_socket != CURL_SOCKET_BAD ||
ntlm->ntlm_auth_hlpr_pid) ntlm->ntlm_auth_hlpr_pid)
@ -180,13 +184,13 @@ static CURLcode ntlm_wb_init(struct connectdata *conn, struct ntlmdata *ntlm,
ntlm_auth = NTLM_WB_FILE; ntlm_auth = NTLM_WB_FILE;
if(access(ntlm_auth, X_OK) != 0) { if(access(ntlm_auth, X_OK) != 0) {
failf(conn->data, "Could not access ntlm_auth: %s errno %d: %s", failf(data, "Could not access ntlm_auth: %s errno %d: %s",
ntlm_auth, errno, Curl_strerror(errno, buffer, sizeof(buffer))); ntlm_auth, errno, Curl_strerror(errno, buffer, sizeof(buffer)));
goto done; goto done;
} }
if(socketpair(AF_UNIX, SOCK_STREAM, 0, sockfds)) { if(socketpair(AF_UNIX, SOCK_STREAM, 0, sockfds)) {
failf(conn->data, "Could not open socket pair. errno %d: %s", failf(data, "Could not open socket pair. errno %d: %s",
errno, Curl_strerror(errno, buffer, sizeof(buffer))); errno, Curl_strerror(errno, buffer, sizeof(buffer)));
goto done; goto done;
} }
@ -195,7 +199,7 @@ static CURLcode ntlm_wb_init(struct connectdata *conn, struct ntlmdata *ntlm,
if(child_pid == -1) { if(child_pid == -1) {
sclose(sockfds[0]); sclose(sockfds[0]);
sclose(sockfds[1]); sclose(sockfds[1]);
failf(conn->data, "Could not fork. errno %d: %s", failf(data, "Could not fork. errno %d: %s",
errno, Curl_strerror(errno, buffer, sizeof(buffer))); errno, Curl_strerror(errno, buffer, sizeof(buffer)));
goto done; goto done;
} }
@ -207,13 +211,13 @@ static CURLcode ntlm_wb_init(struct connectdata *conn, struct ntlmdata *ntlm,
/* Don't use sclose in the child since it fools the socket leak detector */ /* Don't use sclose in the child since it fools the socket leak detector */
sclose_nolog(sockfds[0]); sclose_nolog(sockfds[0]);
if(dup2(sockfds[1], STDIN_FILENO) == -1) { if(dup2(sockfds[1], STDIN_FILENO) == -1) {
failf(conn->data, "Could not redirect child stdin. errno %d: %s", failf(data, "Could not redirect child stdin. errno %d: %s",
errno, Curl_strerror(errno, buffer, sizeof(buffer))); errno, Curl_strerror(errno, buffer, sizeof(buffer)));
exit(1); exit(1);
} }
if(dup2(sockfds[1], STDOUT_FILENO) == -1) { if(dup2(sockfds[1], STDOUT_FILENO) == -1) {
failf(conn->data, "Could not redirect child stdout. errno %d: %s", failf(data, "Could not redirect child stdout. errno %d: %s",
errno, Curl_strerror(errno, buffer, sizeof(buffer))); errno, Curl_strerror(errno, buffer, sizeof(buffer)));
exit(1); exit(1);
} }
@ -233,7 +237,7 @@ static CURLcode ntlm_wb_init(struct connectdata *conn, struct ntlmdata *ntlm,
NULL); NULL);
sclose_nolog(sockfds[1]); sclose_nolog(sockfds[1]);
failf(conn->data, "Could not execl(). errno %d: %s", failf(data, "Could not execl(). errno %d: %s",
errno, Curl_strerror(errno, buffer, sizeof(buffer))); errno, Curl_strerror(errno, buffer, sizeof(buffer)));
exit(1); exit(1);
} }
@ -254,13 +258,16 @@ done:
/* if larger than this, something is seriously wrong */ /* if larger than this, something is seriously wrong */
#define MAX_NTLM_WB_RESPONSE 100000 #define MAX_NTLM_WB_RESPONSE 100000
static CURLcode ntlm_wb_response(struct connectdata *conn, static CURLcode ntlm_wb_response(struct Curl_easy *data, struct ntlmdata *ntlm,
struct ntlmdata *ntlm, const char *input, const char *input, curlntlm state)
curlntlm state)
{ {
char *buf = malloc(NTLM_BUFSIZE); char *buf = malloc(NTLM_BUFSIZE);
size_t len_in = strlen(input), len_out = 0; size_t len_in = strlen(input), len_out = 0;
#if defined(CURL_DISABLE_VERBOSE_STRINGS)
(void) data;
#endif
if(!buf) if(!buf)
return CURLE_OUT_OF_MEMORY; return CURLE_OUT_OF_MEMORY;
@ -297,7 +304,7 @@ static CURLcode ntlm_wb_response(struct connectdata *conn,
} }
if(len_out > MAX_NTLM_WB_RESPONSE) { if(len_out > MAX_NTLM_WB_RESPONSE) {
failf(conn->data, "too large ntlm_wb response!"); failf(data, "too large ntlm_wb response!");
free(buf); free(buf);
return CURLE_OUT_OF_MEMORY; return CURLE_OUT_OF_MEMORY;
} }
@ -435,10 +442,10 @@ CURLcode Curl_output_ntlm_wb(struct connectdata *conn,
* request handling process. * request handling process.
*/ */
/* Create communication with ntlm_auth */ /* Create communication with ntlm_auth */
res = ntlm_wb_init(conn, ntlm, userp); res = ntlm_wb_init(conn->data, ntlm, userp);
if(res) if(res)
return res; return res;
res = ntlm_wb_response(conn, ntlm, "YR\n", *state); res = ntlm_wb_response(conn->data, ntlm, "YR\n", *state);
if(res) if(res)
return res; return res;
@ -456,7 +463,7 @@ CURLcode Curl_output_ntlm_wb(struct connectdata *conn,
char *input = aprintf("TT %s\n", ntlm->challenge); char *input = aprintf("TT %s\n", ntlm->challenge);
if(!input) if(!input)
return CURLE_OUT_OF_MEMORY; return CURLE_OUT_OF_MEMORY;
res = ntlm_wb_response(conn, ntlm, input, *state); res = ntlm_wb_response(conn->data, ntlm, input, *state);
free(input); free(input);
if(res) if(res)
return res; return res;