]>
git.ipfire.org Git - thirdparty/pdns.git/blob - pdns/auth-catalogzone.cc
b8d825dd5de53c0a7ef596c29703a11fdedfc9df
2 * This file is part of PowerDNS or dnsdist.
3 * Copyright -- PowerDNS.COM B.V. and its contributors
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of version 2 of the GNU General Public License as
7 * published by the Free Software Foundation.
9 * In addition, for the avoidance of any doubt, permission is granted to
10 * link this program with OpenSSL and to (re)distribute the binaries
11 * produced as the result of such linking.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
27 #include "dnsbackend.hh"
29 void CatalogInfo::fromJson(const std::string
& json
, CatalogType type
)
32 if (d_type
== CatalogType::None
) {
33 throw std::runtime_error("CatalogType is set to None");
39 d_doc
= json11::Json::parse(json
, err
);
40 if (!d_doc
.is_null()) {
41 if (!d_doc
[getTypeString(d_type
)].is_null()) {
42 auto items
= d_doc
[getTypeString(type
)].object_items();
43 if (!items
["coo"].is_null()) {
44 if (items
["coo"].is_string()) {
45 if (!items
["coo"].string_value().empty()) {
46 d_coo
= DNSName(items
["coo"].string_value());
50 throw std::out_of_range("Key 'coo' is not a string");
53 if (!items
["unique"].is_null()) {
54 if (items
["unique"].is_string()) {
55 if (!items
["unique"].string_value().empty()) {
56 d_unique
= DNSName(items
["unique"].string_value());
60 throw std::out_of_range("Key 'unique' is not a string");
63 if (!items
["group"].is_null()) {
64 if (items
["group"].is_array()) {
65 for (const auto& value
: items
["group"].array_items()) {
66 d_group
.insert(value
.string_value());
70 throw std::out_of_range("Key 'group' is not an array");
76 throw std::runtime_error("Parsing of JSON options failed: " + err
);
80 std::string
CatalogInfo::toJson() const
82 if (d_type
== CatalogType::None
) {
83 throw std::runtime_error("CatalogType is set to None");
85 json11::Json::object object
;
87 object
["coo"] = d_coo
.toString();
89 if (!d_unique
.empty()) {
90 if (d_unique
.countLabels() > 1) {
91 throw std::out_of_range("Multiple labels in a unique value are not allowed");
93 object
["unique"] = d_unique
.toString();
95 if (!d_group
.empty()) {
96 json11::Json::array entries
;
97 for (const string
& group
: d_group
) {
98 entries
.push_back(group
);
100 object
["group"] = entries
;
102 auto tmp
= d_doc
.object_items();
103 tmp
[getTypeString(d_type
)] = object
;
104 const json11::Json ret
= tmp
;
108 void CatalogInfo::updateHash(CatalogHashMap
& hashes
, const DomainInfo
& di
) const
110 hashes
[di
.catalog
].process(static_cast<char>(di
.id
) + di
.zone
.toLogString() + "\0" + d_coo
.toLogString() + "\0" + d_unique
.toLogString());
113 DNSZoneRecord
CatalogInfo::getCatalogVersionRecord(const DNSName
& zone
)
116 dzr
.dr
.d_name
= DNSName("version") + zone
;
118 dzr
.dr
.d_type
= QType::TXT
;
119 dzr
.dr
.setContent(std::make_shared
<TXTRecordContent
>("2"));
123 void CatalogInfo::toDNSZoneRecords(const DNSName
& zone
, vector
<DNSZoneRecord
>& dzrs
) const
126 if (d_unique
.empty()) {
127 prefix
= getUnique();
132 prefix
+= DNSName("zones") + zone
;
135 dzr
.dr
.d_name
= prefix
;
137 dzr
.dr
.d_type
= QType::PTR
;
138 dzr
.dr
.setContent(std::make_shared
<PTRRecordContent
>(d_zone
.toString()));
139 dzrs
.emplace_back(dzr
);
141 if (!d_coo
.empty()) {
142 dzr
.dr
.d_name
= DNSName("coo") + prefix
;
144 dzr
.dr
.d_type
= QType::PTR
;
145 dzr
.dr
.setContent(std::make_shared
<PTRRecordContent
>(d_coo
));
146 dzrs
.emplace_back(dzr
);
149 for (const auto& group
: d_group
) {
150 dzr
.dr
.d_name
= DNSName("group") + prefix
;
152 dzr
.dr
.d_type
= QType::TXT
;
153 dzr
.dr
.setContent(std::make_shared
<TXTRecordContent
>("\"" + group
+ "\""));
154 dzrs
.emplace_back(dzr
);