diff options
Diffstat (limited to 'daemon/httpauthd.c')
-rw-r--r-- | daemon/httpauthd.c | 58 |
1 files changed, 53 insertions, 5 deletions
diff --git a/daemon/httpauthd.c b/daemon/httpauthd.c index 2b74586..f640b5d 100644 --- a/daemon/httpauthd.c +++ b/daemon/httpauthd.c @@ -373,9 +373,12 @@ int usage() void* httpauth_thread(void* arg) { - int fd = (int)arg; - int r = httpauth_processor(fd, fd); - return (void*)r; + int fd, r; + + ASSERT(arg); + + fd = (int)arg; + return (void*)httpauth_processor(fd, fd); } /* ----------------------------------------------------------------------- @@ -390,6 +393,9 @@ int httpauth_read(int ifd, ha_request_t* req, int i, r; int more = 1; + ASSERT(req && buf); + ASSERT(ifd != -1); + /* Clean up the request header */ memset(req, 0, sizeof(*req)); req->type = -1; @@ -536,6 +542,9 @@ int write_data(int ofd, const char* data) { int r; + ASSERT(data); + ASSERT(ofd != -1); + while(*data != 0) { r = write(ofd, data, strlen(data)); @@ -564,6 +573,9 @@ int httpauth_respond(int ofd, int code, const char* msg) const char* t; char num[16]; + ASSERT(ofd != -1); + ASSERT(code > 99 && code < 1000); + sprintf(num, "%d", code); if(write_data(ofd, num) == -1 || @@ -607,6 +619,9 @@ int httpauth_write(int ofd, ha_response_t* resp) int i; int wrote = 0; + ASSERT(ofd != -1); + ASSERT(resp); + if(httpauth_respond(ofd, resp->code, resp->detail) == -1) return -1; @@ -635,6 +650,9 @@ int httpauth_ready(int ofd, ha_buffer_t* buf) const char* t; httpauth_loaded_t* h; + ASSERT(ofd != -1); + ASSERT(buf); + /* We send a ready banner to our client */ for(h = g_handlers; h; h = h->next) @@ -661,6 +679,9 @@ int httpauth_processor(int ifd, int ofd) int result = -1; int r; + ASSERT(ifd != -1); + ASSERT(ofd != -1); + /* Initialize the memory buffers */ ha_bufinit(&inb); ha_bufinit(&outb); @@ -742,11 +763,13 @@ int process_auth(ha_request_t* req, ha_response_t* resp, { httpauth_loaded_t* h; + ASSERT(req && resp && outb); + /* Clear out our response */ memset(resp, 0, sizeof(*resp)); /* Check our connection argument */ - if(!req->args[1] || !(req->args[1][0])) + if(!req->args[AUTH_ARG_CONN] || !(req->args[AUTH_ARG_CONN][0])) { ha_messagex(LOG_ERR, "Missing connection ID in request"); resp->detail = "Missing connection ID"; @@ -754,6 +777,25 @@ int process_auth(ha_request_t* req, ha_response_t* resp, return 0; } + /* Check our uri argument */ + if(!req->args[AUTH_ARG_URI] || !(req->args[AUTH_ARG_URI][0])) + { + ha_messagex(LOG_ERR, "Missing URI in request"); + resp->detail = "Missing URI"; + resp->code = HA_SERVER_BADREQ; + return 0; + } + + /* Check our connection arguments */ + if(!req->args[AUTH_ARG_METHOD] || !(req->args[AUTH_ARG_METHOD][0])) + { + ha_messagex(LOG_ERR, "Missing method in request"); + resp->detail = "Missing method"; + resp->code = HA_SERVER_BADREQ; + return 0; + } + + /* Find a handler for this type */ for(h = g_handlers; h; h = h->next) { @@ -781,7 +823,11 @@ ha_context_t* config_addhandler(ha_buffer_t* buf, const char* alias, ha_handler_t* handler, const ha_context_t* defaults) { httpauth_loaded_t* loaded; - int len = sizeof(httpauth_loaded_t) + handler->context_size; + int len; + + ASSERT(buf && alias && handler && defaults); + + len = sizeof(httpauth_loaded_t) + handler->context_size; loaded = (httpauth_loaded_t*)ha_bufmalloc(buf, len); if(!loaded) @@ -848,6 +894,8 @@ int config_parse(const char* file, ha_buffer_t* buf) int recog; int r, i; + ASSERT(file && buf); + /* Open the configuration file */ fd = open(file, O_RDONLY); if(fd == -1) |