summaryrefslogtreecommitdiff
path: root/daemon/simple.c
diff options
context:
space:
mode:
authorStef Walter <stef@memberwebs.com>2004-05-07 17:52:22 +0000
committerStef Walter <stef@memberwebs.com>2004-05-07 17:52:22 +0000
commit0bc8575dbfb281f5f5e9fb530247d29ba1f296fc (patch)
tree4e0eda73d880c01e9434b4f1ebb52f513119269b /daemon/simple.c
parentc9b851b3194bf4bff6059e9ff471d125afc39c0f (diff)
Protocol:
- version added to initial Ready - Added SET command - Added 202 Accept response Some structure changes
Diffstat (limited to 'daemon/simple.c')
-rw-r--r--daemon/simple.c43
1 files changed, 21 insertions, 22 deletions
diff --git a/daemon/simple.c b/daemon/simple.c
index d45668f..7165c9c 100644
--- a/daemon/simple.c
+++ b/daemon/simple.c
@@ -26,8 +26,8 @@ unsigned char g_simple_secret[DIGEST_SECRET_LEN];
typedef struct simple_context
{
/* Settings ----------------------------------------------------------- */
- const char* filename; /* The file name with the user names */
- ha_options_t* opts; /* Options from httpauthd.c */
+ const char* filename; /* The file name with the user names */
+ const ha_context_opts_t* opts; /* Options from httpauthd.c */
/* Context ----------------------------------------------------------- */
hash_t* cache; /* Some cached records or basic */
@@ -379,7 +379,7 @@ finally:
if(ret == HA_OK)
{
- resp->code = HA_SERVER_ACCEPT;
+ resp->code = HA_SERVER_OK;
resp->detail = basic.user;
/* We put this connection into the successful connections */
@@ -389,8 +389,8 @@ finally:
return ret;
}
-static int simple_digest_challenge(simple_context_t* ctx, ha_response_t* resp,
- ha_buffer_t* buf, int stale)
+static int simple_digest_challenge(simple_context_t* ctx, const ha_request_t* req,
+ ha_response_t* resp, ha_buffer_t* buf, int stale)
{
const char* nonce_str;
const char* header;
@@ -419,7 +419,7 @@ static int simple_digest_challenge(simple_context_t* ctx, ha_response_t* resp,
/* Now generate a message to send */
header = digest_challenge(buf, nonce_str, ctx->opts->realm,
- ctx->opts->digest_domains, stale);
+ req->opts->digest_domains, stale);
if(!header)
return HA_CRITERROR;
@@ -433,8 +433,7 @@ static int simple_digest_challenge(simple_context_t* ctx, ha_response_t* resp,
}
static int simple_digest_response(simple_context_t* ctx, const char* header,
- const char* method, const char* uri,
- ha_response_t* resp, ha_buffer_t* buf)
+ const ha_request_t* req, ha_response_t* resp, ha_buffer_t* buf)
{
unsigned char nonce[DIGEST_NONCE_LEN];
digest_header_t dg;
@@ -445,7 +444,7 @@ static int simple_digest_response(simple_context_t* ctx, const char* header,
int stale = 0;
int r;
- ASSERT(ctx && header && method && uri && resp && buf);
+ ASSERT(ctx && header && req && resp && buf);
/* We use this below to send a default response */
resp->code = -1;
@@ -525,7 +524,8 @@ static int simple_digest_response(simple_context_t* ctx, const char* header,
rec->nc++;
}
- ret = digest_check(&dg, rec, ctx->opts, buf, method, uri);
+ ret = digest_check(&dg, rec, ctx->opts, buf,
+ req->args[AUTH_ARG_METHOD], req->args[AUTH_ARG_URI]);
if(ret == HA_BADREQ)
{
@@ -535,7 +535,7 @@ static int simple_digest_response(simple_context_t* ctx, const char* header,
else if(ret == HA_OK)
{
- resp->code = HA_SERVER_ACCEPT;
+ resp->code = HA_SERVER_OK;
resp->detail = dg.username;
/* Figure out if we need a new nonce */
@@ -576,7 +576,7 @@ finally:
/* If nobody above responded then challenge the client again */
if(resp->code == -1)
- return simple_digest_challenge(ctx, resp, buf, stale);
+ return simple_digest_challenge(ctx, req, resp, buf, stale);
return ret;
}
@@ -619,7 +619,7 @@ int simple_init(ha_context_t* context)
ASSERT(ctx);
/* Make sure there are some types of authentication we can do */
- if(!(context->opts.types & (HA_TYPE_BASIC | HA_TYPE_DIGEST)))
+ if(!(context->opts->types & (HA_TYPE_BASIC | HA_TYPE_DIGEST)))
{
ha_messagex(LOG_ERR, "simple: module configured, but does not implement any "
"configured authentication type.");
@@ -654,7 +654,7 @@ int simple_init(ha_context_t* context)
}
/* Copy some settings over for easy access */
- ctx->opts = &(context->opts);
+ ctx->opts = context->opts;
ha_messagex(LOG_INFO, "simple: initialized handler");
}
@@ -677,7 +677,7 @@ void simple_destroy(ha_context_t* context)
}
}
-int simple_process(ha_context_t* context, ha_request_t* req,
+int simple_process(ha_context_t* context, const ha_request_t* req,
ha_response_t* resp, ha_buffer_t* buf)
{
simple_context_t* ctx = (simple_context_t*)(context->data);
@@ -706,21 +706,20 @@ int simple_process(ha_context_t* context, ha_request_t* req,
/* Check the headers and see if we got a response thingy */
- if(context->opts.types & HA_TYPE_DIGEST)
+ if(context->opts->types & HA_TYPE_DIGEST)
{
header = ha_getheader(req, "Authorization", HA_PREFIX_DIGEST);
if(header)
{
ha_messagex(LOG_DEBUG, "simple: processing digest auth header");
- ret = simple_digest_response(ctx, header, req->args[AUTH_ARG_METHOD],
- req->args[AUTH_ARG_URI], resp, buf);
+ ret = simple_digest_response(ctx, header, req, resp, buf);
if(ret < 0)
return ret;
}
}
/* Or a basic authentication */
- if(!header && context->opts.types & HA_TYPE_BASIC)
+ if(!header && context->opts->types & HA_TYPE_BASIC)
{
ha_messagex(LOG_DEBUG, "simple: processing basic auth header");
header = ha_getheader(req, "Authorization", HA_PREFIX_BASIC);
@@ -738,7 +737,7 @@ int simple_process(ha_context_t* context, ha_request_t* req,
{
resp->code = HA_SERVER_DECLINE;
- if(context->opts.types & HA_TYPE_BASIC)
+ if(context->opts->types & HA_TYPE_BASIC)
{
ha_bufmcat(buf, "BASIC realm=\"", ctx->opts->realm , "\"", NULL);
@@ -749,9 +748,9 @@ int simple_process(ha_context_t* context, ha_request_t* req,
ha_messagex(LOG_DEBUG, "simple: sent basic auth request");
}
- if(context->opts.types & HA_TYPE_DIGEST)
+ if(context->opts->types & HA_TYPE_DIGEST)
{
- ret = simple_digest_challenge(ctx, resp, buf, 0);
+ ret = simple_digest_challenge(ctx, req, resp, buf, 0);
if(ret < 0)
return ret;
}