VERSION: Move on to beta5!
[Samba.git] / source3 / include / smbldap.h
blob5051fcf333734aa587d474ea4aa639f43287ea4d
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;
47 int (*bind_callback)(LDAP *ldap_struct, struct smbldap_state *ldap_state, void *data);
48 void *bind_callback_data;
50 bool paged_results;
52 unsigned int num_failures;
54 time_t last_use; /* monotonic */
55 struct tevent_context *tevent_context;
56 struct timed_event *idle_event;
58 struct timeval last_rebind; /* monotonic */
61 /* struct used by both pdb_ldap.c and pdb_nds.c */
63 struct ipasam_privates;
65 struct ldapsam_privates {
66 struct smbldap_state *smbldap_state;
68 /* Former statics */
69 LDAPMessage *result;
70 LDAPMessage *entry;
71 int index;
73 const char *domain_name;
74 struct dom_sid domain_sid;
76 /* configuration items */
77 int schema_ver;
79 char *domain_dn;
81 /* Is this NDS ldap? */
82 int is_nds_ldap;
84 /* Is this IPA ldap? */
85 int is_ipa_ldap;
86 struct ipasam_privates *ipasam_privates;
88 /* ldap server location parameter */
89 char *location;
91 struct {
92 char *filter;
93 LDAPMessage *result;
94 } search_cache;
97 /* The following definitions come from lib/smbldap.c */
99 NTSTATUS smbldap_init(TALLOC_CTX *mem_ctx,
100 struct tevent_context *tevent_ctx,
101 const char *location,
102 bool anon,
103 const char *bind_dn,
104 const char *bind_secret,
105 struct smbldap_state **smbldap_state);
107 void smbldap_set_mod (LDAPMod *** modlist, int modop, const char *attribute, const char *value);
108 void smbldap_set_mod_blob(LDAPMod *** modlist, int modop, const char *attribute, const DATA_BLOB *newblob);
109 void smbldap_make_mod(LDAP *ldap_struct, LDAPMessage *existing,
110 LDAPMod ***mods,
111 const char *attribute, const char *newval);
112 void smbldap_make_mod_blob(LDAP *ldap_struct, LDAPMessage *existing,
113 LDAPMod ***mods,
114 const char *attribute, const DATA_BLOB *newblob);
115 bool smbldap_get_single_attribute (LDAP * ldap_struct, LDAPMessage * entry,
116 const char *attribute, char *value,
117 int max_len);
118 int smbldap_modify(struct smbldap_state *ldap_state,
119 const char *dn,
120 LDAPMod *attrs[]);
121 int smb_ldap_start_tls(LDAP *ldap_struct, int version);
122 int smb_ldap_setup_full_conn(LDAP **ldap_struct, const char *uri);
123 int smbldap_search(struct smbldap_state *ldap_state,
124 const char *base, int scope, const char *filter,
125 const char *attrs[], int attrsonly,
126 LDAPMessage **res);
127 int smbldap_search_paged(struct smbldap_state *ldap_state,
128 const char *base, int scope, const char *filter,
129 const char **attrs, int attrsonly, int pagesize,
130 LDAPMessage **res, void **cookie);
131 int smbldap_modify(struct smbldap_state *ldap_state, const char *dn, LDAPMod *attrs[]);
132 int smbldap_add(struct smbldap_state *ldap_state, const char *dn, LDAPMod *attrs[]);
133 int smbldap_delete(struct smbldap_state *ldap_state, const char *dn);
134 int smbldap_extended_operation(struct smbldap_state *ldap_state,
135 LDAP_CONST char *reqoid, struct berval *reqdata,
136 LDAPControl **serverctrls, LDAPControl **clientctrls,
137 char **retoidp, struct berval **retdatap);
138 int smbldap_search_suffix (struct smbldap_state *ldap_state,
139 const char *filter, const char **search_attr,
140 LDAPMessage ** result);
141 void smbldap_free_struct(struct smbldap_state **ldap_state) ;
142 bool smbldap_has_control(LDAP *ld, const char *control);
143 bool smbldap_has_extension(LDAP *ld, const char *extension);
144 bool smbldap_has_naming_context(LDAP *ld, const char *naming_context);
145 bool smbldap_set_creds(struct smbldap_state *ldap_state, bool anon, const char *dn, const char *secret);
146 char * smbldap_talloc_single_attribute(LDAP *ldap_struct, LDAPMessage *entry,
147 const char *attribute,
148 TALLOC_CTX *mem_ctx);
149 char * smbldap_talloc_first_attribute(LDAP *ldap_struct, LDAPMessage *entry,
150 const char *attribute,
151 TALLOC_CTX *mem_ctx);
152 char * smbldap_talloc_smallest_attribute(LDAP *ldap_struct, LDAPMessage *entry,
153 const char *attribute,
154 TALLOC_CTX *mem_ctx);
155 bool smbldap_talloc_single_blob(TALLOC_CTX *mem_ctx, LDAP *ld,
156 LDAPMessage *msg, const char *attrib,
157 DATA_BLOB *blob);
158 bool smbldap_pull_sid(LDAP *ld, LDAPMessage *msg, const char *attrib,
159 struct dom_sid *sid);
160 void talloc_autofree_ldapmsg(TALLOC_CTX *mem_ctx, LDAPMessage *result);
161 void talloc_autofree_ldapmod(TALLOC_CTX *mem_ctx, LDAPMod **mod);
162 char *smbldap_talloc_dn(TALLOC_CTX *mem_ctx, LDAP *ld,
163 LDAPMessage *entry);
165 #endif /* HAVE_LDAP */
167 #endif /* _SMBLDAP_H */