1 --- src/ne_auth.c 2010-10-14 17:00:53.000000000 +0200
2 +++ src/ne_auth.c 2011-02-03 10:31:22.000000000 +0100
4 static int get_credentials(auth_session *sess, ne_buffer **errmsg, int attempt,
5 struct auth_challenge *chall, char *pwbuf)
7 - if (chall->handler->creds(chall->handler->userdata, sess->realm,
8 + if (chall->handler->creds(chall->handler->userdata, chall->protocol->name, sess->realm,
9 chall->handler->attempt++, sess->username, pwbuf) == 0) {
14 char *tmp, password[NE_ABUFSIZ];
16 +#if 0 /* Workaround - IIS sends challenge without realm. */
18 /* Verify challenge... must have a realm */
19 if (parms->realm == NULL) {
20 challenge_error(errmsg, _("missing realm in Basic challenge"));
27 - sess->realm = ne_strdup(parms->realm);
28 + if (parms->realm != NULL)
29 + sess->realm = ne_strdup(parms->realm);
31 if (get_credentials(sess, errmsg, attempt, parms, password)) {
32 /* Failed to get credentials */
37 -static int continue_sspi(auth_session *sess, int ntlm, const char *hdr)
38 +static int continue_sspi(auth_session *sess, int ntlm, const char *hdr,
39 + int attempt, struct auth_challenge *parms, ne_buffer **errmsg)
42 char *response = NULL;
43 + char password[NE_ABUFSIZ];
45 NE_DEBUG(NE_DBG_HTTPAUTH, "auth: SSPI challenge.\n");
52 - status = ne_sspi_authenticate(sess->sspi_context, hdr, &response);
54 + /* Authentification needs more than one http request.
55 + * As long as authentification in progress use the existing credentials.
56 + * Otherwise get new credentials.*/
58 + if (get_credentials(sess, errmsg, attempt, parms, password)) {
59 + /* Failed to get credentials */
63 + status = ne_sspi_authenticate(sess->sspi_context, hdr, &response, sess->username, password);
69 int ntlm = ne_strcasecmp(parms->protocol->name, "NTLM") == 0;
71 - return continue_sspi(sess, ntlm, parms->opaque);
72 + return continue_sspi(sess, ntlm, parms->opaque, attempt, parms, errmsg);
75 static int verify_sspi(struct auth_request *req, auth_session *sess,
80 - return continue_sspi(sess, ntlm, ptr);
81 + return continue_sspi(sess, ntlm, ptr, 0, NULL, NULL);
85 --- src/ne_auth.h 2009-09-01 22:13:12.000000000 +0200
86 +++ src/ne_auth.h 2011-02-03 10:26:20.000000000 +0100
88 * Hint: if you just wish to attempt authentication just once (even if
89 * the user gets the username/password wrong), have the callback
90 * function use 'attempt' value as the function return value. */
91 -typedef int (*ne_auth_creds)(void *userdata, const char *realm, int attempt,
92 - char *username, char *password);
93 +typedef int (*ne_auth_creds)(void *userdata, const char * auth_protocol,
94 + const char *realm, int attempt, char *username, char *password);
96 /* Set callbacks to provide credentials for server and proxy
97 * authentication, using the default set of authentication protocols.
98 --- src/ne_defs.h 2010-01-11 23:57:34.000000000 +0100
99 +++ src/ne_defs.h 2011-02-03 10:26:20.000000000 +0100
103 /* define ssize_t for Win32 */
104 -#if defined(WIN32) && !defined(ssize_t)
105 +#if defined(WIN32) && !defined(ssize_t) && !defined(__MINGW32__)
109 --- src/ne_locks.c 2007-02-05 11:09:27.000000000 +0100
110 +++ src/ne_locks.c 2011-02-03 10:26:21.000000000 +0100
112 const char *token = ne_get_response_header(ctx->req, "Lock-Token");
113 /* at the root element; retrieve the Lock-Token header,
114 * and bail if it wasn't given. */
115 +#ifdef IIS_LOCK_BUG_WORKAROUND
116 + /* MS IIS violates RFC 2518/4918. It does not send a Lock-Token response
117 + header upon successful creation of a new lock. As a workaround, we
118 + will try to pick the lock token from the response body (although
119 + this is not 100% safe in case of multiple activelocks). */
121 + NE_DEBUG(NE_DBG_LOCKS,
122 + "Ignoring missing LOCK response Lock-Token header\n");
124 + if (token != NULL) {
125 + if (token[0] == '<') token++;
126 + ctx->token = ne_strdup(token);
127 + ne_shave(ctx->token, ">");
128 + NE_DEBUG(NE_DBG_LOCKS, "lk_startelm: Finding token %s\n",
133 ne_xml_set_error(ctx->parser,
134 _("LOCK response missing Lock-Token header"));
135 @@ -590,12 +607,28 @@
136 ne_shave(ctx->token, ">");
137 NE_DEBUG(NE_DBG_LOCKS, "lk_startelm: Finding token %s\n",
142 /* TODO: only accept 'prop' as root for LOCK response */
143 if (!can_accept(parent, id))
144 return NE_XML_DECLINE;
146 +#ifdef IIS_LOCK_BUG_WORKAROUND
147 + if (id == ELM_activelock && ctx->found) {
148 + /* Found another activelock... */
149 + const char *token = ne_get_response_header(ctx->req, "Lock-Token");
150 + if (token == NULL) {
151 + /* Response contains more than one activelock and no Lock-Token
152 + * response header. We are doomed. No safe workaround for IIS
153 + * lock bug possible. */
154 + ne_xml_set_error(ctx->parser,
155 + _("LOCK response missing Lock-Token header and more than one activelock"));
156 + return NE_XML_ABORT;
161 if (id == ELM_activelock && !ctx->found) {
162 /* a new activelock */
163 ne_lock_free(&ctx->active);
167 if (state == ELM_activelock) {
168 +#ifdef IIS_LOCK_BUG_WORKAROUND
169 + if (ctx->active.token) {
170 + ctx->token = ne_strdup(ctx->active.token);
172 if (ctx->active.token && strcmp(ctx->active.token, ctx->token) == 0) {
177 --- src/ne_sspi.c 2007-08-10 17:26:08.000000000 +0200
178 +++ src/ne_sspi.c 2011-02-03 10:26:21.000000000 +0100
183 + * Simplification wrapper arround AcquireCredentialsHandle as most of
184 + * the parameters do not change.
186 +static int acquireCredentialsHandleForUsername(CredHandle * credentials, char *package, const char *username, const char *password)
188 + SECURITY_STATUS status;
189 + TimeStamp timestamp;
191 + const char *domain = "";
194 + SecPkgInfo *secPackInfo;
195 + SEC_WINNT_AUTH_IDENTITY *nameAndPwd = NULL;
196 + int bytesReceived = 0, bytesSent = 0;
198 + nameAndPwd = (SEC_WINNT_AUTH_IDENTITY *) malloc( sizeof(SEC_WINNT_AUTH_IDENTITY) );
199 + memset( nameAndPwd, '\0', sizeof (*nameAndPwd) );
200 + nameAndPwd->Domain = (unsigned char *) _strdup( domain? domain: "" );
201 + nameAndPwd->DomainLength = domain? strlen( domain ): 0;
202 + nameAndPwd->User = (unsigned char *) _strdup( username? username: "" );
203 + nameAndPwd->UserLength = username? strlen( username ): 0;
204 + nameAndPwd->Password = (unsigned char *) _strdup( password? password: "" );
205 + nameAndPwd->PasswordLength = password? strlen( password ): 0;
206 + nameAndPwd->Flags = SEC_WINNT_AUTH_IDENTITY_ANSI;
208 + status = pSFT->AcquireCredentialsHandle( NULL, package, SECPKG_CRED_OUTBOUND,
209 + NULL, nameAndPwd, NULL, NULL, credentials, ×tamp );
211 + if (status != SEC_E_OK) {
212 + NE_DEBUG(NE_DBG_HTTPAUTH,
213 + "sspi: AcquireCredentialsHandle [fail] [%x].\n", status);
222 * Wrapper arround initializeSecurityContext. Supplies several
223 * default parameters as well as logging in case of errors.
226 * Processes received authentication tokens as well as supplies the
229 -int ne_sspi_authenticate(void *context, const char *base64Token, char **responseToken)
230 +int ne_sspi_authenticate(void *context, const char *base64Token, char **responseToken, const char* username, const char* password)
232 SecBufferDesc outBufferDesc;
234 @@ -561,13 +600,22 @@
235 /* Reset any existing context since we are starting over */
236 resetContext(sspiContext);
238 - if (acquireCredentialsHandle
239 - (&sspiContext->credentials, sspiContext->mechanism) != SEC_E_OK) {
240 - freeBuffer(&outBufferDesc);
241 - NE_DEBUG(NE_DBG_HTTPAUTH,
242 - "sspi: acquireCredentialsHandle failed.\n");
245 + if (strlen(username) != 0) {
246 + if (acquireCredentialsHandleForUsername
247 + (&sspiContext->credentials, sspiContext->mechanism, username, password) != SEC_E_OK) {
248 + freeBuffer(&outBufferDesc);
249 + NE_DEBUG(NE_DBG_HTTPAUTH, "sspi: acquireCredentialsHandleForUsername failed.\n");
253 + if (acquireCredentialsHandle
254 + (&sspiContext->credentials, sspiContext->mechanism) != SEC_E_OK) {
255 + freeBuffer(&outBufferDesc);
256 + NE_DEBUG(NE_DBG_HTTPAUTH, "sspi: acquireCredentialsHandle failed.\n");
263 initializeSecurityContext(&sspiContext->credentials, NULL,
264 --- src/ne_sspi.h 2006-02-12 13:05:14.000000000 +0100
265 +++ src/ne_sspi.h 2011-02-03 10:26:21.000000000 +0100
267 int ne_sspi_clear_context(void *context);
269 int ne_sspi_authenticate(void *context, const char *base64Token,
270 - char **responseToken);
271 + char **responseToken, const char* username, const char* password);
273 #endif /* HAVE_SSPI */
275 --- src/ne_uri.c 2007-12-05 12:04:47.000000000 +0100
276 +++ src/ne_uri.c 2011-02-03 10:26:21.000000000 +0100
278 #include "ne_alloc.h"
281 -/* URI ABNF from RFC 3986: */
282 +/* URI ABNF from RFC 3986: (TKR: SharePoint is contradictory to this RFC. So I fix it here. )*/
284 #define PS (0x0001) /* "+" */
285 #define PC (0x0002) /* "%" */
288 #define OT (0x4000) /* others */
290 +/* TKR new symbol */
291 +#define WS (0x8000) /* Whitespaces ( Space, Tab ) */
293 #define URI_ALPHA (AL)
294 #define URI_DIGIT (DG)
297 /* pchar = unreserved / pct-encoded / sub-delims / ":" / "@" */
298 #define URI_PCHAR (URI_UNRESERVED | PC | URI_SUBDELIM | CL | AT)
299 /* invented: segchar = pchar / "/" */
300 -#define URI_SEGCHAR (URI_PCHAR | FS)
301 +/* (TKR) WS added */
302 +#define URI_SEGCHAR (URI_PCHAR | FS | WS)
303 /* query = *( pchar / "/" / "?" ) */
304 #define URI_QUERY (URI_PCHAR | FS | QU)
305 /* fragment == query */
306 #define URI_FRAGMENT URI_QUERY
308 /* any characters which should be path-escaped: */
309 -#define URI_ESCAPE ((URI_GENDELIM & ~(FS)) | URI_SUBDELIM | OT | PC)
310 +#define URI_ESCAPE ((URI_GENDELIM & ~(FS)) | URI_SUBDELIM | OT | WS | PC)
312 static const unsigned int uri_chars[256] = {
313 /* 0xXX x0 x2 x4 x6 x8 xA xC xE */
314 -/* 0x */ OT, OT, OT, OT, OT, OT, OT, OT, OT, OT, OT, OT, OT, OT, OT, OT,
315 +/* 0x */ OT, OT, OT, OT, OT, OT, OT, OT, OT, WS, OT, OT, OT, OT, OT, OT,
316 /* 1x */ OT, OT, OT, OT, OT, OT, OT, OT, OT, OT, OT, OT, OT, OT, OT, OT,
317 -/* 2x */ OT, SD, OT, GD, SD, PC, SD, SD, SD, SD, SD, PS, SD, DS, DT, FS,
318 +/* 2x */ WS, SD, OT, GD, SD, PC, SD, SD, SD, SD, SD, PS, SD, DS, DT, FS,
319 /* 3x */ DG, DG, DG, DG, DG, DG, DG, DG, DG, DG, CL, SD, OT, SD, OT, QU,
320 /* 4x */ AT, AL, AL, AL, AL, AL, AL, AL, AL, AL, AL, AL, AL, AL, AL, AL,
321 /* 5x */ AL, AL, AL, AL, AL, AL, AL, AL, AL, AL, AL, GD, OT, GD, OT, US,
322 --- src/ne_utils.c 2006-03-07 10:36:43.000000000 +0100
323 +++ src/ne_utils.c 2011-02-03 10:26:21.000000000 +0100
326 ", GNU TLS " LIBGNUTLS_VERSION
327 #endif /* HAVE_GNUTLS */
330 +#endif /* HAVE_SSPI */
336 #if defined(NE_HAVE_SSL) || defined(NE_HAVE_ZLIB) || defined(NE_HAVE_IPV6) \
337 || defined(NE_HAVE_SOCKS) || defined(NE_HAVE_LFS) \
338 - || defined(NE_HAVE_TS_SSL) || defined(NE_HAVE_I18N)
339 + || defined(NE_HAVE_TS_SSL) || defined(NE_HAVE_I18N) || defined(HAVE_SSPI)
345 case NE_FEATURE_I18N:
348 + case NE_FEATURE_SSPI:
351 #endif /* NE_HAVE_* */
353 --- src/ne_utils.h 2007-07-16 08:54:57.000000000 +0200
354 +++ src/ne_utils.h 2011-02-03 10:26:21.000000000 +0100
356 #define NE_FEATURE_SOCKS (5) /* SOCKSv5 support */
357 #define NE_FEATURE_TS_SSL (6) /* Thread-safe SSL/TLS support */
358 #define NE_FEATURE_I18N (7) /* i18n error message support */
359 +#define NE_FEATURE_SSPI (8) /* NTLM/Negotiate authentication protocol via SSPI */
361 /* Returns non-zero if library is built with support for the given
362 * NE_FEATURE_* feature code 'code'. */
370 +#define X509_NAME WIN32_X509_NAME
371 +#include <windows.h>
372 +#include <wincrypt.h>
377 #include "ne_string.h"
378 #include "ne_session.h"
380 X509_STORE_load_locations(store, NE_SSL_CA_BUNDLE, NULL);
382 X509_STORE_set_default_paths(store);
386 + PCCERT_CONTEXT pContext = NULL;
389 + hStore = CertOpenSystemStore(0, "ROOT");
392 + while (pContext = CertEnumCertificatesInStore(hStore, pContext))
394 + x509 = d2i_X509(NULL, &pContext->pbCertEncoded, pContext->cbCertEncoded);
397 + X509_STORE_add_cert(store, x509);
403 + CertFreeCertificateContext(pContext);
404 + CertCloseStore(hStore, 0);