Browse Source

Radius: actually take hostname/port/secret from Kea configuration

Baptiste Jonglez 7 years ago
parent
commit
3c2fb160a8
1 changed files with 58 additions and 1 deletions
  1. 58 1
      src/lib/dhcpsrv/radius_host_data_source.cc

+ 58 - 1
src/lib/dhcpsrv/radius_host_data_source.cc

@@ -75,6 +75,14 @@ const uint8_t MAX_IDENTIFIER_TYPE = static_cast<uint8_t>(Host::LAST_IDENTIFIER_T
 namespace isc {
 namespace dhcp {
 
+static std::string getParameter(const DatabaseConnection::ParameterMap& parameters, const std::string& name) {
+    DatabaseConnection::ParameterMap::const_iterator param = parameters.find(name);
+    if (param == parameters.end()) {
+        isc_throw(BadValue, "Parameter " << name << " not found");
+    }
+    return (param->second);
+}
+
 RadiusHostDataSource::
 RadiusHostDataSource(const DatabaseConnection::ParameterMap& parameters) {
     int res;
@@ -103,7 +111,56 @@ RadiusHostDataSource(const DatabaseConnection::ParameterMap& parameters) {
     if (res != 0) {
          isc_throw(isc::Exception, "Failed to configure Radius retries");
     }
-    res = rc_add_config(rh, "authserver", "127.0.0.1:1812:testing123", NULL, 0);
+
+    const char* host = "localhost";
+    string shost;
+    try {
+        shost = getParameter(parameters, "host");
+        host = shost.c_str();
+    } catch (...) {
+        // No host.  Fine, we'll use "localhost"
+    }
+
+    unsigned int port = 0;
+    string sport;
+    try {
+        sport = getParameter(parameters, "port");
+    } catch (...) {
+        // No port parameter, we are going to use the default port.
+        sport = "";
+    }
+
+    if (sport.size() > 0) {
+        // Port was given, so try to convert it to an integer.
+
+        try {
+            port = boost::lexical_cast<unsigned int>(sport);
+        } catch (...) {
+            // Port given but could not be converted to an unsigned int.
+            // Just fall back to the default value.
+            port = 0;
+        }
+
+        // The port is only valid when it is in the 0..65535 range.
+        // Again fall back to the default when the given value is invalid.
+        if (port > numeric_limits<uint16_t>::max()) {
+            port = 0;
+        }
+    }
+
+    const char* password = NULL;
+    string spassword;
+    try {
+        spassword = getParameter(parameters, "password");
+        password = spassword.c_str();
+    } catch (...) {
+        // No secret.  Throw an exception
+        isc_throw(isc::Exception, "must specify a secret (password) for Radius connection");
+    }
+
+    char authserver[512];
+    snprintf(authserver, sizeof(authserver), "%s:%u:%s", host, port, password);
+    res = rc_add_config(rh, "authserver", authserver, NULL, 0);
     if (res != 0) {
          isc_throw(isc::Exception, "Failed to configure Radius authserver");
     }