summaryrefslogtreecommitdiff
path: root/daemon/simple.c
diff options
context:
space:
mode:
Diffstat (limited to 'daemon/simple.c')
-rw-r--r--daemon/simple.c82
1 files changed, 41 insertions, 41 deletions
diff --git a/daemon/simple.c b/daemon/simple.c
index d570a25..bda60c3 100644
--- a/daemon/simple.c
+++ b/daemon/simple.c
@@ -20,17 +20,17 @@
typedef struct simple_context
{
- /* Base Handler ------------------------------------------------------ */
- bd_context_t bd;
+ /* Base Handler ------------------------------------------------------ */
+ bd_context_t bd;
- /* Settings ---------------------------------------------------------- */
- const char* filename; /* The file name with the user names */
+ /* Settings ---------------------------------------------------------- */
+ const char* filename; /* The file name with the user names */
}
simple_context_t;
/* Forward declarations for callbacks */
-static int complete_digest(const ha_request_t* req, const char* user, unsigned char* ha1);
-static int validate_basic(const ha_request_t* req, const char* user, const char* password);
+static int complete_digest(ha_request_t* rq, const char* user, unsigned char* ha1);
+static int validate_basic(ha_request_t* rq, const char* user, const char* password);
/* The defaults for the context */
static const simple_context_t simple_defaults =
@@ -43,9 +43,9 @@ static const simple_context_t simple_defaults =
* Internal Functions
*/
-static int complete_digest(const ha_request_t* req, const char* user, unsigned char* ha1)
+static int complete_digest(ha_request_t* rq, const char* user, unsigned char* ha1)
{
- simple_context_t* ctx = (simple_context_t*)req->context->ctx_data;
+ simple_context_t* ctx = (simple_context_t*)rq->context->ctx_data;
FILE* f;
char* t;
char* t2;
@@ -53,13 +53,13 @@ static int complete_digest(const ha_request_t* req, const char* user, unsigned c
char line[SIMPLE_MAXLINE];
int ret = HA_FALSE;
- ASSERT(ctx && req && user && user[0]);
- ha_messagex(LOG_DEBUG, "searching password file for user's ha1: %s", user);
+ ASSERT(ctx && rq && user && user[0]);
+ ha_messagex(rq, LOG_DEBUG, "searching password file for user's ha1: %s", user);
f = fopen(ctx->filename, "r");
if(!f)
{
- ha_message(LOG_ERR, "simple: can't open file for basic auth: %s", ctx->filename);
+ ha_message(rq, LOG_ERR, "can't open file for basic auth: %s", ctx->filename);
return HA_FAILED;
}
@@ -75,7 +75,7 @@ static int complete_digest(const ha_request_t* req, const char* user, unsigned c
if(ferror(f))
{
- ha_message(LOG_ERR, "simple: error reading basic password file");
+ ha_message(rq, LOG_ERR, "error reading basic password file");
ret = HA_FAILED;
break;
}
@@ -98,15 +98,15 @@ static int complete_digest(const ha_request_t* req, const char* user, unsigned c
t2++;
/* Check the realm */
- if(strcmp(t, req->context->realm) == 0)
+ if(strcmp(t, rq->context->realm) == 0)
{
len = MD5_LEN;
/* Now try and decode the ha1 */
- t = ha_bufdechex(req->buf, t2, &len);
+ t = ha_bufdechex(rq->buf, t2, &len);
if(t && len == MD5_LEN)
{
- ha_messagex(LOG_DEBUG, "simple: found ha1 for user: %s", user);
+ ha_messagex(rq, LOG_DEBUG, "found ha1 for user: %s", user);
memcpy(ha1, t, MD5_LEN);
ret = HA_OK;
break;
@@ -115,22 +115,22 @@ static int complete_digest(const ha_request_t* req, const char* user, unsigned c
}
if(!t2 || ret != HA_OK)
- ha_messagex(LOG_WARNING, "simple: user '%s' found in file, but password not in digest format", user);
+ ha_messagex(rq, LOG_WARNING, "user '%s' found in file, but password not in digest format", user);
}
}
}
fclose(f);
- if(ha_buferr(req->buf))
+ if(ha_buferr(rq->buf))
return HA_CRITERROR;
return ret;
}
-static int validate_basic(const ha_request_t* req, const char* user, const char* password)
+static int validate_basic(ha_request_t* rq, const char* user, const char* password)
{
- simple_context_t* ctx = (simple_context_t*)req->context->ctx_data;
+ simple_context_t* ctx = (simple_context_t*)rq->context->ctx_data;
FILE* f;
char line[SIMPLE_MAXLINE];
unsigned char ha1[MD5_LEN];
@@ -139,18 +139,18 @@ static int validate_basic(const ha_request_t* req, const char* user, const char*
size_t len;
int ret = HA_FALSE;
- ASSERT(ctx && req);
+ ASSERT(ctx && rq);
ASSERT(user && user[0] && password);
- ha_messagex(LOG_DEBUG, "simple: validating user against password file: %s", user);
+ ha_messagex(rq, LOG_DEBUG, "validating user against password file: %s", user);
f = fopen(ctx->filename, "r");
if(!f)
{
- ha_message(LOG_ERR, "simple: can't open file for basic auth: %s", ctx->filename);
+ ha_message(rq, LOG_ERR, "can't open file for basic auth: %s", ctx->filename);
return HA_FAILED;
}
- digest_makeha1(ha1, user, req->context->realm, password);
+ digest_makeha1(ha1, user, rq->context->realm, password);
/*
* Note: There should be no returns or jumps between
@@ -164,7 +164,7 @@ static int validate_basic(const ha_request_t* req, const char* user, const char*
if(ferror(f))
{
- ha_message(LOG_ERR, "simple: error reading basic password file");
+ ha_message(rq, LOG_ERR, "error reading basic password file");
ret = HA_FAILED;
break;
}
@@ -192,7 +192,7 @@ static int validate_basic(const ha_request_t* req, const char* user, const char*
if(strcmp(t2, t) == 0)
{
- ha_messagex(LOG_DEBUG, "simple: found valid crypt password for user: %s", user);
+ ha_messagex(rq, LOG_DEBUG, "found valid crypt password for user: %s", user);
ret = HA_OK;
break;
}
@@ -205,22 +205,22 @@ static int validate_basic(const ha_request_t* req, const char* user, const char*
t2++;
/* Check the realm */
- if(strcmp(t, req->context->realm) == 0)
+ if(strcmp(t, rq->context->realm) == 0)
{
len = MD5_LEN;
/* Now try antd decode the ha1 */
- t = ha_bufdechex(req->buf, t2, &len);
+ t = ha_bufdechex(rq->buf, t2, &len);
if(t && len == MD5_LEN && memcmp(ha1, t, MD5_LEN) == 0)
{
- ha_messagex(LOG_DEBUG, "simple: found valid ha1 for user: %s", user);
+ ha_messagex(rq, LOG_DEBUG, "found valid ha1 for user: %s", user);
ret = HA_OK;
break;
}
}
}
- if(ha_buferr(req->buf))
+ if(ha_buferr(rq->buf))
break;
}
}
@@ -228,7 +228,7 @@ static int validate_basic(const ha_request_t* req, const char* user, const char*
fclose(f);
- if(ha_buferr(req->buf))
+ if(ha_buferr(rq->buf))
return HA_CRITERROR;
return ret;
@@ -270,21 +270,21 @@ int simple_init(ha_context_t* context)
/* Check to make sure the file exists */
if(!ctx->filename)
{
- ha_messagex(LOG_ERR, "simple: configuration incomplete. "
- "Must have a PasswordFile configured.");
+ ha_messagex(NULL, LOG_ERR, "configuration incomplete. "
+ "Must have a PasswordFile configured.");
return HA_FAILED;
}
fd = open(ctx->filename, O_RDONLY);
if(fd == -1)
{
- ha_message(LOG_ERR, "simple: can't open file for authentication: %s", ctx->filename);
+ ha_message(NULL, LOG_ERR, "can't open file for authentication: %s", ctx->filename);
return HA_FAILED;
}
close(fd);
- ha_messagex(LOG_INFO, "simple: initialized handler");
+ ha_messagex(NULL, LOG_INFO, "initialized simple handler");
}
return HA_OK;
@@ -297,12 +297,12 @@ int simple_init(ha_context_t* context)
ha_handler_t simple_handler =
{
- "SIMPLE", /* The type */
- simple_init, /* Initialization function */
- bd_destroy, /* Uninitialization routine */
- simple_config, /* Config routine */
- bd_process, /* Processing routine */
- NULL, /* A default context */
- sizeof(simple_context_t) /* Size of the context */
+ "SIMPLE", /* The type */
+ simple_init, /* Initialization function */
+ bd_destroy, /* Uninitialization routine */
+ simple_config, /* Config routine */
+ bd_process, /* Processing routine */
+ NULL, /* A default context */
+ sizeof(simple_context_t) /* Size of the context */
};