summaryrefslogtreecommitdiff
path: root/daemon/simple.c
diff options
context:
space:
mode:
authorStef Walter <stef@memberwebs.com>2004-04-24 23:57:22 +0000
committerStef Walter <stef@memberwebs.com>2004-04-24 23:57:22 +0000
commitb9cab65e320fccc04cd06694e717db5e4abb5dcc (patch)
treeb64b5f1ca32b7b48b8ad96510ba88809497acce0 /daemon/simple.c
parentcbbe71752d7f9c6204ab0f16600fe7f10490f203 (diff)
Put nice assertions all over the place.
Diffstat (limited to 'daemon/simple.c')
-rw-r--r--daemon/simple.c31
1 files changed, 29 insertions, 2 deletions
diff --git a/daemon/simple.c b/daemon/simple.c
index cd1b812..fdaa0e0 100644
--- a/daemon/simple.c
+++ b/daemon/simple.c
@@ -60,6 +60,8 @@ static digest_record_t* get_cached_digest(simple_context_t* ctx, unsigned char*
{
digest_record_t* rec;
+ ASSERT(ctx && nonce);
+
if(ctx->cache_max == 0)
return NULL;
@@ -81,6 +83,8 @@ static int have_cached_basic(simple_context_t* ctx, unsigned char* key)
{
int ret = 0;
+ ASSERT(ctx && key);
+
ha_lock(NULL);
ret = (hash_get(ctx->cache, key) == BASIC_ESTABLISHED);
@@ -94,6 +98,8 @@ static int save_cached_digest(simple_context_t* ctx, digest_record_t* rec)
{
int r;
+ ASSERT(ctx && rec);
+
if(ctx->cache_max == 0)
return HA_FALSE;
@@ -119,6 +125,8 @@ static int add_cached_basic(simple_context_t* ctx, unsigned char* key)
{
int r;
+ ASSERT(ctx && key);
+
if(ctx->cache_max == 0)
return HA_FALSE;
@@ -148,6 +156,8 @@ static int complete_digest_ha1(simple_context_t* ctx, digest_record_t* rec,
char* t;
char line[SIMPLE_MAXLINE];
+ ASSERT(ctx && rec && buf && user && user[0] && code);
+
f = fopen(ctx->filename, "r");
if(!f)
{
@@ -222,6 +232,9 @@ static int validate_user_password(simple_context_t* ctx, ha_buffer_t* buf,
char* t;
char* t2;
+ ASSERT(ctx && buf && code);
+ ASSERT(user && user[0] && clearpw);
+
f = fopen(ctx->filename, "r");
if(!f)
{
@@ -349,6 +362,8 @@ static int simple_digest_challenge(simple_context_t* ctx, ha_response_t* resp,
unsigned char nonce[DIGEST_NONCE_LEN];
const char* header;
+ ASSERT(ctx && resp && buf);
+
/* Generate an nonce */
digest_makenonce(nonce, g_simple_secret, NULL);
@@ -378,6 +393,8 @@ static int simple_digest_response(simple_context_t* ctx, const char* header,
int stale = 0;
int r;
+ ASSERT(ctx && header && method && uri && resp && buf);
+
/* We use this below to send a default response */
resp->code = -1;
@@ -481,6 +498,8 @@ int simple_config(ha_context_t* context, const char* name, const char* value)
{
simple_context_t* ctx = (simple_context_t*)(context->data);
+ ASSERT(name && name[0] && value && value[0]);
+
if(strcmp(name, "passwordfile") == 0)
{
ctx->filename = value;
@@ -521,6 +540,8 @@ int simple_init(ha_context_t* context)
simple_context_t* ctx = (simple_context_t*)(context->data);
int fd;
+ ASSERT(ctx);
+
/* Make sure there are some types of authentication we can do */
if(!(context->types & (HA_TYPE_BASIC | HA_TYPE_DIGEST)))
{
@@ -547,6 +568,8 @@ int simple_init(ha_context_t* context)
close(fd);
+ ASSERT(!ctx->cache);
+
/* The cache for digest records and basic */
if(!(ctx->cache = hash_create(MD5_LEN, free_hash_object, NULL)))
{
@@ -563,10 +586,11 @@ void simple_destroy(ha_context_t* context)
/* Per context destroy */
if(context)
{
+ /* Note: We don't need to be thread safe here anymore */
simple_context_t* ctx = (simple_context_t*)(context->data);
- /* Note: We don't need to be thread safe here anymore */
- hash_free(ctx->cache);
+ if(ctx->cache)
+ hash_free(ctx->cache);
}
}
@@ -579,6 +603,9 @@ int simple_process(ha_context_t* context, ha_request_t* req,
int found = 0;
basic_header_t basic;
+ ASSERT(context && req && resp && buf);
+ ASSERT(req->args[AUTH_ARG_METHOD]);
+ ASSERT(req->args[AUTH_ARG_URI]);
ha_lock(NULL);