summaryrefslogtreecommitdiff
path: root/daemon/httpauthd.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/httpauthd.c
parentc9b851b3194bf4bff6059e9ff471d125afc39c0f (diff)
Protocol:
- version added to initial Ready - Added SET command - Added 202 Accept response Some structure changes
Diffstat (limited to 'daemon/httpauthd.c')
-rw-r--r--daemon/httpauthd.c237
1 files changed, 132 insertions, 105 deletions
diff --git a/daemon/httpauthd.c b/daemon/httpauthd.c
index 55092db..1092e94 100644
--- a/daemon/httpauthd.c
+++ b/daemon/httpauthd.c
@@ -67,7 +67,6 @@ httpauth_command_t;
const char* kAuthHeaders[] =
{
"Authorization",
- "Proxy-Authorization",
NULL
};
@@ -75,6 +74,7 @@ const char* kAuthHeaders[] =
const httpauth_command_t kCommands[] =
{
{ "auth", REQTYPE_AUTH, 4, kAuthHeaders },
+ { "set", REQTYPE_SET, 2, 0 },
{ "quit", REQTYPE_QUIT, 0, 0 },
{ NULL, -1, -1 }
};
@@ -723,7 +723,7 @@ static int httpauth_respond(int ofd, int scode, int ccode, const char* msg)
ASSERT(ccode == 0 || (ccode > 99 && ccode < 1000));
/* Can only have a client code when server code is 200 */
- ASSERT(ccode == 0 || scode == HA_SERVER_ACCEPT);
+ ASSERT(ccode == 0 || scode == HA_SERVER_OK);
sprintf(num, "%d ", scode);
@@ -777,7 +777,7 @@ static int httpauth_write(int ofd, ha_response_t* resp)
ASSERT(ofd != -1);
ASSERT(resp);
- if(httpauth_respond(ofd, HA_SERVER_ACCEPT, resp->code, resp->detail) < 0)
+ if(httpauth_respond(ofd, HA_SERVER_OK, resp->code, resp->detail) < 0)
return HA_CRITERROR;
for(i = 0; i < HA_MAX_HEADERS; i++)
@@ -841,31 +841,112 @@ static int httpauth_ready(int ofd, ha_buffer_t* buf)
/* We send a ready banner to our client */
+ if(ha_buferr(buf))
+ return httpauth_error(ofd, HA_CRITERROR);
+
+ else
+ return httpauth_respond(ofd, HA_SERVER_READY, 0, "HTTPAUTH/1.0");
+
+}
+
+static int httpauth_auth(int ofd, ha_request_t* req,
+ ha_response_t* resp, ha_buffer_t* outb)
+{
+ httpauth_loaded_t* h;
+ int processed = 0;
+ int r;
+
+ ASSERT(req && resp && outb);
+
+ /* Clear out our response */
+ memset(resp, 0, sizeof(*resp));
+
+ /* Check our connection argument */
+ if(!req->args[AUTH_ARG_CONN] || !(req->args[AUTH_ARG_CONN][0]))
+ {
+ ha_messagex(LOG_ERR, "missing connection ID in request");
+ return HA_BADREQ;
+ }
+
+ /* Check our uri argument */
+ if(!req->args[AUTH_ARG_URI] || !(req->args[AUTH_ARG_URI][0]))
+ {
+ ha_messagex(LOG_ERR, "missing URI in request");
+ return HA_BADREQ;
+ }
+
+ /* Check our connection arguments */
+ if(!req->args[AUTH_ARG_METHOD] || !(req->args[AUTH_ARG_METHOD][0]))
+ {
+ ha_messagex(LOG_ERR, "missing method in request");
+ return HA_BADREQ;
+ }
+
+ /* Find a handler for this type */
for(h = g_handlers; h; h = h->next)
{
- if(h != g_handlers)
- ha_bufjoin(buf);
+ if(strcasecmp(h->ctx.name, req->args[0]) == 0)
+ {
+ ha_messagex(LOG_INFO, "processing request with method: %s (%s)",
+ h->ctx.name, h->ctx.handler->type);
+
+ /* Now let the handler handle it */
+ ASSERT(h->ctx.handler->f_process);
- ha_bufmcat(buf, (h != g_handlers) ? " " : "",
- h->ctx.name, NULL);
+ processed = 1;
+ r = (h->ctx.handler->f_process)(&(h->ctx), req, resp, outb);
+ if(r < 0)
+ return r;
+ }
}
- if(ha_buferr(buf))
+ if(!processed)
{
- return httpauth_error(ofd, HA_CRITERROR);
+ ha_messagex(LOG_ERR, "unknown authentication type: %s", req->args[0]);
+ return HA_BADREQ;
+ }
+
+ if(httpauth_write(ofd, resp) < 0)
+ return HA_CRITERROR;
+
+ return HA_OK;
+}
+
+static int httpauth_set(int ofd, ha_request_t* req, ha_request_opts_t* opts,
+ ha_buffer_t* outb)
+{
+ const char* name = req->args[0];
+ const char* value = req->args[1];
+
+ /* Check our name argument */
+ if(!name || !*name)
+ {
+ ha_messagex(LOG_ERR, "missing name in SET request");
+ return HA_BADREQ;
+ }
+
+ if(strcasecmp(name, "Domain") == 0)
+ {
+ opts->digest_domains = value ? value : "";
}
+
else
{
- return httpauth_respond(ofd, HA_SERVER_READY, 0, ha_bufdata(buf));
+ ha_messagex(LOG_ERR, "bad option in SET request");
+ return HA_BADREQ;
}
+
+ return httpauth_respond(ofd, HA_SERVER_ACCEPTED, 0, NULL);
}
+
static int httpauth_processor(int ifd, int ofd)
{
ha_buffer_t inb;
ha_buffer_t outb;
ha_request_t req;
ha_response_t resp;
+ ha_request_opts_t opts;
int result = -1;
int r;
@@ -876,6 +957,10 @@ static int httpauth_processor(int ifd, int ofd)
ha_bufinit(&inb);
ha_bufinit(&outb);
+ /* Initialize default options */
+ memset(&opts, 0, sizeof(opts));
+ opts.digest_domains = "";
+
if(httpauth_ready(ofd, &outb) == -1)
{
result = 1;
@@ -908,56 +993,46 @@ static int httpauth_processor(int ifd, int ofd)
if(r == 0)
result = 0;
+ req.opts = &opts;
+
switch(req.type)
{
case REQTYPE_AUTH:
-
- r = process_auth(&req, &resp, &outb);
-
- if(g_quit)
- continue;
-
- if(ha_buferr(&outb))
- r = HA_CRITERROR;
-
- if(r < 0)
- {
- httpauth_error(ofd, r);
-
- if(r == HA_CRITERROR)
- result = 1;
-
- continue;
- }
-
- if(httpauth_write(ofd, &resp) < 0)
- {
- /* If writing failed then we don't bother notifying the client */
- result = 1;
- continue;
- }
-
+ r = httpauth_auth(ofd, &req, &resp, &outb);
break;
+ case REQTYPE_SET:
+ r = httpauth_set(ofd, &req, &opts, &outb);
+ break;
case REQTYPE_QUIT:
+ r = HA_OK;
result = 0;
break;
case REQTYPE_IGNORE:
+ r = HA_FALSE;
break;
default:
ha_messagex(LOG_WARNING, "received unknown command from client: %d", ifd);
-
- if(httpauth_respond(ofd, HA_SERVER_BADREQ, 0, "Unknown command") == -1)
- {
- result = -1;
- continue;
- }
-
+ r = httpauth_respond(ofd, HA_SERVER_BADREQ, 0, "Unknown command");
break;
};
+
+ if(g_quit)
+ continue;
+
+ if(ha_buferr(&outb))
+ r = HA_CRITERROR;
+
+ if(r < 0)
+ {
+ httpauth_error(ofd, r);
+
+ if(r == HA_CRITERROR)
+ result = 1;
+ }
}
if(ifd == ofd)
@@ -972,80 +1047,38 @@ finally:
return result;
}
-static int process_auth(ha_request_t* req, ha_response_t* resp,
- ha_buffer_t* outb)
-{
- httpauth_loaded_t* h;
-
- ASSERT(req && resp && outb);
-
- /* Clear out our response */
- memset(resp, 0, sizeof(*resp));
-
- /* Check our connection argument */
- if(!req->args[AUTH_ARG_CONN] || !(req->args[AUTH_ARG_CONN][0]))
- {
- ha_messagex(LOG_ERR, "missing connection ID in request");
- return HA_BADREQ;
- }
-
- /* Check our uri argument */
- if(!req->args[AUTH_ARG_URI] || !(req->args[AUTH_ARG_URI][0]))
- {
- ha_messagex(LOG_ERR, "missing URI in request");
- return HA_BADREQ;
- }
-
- /* Check our connection arguments */
- if(!req->args[AUTH_ARG_METHOD] || !(req->args[AUTH_ARG_METHOD][0]))
- {
- ha_messagex(LOG_ERR, "missing method in request");
- return HA_BADREQ;
- }
-
-
- /* Find a handler for this type */
- for(h = g_handlers; h; h = h->next)
- {
- if(strcasecmp(h->ctx.name, req->args[0]) == 0)
- {
- ha_messagex(LOG_INFO, "processing request with method: %s (%s)",
- h->ctx.name, h->ctx.handler->type);
-
- /* Now let the handler handle it */
- ASSERT(h->ctx.handler->f_process);
- return (h->ctx.handler->f_process)(&(h->ctx), req, resp, outb);
- }
- }
-
- ha_messagex(LOG_ERR, "unknown authentication type: %s", req->args[0]);
- return HA_BADREQ;
-}
-
/* -----------------------------------------------------------------------
* Configuration
*/
static ha_context_t* config_addhandler(ha_buffer_t* buf, const char* alias,
- ha_handler_t* handler, const ha_options_t* defaults)
+ ha_handler_t* handler, const ha_context_opts_t* defaults)
{
httpauth_loaded_t* loaded;
+ ha_context_opts_t* opts;
int len;
ASSERT(buf && alias && handler && defaults);
- len = sizeof(httpauth_loaded_t) + handler->context_size;
+ len = sizeof(httpauth_loaded_t) + sizeof(ha_context_opts_t) +
+ handler->context_size;
loaded = (httpauth_loaded_t*)ha_bufmalloc(buf, len);
if(!loaded)
errx(1, "out of memory");
memset(loaded, 0, len);
- memcpy(&(loaded->ctx.opts), defaults, sizeof(ha_options_t));
+
+ /* Setup the options */
+ opts = (ha_context_opts_t*)(((unsigned char*)loaded) +
+ sizeof(httpauth_loaded_t));
+
+ memcpy(opts, defaults, sizeof(ha_context_opts_t));
+ loaded->ctx.opts = opts;
if(handler->context_size)
{
- void* mem = ((unsigned char*)loaded) + sizeof(httpauth_loaded_t);
+ void* mem = ((unsigned char*)(opts)) + sizeof(ha_context_opts_t);
/* Initialize the defaults properly */
if(handler->context_default)
@@ -1090,7 +1123,7 @@ static ha_context_t* config_addhandler(ha_buffer_t* buf, const char* alias,
static int config_parse(const char* file, ha_buffer_t* buf)
{
- ha_options_t defaults;
+ ha_context_opts_t defaults;
ha_context_t* ctx = NULL;
int line = 0;
int fd;
@@ -1235,7 +1268,7 @@ static int config_parse(const char* file, ha_buffer_t* buf)
/* Options that are legal in both global and internal sections */
if(!recog)
{
- ha_options_t* opts = ctx ? &(ctx->opts) : &defaults;
+ ha_context_opts_t* opts = ctx ? (ha_context_opts_t*)(ctx->opts) : &defaults;
ASSERT(opts);
if(strcmp(name, "cachetimeout") == 0)
@@ -1324,12 +1357,6 @@ static int config_parse(const char* file, ha_buffer_t* buf)
recog = 1;
}
- else if(strcmp(name, "digestdomains") == 0)
- {
- opts->digest_domains = value;
- recog = 1;
- }
-
#ifdef _DEBUG
else if(strcmp(name, "digestdebugnonce") == 0)
{