summaryrefslogtreecommitdiff
path: root/daemon/httpauthd.c
diff options
context:
space:
mode:
Diffstat (limited to 'daemon/httpauthd.c')
-rw-r--r--daemon/httpauthd.c54
1 files changed, 41 insertions, 13 deletions
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;
}