radius_host_data_source.cc 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  1. // Copyright (C) 2015-2017 Internet Systems Consortium, Inc. ("ISC")
  2. //
  3. // This Source Code Form is subject to the terms of the Mozilla Public
  4. // License, v. 2.0. If a copy of the MPL was not distributed with this
  5. // file, You can obtain one at http://mozilla.org/MPL/2.0/.
  6. #include <config.h>
  7. #include <dhcp/libdhcp++.h>
  8. #include <dhcp/option.h>
  9. #include <dhcp/option_definition.h>
  10. #include <dhcp/option_space.h>
  11. #include <dhcpsrv/cfg_option.h>
  12. #include <dhcpsrv/db_exceptions.h>
  13. #include <dhcpsrv/dhcpsrv_log.h>
  14. #include <dhcpsrv/radius_host_data_source.h>
  15. #include <dhcpsrv/db_exceptions.h>
  16. #include <util/buffer.h>
  17. #include <util/optional_value.h>
  18. #include <boost/algorithm/string/split.hpp>
  19. #include <boost/algorithm/string/classification.hpp>
  20. #include <boost/array.hpp>
  21. #include <boost/pointer_cast.hpp>
  22. #include <boost/static_assert.hpp>
  23. #include <radcli/radcli.h>
  24. #include <stdint.h>
  25. #include <string>
  26. using namespace isc;
  27. using namespace isc::asiolink;
  28. using namespace isc::dhcp;
  29. using namespace isc::util;
  30. using namespace std;
  31. /// @brief Maximum size of an IPv6 address represented as a text string.
  32. ///
  33. /// This is 32 hexadecimal characters written in 8 groups of four, plus seven
  34. /// colon separators.
  35. const size_t ADDRESS6_TEXT_MAX_LEN = 39;
  36. /// @brief Maximum length of classes stored in a dhcp4/6_client_classes
  37. /// columns.
  38. const size_t CLIENT_CLASSES_MAX_LEN = 255;
  39. /// @brief Maximum length of the hostname stored in DNS.
  40. ///
  41. /// This length is restricted by the length of the domain-name carried
  42. /// in the Client FQDN %Option (see RFC4702 and RFC4704).
  43. const size_t HOSTNAME_MAX_LEN = 255;
  44. /// @brief Maximum length of option value.
  45. const size_t OPTION_VALUE_MAX_LEN = 4096;
  46. /// @brief Maximum length of option value specified in textual format.
  47. const size_t OPTION_FORMATTED_VALUE_MAX_LEN = 8192;
  48. /// @brief Maximum length of option space name.
  49. const size_t OPTION_SPACE_MAX_LEN = 128;
  50. /// @brief Maximum length of the server hostname.
  51. const size_t SERVER_HOSTNAME_MAX_LEN = 64;
  52. /// @brief Maximum length of the boot file name.
  53. const size_t BOOT_FILE_NAME_MAX_LEN = 128;
  54. /// @brief Numeric value representing last supported identifier.
  55. ///
  56. /// This value is used to validate whether the identifier type stored in
  57. /// a database is within bounds. of supported identifiers.
  58. const uint8_t MAX_IDENTIFIER_TYPE = static_cast<uint8_t>(Host::LAST_IDENTIFIER_TYPE);
  59. namespace isc {
  60. namespace dhcp {
  61. RadiusHostDataSource::
  62. RadiusHostDataSource(const DatabaseConnection::ParameterMap& parameters) {
  63. int res;
  64. rh = rc_new();
  65. if (rh == NULL) {
  66. isc_throw(isc::Exception, "Failed to initialize Radius client");
  67. }
  68. res = rc_add_config(rh, "authserver", "127.0.0.1", NULL, 0);
  69. if (res != 0) {
  70. isc_throw(isc::Exception, "Failed to initialize Radius client");
  71. }
  72. res = rc_add_config(rh, "radius_timeout", "1", NULL, 0);
  73. res = rc_add_config(rh, "radius_retries", "2", NULL, 0);
  74. res = rc_add_config(rh, "serv-type", "tcp", NULL, 0);
  75. }
  76. RadiusHostDataSource::~RadiusHostDataSource() {
  77. }
  78. void
  79. RadiusHostDataSource::add(const HostPtr& host) {
  80. // cannot add a host with radius
  81. isc_throw(NotImplemented, "RadiusHostDataSource::add not implemented");
  82. }
  83. bool
  84. RadiusHostDataSource::del(const SubnetID& subnet_id, const asiolink::IOAddress& addr) {
  85. // cannot delete hosts with radius
  86. isc_throw(NotImplemented, "RadiusHostDataSource::del not implemented");
  87. return false;
  88. }
  89. bool
  90. RadiusHostDataSource::del4(const SubnetID& subnet_id,
  91. const Host::IdentifierType& identifier_type,
  92. const uint8_t* identifier_begin, const size_t identifier_len) {
  93. // cannot delete hosts with radius
  94. isc_throw(NotImplemented, "RadiusHostDataSource::del4 not implemented");
  95. return false;
  96. }
  97. bool
  98. RadiusHostDataSource::del6(const SubnetID& subnet_id,
  99. const Host::IdentifierType& identifier_type,
  100. const uint8_t* identifier_begin, const size_t identifier_len) {
  101. // cannot delete hosts with radius
  102. isc_throw(NotImplemented, "RadiusHostDataSource::del6 not implemented");
  103. return false;
  104. }
  105. ConstHostCollection
  106. RadiusHostDataSource::getAll(const HWAddrPtr& hwaddr,
  107. const DuidPtr& duid) const {
  108. // TODO: libradcli call
  109. return (ConstHostCollection());
  110. }
  111. ConstHostCollection
  112. RadiusHostDataSource::getAll(const Host::IdentifierType& identifier_type,
  113. const uint8_t* identifier_begin,
  114. const size_t identifier_len) const {
  115. // TODO: libradcli call
  116. return (ConstHostCollection());
  117. }
  118. ConstHostCollection
  119. RadiusHostDataSource::getAll4(const asiolink::IOAddress& address) const {
  120. return (ConstHostCollection());
  121. }
  122. ConstHostPtr
  123. RadiusHostDataSource::get4(const SubnetID& subnet_id, const HWAddrPtr& hwaddr,
  124. const DuidPtr& duid) const {
  125. // TODO: libradcli call
  126. ConstHostPtr result = NULL;
  127. return (result);
  128. }
  129. ConstHostPtr
  130. RadiusHostDataSource::get4(const SubnetID& subnet_id,
  131. const Host::IdentifierType& identifier_type,
  132. const uint8_t* identifier_begin,
  133. const size_t identifier_len) const {
  134. // TODO: libradcli call
  135. ConstHostPtr result = NULL;
  136. return (result);
  137. }
  138. ConstHostPtr
  139. RadiusHostDataSource::get4(const SubnetID& subnet_id,
  140. const asiolink::IOAddress& address) const {
  141. // TODO: libradcli call
  142. ConstHostPtr result = NULL;
  143. return (result);
  144. }
  145. ConstHostPtr
  146. RadiusHostDataSource::get6(const SubnetID& subnet_id, const DuidPtr& duid,
  147. const HWAddrPtr& hwaddr) const {
  148. // TODO: libradcli call
  149. ConstHostPtr result = NULL;
  150. return (result);
  151. }
  152. ConstHostPtr
  153. RadiusHostDataSource::get6(const SubnetID& subnet_id,
  154. const Host::IdentifierType& identifier_type,
  155. const uint8_t* identifier_begin,
  156. const size_t identifier_len) const {
  157. // TODO: libradcli call
  158. ConstHostPtr result = NULL;
  159. return (result);
  160. }
  161. ConstHostPtr
  162. RadiusHostDataSource::get6(const asiolink::IOAddress& prefix,
  163. const uint8_t prefix_len) const {
  164. // TODO: libradcli call
  165. ConstHostPtr result = NULL;
  166. return (result);
  167. }
  168. ConstHostPtr
  169. RadiusHostDataSource::get6(const SubnetID& subnet_id,
  170. const asiolink::IOAddress& address) const {
  171. // TODO: libradcli call
  172. ConstHostPtr result = NULL;
  173. return (result);
  174. }
  175. // Miscellaneous database methods.
  176. std::string RadiusHostDataSource::getName() const {
  177. std::string name = "";
  178. return (name);
  179. }
  180. std::string RadiusHostDataSource::getDescription() const {
  181. return (std::string("Host data source that retrieves host information"
  182. "in radius server"));
  183. }
  184. std::pair<uint32_t, uint32_t> RadiusHostDataSource::getVersion() const {
  185. // TODO: Not relevant for libradcli ?
  186. return std::make_pair(0,0);
  187. }
  188. void
  189. RadiusHostDataSource::commit() {
  190. // Not relevant for radius.
  191. }
  192. void
  193. RadiusHostDataSource::rollback() {
  194. // Not relevant for radius.
  195. }
  196. }; // end of isc::dhcp namespace
  197. }; // end of isc namespace