]>
Commit | Line | Data |
---|---|---|
fe1ce82e BH |
1 | /* |
2 | * PowerDNS LDAP Connector | |
3 | * By PowerDNS.COM BV | |
8e20e603 | 4 | * By Norbert Sendetzky <norbert@linuxnetworks.de> (2003-2007) |
fe1ce82e BH |
5 | * |
6 | * This program is free software; you can redistribute it and/or modify | |
22dc646a | 7 | * it under the terms of the GNU General Public License version 2 |
8e20e603 | 8 | * as published by the Free Software Foundation. |
fe1ce82e BH |
9 | * |
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. | |
14 | * | |
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 | |
06bd9ccf | 17 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
fe1ce82e BH |
18 | */ |
19 | ||
20 | ||
21 | ||
4bb1fb74 | 22 | #include <map> |
bdf40704 | 23 | #include <string> |
4bb1fb74 | 24 | #include <vector> |
4bb1fb74 BH |
25 | #include <exception> |
26 | #include <stdexcept> | |
c0ff3710 | 27 | #include <inttypes.h> |
fe1ce82e | 28 | #include <errno.h> |
4bb1fb74 BH |
29 | #include <lber.h> |
30 | #include <ldap.h> | |
31 | ||
c533708a | 32 | |
bdf40704 | 33 | |
fe1ce82e | 34 | |
bdf40704 BH |
35 | #ifndef POWERLDAP_HH |
36 | #define POWERLDAP_HH | |
37 | ||
38 | using std::map; | |
39 | using std::string; | |
40 | using std::vector; | |
41 | ||
bdf40704 | 42 | class LDAPException : public std::runtime_error |
4bb1fb74 BH |
43 | { |
44 | public: | |
e0ec6e79 | 45 | explicit LDAPException( const string &str ) : std::runtime_error( str ) {} |
4bb1fb74 BH |
46 | }; |
47 | ||
48 | class LDAPTimeout : public LDAPException | |
49 | { | |
50 | public: | |
e0ec6e79 | 51 | explicit LDAPTimeout() : LDAPException( "Timeout" ) {} |
4bb1fb74 BH |
52 | }; |
53 | ||
54 | class PowerLDAP | |
55 | { | |
e0ec6e79 | 56 | LDAP* d_ld; |
4e755e98 BH |
57 | string d_hosts; |
58 | int d_port; | |
59 | bool d_tls; | |
bdf40704 | 60 | |
e0ec6e79 BH |
61 | const string getError( int rc = -1 ); |
62 | int waitResult( int msgid = LDAP_RES_ANY, int timeout = 0, LDAPMessage** result = NULL ); | |
4e755e98 BH |
63 | void ensureConnect(); |
64 | ||
4bb1fb74 | 65 | public: |
e0ec6e79 BH |
66 | typedef map<string, vector<string> > sentry_t; |
67 | typedef vector<sentry_t> sresult_t; | |
bdf40704 | 68 | |
e0ec6e79 BH |
69 | PowerLDAP( const string& hosts = "ldap://127.0.0.1/", uint16_t port = LDAP_PORT, bool tls = false ); |
70 | ~PowerLDAP(); | |
bdf40704 | 71 | |
e0ec6e79 BH |
72 | void getOption( int option, int* value ); |
73 | void setOption( int option, int value ); | |
bdf40704 | 74 | |
e0ec6e79 BH |
75 | void bind( const string& ldapbinddn = "", const string& ldapsecret = "", int method = LDAP_AUTH_SIMPLE, int timeout = 5 ); |
76 | void simpleBind( const string& ldapbinddn = "", const string& ldapsecret = "" ); | |
77 | int search( const string& base, int scope, const string& filter, const char** attr = 0 ); | |
bdf40704 | 78 | |
e0ec6e79 BH |
79 | bool getSearchEntry( int msgid, sentry_t& entry, bool dn = false, int timeout = 5 ); |
80 | void getSearchResults( int msgid, sresult_t& result, bool dn = false, int timeout = 5 ); | |
bdf40704 | 81 | |
e0ec6e79 | 82 | static const string escape( const string& tobe ); |
4bb1fb74 BH |
83 | }; |
84 | ||
fe1ce82e BH |
85 | |
86 | ||
4bb1fb74 | 87 | #endif |