16#include <boost/scoped_ptr.hpp> 
   17#include <boost/algorithm/string/predicate.hpp> 
   33                   const size_t dns_server_timeout,
 
   36    : ip_address_(ip_address),
 
   38    dns_server_timeout_(dns_server_timeout),
 
   39    ncr_protocol_(ncr_protocol),
 
   40    ncr_format_(ncr_format) {
 
 
   46     port_(53001), dns_server_timeout_(500),
 
 
   60    if (dns_server_timeout_ < 1) {
 
   62                  "D2Params: DNS server timeout must be larger than 0");
 
   68                  << 
" is not yet supported");
 
   74                  << 
" is not yet supported");
 
 
   82      << 
", using " << ncrProtocolToString(ncr_protocol_);
 
 
   88    return ((ip_address_ == other.ip_address_) &&
 
   89            (port_ == other.port_) &&
 
   90            (dns_server_timeout_ == other.dns_server_timeout_) &&
 
   91            (ncr_protocol_ == other.ncr_protocol_) &&
 
   92            (ncr_format_ == other.ncr_format_));
 
 
   97    return (!(*
this == other));
 
 
  102    std::ostringstream stream;
 
  104    stream << 
", ip-address: " << ip_address_.toText()
 
  105           << 
", port: " << port_
 
  106           << 
", dns-server-timeout_: " << dns_server_timeout_
 
  107           << 
", ncr-protocol: " 
  109           << 
