s3:registry: fix seqnum race in regdb_fetch_keys_internal
[Samba/vl.git] / source3 / include / smbldap.h
blobdf9df766b3aef6aab7dd8dfc6860379ea5168733
1 /*
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/>.
21 #ifndef _SMBLDAP_H
22 #define _SMBLDAP_H
24 #include "include/smb_ldap.h"
26 #ifdef HAVE_LDAP
28 #include <talloc.h>
29 #include <tevent.h>
31 /**
32 * Struct to keep the state for all the ldap stuff
36 struct smbldap_state {
37 LDAP *ldap_struct;
38 pid_t pid;
39 time_t last_ping; /* monotonic */
40 /* retrive-once info */
41 const char *uri;
43 /* credentials */
44 bool anonymous;
45 char *bind_dn;
46 char *bind_secret;
48 bool paged_results;
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;
66 /* Former statics */
67 LDAPMessage *result;
68 LDAPMessage *entry;
69 int index;
71 const char *domain_name;
72 struct dom_sid domain_sid;
74 /* configuration items */
75 int schema_ver;
77 char *domain_dn;
79 /* Is this NDS ldap? */
80 int is_nds_ldap;
82 /* Is this IPA ldap? */
83 int is_ipa_ldap;
84 struct ipasam_privates *ipasam_privates;
86 /* ldap server location parameter */
87 char *location;
89 struct {
90 char *filter;
91 LDAPMessage *result;
92 } search_cache;
95 /* The following definitions come from lib/smbldap.c */
97 NTSTATUS smbldap_init(TALLOC_CTX *mem_ctx,
98 struct tevent_context *tevent_ctx,
99 const char *location,
100 bool anon,
101 const char *bind_dn,
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,
108 LDAPMod ***mods,
109 const char *attribute, const char *newval);
110 void smbldap_make_mod_blob(LDAP *ldap_struct, LDAPMessage *existing,
111 LDAPMod ***mods,
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,
115 int max_len);
116 int smbldap_modify(struct smbldap_state *ldap_state,
117 const char *dn,
118 LDAPMod *attrs[]);
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,
124 LDAPMessage **res);
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,
155 DATA_BLOB *blob);
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,
161 LDAPMessage *entry);
163 #endif /* HAVE_LDAP */
165 #endif /* _SMBLDAP_H */