Browse Source

radius: finish initial test implementation

It works but `rc_avpair_add(..., PW_USER_NAME)` fails for some reason
(maybe missing initialisation?)
Baptiste Jonglez 7 years ago
parent
commit
75349dda4a
1 changed files with 35 additions and 10 deletions
  1. 35 10
      src/lib/dhcpsrv/radius_host_data_source.cc

+ 35 - 10
src/lib/dhcpsrv/radius_host_data_source.cc

@@ -150,8 +150,9 @@ RadiusHostDataSource::getAll(const Host::IdentifierType& identifier_type,
                             const uint8_t* identifier_begin,
                             const size_t identifier_len) const {
     ConstHostCollection result;
+    HostPtr host;
     int res;
-    VALUE_PAIR 	*send, *received;
+    VALUE_PAIR 	*send = NULL, *received;
     if (rc_avpair_add(rh, &send, PW_USER_NAME, identifier_begin, identifier_len, 0) == NULL)
         isc_throw(isc::Exception, "Failed to set username");
 
@@ -170,6 +171,11 @@ RadiusHostDataSource::getAll(const Host::IdentifierType& identifier_type,
             }
             vp = vp->next;
         }
+        host.reset(new Host(identifier_begin, identifier_len,
+                            identifier_type, SubnetID(),
+                            // TODO: set real IP address
+                            SubnetID(), asiolink::IOAddress("10.42.42.42")));
+        result.push_back(host);
     } else {
         fprintf(stderr, "\"%s\" RADIUS Authentication failure (RC=%i)\n", identifier_begin, res);
     }
@@ -184,10 +190,27 @@ RadiusHostDataSource::getAll4(const asiolink::IOAddress& address) const {
 
 ConstHostPtr
 RadiusHostDataSource::get4(const SubnetID& subnet_id, const HWAddrPtr& hwaddr,
-                          const DuidPtr& duid) const {
-    // TODO: libradcli call
-    ConstHostPtr result = NULL;
-    return (result);
+                           const DuidPtr& duid) const {
+    if (hwaddr && duid) {
+        isc_throw(BadValue, "Radius host data source get4() called with both"
+                  " hwaddr and duid, only one of them is allowed");
+    }
+    if (!hwaddr && !duid) {
+        isc_throw(BadValue, "Radius host data source get4() called with "
+                  "neither hwaddr or duid specified, one of them is required");
+    }
+
+    // Choosing one of the identifiers
+    if (hwaddr) {
+        return (get4(subnet_id, Host::IDENT_HWADDR, &hwaddr->hwaddr_[0],
+                     hwaddr->hwaddr_.size()));
+
+    } else if (duid) {
+        return (get4(subnet_id, Host::IDENT_DUID, &duid->getDuid()[0],
+                     duid->getDuid().size()));
+    }
+
+    return (ConstHostPtr());
 }
 
 ConstHostPtr
@@ -195,17 +218,19 @@ RadiusHostDataSource::get4(const SubnetID& subnet_id,
                           const Host::IdentifierType& identifier_type,
                           const uint8_t* identifier_begin,
                           const size_t identifier_len) const {
-    // TODO: libradcli call
-    ConstHostPtr result = NULL;
+    ConstHostCollection collection = getAll(identifier_type, identifier_begin, identifier_len);
+    ConstHostPtr result;
+    if (!collection.empty())
+        result = *collection.begin();
     return (result);
 }
 
 ConstHostPtr
 RadiusHostDataSource::get4(const SubnetID& subnet_id,
                           const asiolink::IOAddress& address) const {
-    // TODO: libradcli call
-    ConstHostPtr result = NULL;
-    return (result);
+    // Not relevant for Radius
+    isc_throw(NotImplemented, "RadiusHostDataSource::get4 not implemented");
+    return (ConstHostPtr());
 }
 
 ConstHostPtr