From 66d68a58fbbeacfaa51f5210e9d6a549a677014f Mon Sep 17 00:00:00 2001 From: Stef Walter Date: Wed, 9 Jun 2004 16:39:31 +0000 Subject: - Changed 'method' to 'handler' throughout - Fixed bug in hash.c with unitialized memory - Imported new hash table features - Writes out pid file when requested with -p option --- daemon/httpauthd.c | 54 +++++++++++++++++++++++++++++++++++++++++------------- daemon/ldap.c | 7 ++++++- daemon/ntlm.c | 9 +++++++-- daemon/simple.c | 7 ++++++- 4 files changed, 60 insertions(+), 17 deletions(-) (limited to 'daemon') diff --git a/daemon/httpauthd.c b/daemon/httpauthd.c index 00cb261..03a331a 100644 --- a/daemon/httpauthd.c +++ b/daemon/httpauthd.c @@ -122,6 +122,7 @@ pthread_mutexattr_t g_mutexattr; */ static int usage(); +static void writepid(const char* pid); static void* httpauth_thread(void* arg); static int httpauth_processor(int ifd, int ofd); static int httpauth_respond(int ofd, int scode, int ccode, const char* msg); @@ -137,6 +138,7 @@ static void on_quit(int signal); int main(int argc, char* argv[]) { const char* conf = DEFAULT_CONFIG; + const char* pidfile = NULL; httpauth_thread_t* threads = NULL; httpauth_loaded_t* h; int daemonize = 1; @@ -154,7 +156,7 @@ int main(int argc, char* argv[]) errx(1, "threading problem. can't create mutex"); /* Parse the arguments nicely */ - while((ch = getopt(argc, argv, "d:f:X")) != -1) + while((ch = getopt(argc, argv, "d:f:p:X")) != -1) { switch(ch) { @@ -176,6 +178,11 @@ int main(int argc, char* argv[]) conf = optarg; break; + /* Write out a pid file */ + case 'p': + pidfile = optarg; + break; + /* Process console input instead */ case 'X': g_console = 1; @@ -282,9 +289,12 @@ int main(int argc, char* argv[]) exit(1); } + ha_messagex(LOG_DEBUG, "running as a daemon"); g_daemonized = 1; } + writepid(pidfile); + /* Handle some signals */ signal(SIGPIPE, SIG_IGN); signal(SIGHUP, SIG_IGN); @@ -413,10 +423,28 @@ static void on_quit(int signal) static int usage() { - fprintf(stderr, "usage: httpauthd [-d level] [-X] [-f conffile]\n"); + fprintf(stderr, "usage: httpauthd [-d level] [-X] [-p pidfile] [-f conffile]\n"); return 2; } +static void writepid(const char* pidfile) +{ + FILE* f = fopen(pidfile, "w"); + if(f == NULL) + { + warnx("couldn't open pid file: %s", pidfile); + } + else + { + fprintf(f, "%d\n", (int)getpid()); + + if(ferror(f)) + warnx("couldn't write to pid file: %s", pidfile); + + fclose(f); + } +} + static void* httpauth_thread(void* arg) { httpauth_thread_t* thread = (httpauth_thread_t*)arg; @@ -868,8 +896,8 @@ static int httpauth_auth(int ofd, ha_request_t* req, ha_response_t* resp) if(!req->context) { - ha_messagex(LOG_ERR, "no auth method set"); - return httpauth_respond(ofd, HA_SERVER_BADREQ, 0, "No Auth Method Set"); + ha_messagex(LOG_ERR, "no auth handler set"); + return httpauth_respond(ofd, HA_SERVER_BADREQ, 0, "No Auth Handler Set"); } /* Clear out our response */ @@ -930,11 +958,11 @@ static int httpauth_set(int ofd, ha_request_t* req) req->digest_domain = value ? value : ""; } - else if(strcasecmp(name, "Method") == 0) + else if(strcasecmp(name, "Handler") == 0) { if(!value || !*value) { - ha_messagex(LOG_ERR, "no auth method specified in SET request."); + ha_messagex(LOG_ERR, "no auth handler specified in SET request."); return HA_BADREQ; } @@ -952,7 +980,7 @@ static int httpauth_set(int ofd, ha_request_t* req) if(value != NULL) { ha_messagex(LOG_ERR, "unknown authentication type: %s", req->args[0]); - return httpauth_respond(ofd, HA_SERVER_BADREQ, 0, "Unknown Auth Method"); + return httpauth_respond(ofd, HA_SERVER_BADREQ, 0, "Unknown Auth Handler"); } } @@ -1126,7 +1154,7 @@ static ha_context_t* config_addhandler(ha_buffer_t* buf, const char* alias, for(;;) { if(strcasecmp(alias, l->ctx.name) == 0) - errx(1, "duplicate method section for '%s'", alias); + errx(1, "duplicate handler section for '%s'", alias); if(!(l->next)) break; @@ -1137,7 +1165,7 @@ static ha_context_t* config_addhandler(ha_buffer_t* buf, const char* alias, l->next = loaded; } - ha_messagex(LOG_DEBUG, "configuration: method: %s (%s)", alias, handler->type); + ha_messagex(LOG_DEBUG, "configuration: handler: %s (%s)", alias, handler->type); return &(loaded->ctx); } @@ -1202,7 +1230,7 @@ static int config_parse(const char* file, ha_buffer_t* buf) name = ha_bufparseline(buf, 1); if(!name || name[strlen(name) - 1] != ']') - errx(1, "method section invalid (line %d)", line); + errx(1, "handler section invalid (line %d)", line); /* remove the bracket */ @@ -1223,7 +1251,7 @@ static int config_parse(const char* file, ha_buffer_t* buf) /* Validate the alias name */ if(!*t || strspn(t, VALID_ALIAS_CHARS) != strlen(t)) - errx(1, "invalid name for method: %s", t); + errx(1, "invalid name for handler: %s", t); } /* Rid of whitespace */ @@ -1241,7 +1269,7 @@ static int config_parse(const char* file, ha_buffer_t* buf) } if(handler == NULL) - errx(1, "unknown method type '%s' (line %d)", name, line); + errx(1, "unknown handler type '%s' (line %d)", name, line); /* If we had a last handler then add it to handlers */ ctx = config_addhandler(buf, t ? t : name, handler, &defaults); @@ -1404,7 +1432,7 @@ static int config_parse(const char* file, ha_buffer_t* buf) } if(!g_handlers) - ha_messagex(LOG_WARNING, "configuration: no methods found in configuration file"); + ha_messagex(LOG_WARNING, "configuration: no handlers found in configuration file"); return 0; } diff --git a/daemon/ldap.c b/daemon/ldap.c index a996305..37ef27a 100644 --- a/daemon/ldap.c +++ b/daemon/ldap.c @@ -1310,6 +1310,7 @@ int ldap_inithand(ha_context_t* context) else { ldap_context_t* ctx = (ldap_context_t*)(context->ctx_data); + hash_table_calls_t htc; ASSERT(ctx); @@ -1337,12 +1338,16 @@ int ldap_inithand(ha_context_t* context) } /* The cache for digest records and basic */ - if(!(ctx->cache = hash_create(MD5_LEN, free_hash_object, NULL))) + if(!(ctx->cache = hash_create(MD5_LEN))) { ha_messagex(LOG_CRIT, "out of memory"); return HA_CRITERROR; } + htc.f_freeval = free_hash_object; + htc.arg = NULL; + hash_set_table_calls(ctx->cache, &htc); + ASSERT(!ctx->pool); ASSERT(ctx->ldap_max > 0); diff --git a/daemon/ntlm.c b/daemon/ntlm.c index 85bee1d..37de9e8 100644 --- a/daemon/ntlm.c +++ b/daemon/ntlm.c @@ -581,6 +581,7 @@ int ntlm_init(ha_context_t* context) if(context) { ntlm_context_t* ctx = (ntlm_context_t*)(context->ctx_data); + hash_table_calls_t htc; ASSERT(ctx); @@ -604,13 +605,17 @@ int ntlm_init(ha_context_t* context) 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))) + if(!(ctx->pending = hash_create(NTLM_HASH_KEY_LEN)) || + !(ctx->established = hash_create(NTLM_HASH_KEY_LEN))) { ha_messagex(LOG_CRIT, "out of memory"); return HA_CRITERROR; } + htc.f_freeval = free_hash_object; + htc.arg = NULL; + hash_set_table_calls(ctx->pending, &htc); + ha_messagex(LOG_INFO, "ntlm: initialized handler"); } diff --git a/daemon/simple.c b/daemon/simple.c index 8059051..52d565d 100644 --- a/daemon/simple.c +++ b/daemon/simple.c @@ -611,6 +611,7 @@ int simple_init(ha_context_t* context) else { simple_context_t* ctx = (simple_context_t*)(context->ctx_data); + hash_table_calls_t htc; int fd; ASSERT(ctx); @@ -644,12 +645,16 @@ int simple_init(ha_context_t* context) ASSERT(!ctx->cache); /* The cache for digest records and basic */ - if(!(ctx->cache = hash_create(MD5_LEN, free_hash_object, NULL))) + if(!(ctx->cache = hash_create(MD5_LEN))) { ha_messagex(LOG_CRIT, "out of memory"); return HA_CRITERROR; } + htc.f_freeval = free_hash_object; + htc.arg = NULL; + hash_set_table_calls(ctx->cache, &htc); + ha_messagex(LOG_INFO, "simple: initialized handler"); } -- cgit v1.2.3