Kea 1.5.0
masterload.cc
Go to the documentation of this file.
1// Copyright (C) 2010-2015 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
7#include <config.h>
8
9#include <istream>
10#include <fstream>
11#include <sstream>
12#include <string>
13#include <cctype>
14#include <cerrno>
15
16#include <boost/bind.hpp>
17#include <boost/scoped_ptr.hpp>
18
20
21#include <dns/masterload.h>
22#include <dns/master_loader.h>
23#include <dns/name.h>
24#include <dns/rdata.h>
25#include <dns/rdataclass.h>
26#include <dns/rrclass.h>
27#include <dns/rrset.h>
28#include <dns/rrttl.h>
29#include <dns/rrtype.h>
30#include <dns/rrcollator.h>
31
32using namespace std;
33using namespace boost;
34using namespace isc::dns::rdata;
35
36namespace isc {
37namespace dns {
38namespace {
39void
40callbackWrapper(const RRsetPtr& rrset, MasterLoadCallback callback,
41 const Name* origin)
42{
43 // Origin related validation:
44 // - reject out-of-zone data
45 // - reject SOA whose owner is not at the top of zone
46 const NameComparisonResult cmp_result =
47 rrset->getName().compare(*origin);
48 if (cmp_result.getRelation() != NameComparisonResult::EQUAL &&
50 isc_throw(MasterLoadError, "Out-of-zone data for " << *origin
51 << "/" << rrset->getClass() << ": " << rrset->getName());
52 }
53 if (rrset->getType() == RRType::SOA() &&
55 isc_throw(MasterLoadError, "SOA not at top of zone: "
56 << *rrset);
57 }
58
59 callback(rrset);
60}
61
62template <typename InputType>
63void
64loadHelper(InputType input, const Name& origin,
65 const RRClass& zone_class, MasterLoadCallback callback)
66{
67 RRCollator rr_collator(boost::bind(callbackWrapper, _1,
68 callback, &origin));
69 MasterLoader loader(input, origin, zone_class,
71 rr_collator.getCallback());
72 try {
73 loader.load();
74 } catch (const MasterLoaderError& ex) {
76 }
77 rr_collator.flush();
78}
79}
80
81void
82masterLoad(const char* const filename, const Name& origin,
83 const RRClass& zone_class, MasterLoadCallback callback)
84{
85 if ((filename == NULL) || (*filename == '\0')) {
86 isc_throw(MasterLoadError, "Name of master file must not be null");
87 }
88
89 loadHelper<const char*>(filename, origin, zone_class, callback);
90}
91
92void
93masterLoad(istream& input, const Name& origin, const RRClass& zone_class,
94 MasterLoadCallback callback, const char*)
95{
96 loadHelper<istream&>(input, origin, zone_class, callback);
97}
98
99} // namespace dns
100} // namespace isc
virtual const char * what() const
Returns a C-style character string of the cause of the exception.
An exception that is thrown if an error occurs while loading a master zone data.
Definition: masterload.h:25
static MasterLoaderCallbacks getNullCallbacks()
Return a callbacks instance with null callbacks.
Error while loading by MasterLoader without specifying the MANY_ERRORS option.
Definition: master_loader.h:22
A class able to load DNS master files.
Definition: master_loader.h:36
This is a supplemental class used only as a return value of Name::compare() and LabelSequence::compar...
Definition: name.h:117
NameRelation getRelation() const
Returns the NameRelation of the comparison result.
Definition: name.h:172
The Name class encapsulates DNS names.
Definition: name.h:223
The RRClass class encapsulates DNS resource record classes.
Definition: rrclass.h:98
A converter from a stream of RRs to a stream of collated RRsets.
Definition: rrcollator.h:45
static const RRType & SOA()
Definition: rrtype.h:485
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
void masterLoad(const char *const filename, const Name &origin, const RRClass &zone_class, MasterLoadCallback callback)
Master zone file loader from a file.
Definition: masterload.cc:82
boost::shared_ptr< AbstractRRset > RRsetPtr
A pointer-like type pointing to an RRset object.
Definition: rrset.h:53
boost::function< void(RRsetPtr)> MasterLoadCallback
The type of the callback parameter of masterLoad().
Definition: masterload.h:35
Defines the logger used by the top-level component of kea-dhcp-ddns.