-
Notifications
You must be signed in to change notification settings - Fork 923
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
auth+rec secpoll: Combine secpoll result parsing code
- Loading branch information
1 parent
607f2b3
commit 2d40d42
Showing
10 changed files
with
161 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../secpoll.cc |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../secpoll.hh |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
/* | ||
* This file is part of PowerDNS or dnsdist. | ||
* Copyright -- PowerDNS.COM B.V. and its contributors | ||
* | ||
* This program is free software; you can redistribute it and/or modify | ||
* it under the terms of version 2 of the GNU General Public License as | ||
* published by the Free Software Foundation. | ||
* | ||
* In addition, for the avoidance of any doubt, permission is granted to | ||
* link this program with OpenSSL and to (re)distribute the binaries | ||
* produced as the result of such linking. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program; if not, write to the Free Software | ||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | ||
*/ | ||
|
||
#include <string> | ||
#include <vector> | ||
#include "dnsrecords.hh" | ||
#include "pdnsexception.hh" | ||
#include "misc.hh" | ||
|
||
bool isReleaseVersion(const std::string &version) { | ||
return std::count(version.begin(), version.end(), '.') == 2; | ||
} | ||
|
||
void processSecPoll(const int res, const std::vector<DNSRecord> &ret, int &secPollStatus, std::string &secPollMessage) { | ||
secPollMessage.clear(); | ||
if (res != 0) { // not NOERROR | ||
if(secPollStatus == 1) // it was ok, now it is unknown | ||
secPollStatus = 0; | ||
throw PDNSException("RCODE was not NOERROR but " + RCode::to_s(res)); | ||
} | ||
|
||
if (ret.empty()) { // empty NOERROR... wat? | ||
if(secPollStatus == 1) // it was ok, now it is unknown | ||
secPollStatus = 0; | ||
throw PDNSException("Had empty answer on NOERROR RCODE"); | ||
} | ||
|
||
DNSRecord record; | ||
for (auto const &r: ret) { | ||
if (r.d_type == QType::TXT && r.d_place == DNSResourceRecord::Place::ANSWER) { | ||
record = r; | ||
break; | ||
} | ||
} | ||
|
||
if (record.d_name.empty()) { | ||
throw PDNSException("No TXT record found in response"); | ||
} | ||
|
||
auto recordContent = getRR<TXTRecordContent>(record); | ||
if (recordContent == nullptr) { | ||
throw PDNSException("Could not parse TXT record content"); | ||
} | ||
string content = recordContent->d_text; | ||
|
||
pair<string, string> split = splitField(unquotify(content), ' '); | ||
|
||
try { | ||
secPollStatus = std::stoi(split.first); | ||
} catch (const std::exception &e) { | ||
throw PDNSException(std::string("Could not parse status number: ") + e.what()); | ||
} | ||
secPollMessage = split.second; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/* | ||
* This file is part of PowerDNS or dnsdist. | ||
* Copyright -- PowerDNS.COM B.V. and its contributors | ||
* | ||
* This program is free software; you can redistribute it and/or modify | ||
* it under the terms of version 2 of the GNU General Public License as | ||
* published by the Free Software Foundation. | ||
* | ||
* In addition, for the avoidance of any doubt, permission is granted to | ||
* link this program with OpenSSL and to (re)distribute the binaries | ||
* produced as the result of such linking. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program; if not, write to the Free Software | ||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | ||
*/ | ||
#pragma once | ||
#include <string> | ||
#include <vector> | ||
#include "dnsrecords.hh" | ||
|
||
/* Parses the result of a security poll, will throw a PDNSException when it could not be parsed, secPollStatus is | ||
* set correctly regardless whether or not an exception was thrown. | ||
* | ||
* res: DNS Rcode result from the secpoll | ||
* ret: Records returned during secpoll | ||
* secPollStatus: The actual secpoll status, pass the current status in here and it is changed to the new status | ||
* secPollMessage: Will be cleared and filled with the message from the secpoll message | ||
*/ | ||
void processSecPoll(const int res, const std::vector<DNSRecord> &ret, int &secPollStatus, std::string &secPollMessage); | ||
bool isReleaseVersion(const std::string &version); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters