From 24c4a4e1dc39e5dc788e2a489776785b418ae5c7 Mon Sep 17 00:00:00 2001
From: Wichert Akkerman <wichert@wiggy.net>
Date: Mon, 28 Apr 2008 12:04:28 +0200
Subject: [PATCH] Add authentication related settings to the configuration

---
 src/conf.c   |   23 +++++++++++++++++++++++
 src/conf.h   |    3 +++
 wifidog.conf |   18 ++++++++++++++++++
 3 files changed, 44 insertions(+), 0 deletions(-)

diff --git a/src/conf.c b/src/conf.c
index ff2cd1c..617ba42 100644
--- a/src/conf.c
+++ b/src/conf.c
@@ -84,6 +84,9 @@ typedef enum {
 	oAuthServAuthScriptPathFragment,
 	oHTTPDMaxConn,
 	oHTTPDName,
+	oHTTPDRealm,
+        oHTTPDUsername,
+        oHTTPDPassword,
 	oClientTimeout,
 	oCheckInterval,
 	oWdctlSocket,
@@ -111,6 +114,9 @@ static const struct {
 	{ "authserver",         oAuthServer },
 	{ "httpdmaxconn",       oHTTPDMaxConn },
 	{ "httpdname",          oHTTPDName },
+	{ "httpdrealm",		oHTTPDRealm },
+	{ "httpdusername",	oHTTPDUsername },
+	{ "httpdpassword",	oHTTPDPassword },
 	{ "clienttimeout",      oClientTimeout },
 	{ "checkinterval",      oCheckInterval },
 	{ "syslogfacility", 	oSyslogFacility },
@@ -165,6 +171,9 @@ config_init(void)
 	config.gw_port = DEFAULT_GATEWAYPORT;
 	config.auth_servers = NULL;
 	config.httpdname = NULL;
+	config.httpdrealm = DEFAULT_HTTPDNAME;
+	config.httpdusername = NULL;
+	config.httpdpassword = NULL;
 	config.clienttimeout = DEFAULT_CLIENTTIMEOUT;
 	config.checkinterval = DEFAULT_CHECKINTERVAL;
 	config.syslog_facility = DEFAULT_SYSLOG_FACILITY;
@@ -705,6 +714,15 @@ config_read(char *filename)
 				case oHTTPDMaxConn:
 					sscanf(p1, "%d", &config.httpdmaxconn);
 					break;
+				case oHTTPDRealm:
+					config.httpdrealm = safe_strdup(p1);
+					break;
+				case oHTTPDUsername:
+					config.httpdusername = safe_strdup(p1);
+					break;
+				case oHTTPDPassword:
+					config.httpdpassword = safe_strdup(p1);
+					break;
 				case oBadOption:
 					debug(LOG_ERR, "Bad option on line %d "
 							"in %s.", linenum,
@@ -734,6 +752,11 @@ config_read(char *filename)
 		}
 	}
 
+	if (config.httpdusername && !config.httpdpassword) {
+		debug(LOG_ERR, "HTTPDUserName requires a HTTPDPassword to be set.");
+		exit(-1);
+	}
+
 	fclose(fd);
 }
 
diff --git a/src/conf.h b/src/conf.h
index 1dbaf56..53a8b79 100644
--- a/src/conf.h
+++ b/src/conf.h
@@ -141,6 +141,9 @@ typedef struct {
 				     replying to a request */
     int httpdmaxconn;		/**< @brief Used by libhttpd, not sure what it
 				     does */
+    char *httpdrealm;		/**< @brief HTTP Authentication realm */
+    char *httpdusername;	/**< @brief Username for HTTP authentication */
+    char *httpdpassword;	/**< @brief Password for HTTP authentication */
     int clienttimeout;		/**< @brief How many CheckIntervals before a client
 				     must be re-authenticated */
     int checkinterval;		/**< @brief Frequency the the client timeout check
diff --git a/wifidog.conf b/wifidog.conf
index 89a97bc..8c7d74d 100644
--- a/wifidog.conf
+++ b/wifidog.conf
@@ -110,6 +110,24 @@ GatewayInterface br0
 # How many sockets to listen to
 # HTTPDMaxConn 10
 
+# Parameter: HTTPDRealm
+# Default: WiFiDog
+# Optional
+#
+# The name of the HTTP authentication realm. This only used when a user
+# tries to access a protected WiFiDog internal page. See HTTPUserName.
+# HTTPDRealm WiFiDog
+
+# Parameter: HTTPDUserName / HTTPDPassword
+# Default: unset
+# Optional
+#
+# The gateway exposes some information such as the status page through its web
+# interface. This information can be protected with a username and password,
+# which can be set through the HTTPDUserName and HTTPDPassword parameters.
+# HTTPDUserName admin
+# HTTPDPassword secret
+
 # Parameter: CheckInterval
 # Default: 60
 # Optional
-- 
1.5.5.1


