2011-08-27 21:16:10 +04:00
|
|
|
/***************************************************************************
|
|
|
|
* _ _ ____ _
|
|
|
|
* Project ___| | | | _ \| |
|
|
|
|
* / __| | | | |_) | |
|
|
|
|
* | (__| |_| | _ <| |___
|
|
|
|
* \___|\___/|_| \_\_____|
|
|
|
|
*
|
2019-02-25 20:12:51 +03:00
|
|
|
* Copyright (C) 1998 - 2019, Daniel Stenberg, <daniel@haxx.se>, et al.
|
2011-08-27 21:16:10 +04:00
|
|
|
*
|
|
|
|
* This software is licensed as described in the file COPYING, which
|
|
|
|
* you should have received as part of this distribution. The terms
|
2016-02-03 02:19:02 +03:00
|
|
|
* are also available at https://curl.haxx.se/docs/copyright.html.
|
2011-08-27 21:16:10 +04:00
|
|
|
*
|
|
|
|
* You may opt to use, copy, modify, merge, publish, distribute and/or sell
|
|
|
|
* copies of the Software, and permit persons to whom the Software is
|
|
|
|
* furnished to do so, under the terms of the COPYING file.
|
|
|
|
*
|
|
|
|
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
|
|
|
* KIND, either express or implied.
|
|
|
|
*
|
|
|
|
***************************************************************************/
|
|
|
|
|
2013-01-06 22:06:49 +04:00
|
|
|
#include "curl_setup.h"
|
2011-08-27 21:16:10 +04:00
|
|
|
|
2014-11-09 15:46:00 +03:00
|
|
|
#if !defined(CURL_DISABLE_HTTP) && defined(USE_NTLM) && \
|
|
|
|
defined(NTLM_WB_ENABLED)
|
2011-08-27 21:16:10 +04:00
|
|
|
|
2011-08-28 09:15:46 +04:00
|
|
|
/*
|
|
|
|
* NTLM details:
|
|
|
|
*
|
2017-02-06 22:21:05 +03:00
|
|
|
* https://davenport.sourceforge.io/ntlm.html
|
2016-04-06 12:57:48 +03:00
|
|
|
* https://www.innovation.ch/java/ntlm.html
|
2011-08-28 09:15:46 +04:00
|
|
|
*/
|
|
|
|
|
2011-08-27 21:16:10 +04:00
|
|
|
#define DEBUG_ME 0
|
|
|
|
|
|
|
|
#ifdef HAVE_SYS_WAIT_H
|
|
|
|
#include <sys/wait.h>
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_SIGNAL_H
|
|
|
|
#include <signal.h>
|
|
|
|
#endif
|
2014-07-11 14:31:40 +04:00
|
|
|
#ifdef HAVE_PWD_H
|
|
|
|
#include <pwd.h>
|
|
|
|
#endif
|
2011-08-27 21:16:10 +04:00
|
|
|
|
2013-01-04 05:50:28 +04:00
|
|
|
#include "urldata.h"
|
|
|
|
#include "sendf.h"
|
|
|
|
#include "select.h"
|
2015-09-12 16:50:02 +03:00
|
|
|
#include "vauth/ntlm.h"
|
2017-09-22 22:47:14 +03:00
|
|
|
#include "curl_ntlm_core.h"
|
2011-08-27 21:16:10 +04:00
|
|
|
#include "curl_ntlm_wb.h"
|
2013-01-04 05:50:28 +04:00
|
|
|
#include "url.h"
|
|
|
|
#include "strerror.h"
|
2016-11-07 12:55:25 +03:00
|
|
|
#include "strdup.h"
|
2019-05-15 18:10:56 +03:00
|
|
|
#include "strcase.h"
|
|
|
|
|
2016-04-29 16:46:40 +03:00
|
|
|
/* The last 3 #include files should be in this order */
|
2015-03-03 14:36:18 +03:00
|
|
|
#include "curl_printf.h"
|
2015-03-25 01:12:03 +03:00
|
|
|
#include "curl_memory.h"
|
2013-01-04 05:50:28 +04:00
|
|
|
#include "memdebug.h"
|
2011-08-27 21:16:10 +04:00
|
|
|
|
|
|
|
#if DEBUG_ME
|
|
|
|
# define DEBUG_OUT(x) x
|
|
|
|
#else
|
2011-09-03 18:06:10 +04:00
|
|
|
# define DEBUG_OUT(x) Curl_nop_stmt
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Portable 'sclose_nolog' used only in child process instead of 'sclose'
|
|
|
|
to avoid fooling the socket leak detector */
|
|
|
|
#if defined(HAVE_CLOSESOCKET)
|
|
|
|
# define sclose_nolog(x) closesocket((x))
|
|
|
|
#elif defined(HAVE_CLOSESOCKET_CAMEL)
|
|
|
|
# define sclose_nolog(x) CloseSocket((x))
|
|
|
|
#else
|
|
|
|
# define sclose_nolog(x) close((x))
|
2011-08-27 21:16:10 +04:00
|
|
|
#endif
|
|
|
|
|
2019-05-11 14:57:42 +03:00
|
|
|
void Curl_http_auth_cleanup_ntlm_wb(struct connectdata *conn)
|
2011-08-27 21:16:10 +04:00
|
|
|
{
|
|
|
|
if(conn->ntlm_auth_hlpr_socket != CURL_SOCKET_BAD) {
|
|
|
|
sclose(conn->ntlm_auth_hlpr_socket);
|
|
|
|
conn->ntlm_auth_hlpr_socket = CURL_SOCKET_BAD;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(conn->ntlm_auth_hlpr_pid) {
|
|
|
|
int i;
|
|
|
|
for(i = 0; i < 4; i++) {
|
|
|
|
pid_t ret = waitpid(conn->ntlm_auth_hlpr_pid, NULL, WNOHANG);
|
|
|
|
if(ret == conn->ntlm_auth_hlpr_pid || errno == ECHILD)
|
|
|
|
break;
|
|
|
|
switch(i) {
|
|
|
|
case 0:
|
|
|
|
kill(conn->ntlm_auth_hlpr_pid, SIGTERM);
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
/* Give the process another moment to shut down cleanly before
|
|
|
|
bringing down the axe */
|
|
|
|
Curl_wait_ms(1);
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
kill(conn->ntlm_auth_hlpr_pid, SIGKILL);
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
conn->ntlm_auth_hlpr_pid = 0;
|
|
|
|
}
|
|
|
|
|
2015-03-16 17:01:15 +03:00
|
|
|
free(conn->challenge_header);
|
2011-08-27 21:16:10 +04:00
|
|
|
conn->challenge_header = NULL;
|
2015-03-16 17:01:15 +03:00
|
|
|
free(conn->response_header);
|
2011-08-27 21:16:10 +04:00
|
|
|
conn->response_header = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static CURLcode ntlm_wb_init(struct connectdata *conn, const char *userp)
|
|
|
|
{
|
|
|
|
curl_socket_t sockfds[2];
|
|
|
|
pid_t child_pid;
|
|
|
|
const char *username;
|
|
|
|
char *slash, *domain = NULL;
|
|
|
|
const char *ntlm_auth = NULL;
|
|
|
|
char *ntlm_auth_alloc = NULL;
|
2014-07-11 14:31:40 +04:00
|
|
|
#if defined(HAVE_GETPWUID_R) && defined(HAVE_GETEUID)
|
|
|
|
struct passwd pw, *pw_res;
|
|
|
|
char pwbuf[1024];
|
|
|
|
#endif
|
2019-02-25 20:12:51 +03:00
|
|
|
char buffer[STRERROR_LEN];
|
2011-08-27 21:16:10 +04:00
|
|
|
|
|
|
|
/* Return if communication with ntlm_auth already set up */
|
|
|
|
if(conn->ntlm_auth_hlpr_socket != CURL_SOCKET_BAD ||
|
|
|
|
conn->ntlm_auth_hlpr_pid)
|
|
|
|
return CURLE_OK;
|
|
|
|
|
|
|
|
username = userp;
|
2014-07-11 14:31:40 +04:00
|
|
|
/* The real ntlm_auth really doesn't like being invoked with an
|
|
|
|
empty username. It won't make inferences for itself, and expects
|
|
|
|
the client to do so (mostly because it's really designed for
|
|
|
|
servers like squid to use for auth, and client support is an
|
|
|
|
afterthought for it). So try hard to provide a suitable username
|
|
|
|
if we don't already have one. But if we can't, provide the
|
|
|
|
empty one anyway. Perhaps they have an implementation of the
|
|
|
|
ntlm_auth helper which *doesn't* need it so we might as well try */
|
|
|
|
if(!username || !username[0]) {
|
|
|
|
username = getenv("NTLMUSER");
|
|
|
|
if(!username || !username[0])
|
|
|
|
username = getenv("LOGNAME");
|
|
|
|
if(!username || !username[0])
|
|
|
|
username = getenv("USER");
|
|
|
|
#if defined(HAVE_GETPWUID_R) && defined(HAVE_GETEUID)
|
|
|
|
if((!username || !username[0]) &&
|
|
|
|
!getpwuid_r(geteuid(), &pw, pwbuf, sizeof(pwbuf), &pw_res) &&
|
|
|
|
pw_res) {
|
|
|
|
username = pw.pw_name;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
if(!username || !username[0])
|
|
|
|
username = userp;
|
|
|
|
}
|
2011-08-27 21:16:10 +04:00
|
|
|
slash = strpbrk(username, "\\/");
|
|
|
|
if(slash) {
|
2016-12-14 03:29:44 +03:00
|
|
|
domain = strdup(username);
|
|
|
|
if(!domain)
|
2011-08-27 21:16:10 +04:00
|
|
|
return CURLE_OUT_OF_MEMORY;
|
|
|
|
slash = domain + (slash - username);
|
|
|
|
*slash = '\0';
|
|
|
|
username = username + (slash - domain) + 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* For testing purposes, when DEBUGBUILD is defined and environment
|
|
|
|
variable CURL_NTLM_WB_FILE is set a fake_ntlm is used to perform
|
|
|
|
NTLM challenge/response which only accepts commands and output
|
|
|
|
strings pre-written in test case definitions */
|
|
|
|
#ifdef DEBUGBUILD
|
|
|
|
ntlm_auth_alloc = curl_getenv("CURL_NTLM_WB_FILE");
|
|
|
|
if(ntlm_auth_alloc)
|
|
|
|
ntlm_auth = ntlm_auth_alloc;
|
|
|
|
else
|
|
|
|
#endif
|
|
|
|
ntlm_auth = NTLM_WB_FILE;
|
|
|
|
|
|
|
|
if(access(ntlm_auth, X_OK) != 0) {
|
|
|
|
failf(conn->data, "Could not access ntlm_auth: %s errno %d: %s",
|
2019-02-25 20:12:51 +03:00
|
|
|
ntlm_auth, errno, Curl_strerror(errno, buffer, sizeof(buffer)));
|
2011-08-27 21:16:10 +04:00
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(socketpair(AF_UNIX, SOCK_STREAM, 0, sockfds)) {
|
|
|
|
failf(conn->data, "Could not open socket pair. errno %d: %s",
|
2019-02-25 20:12:51 +03:00
|
|
|
errno, Curl_strerror(errno, buffer, sizeof(buffer)));
|
2011-08-27 21:16:10 +04:00
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
child_pid = fork();
|
|
|
|
if(child_pid == -1) {
|
|
|
|
sclose(sockfds[0]);
|
|
|
|
sclose(sockfds[1]);
|
|
|
|
failf(conn->data, "Could not fork. errno %d: %s",
|
2019-02-25 20:12:51 +03:00
|
|
|
errno, Curl_strerror(errno, buffer, sizeof(buffer)));
|
2011-08-27 21:16:10 +04:00
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
else if(!child_pid) {
|
|
|
|
/*
|
|
|
|
* child process
|
|
|
|
*/
|
|
|
|
|
2011-09-03 00:15:58 +04:00
|
|
|
/* Don't use sclose in the child since it fools the socket leak detector */
|
2011-09-03 18:06:10 +04:00
|
|
|
sclose_nolog(sockfds[0]);
|
2011-08-27 21:16:10 +04:00
|
|
|
if(dup2(sockfds[1], STDIN_FILENO) == -1) {
|
|
|
|
failf(conn->data, "Could not redirect child stdin. errno %d: %s",
|
2019-02-25 20:12:51 +03:00
|
|
|
errno, Curl_strerror(errno, buffer, sizeof(buffer)));
|
2011-08-27 21:16:10 +04:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
if(dup2(sockfds[1], STDOUT_FILENO) == -1) {
|
|
|
|
failf(conn->data, "Could not redirect child stdout. errno %d: %s",
|
2019-02-25 20:12:51 +03:00
|
|
|
errno, Curl_strerror(errno, buffer, sizeof(buffer)));
|
2011-08-27 21:16:10 +04:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
if(domain)
|
|
|
|
execl(ntlm_auth, ntlm_auth,
|
|
|
|
"--helper-protocol", "ntlmssp-client-1",
|
|
|
|
"--use-cached-creds",
|
|
|
|
"--username", username,
|
|
|
|
"--domain", domain,
|
|
|
|
NULL);
|
|
|
|
else
|
|
|
|
execl(ntlm_auth, ntlm_auth,
|
|
|
|
"--helper-protocol", "ntlmssp-client-1",
|
|
|
|
"--use-cached-creds",
|
|
|
|
"--username", username,
|
|
|
|
NULL);
|
|
|
|
|
2011-09-03 18:06:10 +04:00
|
|
|
sclose_nolog(sockfds[1]);
|
2011-08-27 21:16:10 +04:00
|
|
|
failf(conn->data, "Could not execl(). errno %d: %s",
|
2019-02-25 20:12:51 +03:00
|
|
|
errno, Curl_strerror(errno, buffer, sizeof(buffer)));
|
2011-08-27 21:16:10 +04:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
sclose(sockfds[1]);
|
|
|
|
conn->ntlm_auth_hlpr_socket = sockfds[0];
|
|
|
|
conn->ntlm_auth_hlpr_pid = child_pid;
|
2015-03-16 17:01:15 +03:00
|
|
|
free(domain);
|
|
|
|
free(ntlm_auth_alloc);
|
2011-08-27 21:16:10 +04:00
|
|
|
return CURLE_OK;
|
|
|
|
|
|
|
|
done:
|
2015-03-16 17:01:15 +03:00
|
|
|
free(domain);
|
|
|
|
free(ntlm_auth_alloc);
|
2011-08-27 21:16:10 +04:00
|
|
|
return CURLE_REMOTE_ACCESS_DENIED;
|
|
|
|
}
|
|
|
|
|
2018-09-09 00:03:53 +03:00
|
|
|
/* if larger than this, something is seriously wrong */
|
|
|
|
#define MAX_NTLM_WB_RESPONSE 100000
|
|
|
|
|
2011-08-27 21:16:10 +04:00
|
|
|
static CURLcode ntlm_wb_response(struct connectdata *conn,
|
|
|
|
const char *input, curlntlm state)
|
|
|
|
{
|
2014-07-11 13:27:18 +04:00
|
|
|
char *buf = malloc(NTLM_BUFSIZE);
|
|
|
|
size_t len_in = strlen(input), len_out = 0;
|
|
|
|
|
|
|
|
if(!buf)
|
|
|
|
return CURLE_OUT_OF_MEMORY;
|
2011-08-27 21:16:10 +04:00
|
|
|
|
|
|
|
while(len_in > 0) {
|
|
|
|
ssize_t written = swrite(conn->ntlm_auth_hlpr_socket, input, len_in);
|
|
|
|
if(written == -1) {
|
|
|
|
/* Interrupted by a signal, retry it */
|
|
|
|
if(errno == EINTR)
|
|
|
|
continue;
|
|
|
|
/* write failed if other errors happen */
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
input += written;
|
|
|
|
len_in -= written;
|
|
|
|
}
|
|
|
|
/* Read one line */
|
2014-07-11 13:27:18 +04:00
|
|
|
while(1) {
|
|
|
|
ssize_t size;
|
|
|
|
char *newbuf;
|
|
|
|
|
|
|
|
size = sread(conn->ntlm_auth_hlpr_socket, buf + len_out, NTLM_BUFSIZE);
|
2011-08-27 21:16:10 +04:00
|
|
|
if(size == -1) {
|
|
|
|
if(errno == EINTR)
|
|
|
|
continue;
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
else if(size == 0)
|
|
|
|
goto done;
|
2014-07-11 13:27:18 +04:00
|
|
|
|
|
|
|
len_out += size;
|
|
|
|
if(buf[len_out - 1] == '\n') {
|
|
|
|
buf[len_out - 1] = '\0';
|
2014-12-11 00:43:44 +03:00
|
|
|
break;
|
2011-08-27 21:16:10 +04:00
|
|
|
}
|
2018-09-09 00:03:53 +03:00
|
|
|
|
|
|
|
if(len_out > MAX_NTLM_WB_RESPONSE) {
|
|
|
|
failf(conn->data, "too large ntlm_wb response!");
|
2018-09-13 11:06:05 +03:00
|
|
|
free(buf);
|
2018-09-09 00:03:53 +03:00
|
|
|
return CURLE_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
|
2016-11-07 12:55:25 +03:00
|
|
|
newbuf = Curl_saferealloc(buf, len_out + NTLM_BUFSIZE);
|
|
|
|
if(!newbuf)
|
2014-07-11 13:27:18 +04:00
|
|
|
return CURLE_OUT_OF_MEMORY;
|
2016-11-07 12:55:25 +03:00
|
|
|
|
2014-07-11 13:27:18 +04:00
|
|
|
buf = newbuf;
|
2011-08-27 21:16:10 +04:00
|
|
|
}
|
2014-12-11 00:43:44 +03:00
|
|
|
|
2011-08-27 21:16:10 +04:00
|
|
|
/* Samba/winbind installed but not configured */
|
|
|
|
if(state == NTLMSTATE_TYPE1 &&
|
2014-07-11 13:27:18 +04:00
|
|
|
len_out == 3 &&
|
2011-08-27 21:16:10 +04:00
|
|
|
buf[0] == 'P' && buf[1] == 'W')
|
2015-07-16 21:17:33 +03:00
|
|
|
goto done;
|
2011-08-27 21:16:10 +04:00
|
|
|
/* invalid response */
|
2014-07-11 13:27:18 +04:00
|
|
|
if(len_out < 4)
|
2011-08-27 21:16:10 +04:00
|
|
|
goto done;
|
|
|
|
if(state == NTLMSTATE_TYPE1 &&
|
|
|
|
(buf[0]!='Y' || buf[1]!='R' || buf[2]!=' '))
|
|
|
|
goto done;
|
|
|
|
if(state == NTLMSTATE_TYPE2 &&
|
|
|
|
(buf[0]!='K' || buf[1]!='K' || buf[2]!=' ') &&
|
|
|
|
(buf[0]!='A' || buf[1]!='F' || buf[2]!=' '))
|
|
|
|
goto done;
|
|
|
|
|
2014-07-11 13:27:18 +04:00
|
|
|
conn->response_header = aprintf("NTLM %.*s", len_out - 4, buf + 3);
|
|
|
|
free(buf);
|
2018-10-08 00:34:35 +03:00
|
|
|
if(!conn->response_header)
|
|
|
|
return CURLE_OUT_OF_MEMORY;
|
2011-08-27 21:16:10 +04:00
|
|
|
return CURLE_OK;
|
|
|
|
done:
|
2014-07-11 13:27:18 +04:00
|
|
|
free(buf);
|
2011-08-27 21:16:10 +04:00
|
|
|
return CURLE_REMOTE_ACCESS_DENIED;
|
|
|
|
}
|
|
|
|
|
2019-05-15 18:10:56 +03:00
|
|
|
CURLcode Curl_input_ntlm_wb(struct connectdata *conn,
|
|
|
|
bool proxy,
|
|
|
|
const char *header)
|
|
|
|
{
|
|
|
|
(void) proxy;
|
|
|
|
|
|
|
|
if(!checkprefix("NTLM", header))
|
|
|
|
return CURLE_BAD_CONTENT_ENCODING;
|
|
|
|
|
|
|
|
header += strlen("NTLM");
|
|
|
|
while(*header && ISSPACE(*header))
|
|
|
|
header++;
|
|
|
|
|
|
|
|
if(*header) {
|
|
|
|
conn->challenge_header = strdup(header);
|
|
|
|
if(!conn->challenge_header)
|
|
|
|
return CURLE_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return CURLE_BAD_CONTENT_ENCODING;
|
|
|
|
|
|
|
|
return CURLE_OK;
|
|
|
|
}
|
|
|
|
|
2011-08-27 21:16:10 +04:00
|
|
|
/*
|
|
|
|
* This is for creating ntlm header output by delegating challenge/response
|
|
|
|
* to Samba's winbind daemon helper ntlm_auth.
|
|
|
|
*/
|
|
|
|
CURLcode Curl_output_ntlm_wb(struct connectdata *conn,
|
|
|
|
bool proxy)
|
|
|
|
{
|
|
|
|
/* point to the address of the pointer that holds the string to send to the
|
|
|
|
server, which is for a plain host or for a HTTP proxy */
|
|
|
|
char **allocuserpwd;
|
|
|
|
/* point to the name and password for this */
|
|
|
|
const char *userp;
|
2019-05-13 22:58:39 +03:00
|
|
|
curlntlm *state;
|
2011-08-27 21:16:10 +04:00
|
|
|
struct auth *authp;
|
|
|
|
|
|
|
|
CURLcode res = CURLE_OK;
|
|
|
|
char *input;
|
|
|
|
|
|
|
|
DEBUGASSERT(conn);
|
|
|
|
DEBUGASSERT(conn->data);
|
|
|
|
|
|
|
|
if(proxy) {
|
|
|
|
allocuserpwd = &conn->allocptr.proxyuserpwd;
|
2016-11-16 20:49:15 +03:00
|
|
|
userp = conn->http_proxy.user;
|
2019-05-13 22:58:39 +03:00
|
|
|
state = &conn->proxy_ntlm_state;
|
2011-08-27 21:16:10 +04:00
|
|
|
authp = &conn->data->state.authproxy;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
allocuserpwd = &conn->allocptr.userpwd;
|
|
|
|
userp = conn->user;
|
2019-05-13 22:58:39 +03:00
|
|
|
state = &conn->http_ntlm_state;
|
2011-08-27 21:16:10 +04:00
|
|
|
authp = &conn->data->state.authhost;
|
|
|
|
}
|
|
|
|
authp->done = FALSE;
|
|
|
|
|
|
|
|
/* not set means empty */
|
|
|
|
if(!userp)
|
2017-09-10 00:09:06 +03:00
|
|
|
userp = "";
|
2011-08-27 21:16:10 +04:00
|
|
|
|
2019-05-13 22:58:39 +03:00
|
|
|
switch(*state) {
|
2011-08-27 21:16:10 +04:00
|
|
|
case NTLMSTATE_TYPE1:
|
|
|
|
default:
|
|
|
|
/* Use Samba's 'winbind' daemon to support NTLM authentication,
|
2018-02-24 02:29:01 +03:00
|
|
|
* by delegating the NTLM challenge/response protocol to a helper
|
2011-08-27 21:16:10 +04:00
|
|
|
* in ntlm_auth.
|
|
|
|
* http://devel.squid-cache.org/ntlm/squid_helper_protocol.html
|
2016-02-03 07:09:25 +03:00
|
|
|
* https://www.samba.org/samba/docs/man/manpages-3/winbindd.8.html
|
|
|
|
* https://www.samba.org/samba/docs/man/manpages-3/ntlm_auth.1.html
|
2011-08-27 21:16:10 +04:00
|
|
|
* Preprocessor symbol 'NTLM_WB_ENABLED' is defined when this
|
|
|
|
* feature is enabled and 'NTLM_WB_FILE' symbol holds absolute
|
|
|
|
* filename of ntlm_auth helper.
|
|
|
|
* If NTLM authentication using winbind fails, go back to original
|
|
|
|
* request handling process.
|
|
|
|
*/
|
|
|
|
/* Create communication with ntlm_auth */
|
|
|
|
res = ntlm_wb_init(conn, userp);
|
|
|
|
if(res)
|
|
|
|
return res;
|
2019-05-13 22:58:39 +03:00
|
|
|
res = ntlm_wb_response(conn, "YR\n", *state);
|
2011-08-27 21:16:10 +04:00
|
|
|
if(res)
|
|
|
|
return res;
|
|
|
|
|
2015-03-16 17:01:15 +03:00
|
|
|
free(*allocuserpwd);
|
2011-08-27 21:16:10 +04:00
|
|
|
*allocuserpwd = aprintf("%sAuthorization: %s\r\n",
|
|
|
|
proxy ? "Proxy-" : "",
|
|
|
|
conn->response_header);
|
|
|
|
DEBUG_OUT(fprintf(stderr, "**** Header %s\n ", *allocuserpwd));
|
2015-03-16 17:01:15 +03:00
|
|
|
free(conn->response_header);
|
2018-10-08 00:34:35 +03:00
|
|
|
if(!*allocuserpwd)
|
|
|
|
return CURLE_OUT_OF_MEMORY;
|
2011-08-27 21:16:10 +04:00
|
|
|
conn->response_header = NULL;
|
|
|
|
break;
|
|
|
|
case NTLMSTATE_TYPE2:
|
2013-11-05 00:12:22 +04:00
|
|
|
input = aprintf("TT %s\n", conn->challenge_header);
|
2011-08-27 21:16:10 +04:00
|
|
|
if(!input)
|
|
|
|
return CURLE_OUT_OF_MEMORY;
|
2019-05-13 22:58:39 +03:00
|
|
|
res = ntlm_wb_response(conn, input, *state);
|
2011-08-27 21:16:10 +04:00
|
|
|
free(input);
|
|
|
|
input = NULL;
|
|
|
|
if(res)
|
|
|
|
return res;
|
|
|
|
|
2015-03-16 17:01:15 +03:00
|
|
|
free(*allocuserpwd);
|
2011-08-27 21:16:10 +04:00
|
|
|
*allocuserpwd = aprintf("%sAuthorization: %s\r\n",
|
|
|
|
proxy ? "Proxy-" : "",
|
|
|
|
conn->response_header);
|
|
|
|
DEBUG_OUT(fprintf(stderr, "**** %s\n ", *allocuserpwd));
|
2019-05-13 22:58:39 +03:00
|
|
|
*state = NTLMSTATE_TYPE3; /* we sent a type-3 */
|
2011-08-27 21:16:10 +04:00
|
|
|
authp->done = TRUE;
|
2019-05-11 14:57:42 +03:00
|
|
|
Curl_http_auth_cleanup_ntlm_wb(conn);
|
2018-10-08 00:34:35 +03:00
|
|
|
if(!*allocuserpwd)
|
|
|
|
return CURLE_OUT_OF_MEMORY;
|
2011-08-27 21:16:10 +04:00
|
|
|
break;
|
|
|
|
case NTLMSTATE_TYPE3:
|
|
|
|
/* connection is already authenticated,
|
|
|
|
* don't send a header in future requests */
|
2015-03-11 19:41:01 +03:00
|
|
|
free(*allocuserpwd);
|
2017-09-10 00:09:06 +03:00
|
|
|
*allocuserpwd = NULL;
|
2011-08-27 21:16:10 +04:00
|
|
|
authp->done = TRUE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return CURLE_OK;
|
|
|
|
}
|
|
|
|
|
2014-11-09 15:46:00 +03:00
|
|
|
#endif /* !CURL_DISABLE_HTTP && USE_NTLM && NTLM_WB_ENABLED */
|