Prevent potential side effects and use local variables here
[pdns-ldap-backend/landonf.git] / src / powerldap.hh
blob548334e8c24866a8f8b737365defecb4f8415b23
1 /*
2 * PowerDNS LDAP Connector
3 * By PowerDNS.COM BV
4 * By Norbert Sendetzky <norbert@linuxnetworks.de> (2003-2007)
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2
8 * as published by the Free Software Foundation.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22 #include <list>
23 #include <map>
24 #include <string>
25 #include <vector>
26 #include <stdexcept>
27 #include <inttypes.h>
28 #include <errno.h>
29 #include <lber.h>
30 #include <ldap.h>
32 #ifdef HAVE_CONFIG_H
33 #include <config.h>
34 #endif
38 #ifndef POWERLDAP_HH
39 #define POWERLDAP_HH
41 using std::list;
42 using std::map;
43 using std::string;
44 using std::vector;
46 class LdapAuthenticator;
48 class PowerLDAP
50 LDAP* d_ld;
51 string d_hosts;
52 int d_port;
53 bool d_tls;
54 list<LDAPMessage*> m_results;
56 const string getError( int rc = -1 );
57 int waitResult( int msgid = LDAP_RES_ANY, int timeout = 0, LDAPMessage** result = NULL );
58 void ensureConnect();
60 public:
61 typedef map<string, vector<string> > sentry_t;
62 typedef vector<sentry_t> sresult_t;
64 PowerLDAP( const string& hosts = "ldap://127.0.0.1/", uint16_t port = LDAP_PORT, bool tls = false );
65 ~PowerLDAP();
67 bool connect();
69 void getOption( int option, int* value );
70 void setOption( int option, int value );
72 void bind( LdapAuthenticator *authenticator );
73 void bind( const string& ldapbinddn = "", const string& ldapsecret = "", int method = LDAP_AUTH_SIMPLE, int timeout = 5 );
74 void simpleBind( const string& ldapbinddn = "", const string& ldapsecret = "" );
75 int search( const string& base, int scope, const string& filter, const char** attr = 0 );
76 void modify( const string& dn, LDAPMod *mods[], LDAPControl **scontrols = 0, LDAPControl **ccontrols = 0 );
78 bool getSearchEntry( int msgid, sentry_t& entry, bool dn = false, int timeout = 5 );
79 void getSearchResults( int msgid, sresult_t& result, bool dn = false, int timeout = 5 );
81 static const string escape( const string& tobe );
86 #endif