forked from msktutil/msktutil
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathldapconnection.h
98 lines (76 loc) · 3.41 KB
/
ldapconnection.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
/*
*----------------------------------------------------------------------------
*
* ldapconnection.h
*
* (C) 2004-2006 Dan Perry ([email protected])
* (C) 2006 Brian Elliott Finley ([email protected])
* (C) 2009-2010 Doug Engert ([email protected])
* (C) 2010 James Y Knight ([email protected])
* (C) 2010-2013 Ken Dreyer <ktdreyer at ktdreyer.com>
* (C) 2012-2017 Mark Proehl <mark at mproehl.net>
* (C) 2012-2017 Olaf Flebbe <of at oflebbe.de>
* (C) 2013-2017 Daniel Kobras <d.kobras at science-computing.de>
*
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
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 St, Fifth Floor, Boston, MA 02110-1301 USA
*
*-----------------------------------------------------------------------------
*/
#ifndef LDAPCONNECTION_H
#define LDAPCONNECTION_H 1
#include <ldap.h>
#include <string>
#include <vector>
#ifdef HAVE_SASL_H
#include <sasl.h>
#else
#include <sasl/sasl.h>
#endif
class LDAP_mod {
std::vector<LDAPMod *> attrs;
public:
void add(const std::string& type);
void add(const std::string& type, const std::string& val, bool ucs = false);
void add(const std::string& type, const std::vector<std::string>& val);
std::vector<LDAPMod *> get() const;
~LDAP_mod();
};
class LDAPConnection {
private:
LDAP *m_ldap;
int modify_ext(const std::string &dn, const std::string& type, char *vals[], int op, bool check);
public:
LDAPConnection(const std::string &server, const std::string &sasl_mechanisms, bool no_reverse_lookups = false);
void set_option(int option, const void *invalue);
void get_option(int option, void *outvalue);
bool is_connected() const { return m_ldap != NULL; };
LDAPMessage *search(
const std::string &base_dn, int scope, const std::string &filter, const std::string& attr);
LDAPMessage *search(
const std::string &base_dn, int scope, const std::string &filter, const char *attr[]);
LDAPMessage *search(
const std::string &base_dn, int scope, const std::string &filter, const std::vector<std::string>& attr);
LDAPMessage *first_entry(LDAPMessage *mesg);
int add_attr(const std::string &dn, const std::string &attrName, const std::string &val);
int simple_set_attr(const std::string &dn, const std::string &attrName, const std::string &val);
int remove_attr(const std::string &dn, const std::string& type, const std::string& name);
int flush_attr_no_check(const std::string &dn, const std::string& type);
int add(const std::string &dn, const LDAP_mod& mod);
int del(const std::string &dn);
void print_diagnostics(const char *msg, int err);
std::string get_one_val(LDAPMessage *msg, const std::string& name);
int count_entries(LDAPMessage *msg);
std::vector<std::string> get_all_vals(LDAPMessage *msg, const std::string& name);
~LDAPConnection();
};
#endif