Parcourir la source

Initial radius host reservation implem

Baptiste Jonglez il y a 7 ans
Parent
commit
9a979e8092
1 fichiers modifiés avec 36 ajouts et 3 suppressions
  1. 36 3
      src/lib/dhcpsrv/radius_host_data_source.cc

+ 36 - 3
src/lib/dhcpsrv/radius_host_data_source.cc

@@ -132,7 +132,16 @@ RadiusHostDataSource::del6(const SubnetID& subnet_id,
 ConstHostCollection
 RadiusHostDataSource::getAll(const HWAddrPtr& hwaddr,
                             const DuidPtr& duid) const {
-    // TODO: libradcli call
+    if (duid){
+        return (getAll(Host::IDENT_DUID, &duid->getDuid()[0],
+                       duid->getDuid().size()));
+
+    } else if (hwaddr) {
+        return (getAll(Host::IDENT_HWADDR,
+                       &hwaddr->hwaddr_[0],
+                       hwaddr->hwaddr_.size()));
+    }
+
     return (ConstHostCollection());
 }
 
@@ -140,8 +149,32 @@ ConstHostCollection
 RadiusHostDataSource::getAll(const Host::IdentifierType& identifier_type,
                             const uint8_t* identifier_begin,
                             const size_t identifier_len) const {
-    // TODO: libradcli call
-    return (ConstHostCollection());
+    ConstHostCollection result;
+    int res;
+    VALUE_PAIR 	*send, *received;
+    if (rc_avpair_add(rh, &send, PW_USER_NAME, identifier_begin, identifier_len, 0) == NULL)
+        isc_throw(isc::Exception, "Failed to set username");
+
+    res = rc_auth(rh, 0, send, &received, NULL);
+    if (res == OK_RC) {
+        VALUE_PAIR *vp = received;
+        char name[128];
+        char value[128];
+
+        fprintf(stderr, "\"%s\" RADIUS Authentication OK\n", identifier_begin);
+
+        /* print the known attributes in the reply */
+        while(vp != NULL) {
+            if (rc_avpair_tostr(rh, vp, name, sizeof(name), value, sizeof(value)) == 0) {
+                fprintf(stderr, "%s:\t%s\n", name, value);
+            }
+            vp = vp->next;
+        }
+    } else {
+        fprintf(stderr, "\"%s\" RADIUS Authentication failure (RC=%i)\n", identifier_begin, res);
+    }
+
+    return (result);
 }
 
 ConstHostCollection