", ncr-format: " << ncr_format_
 
  112    return (stream.str());
 
 
  132                         const std::string& secret, std::string secret_file,
 
  134    : name_(
name), algorithm_(algorithm), secret_(secret),
 
  135      secret_file_(secret_file), digestbits_(digestbits), tsig_key_() {
 
 
  162TSIGKeyInfo::remakeKey() {
 
  167        std::ostringstream stream;
 
  171        if (digestbits_ > 0) {
 
  172            stream << 
":" << digestbits_;
 
  175        tsig_key_.reset(
new D2TsigKey(stream.str()));
 
  176    } 
catch (
const std::exception& ex) {
 
  177        isc_throw(D2CfgError, 
"Cannot make D2TsigKey: " << ex.what());
 
  191    if (!secret_file_.empty()) {
 
  197    result->set(
"digest-bits",
 
 
  210    : hostname_(hostname), ip_address_(ip_address), port_(port),
 
  211      enabled_(enabled), tsig_key_info_(tsig_key_info),
 
  212      inherited_key_(inherited_key) {
 
 
  220    if (tsig_key_info_) {
 
  221        return (tsig_key_info_->getName());
 
 
  229    std::ostringstream stream;
 
  231    return (stream.str());
 
 
  246    if (tsig_key_info_ && !inherited_key_) {
 
 
  263                       const std::string& key_name)
 
  264    : name_(
name), servers_(servers), key_name_(key_name) {
 
 
  279    for (
auto const& server : *servers_) {
 
  281        servers->add(dns_server);
 
  284    if (!servers->empty()) {
 
  285        result->set(
"dns-servers", servers);
 
  288    if (!key_name_.empty()) {
 
 
  311                  "DdnsDomainListMgr::setDomains: Domain list may not be null");
 
  320    if (gotit != domains_->end()) {
 
  321            wildcard_domain_ = gotit->second;
 
 
  328    if ((
size() == 1) && (wildcard_domain_)) {
 
  329        domain = wildcard_domain_;
 
  336    size_t req_len = fqdn.size();
 
  337    size_t match_len = 0;
 
  339    for (
auto const& map_pair : *domains_) {
 
  340        std::string domain_name = map_pair.first;
 
  341        size_t dom_len = domain_name.size();
 
  344        if (req_len < dom_len) {
 
  349        if (req_len == dom_len) {
 
  350            if (boost::iequals(fqdn, domain_name)) {
 
  352                domain = map_pair.second;
 
  360            size_t offset = req_len - dom_len;
 
  361            if ((fqdn[offset - 1] == 
'.')  &&
 
  362               (boost::iequals(fqdn.substr(offset), domain_name))) {
 
  365                if (dom_len > match_len) {
 
  367                    best_match = map_pair.second;
 
  376        if (wildcard_domain_) {
 
  377            domain = wildcard_domain_;
 
 
  393    for (
auto const& domain : *domains_) {
 
  394        ElementPtr ddns_domain = domain.second->toElement();
 
  395        result->add(ddns_domain);
 
 
  408    std::string algorithm = 
getString(key_config, 
"algorithm");
 
  409    uint32_t digestbits = 
getInteger(key_config, 
"digest-bits");
 
  410    std::string secret_file;
 
  412    if (key_config->contains(
"secret-file")) {
 
  413        secret_file = 
getString(key_config, 
"secret-file");
 
  416            if (secret.empty()) {
 
  418                          << 
"' to not be empty");
 
  420        } 
catch (
const std::exception& ex) {
 
  426        secret = 
getString(key_config, 
"secret");
 
  442    } 
catch (
const std::exception& ex) {
 
  444                  << 
" (" << 
getPosition(
"algorithm", key_config) << 
")");
 
  450    if ((digestbits > 0) &&
 
  451        ((digestbits < 80) ||
 
  453          && (digestbits < 112)) ||
 
  455          && (digestbits < 128)) ||
 
  457          && (digestbits < 192)) ||
 
  459          && (digestbits < 256)))) {
 
  471                                       secret_file, digestbits));
 
  472    } 
catch (
const std::exception& ex) {
 
  474                  << key_config->getPosition() << 
")");
 
  479        key_info->setContext(user_context);
 
 
  491    for (
auto const& key_config : key_list->listValue()) {
 
  495        if (keys->find(key->getName()) != keys->end()) {
 
  498                      << 
" (" << 
getPosition(
"name", key_config) << 
")");
 
  501        (*keys)[key->getName()] = key;
 
 
  513    std::string hostname = 
getString(server_config, 
"hostname");
 
  514    std::string ip_address = 
getString(server_config, 
"ip-address");
 
  515    uint32_t port = 
getInteger(server_config, 
"port");
 
  516    std::string key_name = 
getString(server_config, 
"key-name");
 
  522    bool inherited_key = 
true;
 
  523    if (key_name.empty()) {
 
  524        std::string domain_key_name = 
getString(domain_config, 
"key-name");
 
  525        if (!domain_key_name.empty()) {
 
  526            key_name = domain_key_name;
 
  529        inherited_key = 
false;
 
  531    if (!key_name.empty()) {
 
  533            TSIGKeyInfoMap::iterator kit = keys->find(key_name);
 
  534            if (kit != keys->end()) {
 
  535                tsig_key_info = kit->second;
 
  539        if (!tsig_key_info) {
 
  542                          << 
"undefined key: " << key_name << 
" (" 
  546                          << 
"undefined key: " << key_name << 
" (" 
  553    if (hostname.empty() == ip_address.empty()) {
 
  555                  " of hostname or IP address" 
  556                  << 
" (" << server_config->getPosition() << 
")");
 
  560    if (!hostname.empty()) {
 
  575                  << 
" (" << 
getPosition(
"hostname", server_config) << 
")");
 
  587                      << 
" (" << 
getPosition(
"ip-address", server_config) << 
")");
 
  593        server_info->setContext(user_context);
 
  596    return (server_info);
 
 
  607    for (
auto const& server_config : server_list->listValue()) {
 
  609            parser.
parse(server_config, domain_config, keys);
 
  610        servers->push_back(server);
 
 
  621    std::string key_name = 
getString(domain_config, 
"key-name");
 
  627        servers_config = domain_config->get(
"dns-servers");
 
  628    } 
catch (
const std::exception& ex) {
 
  630                      << 
" (" << servers_config->getPosition() << 
")");
 
  635        server_parser.
parse(servers_config, domain_config, keys);
 
  636    if (servers->size() == 0) {
 
  638                    << servers_config->getPosition());
 
  646        domain->setContext(user_context);
 
 
  658    for (
auto const& domain_config : domain_list->listValue()) {
 
  662        if (domains->find(domain->getName()) != domains->end()) {
 
  665                      << 
" (" << 
getPosition(
"name", domain_config) << 
")");
 
  668        (*domains)[domain->getName()] = domain;
 
 
  678                               const std::string& mgr_name,
 
  684    if (domains_config) {
 
  689        mgr->setDomains(domains);
 
 
static ElementPtr create(const Position &pos=ZERO_POSITION())
static ElementPtr createMap(const Position &pos=ZERO_POSITION())
Creates an empty MapElement type ElementPtr.
static ElementPtr createList(const Position &pos=ZERO_POSITION())
Creates an empty ListElement type ElementPtr.
A generic exception that is thrown if a parameter given to a method is considered invalid in that con...
The IOAddress class represents an IP addresses (version agnostic)
std::string toText() const
Convert the address to a string.
An exception that is thrown if an error occurs within the IO module.
Exception thrown when the error during configuration handling occurs.
Acts as a storage vault for D2 global scalar parameters.
D2Params()
Default constructor The default constructor creates an instance that has updates disabled.
const isc::asiolink::IOAddress & getIpAddress() const
Return the IP address D2 listens on.
bool operator!=(const D2Params &other) const
Compares two D2Params's for inequality.
size_t getPort() const
Return the TCP/UPD port D2 listens on.
bool operator==(const D2Params &other) const
Compares two D2Params's for equality.
D2Params(const isc::asiolink::IOAddress &ip_address, const size_t port, const size_t dns_server_timeout, const dhcp_ddns::NameChangeProtocol &ncr_protocol, const dhcp_ddns::NameChangeFormat &ncr_format)
Constructor.
virtual ~D2Params()
Destructor.
std::string getConfigSummary() const
Return summary of the configuration used by D2.
std::string toText() const
Generates a string representation of the class contents.
virtual void validateContents()
Validates member values.
DdnsDomainListMgrPtr parse(data::ConstElementPtr mgr_config, const std::string &mgr_name, const TSIGKeyInfoMapPtr keys)
Performs the actual parsing of the given manager element.
Provides storage for and management of a list of DNS domains.
DdnsDomainListMgr(const std::string &name)
Constructor.
virtual bool matchDomain(const std::string &fqdn, DdnsDomainPtr &domain)
Matches a given name to a domain based on a longest match scheme.
void setDomains(DdnsDomainMapPtr domains)
Sets the manger's domain list to the given list of domains.
static const char * wildcard_domain_name_
defines the domain name for denoting the wildcard domain.
virtual ~DdnsDomainListMgr()
Destructor.
uint32_t size() const
Returns the number of domains in the domain list.
virtual isc::data::ElementPtr toElement() const
Unparse a configuration object.
Parser for a list of DdnsDomains.
DdnsDomainMapPtr parse(data::ConstElementPtr domain_list_config, const TSIGKeyInfoMapPtr keys)
Performs the actual parsing of the given list "ddns-domain" elements.
DdnsDomainPtr parse(data::ConstElementPtr domain_config, const TSIGKeyInfoMapPtr keys)
Performs the actual parsing of the given "ddns-domain" element.
Represents a DNS domain that is may be updated dynamically.
DdnsDomain(const std::string &name, DnsServerInfoStoragePtr servers, const std::string &key_name="")
Constructor.
virtual ~DdnsDomain()
Destructor.
virtual isc::data::ElementPtr toElement() const
Unparse a configuration object.
Parser for a list of DnsServerInfos.
DnsServerInfoStoragePtr parse(data::ConstElementPtr server_list_config, data::ConstElementPtr domain_config, const TSIGKeyInfoMapPtr keys)
Performs the actual parsing of the given list "dns-server" elements.
Parser for DnsServerInfo.
DnsServerInfoPtr parse(data::ConstElementPtr server_config, data::ConstElementPtr domain_config, const TSIGKeyInfoMapPtr keys)
Performs the actual parsing of the given "dns-server" element.
Represents a specific DNS Server.
std::string toText() const
Returns a text representation for the server.
const std::string getKeyName() const
Convenience method which returns the server's TSIG key name.
DnsServerInfo(const std::string &hostname, isc::asiolink::IOAddress ip_address, uint32_t port=STANDARD_DNS_PORT, bool enabled=true, const TSIGKeyInfoPtr &tsig_key_info=TSIGKeyInfoPtr(), bool inherited_key=true)
Constructor.
virtual isc::data::ElementPtr toElement() const
Unparse a configuration object.
uint32_t getPort() const
Getter which returns the server's port number.
const isc::asiolink::IOAddress & getIpAddress() const
Getter which returns the server's ip_address.
virtual ~DnsServerInfo()
Destructor.
TSIGKeyInfoMapPtr parse(data::ConstElementPtr key_list_config)
Performs the parsing of the given list "tsig-key" elements.
TSIGKeyInfoPtr parse(data::ConstElementPtr key_config)
Performs the actual parsing of the given "tsig-key" element.
static const char * HMAC_SHA224_STR
TSIGKeyInfo(const std::string &name, const std::string &algorithm, const std::string &secret, std::string secret_file="", uint32_t digestbits=0)
Constructor.
virtual ~TSIGKeyInfo()
Destructor.
static const char * HMAC_MD5_STR
Defines string values for the supported TSIG algorithms.
virtual isc::data::ElementPtr toElement() const
Unparse a configuration object.
static const char * HMAC_SHA1_STR
static const char * HMAC_SHA256_STR
static const dns::Name & stringToAlgorithmName(const std::string &algorithm_id)
Converts algorithm id to dns::TSIGKey algorithm dns::Name.
static const char * HMAC_SHA512_STR
static const char * HMAC_SHA384_STR
static const data::Element::Position & getPosition(const std::string &name, const data::ConstElementPtr parent)
Utility method that returns position of an element.
static std::string getString(isc::data::ConstElementPtr scope, const std::string &name)
Returns a string parameter from a scope.
static int64_t getInteger(isc::data::ConstElementPtr scope, const std::string &name)
Returns an integer parameter from a scope.
The Name class encapsulates DNS names.
std::string toText(bool omit_final_dot=false) const
Convert the Name to a string.
static const Name & HMACMD5_NAME()
Well known algorithm names as defined in RFC2845 and RFC4635.
static const Name & HMACSHA224_NAME()
static const Name & HMACSHA256_NAME()
static const Name & HMACSHA1_NAME()
static const Name & HMACSHA512_NAME()
static const Name & HMACSHA384_NAME()
static bool shouldEnforceSecurity()
Indicates security checks should be enforced.
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
#define LOG_WARN(LOGGER, MESSAGE)
Macro to conveniently test warn output and log it.
A wrapper interface for the ASIO library.
std::ostream & operator<<(std::ostream &os, const IOAddress &address)
Insert the IOAddress as a string into stream.
boost::shared_ptr< DdnsDomainListMgr > DdnsDomainListMgrPtr
Defines a pointer for DdnsDomain instances.
boost::shared_ptr< DdnsDomain > DdnsDomainPtr
Defines a pointer for DdnsDomain instances.
boost::shared_ptr< DdnsDomainMap > DdnsDomainMapPtr
Defines a pointer to DdnsDomain storage containers.
const isc::log::MessageID DHCP_DDNS_TSIG_SECRET_SECURITY_WARNING
boost::shared_ptr< DnsServerInfo > DnsServerInfoPtr
Defines a pointer for DnsServerInfo instances.
std::map< std::string, DdnsDomainPtr > DdnsDomainMap
Defines a map of DdnsDomains, keyed by the domain name.
isc::log::Logger dhcp_to_d2_logger("dhcp-to-d2")
boost::shared_ptr< TSIGKeyInfo > TSIGKeyInfoPtr
Defines a pointer for TSIGKeyInfo instances.
std::vector< DnsServerInfoPtr > DnsServerInfoStorage
Defines a storage container for DnsServerInfo pointers.
std::map< std::string, TSIGKeyInfoPtr > TSIGKeyInfoMap
Defines a map of TSIGKeyInfos, keyed by the name.
boost::shared_ptr< DnsServerInfoStorage > DnsServerInfoStoragePtr
Defines a pointer to DnsServerInfo storage containers.
const isc::log::MessageID DHCP_DDNS_NO_MATCH
boost::shared_ptr< TSIGKeyInfoMap > TSIGKeyInfoMapPtr
Defines a pointer to map of TSIGkeyInfos.
boost::shared_ptr< const Element > ConstElementPtr
boost::shared_ptr< Element > ElementPtr
NameChangeFormat
Defines the list of data wire formats supported.
NameChangeProtocol
Defines the list of socket protocols supported.
std::string ncrProtocolToString(NameChangeProtocol protocol)
Function which converts NameChangeProtocol enums to text labels.
std::string ncrFormatToString(NameChangeFormat format)
Function which converts NameChangeFormat enums to text labels.
string getContent(string const &file_name)
Get the content of a regular file.
Defines the logger used by the top-level component of kea-lfc.
void contextToElement(data::ElementPtr map) const
Merge unparse a user_context object.