| 1 | /* |
| 2 | myldap.h - simple interface to do LDAP requests |
| 3 | This file is part of the nss-pam-ldapd library. |
| 4 | |
| 5 | Copyright (C) 2007-2017 Arthur de Jong |
| 6 | |
| 7 | This library is free software; you can redistribute it and/or |
| 8 | modify it under the terms of the GNU Lesser General Public |
| 9 | License as published by the Free Software Foundation; either |
| 10 | version 2.1 of the License, or (at your option) any later version. |
| 11 | |
| 12 | This library is distributed in the hope that it will be useful, |
| 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 15 | Lesser General Public License for more details. |
| 16 | |
| 17 | You should have received a copy of the GNU Lesser General Public |
| 18 | License along with this library; if not, write to the Free Software |
| 19 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
| 20 | 02110-1301 USA |
| 21 | */ |
| 22 | |
| 23 | /* |
| 24 | This file describes the API of the myldap module which takes the complexity |
| 25 | out of using the OpenLDAP library. Memory management, paging, reconnect |
| 26 | logic, idle timeout of connections, etc is taken care of by the module. |
| 27 | |
| 28 | Use of this module is very straightforward. You first have to create a |
| 29 | session (with myldap_create_session()), with this session you can start |
| 30 | searches (with myldap_search()), from a search you can get entries (with |
| 31 | myldap_get_entry()) from the LDAP database and from these entries you can |
| 32 | get attribute values (with myldap_get_values()). |
| 33 | */ |
| 34 | |
| 35 | #ifndef NSLCD__MYLDAP_H |
| 36 | #define NSLCD__MYLDAP_Hcxx . . $ `nslcd/myldap.h:36:9`! |
| 37 | |
| 38 | /* for size_t */ |
| 39 | #include <stdlib.h> |
| 40 | /* for LDAP_SCOPE_* */ |
| 41 | #include <lber.h> |
| 42 | #include <ldap.h> |
| 43 | |
| 44 | #include "compat/attrs.h"cxx . . $ `<file>/compat/attrs.h`/ |
| 45 | |
| 46 | #ifndef LDAP_SCOPE_DEFAULTcxx . . $ `<external>/675095523251681032/ldap.h:600:9`! |
| 47 | #define LDAP_SCOPE_DEFAULT LDAP_SCOPE_SUBTREE |
| 48 | #endif /* not LDAP_SCOPE_DEFAULT */ |
| 49 | |
| 50 | /* This a a generic session handle. */ |
| 51 | typedef struct ldap_sessioncxx . . $ ldap_session# MYLDAP_SESSIONcxx . . $ MYLDAP_SESSION#; |
| 52 | |
| 53 | /* Note that this session handle may be used within one thread only. No |
| 54 | locking is performed to prevent concurrent modifications. Most LDAP |
| 55 | libraries also are not thread-safe in that a single connection may be |
| 56 | shared by multiple threads. It seems however that OpenLDAP at least does |
| 57 | not have any problems with an LDAP *ld per thread. |
| 58 | http://www.openldap.org/lists/openldap-software/200606/msg00252.html */ |
| 59 | |
| 60 | /* A result set as returned by myldap_search(). */ |
| 61 | typedef struct myldap_searchcxx . . $ myldap_search# MYLDAP_SEARCHcxx . . $ MYLDAP_SEARCH#; |
| 62 | |
| 63 | /* A single entry from the LDAP database as returned by myldap_get_entry(). */ |
| 64 | typedef struct myldap_entrycxx . . $ myldap_entry# MYLDAP_ENTRYcxx . . $ MYLDAP_ENTRY#; |
| 65 | |
| 66 | /* Create a new session, this does not yet connect to the LDAP server. The |
| 67 | connection to the server is made on-demand when a search is performed. This |
| 68 | uses the configuration to find the URLs to attempt connections to. */ |
| 69 | MUST_USEcxx . . $ `compat/attrs.h:70:9`! MYLDAP_SESSIONcxx . . $ MYLDAP_SESSION# *myldap_create_sessioncxx . . $ myldap_create_session(52715709a000e7b6).(void); |
| 70 | |
| 71 | /* Perform a simple bind operation and return the ppolicy results. |
| 72 | This function returns an LDAP status code while response is an NSLCD_PAM_* |
| 73 | code with accompanying message. */ |
| 74 | MUST_USEcxx . . $ `compat/attrs.h:70:9`! int myldap_bindcxx . . $ myldap_bind(df273da466f2c9f5).(MYLDAP_SESSIONcxx . . $ MYLDAP_SESSION# *session, const char *dn, |
| 75 | const char *password, |
| 76 | int *response, const char **message); |
| 77 | |
| 78 | /* Closes all pending searches and deallocates any memory that is allocated |
| 79 | with these searches. This does not close the session. */ |
| 80 | void myldap_session_cleanupcxx . . $ myldap_session_cleanup(eff897e83fafc25).(MYLDAP_SESSIONcxx . . $ MYLDAP_SESSION# *session); |
| 81 | |
| 82 | /* This checks the timeout value of the session and closes the connection |
| 83 | to the LDAP server if the timeout has expired and there are no pending |
| 84 | searches. */ |
| 85 | void myldap_session_checkcxx . . $ myldap_session_check(eff897e83fafc25).(MYLDAP_SESSIONcxx . . $ MYLDAP_SESSION# *session); |
| 86 | |
| 87 | /* Close the session and free all the resources allocated for the session. |
| 88 | After a call to this function the referenced handle is invalid. */ |
| 89 | void myldap_session_closecxx . . $ myldap_session_close(eff897e83fafc25).(MYLDAP_SESSIONcxx . . $ MYLDAP_SESSION# *session); |
| 90 | |
| 91 | /* Mark all failing LDAP servers as needing quick retries. This ensures that the |
| 92 | reconnect_sleeptime and reconnect_retrytime sleeping period is cut short. */ |
| 93 | void myldap_immediate_reconnectcxx . . $ myldap_immediate_reconnect(49f6e7a06ebc5aa8).(void); |
| 94 | |
| 95 | /* Do an LDAP search and return a reference to the results (returns NULL on |
| 96 | error). This function uses paging, and does reconnects to the configured |
| 97 | URLs transparently. The function returns an LDAP status code in the |
| 98 | location pointed to by rcp if it is non-NULL. */ |
| 99 | MUST_USEcxx . . $ `compat/attrs.h:70:9`! MYLDAP_SEARCHcxx . . $ MYLDAP_SEARCH# *myldap_searchcxx . . $ myldap_search(ae5ff49387da2fa5).(MYLDAP_SESSIONcxx . . $ MYLDAP_SESSION# *session, |
| 100 | const char *base, int scope, |
| 101 | const char *filter, const char **attrs, |
| 102 | int *rcp); |
| 103 | |
| 104 | /* Close the specified search. This frees all the memory that was allocated |
| 105 | for the search and its results. */ |
| 106 | void myldap_search_closecxx . . $ myldap_search_close(db162844fbd6424b).(MYLDAP_SEARCHcxx . . $ MYLDAP_SEARCH# *search); |
| 107 | |
| 108 | /* Get an entry from the result set, going over all results (returns NULL if |
| 109 | no more entries are available). Note that any memory allocated to return |
| 110 | information about the previous entry (e.g. with myldap_get_values()) is |
| 111 | freed with this call. The search is automatically closed when no more |
| 112 | results are available. The function returns an LDAP status code in the |
| 113 | location pointed to by rcp if it is non-NULL. */ |
| 114 | MUST_USEcxx . . $ `compat/attrs.h:70:9`! MYLDAP_ENTRYcxx . . $ MYLDAP_ENTRY# *myldap_get_entrycxx . . $ myldap_get_entry(d934753664bc01ce).(MYLDAP_SEARCHcxx . . $ MYLDAP_SEARCH# *search, int *rcp); |
| 115 | |
| 116 | /* Get the DN from the entry. This function does not return NULL (on error |
| 117 | "unknown" is returned). */ |
| 118 | MUST_USEcxx . . $ `compat/attrs.h:70:9`! const char *myldap_get_dncxx . . $ myldap_get_dn(dbe6544467068988).(MYLDAP_ENTRYcxx . . $ MYLDAP_ENTRY# *entry); |
| 119 | |
| 120 | /* Just like myldap_get_dn() but copies the result into the buffer. */ |
| 121 | char *myldap_cpy_dncxx . . $ myldap_cpy_dn(618b928b10500064).(MYLDAP_ENTRYcxx . . $ MYLDAP_ENTRY# *entry, char *buf, size_t buflen); |
| 122 | |
| 123 | /* Get the attribute values from a certain entry as a NULL terminated list. |
| 124 | May return NULL or an empty array. */ |
| 125 | MUST_USEcxx . . $ `compat/attrs.h:70:9`! const char **myldap_get_valuescxx . . $ myldap_get_values(d5817fb650d68070).(MYLDAP_ENTRYcxx . . $ MYLDAP_ENTRY# *entry, const char *attr); |
| 126 | |
| 127 | /* Get the attribute values from a certain entry as a NULL terminated list. |
| 128 | May return NULL or an empty array. */ |
| 129 | MUST_USEcxx . . $ `compat/attrs.h:70:9`! const char **myldap_get_values_lencxx . . $ myldap_get_values_len(d5817fb650d68070).(MYLDAP_ENTRYcxx . . $ MYLDAP_ENTRY# *entry, const char *attr); |
| 130 | |
| 131 | /* Checks to see if the entry has the specified object class. */ |
| 132 | MUST_USEcxx . . $ `compat/attrs.h:70:9`! int myldap_has_objectclasscxx . . $ myldap_has_objectclass(85c97ba28c137b8f).(MYLDAP_ENTRYcxx . . $ MYLDAP_ENTRY# *entry, const char *objectclass); |
| 133 | |
| 134 | /* See if the entry has any deref controls attached to it and deref attr |
| 135 | derefattr to get the getattr values. Will return two lists of attribute |
| 136 | values. One list of deref'ed attribute values and one list of original |
| 137 | attribute values that could not be deref'ed. */ |
| 138 | MUST_USEcxx . . $ `compat/attrs.h:70:9`! const char ***myldap_get_deref_valuescxx . . $ myldap_get_deref_values(41b1bc8c869a94c7).(MYLDAP_ENTRYcxx . . $ MYLDAP_ENTRY# *entry, |
| 139 | const char *derefattr, const char *getattr); |
| 140 | |
| 141 | /* Get the RDN's value: eg. if the DN was cn=lukeh, ou=People, dc=example, |
| 142 | dc=com getrdnvalue(entry, cn) would return lukeh. If the attribute was not |
| 143 | found in the DN or if some error occurs NULL is returned. This method may |
| 144 | be used to get the "most authoritative" value for an attribute. */ |
| 145 | MUST_USEcxx . . $ `compat/attrs.h:70:9`! const char *myldap_get_rdn_valuecxx . . $ myldap_get_rdn_value(475a0395c67f495e).(MYLDAP_ENTRYcxx . . $ MYLDAP_ENTRY# *entry, const char *attr); |
| 146 | |
| 147 | /* Just like myldap_get_rdn_value() but use the supplied character sequence |
| 148 | and copies the result into the buffer. |
| 149 | Returns a pointer to the start of the string on success and NULL on |
| 150 | failure. */ |
| 151 | MUST_USEcxx . . $ `compat/attrs.h:70:9`! const char *myldap_cpy_rdn_valuecxx . . $ myldap_cpy_rdn_value(c14171b993158097).(const char *dn, const char *attr, |
| 152 | char *buf, size_t buflen); |
| 153 | |
| 154 | /* Escapes characters in a string for use in a search filter. */ |
| 155 | MUST_USEcxx . . $ `compat/attrs.h:70:9`! int myldap_escapecxx . . $ myldap_escape(8cded89eb41cb9be).(const char *src, char *buffer, size_t buflen); |
| 156 | |
| 157 | /* Set the debug level globally. Returns an LDAP status code. */ |
| 158 | int myldap_set_debuglevelcxx . . $ myldap_set_debuglevel(7864480464b09eea).(int level); |
| 159 | |
| 160 | /* Perform an EXOP password modification call. Returns an LDAP status code. */ |
| 161 | int myldap_passwdcxx . . $ myldap_passwd(2a2f5f98b3574e22).(MYLDAP_SESSIONcxx . . $ MYLDAP_SESSION# *session, |
| 162 | const char *userdn, const char *oldpassword, |
| 163 | const char *newpasswd); |
| 164 | |
| 165 | /* Perform an LDAP modification request. Returns an LDAP status code. */ |
| 166 | int myldap_modifycxx . . $ myldap_modify(3baff0d02f6ca22c).(MYLDAP_SESSIONcxx . . $ MYLDAP_SESSION# *session, const char *dn, LDAPModcxx . . $ LDAPMod# * mods[]); |
| 167 | |
| 168 | /* Get an LDAP error message from the supplied rc and optionally any extra |
| 169 | information in the connection. */ |
| 170 | int myldap_error_messagecxx . . $ myldap_error_message(4f7ee7a0df720083).(MYLDAP_SESSIONcxx . . $ MYLDAP_SESSION# *session, int rc, |
| 171 | char *buffer, size_t buflen); |
| 172 | |
| 173 | #endif /* not NSLCD__MYLDAP_H */ |