diff options
author | Stef Walter <stef@memberwebs.com> | 2004-04-24 23:57:22 +0000 |
---|---|---|
committer | Stef Walter <stef@memberwebs.com> | 2004-04-24 23:57:22 +0000 |
commit | b9cab65e320fccc04cd06694e717db5e4abb5dcc (patch) | |
tree | b64b5f1ca32b7b48b8ad96510ba88809497acce0 /daemon/ntlm.c | |
parent | cbbe71752d7f9c6204ab0f16600fe7f10490f203 (diff) |
Put nice assertions all over the place.
Diffstat (limited to 'daemon/ntlm.c')
-rw-r--r-- | daemon/ntlm.c | 39 |
1 files changed, 35 insertions, 4 deletions
diff --git a/daemon/ntlm.c b/daemon/ntlm.c index bdf2116..d567fe2 100644 --- a/daemon/ntlm.c +++ b/daemon/ntlm.c @@ -74,6 +74,8 @@ static ntlm_connection_t* getpending(ntlm_context_t* ctx, const void* key) { ntlm_connection_t* ret; + ASSERT(ctx && key); + ha_lock(NULL); ret = (ntlm_connection_t*)hash_rem(ctx->pending, key); @@ -87,6 +89,9 @@ static int putpending(ntlm_context_t* ctx, const void* key, ntlm_connection_t* c { int r = 0; + ASSERT(ctx && key && conn); + ASSERT(conn->handle); + if(!hash_get(ctx->pending, key)) { ha_lock(NULL); @@ -107,6 +112,8 @@ static ntlm_connection_t* makeconnection(ntlm_context_t* ctx) { ntlm_connection_t* conn; + ASSERT(ctx); + conn = (ntlm_connection_t*)malloc(sizeof(ntlm_connection_t)); if(!conn) { @@ -130,10 +137,14 @@ static ntlm_connection_t* makeconnection(ntlm_context_t* ctx) free(conn); return NULL; } + + return conn; } static void freeconnection(ntlm_connection_t* conn) { + ASSERT(conn); + if(conn->handle) { ntlmssp_disconnect(conn->handle); @@ -146,7 +157,10 @@ static void freeconnection(ntlm_connection_t* conn) static void free_hash_object(void* arg, void* val) { if(val) + { + ASSERT(val != NTLM_ESTABLISHED); freeconnection((ntlm_connection_t*)val); + } } int ntlm_auth_basic(ntlm_context_t* ctx, char* key, const char* header, @@ -158,6 +172,8 @@ int ntlm_auth_basic(ntlm_context_t* ctx, char* key, const char* header, const char* domain = NULL; int found = 0; + ASSERT(ctx && key && header && resp && buf); + /* * We're doing basic authentication on the connection * which invalidates any NTLM authentication we've started @@ -201,7 +217,7 @@ int ntlm_auth_basic(ntlm_context_t* ctx, char* key, const char* header, /* Make sure above did not fail */ if(!found && basic.user && basic.user[0] && basic.password && - basic.password[0] && domain && domain[0]) + domain && domain[0]) { /* We need to lock to go into smblib */ ha_lock(&g_smblib_mutex); @@ -251,6 +267,8 @@ int ntlm_auth_ntlm(ntlm_context_t* ctx, void* key, const char* header, int ret = HA_FALSE; int r; + ASSERT(ctx && key && header && resp && buf); + /* * Retrieve and remove the connection from the pending bag. * We add it back again below if that's necessary. @@ -493,6 +511,8 @@ int ntlm_config(ha_context_t* context, const char* name, const char* value) { ntlm_context_t* ctx = (ntlm_context_t*)(context->data); + ASSERT(name && value && value[0]); + if(strcmp(name, "ntlmserver") == 0) { ctx->server = value; @@ -537,6 +557,8 @@ int ntlm_init(ha_context_t* context) { ntlm_context_t* ctx = (ntlm_context_t*)(context->data); + ASSERT(ctx); + /* Make sure there are some types of authentication we can do */ if(!(context->types & (HA_TYPE_BASIC | HA_TYPE_NTLM))) { @@ -553,6 +575,9 @@ int ntlm_init(ha_context_t* context) return HA_ERROR; } + ASSERT(!ctx->pending); + ASSERT(!ctx->established); + /* Initialize our tables */ if(!(ctx->pending = hash_create(NTLM_HASH_KEY_LEN, free_hash_object, NULL)) || !(ctx->established = hash_create(NTLM_HASH_KEY_LEN, NULL, NULL))) @@ -583,11 +608,14 @@ void ntlm_destroy(ha_context_t* context) /* Per context destroy */ if(context) { + /* Note: We don't need to be thread safe here anymore */ ntlm_context_t* ctx = (ntlm_context_t*)(context->data); - /* Note: We don't need to be thread safe here anymore */ - hash_free(ctx->pending); - hash_free(ctx->established); + if(ctx->pending) + hash_free(ctx->pending); + + if(ctx->established) + hash_free(ctx->established); } /* Global Destroy */ @@ -609,6 +637,9 @@ int ntlm_process(ha_context_t* context, ha_request_t* req, time_t t = time(NULL); int ret; + ASSERT(context && req && resp && buf); + ASSERT(req->args[AUTH_ARG_CONN]); + resp->code = -1; /* Hash the unique key */ |