From 80b0e2c0fdad108454ae87130496f595f0b81b81 Mon Sep 17 00:00:00 2001 From: Stef Walter Date: Fri, 7 May 2004 22:02:29 +0000 Subject: - Reworked the internal API - Added common functions for trimming - Debugging - Reworked the module to the new protocol --- daemon/ntlm.c | 42 ++++++++++++++++++++---------------------- 1 file changed, 20 insertions(+), 22 deletions(-) (limited to 'daemon/ntlm.c') diff --git a/daemon/ntlm.c b/daemon/ntlm.c index a46eecc..85bee1d 100644 --- a/daemon/ntlm.c +++ b/daemon/ntlm.c @@ -7,6 +7,7 @@ #include "defaults.h" #include "md5.h" #include "basic.h" +#include "stringx.h" #include @@ -539,7 +540,7 @@ finally: int ntlm_config(ha_context_t* context, const char* name, const char* value) { - ntlm_context_t* ctx = (ntlm_context_t*)(context->data); + ntlm_context_t* ctx = (ntlm_context_t*)(context->ctx_data); ASSERT(name && value && value[0]); @@ -579,12 +580,12 @@ int ntlm_init(ha_context_t* context) /* Per context initialization */ if(context) { - ntlm_context_t* ctx = (ntlm_context_t*)(context->data); + ntlm_context_t* ctx = (ntlm_context_t*)(context->ctx_data); ASSERT(ctx); /* Make sure there are some types of authentication we can do */ - if(!(context->opts->types & (HA_TYPE_BASIC | HA_TYPE_NTLM))) + if(!(context->allowed_types & (HA_TYPE_BASIC | HA_TYPE_NTLM))) { ha_messagex(LOG_ERR, "NTLM module configured, but does not implement any " "configured authentication type."); @@ -635,7 +636,7 @@ void ntlm_destroy(ha_context_t* context) if(context) { /* Note: We don't need to be thread safe here anymore */ - ntlm_context_t* ctx = (ntlm_context_t*)(context->data); + ntlm_context_t* ctx = (ntlm_context_t*)(context->ctx_data); if(ctx->pending) hash_free(ctx->pending); @@ -655,17 +656,16 @@ void ntlm_destroy(ha_context_t* context) } } -int ntlm_process(ha_context_t* context, const ha_request_t* req, - ha_response_t* resp, ha_buffer_t* buf) +int ntlm_process(const ha_request_t* req, ha_response_t* resp) { - ntlm_context_t* ctx = (ntlm_context_t*)(context->data); + ntlm_context_t* ctx = (ntlm_context_t*)(req->context->ctx_data); void* ntlm_connection_t = NULL; unsigned char key[NTLM_HASH_KEY_LEN]; const char* header = NULL; time_t t = time(NULL); int ret, r; - ASSERT(context && req && resp && buf); + ASSERT(req && resp); ASSERT(req->args[AUTH_ARG_CONN]); resp->code = -1; @@ -682,7 +682,7 @@ int ntlm_process(ha_context_t* context, const ha_request_t* req, * well as half open connections which expire. */ r = hash_purge(ctx->pending, t - ctx->pending_timeout); - r += hash_purge(ctx->established, t - context->opts->cache_timeout); + r += hash_purge(ctx->established, t - req->context->cache_timeout); ha_unlock(NULL); @@ -690,35 +690,33 @@ int ntlm_process(ha_context_t* context, const ha_request_t* req, ha_messagex(LOG_DEBUG, "ntlm: purged info from cache: %d", r); /* Look for a NTLM header */ - if(context->opts->types & HA_TYPE_NTLM) + if(req->context->allowed_types & HA_TYPE_NTLM) { header = ha_getheader(req, "Authorization", HA_PREFIX_NTLM); if(header) { /* Trim off for decoding */ - while(*header && isspace(*header)) - header++; + header = trim_start(header); ha_messagex(LOG_DEBUG, "ntlm: processing ntlm auth header"); - ret = ntlm_auth_ntlm(ctx, key, header, resp, buf); + ret = ntlm_auth_ntlm(ctx, key, header, resp, req->buf); if(ret < 0) return ret; } } /* If basic is enabled, and no NTLM */ - if(!header && context->opts->types & HA_TYPE_BASIC) + if(!header && req->context->allowed_types & HA_TYPE_BASIC) { /* Look for a Basic header */ header = ha_getheader(req, "Authorization", HA_PREFIX_BASIC); if(header) { /* Trim off for decoding */ - while(*header && isspace(*header)) - header++; + header = trim_start(header); ha_messagex(LOG_DEBUG, "ntlm: processing basic auth header"); - ret = ntlm_auth_basic(ctx, key, header, resp, buf); + ret = ntlm_auth_basic(ctx, key, header, resp, req->buf); if(ret < 0) return ret; } @@ -757,20 +755,20 @@ int ntlm_process(ha_context_t* context, const ha_request_t* req, /* If authentication failed tell the browser about it */ resp->code = HA_SERVER_DECLINE; - if(context->opts->types & HA_TYPE_NTLM) + if(req->context->allowed_types & HA_TYPE_NTLM) { ha_addheader(resp, "WWW-Authenticate", HA_PREFIX_NTLM); ha_messagex(LOG_DEBUG, "ntlm: sent ntlm auth request"); } - if(context->opts->types & HA_TYPE_BASIC) + if(req->context->allowed_types & HA_TYPE_BASIC) { - ha_bufmcat(buf, HA_PREFIX_BASIC, "realm=\"", context->opts->realm, "\"", NULL); + ha_bufmcat(req->buf, HA_PREFIX_BASIC, "realm=\"", req->context->realm, "\"", NULL); - if(ha_buferr(buf)) + if(ha_buferr(req->buf)) return HA_CRITERROR; - ha_addheader(resp, "WWW-Authenticate", ha_bufdata(buf)); + ha_addheader(resp, "WWW-Authenticate", ha_bufdata(req->buf)); ha_messagex(LOG_DEBUG, "ntlm: sent basic auth request"); } } -- cgit v1.2.3