Browse Source

radius: throw the correct exceptions

Baptiste Jonglez 7 years ago
parent
commit
4398fe2d1c
2 changed files with 19 additions and 11 deletions
  1. 11 11
      src/lib/dhcpsrv/radius_host_data_source.cc
  2. 8 0
      src/lib/dhcpsrv/radius_host_data_source.h

+ 11 - 11
src/lib/dhcpsrv/radius_host_data_source.cc

@@ -88,28 +88,28 @@ RadiusHostDataSource(const DatabaseConnection::ParameterMap& parameters) {
     int res;
     rh = rc_new();
     if (rh == NULL) {
-         isc_throw(isc::Exception, "Failed to initialize Radius client");
+         isc_throw(DbOpenError, "Failed to initialize Radius client");
     }
     rh = rc_config_init(rh);
     if (rh == NULL) {
-         isc_throw(isc::Exception, "Failed to initialize Radius client");
+         isc_throw(DbOpenError, "Failed to initialize Radius client");
     }
     res = rc_add_config(rh, "auth_order", "radius", NULL, 0);
     if (res != 0) {
-         isc_throw(isc::Exception, "Failed to configure Radius auth_order");
+         isc_throw(DbOpenError, "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");
+         isc_throw(DbOpenError, "Failed to configure Radius dictionary");
     }
     res = rc_add_config(rh, "radius_timeout", "1", NULL, 0);
     if (res != 0) {
-         isc_throw(isc::Exception, "Failed to configure Radius timeout");
+         isc_throw(DbOpenError, "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");
+         isc_throw(DbOpenError, "Failed to configure Radius retries");
     }
 
     const char* host = "localhost";
@@ -155,25 +155,25 @@ RadiusHostDataSource(const DatabaseConnection::ParameterMap& parameters) {
         password = spassword.c_str();
     } catch (...) {
         // No secret.  Throw an exception
-        isc_throw(isc::Exception, "must specify a secret (password) for Radius connection");
+        isc_throw(NoPassword, "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");
+         isc_throw(DbOpenError, "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");
+         isc_throw(DbOpenError, "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");
+         isc_throw(DbOpenError, "Failed to read Radius dictionary");
     }
 }
 
@@ -254,7 +254,7 @@ RadiusHostDataSource::getAll(const Host::IdentifierType& identifier_type,
     const char* identifier_hex = tmp2.c_str();
     // Build radius request
     if (rc_avpair_add(rh, &send, PW_USER_NAME, identifier_hex, -1, 0) == NULL)
-        isc_throw(isc::Exception, "Failed to set username");
+        isc_throw(DbOperationError, "Failed to set username");
 
     res = rc_auth(rh, 0, send, &received, NULL);
     if (res == OK_RC) {

+ 8 - 0
src/lib/dhcpsrv/radius_host_data_source.h

@@ -7,6 +7,7 @@
 #ifndef RADIUS_HOST_DATA_SOURCE_H
 #define RADIUS_HOST_DATA_SOURCE_H
 
+#include <exceptions/exceptions.h>
 #include <dhcpsrv/base_host_data_source.h>
 #include <dhcpsrv/database_connection.h>
 #include <dhcpsrv/db_exceptions.h>
@@ -16,6 +17,13 @@
 namespace isc {
 namespace dhcp {
 
+/// @brief Exception thrown if password of database is not specified
+class NoPassword : public Exception {
+public:
+    NoPassword(const char* file, size_t line, const char* what) :
+        isc::Exception(file, line, what) {}
+};
+
 /// @brief Radius Host Data Source
 ///
 /// This class implements the @ref isc::dhcp::BaseHostDataSource interface to