Prevent potential side effects and use local variables here
[pdns-ldap-backend/landonf.git] / src / ldapbackend.hh
blob06eb23dfa5bff2b5b6f185e76893dee37dcbbd51
1 /*
2 * PowerDNS LDAP Backend
3 * Copyright (C) 2003-2007 Norbert Sendetzky <norbert@linuxnetworks.de>
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2
7 * as published by the Free Software Foundation.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21 #include <algorithm>
22 #include <sstream>
23 #include <utility>
24 #include <string>
25 #include <cstdlib>
26 #include <cctype>
27 #include <inttypes.h>
28 #include <pdns/dns.hh>
29 #include <pdns/utility.hh>
30 #include <pdns/dnspacket.hh>
31 #include <pdns/dnsbackend.hh>
32 #include <pdns/ueberbackend.hh>
33 #include <pdns/ahuexception.hh>
34 #include <pdns/arguments.hh>
35 #include <pdns/logger.hh>
36 #include "powerldap.hh"
37 #include "utils.hh"
39 #ifdef HAVE_CONFIG_H
40 #include <config.h>
41 #endif
44 #ifndef LDAPBACKEND_HH
45 #define LDAPBACKEND_HH
47 using std::string;
48 using std::vector;
50 class LdapAuthenticator;
53 * Known DNS RR types
54 * Types which aren't active are currently not supported by PDNS
57 static const char* ldap_attrany[] = {
58 "associatedDomain",
59 "dNSTTL",
60 "aRecord",
61 "nSRecord",
62 "cNAMERecord",
63 "sOARecord",
64 "pTRRecord",
65 "hInfoRecord",
66 "mXRecord",
67 "tXTRecord",
68 "rPRecord",
69 "aFSDBRecord",
70 // "SigRecord",
71 "KeyRecord",
72 // "gPosRecord",
73 "aAAARecord",
74 "lOCRecord",
75 "sRVRecord",
76 "nAPTRRecord",
77 "kXRecord",
78 "certRecord",
79 // "a6Record",
80 // "dNameRecord",
81 // "aPLRecord",
82 "dSRecord",
83 "sSHFPRecord",
84 "iPSecKeyRecord",
85 "rRSIGRecord",
86 "nSECRecord",
87 "dNSKeyRecord",
88 "dHCIDRecord",
89 "sPFRecord",
90 "modifyTimestamp",
91 NULL
96 class LdapBackend : public DNSBackend
98 bool m_getdn;
99 bool m_qlog;
100 int m_msgid;
101 uint32_t m_ttl;
102 uint32_t m_default_ttl;
103 unsigned int m_axfrqlen;
104 time_t m_last_modified;
105 string m_myname;
106 string m_qname;
107 PowerLDAP* m_pldap;
108 LdapAuthenticator *m_authenticator;
109 PowerLDAP::sentry_t m_result;
110 PowerLDAP::sentry_t::iterator m_attribute;
111 vector<string>::iterator m_value, m_adomain;
112 vector<string> m_adomains;
113 int m_reconnect_attempts;
115 bool (LdapBackend::*m_list_fcnt)( const string&, int );
116 void (LdapBackend::*m_lookup_fcnt)( const QType&, const string&, DNSPacket*, int );
117 bool (LdapBackend::*m_prepare_fcnt)();
119 bool list_simple( const string& target, int domain_id );
120 bool list_strict( const string& target, int domain_id );
122 void lookup_simple( const QType& qtype, const string& qdomain, DNSPacket* p, int zoneid );
123 void lookup_strict( const QType& qtype, const string& qdomain, DNSPacket* p, int zoneid );
124 void lookup_tree( const QType& qtype, const string& qdomain, DNSPacket* p, int zoneid );
126 bool prepare();
127 bool prepare_simple();
128 bool prepare_strict();
130 bool getDomainInfo( const string& domain, DomainInfo& di );
132 bool reconnect();
134 public:
136 LdapBackend( const string &suffix="" );
137 ~LdapBackend();
139 // Native backend
140 bool list( const string& target, int domain_id );
141 void lookup( const QType& qtype, const string& qdomain, DNSPacket* p = 0, int zoneid = -1 );
142 bool get( DNSResourceRecord& rr );
144 // Master backend
145 void getUpdatedMasters( vector<DomainInfo>* domains );
146 void setNotified( uint32_t id, uint32_t serial );
149 #endif /* LDAPBACKEND_HH */