File: ldapconnection.h

package info (click to toggle)
msktutil 1.0-1
  • links: PTS, VCS
  • area: main
  • in suites: buster, sid, stretch
  • size: 568 kB
  • ctags: 363
  • sloc: cpp: 4,051; xml: 231; ansic: 85; makefile: 47; sh: 44
file content (97 lines) | stat: -rw-r--r-- 3,412 bytes parent folder | download
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 (dperry@pppl.gov)
 * (C) 2006 Brian Elliott Finley (finley@anl.gov)
 * (C) 2009-2010 Doug Engert (deengert@anl.gov)
 * (C) 2010 James Y Knight (foom@fuhm.net)
 * (C) 2010-2013 Ken Dreyer <ktdreyer at ktdreyer.com>
 * (C) 2012-2016 Mark Proehl <mark at mproehl.net>
 * (C) 2012-2016 Olaf Flebbe <of at oflebbe.de>
 * (C) 2013-2016 Daniel Kobras <d.kobras@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, 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);

    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