2 Unix SMB/CIFS mplementation.
3 LDAP protocol helper functions for SAMBA
4 Copyright (C) Gerald Carter 2001-2003
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>.
24 #include "include/smb_ldap.h"
32 * Struct to keep the state for all the ldap stuff
36 struct smbldap_state {
39 time_t last_ping; /* monotonic */
40 /* retrive-once info */
50 unsigned int num_failures;
52 time_t last_use; /* monotonic */
53 struct tevent_context *tevent_context;
54 struct timed_event *idle_event;
56 struct timeval last_rebind; /* monotonic */
59 /* struct used by both pdb_ldap.c and pdb_nds.c */
61 struct ipasam_privates;
63 struct ldapsam_privates {
64 struct smbldap_state *smbldap_state;
71 const char *domain_name;
72 struct dom_sid domain_sid;
74 /* configuration items */
79 /* Is this NDS ldap? */
82 /* Is this IPA ldap? */
84 struct ipasam_privates *ipasam_privates;
86 /* ldap server location parameter */
95 /* The following definitions come from lib/smbldap.c */
97 NTSTATUS smbldap_init(TALLOC_CTX *mem_ctx,
98 struct tevent_context *tevent_ctx,
102 const char *bind_secret,
103 struct smbldap_state **smbldap_state);
105 void smbldap_set_mod (LDAPMod *** modlist, int modop, const char *attribute, const char *value);
106 void smbldap_set_mod_blob(LDAPMod *** modlist, int modop, const char *attribute, const DATA_BLOB *newblob);
107 void smbldap_make_mod(LDAP *ldap_struct, LDAPMessage *existing,
109 const char *attribute, const char *newval);
110 void smbldap_make_mod_blob(LDAP *ldap_struct, LDAPMessage *existing,
112 const char *attribute, const DATA_BLOB *newblob);
113 bool smbldap_get_single_attribute (LDAP * ldap_struct, LDAPMessage * entry,
114 const char *attribute, char *value,
116 int smbldap_modify(struct smbldap_state *ldap_state,
119 int smb_ldap_start_tls(LDAP *ldap_struct, int version);
120 int smb_ldap_setup_full_conn(LDAP **ldap_struct, const char *uri);
121 int smbldap_search(struct smbldap_state *ldap_state,
122 const char *base, int scope, const char *filter,
123 const char *attrs[], int attrsonly,
125 int smbldap_search_paged(struct smbldap_state *ldap_state,
126 const char *base, int scope, const char *filter,
127 const char **attrs, int attrsonly, int pagesize,
128 LDAPMessage **res, void **cookie);
129 int smbldap_modify(struct smbldap_state *ldap_state, const char *dn, LDAPMod *attrs[]);
130 int smbldap_add(struct smbldap_state *ldap_state, const char *dn, LDAPMod *attrs[]);
131 int smbldap_delete(struct smbldap_state *ldap_state, const char *dn);
132 int smbldap_extended_operation(struct smbldap_state *ldap_state,
133 LDAP_CONST char *reqoid, struct berval *reqdata,
134 LDAPControl **serverctrls, LDAPControl **clientctrls,
135 char **retoidp, struct berval **retdatap);
136 int smbldap_search_suffix (struct smbldap_state *ldap_state,
137 const char *filter, const char **search_attr,
138 LDAPMessage ** result);
139 void smbldap_free_struct(struct smbldap_state **ldap_state) ;
140 bool smbldap_has_control(LDAP *ld, const char *control);
141 bool smbldap_has_extension(LDAP *ld, const char *extension);
142 bool smbldap_has_naming_context(LDAP *ld, const char *naming_context);
143 bool smbldap_set_creds(struct smbldap_state *ldap_state, bool anon, const char *dn, const char *secret);
144 char * smbldap_talloc_single_attribute(LDAP *ldap_struct, LDAPMessage *entry,
145 const char *attribute,
146 TALLOC_CTX *mem_ctx);
147 char * smbldap_talloc_first_attribute(LDAP *ldap_struct, LDAPMessage *entry,
148 const char *attribute,
149 TALLOC_CTX *mem_ctx);
150 char * smbldap_talloc_smallest_attribute(LDAP *ldap_struct, LDAPMessage *entry,
151 const char *attribute,
152 TALLOC_CTX *mem_ctx);
153 bool smbldap_talloc_single_blob(TALLOC_CTX *mem_ctx, LDAP *ld,
154 LDAPMessage *msg, const char *attrib,
156 bool smbldap_pull_sid(LDAP *ld, LDAPMessage *msg, const char *attrib,
157 struct dom_sid *sid);
158 void talloc_autofree_ldapmsg(TALLOC_CTX *mem_ctx, LDAPMessage *result);
159 void talloc_autofree_ldapmod(TALLOC_CTX *mem_ctx, LDAPMod **mod);
160 char *smbldap_talloc_dn(TALLOC_CTX *mem_ctx, LDAP *ld,
163 #endif /* HAVE_LDAP */
165 #endif /* _SMBLDAP_H */