Browse Source

Properly initialize radcli (no more segfaults)

Baptiste Jonglez 7 years ago
parent
commit
17c4f3b0b3
1 changed files with 29 additions and 4 deletions
  1. 29 4
      src/lib/dhcpsrv/radius_host_data_source.cc

+ 29 - 4
src/lib/dhcpsrv/radius_host_data_source.cc

@@ -86,13 +86,38 @@ RadiusHostDataSource(const DatabaseConnection::ParameterMap& parameters) {
     if (rh == NULL) {
     if (rh == NULL) {
          isc_throw(isc::Exception, "Failed to initialize Radius client");
          isc_throw(isc::Exception, "Failed to initialize Radius client");
     }
     }
-    res = rc_add_config(rh, "authserver", "127.0.0.1", NULL, 0);
+    res = rc_add_config(rh, "auth_order", "radius", NULL, 0);
     if (res != 0) {
     if (res != 0) {
-         isc_throw(isc::Exception, "Failed to initialize Radius client");
+         isc_throw(isc::Exception, "Failed to configure Radius auth_order");
+    }
+    /* TODO: just define manually the few attributes we need */
+    res = rc_add_config(rh, "dictionary", "/usr/share/radcli/dictionary", NULL, 0);
+    if (res != 0) {
+         isc_throw(isc::Exception, "Failed to configure Radius dictionary");
     }
     }
     res = rc_add_config(rh, "radius_timeout", "1", NULL, 0);
     res = rc_add_config(rh, "radius_timeout", "1", NULL, 0);
-    res = rc_add_config(rh, "radius_retries", "2", NULL, 0);
-    res = rc_add_config(rh, "serv-type", "udp", NULL, 0);
+    if (res != 0) {
+         isc_throw(isc::Exception, "Failed to configure Radius timeout");
+    }
+    res = rc_add_config(rh, "radius_retries", "1", NULL, 0);
+    if (res != 0) {
+         isc_throw(isc::Exception, "Failed to configure Radius retries");
+    }
+    res = rc_add_config(rh, "authserver", "127.0.0.1:1812:mysecret", NULL, 0);
+    if (res != 0) {
+         isc_throw(isc::Exception, "Failed to configure Radius authserver");
+    }
+    // Test and apply config (this also setups the necessary structures to
+    // send requests to the radius server)
+    res = rc_test_config(rh, "kea");
+    if (res != 0) {
+         isc_throw(isc::Exception, "Failed to apply radcli configuration");
+    }
+    // Load dictionary
+    res = rc_read_dictionary(rh, rc_conf_str(rh, "dictionary"));
+    if (res != 0) {
+         isc_throw(isc::Exception, "Failed to read Radius dictionary");
+    }
 }
 }
 
 
 RadiusHostDataSource::~RadiusHostDataSource() {
 RadiusHostDataSource::~RadiusHostDataSource() {