|
@@ -178,7 +178,23 @@ RadiusHostDataSource::getAll(const Host::IdentifierType& identifier_type,
|
|
HostPtr host;
|
|
HostPtr host;
|
|
int res;
|
|
int res;
|
|
VALUE_PAIR *send = NULL, *received;
|
|
VALUE_PAIR *send = NULL, *received;
|
|
- if (rc_avpair_add(rh, &send, PW_USER_NAME, identifier_begin, identifier_len, 0) == NULL)
|
|
|
|
|
|
+ // Convert binary identifier (DUID or MAC address) to an hexadecimal
|
|
|
|
+ // string, with each byte separated by a colon.
|
|
|
|
+ std::stringstream tmp;
|
|
|
|
+ tmp << std::hex;
|
|
|
|
+ bool delim = false;
|
|
|
|
+ for (int i = 0; i < identifier_len; ++i) {
|
|
|
|
+ if (delim) {
|
|
|
|
+ tmp << ":";
|
|
|
|
+ }
|
|
|
|
+ tmp << std::setw(2) << std::setfill('0') << static_cast<unsigned int>(identifier_begin[i]);
|
|
|
|
+ delim = true;
|
|
|
|
+ }
|
|
|
|
+ // Necessary because of variable lifetime, see https://stackoverflow.com/a/1374485/4113356
|
|
|
|
+ const std::string tmp2 = tmp.str();
|
|
|
|
+ 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(isc::Exception, "Failed to set username");
|
|
|
|
|
|
res = rc_auth(rh, 0, send, &received, NULL);
|
|
res = rc_auth(rh, 0, send, &received, NULL);
|
|
@@ -187,7 +203,7 @@ RadiusHostDataSource::getAll(const Host::IdentifierType& identifier_type,
|
|
char name[128];
|
|
char name[128];
|
|
char value[128];
|
|
char value[128];
|
|
|
|
|
|
- fprintf(stderr, "\"%s\" RADIUS Authentication OK\n", identifier_begin);
|
|
|
|
|
|
+ fprintf(stderr, "\"%s\" RADIUS Authentication OK\n", identifier_hex);
|
|
|
|
|
|
/* print the known attributes in the reply */
|
|
/* print the known attributes in the reply */
|
|
while(vp != NULL) {
|
|
while(vp != NULL) {
|
|
@@ -202,7 +218,7 @@ RadiusHostDataSource::getAll(const Host::IdentifierType& identifier_type,
|
|
SubnetID(), asiolink::IOAddress("10.42.42.42")));
|
|
SubnetID(), asiolink::IOAddress("10.42.42.42")));
|
|
result.push_back(host);
|
|
result.push_back(host);
|
|
} else {
|
|
} else {
|
|
- fprintf(stderr, "\"%s\" RADIUS Authentication failure (RC=%i)\n", identifier_begin, res);
|
|
|
|
|
|
+ fprintf(stderr, "\"%s\" RADIUS Authentication failure (RC=%i)\n", identifier_hex, res);
|
|
}
|
|
}
|
|
|
|
|
|
return (result);
|
|
return (result);
|