]> git.samba.org - mat/samba.git/blob - source3/include/smbldap.h
s3-smbldap: remove duplicate prototype.
[mat/samba.git] / source3 / include / smbldap.h
1 /* 
2    Unix SMB/CIFS mplementation.
3    LDAP protocol helper functions for SAMBA
4    Copyright (C) Gerald Carter                  2001-2003
5
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.
10
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.
15
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/>.
18
19 */
20
21 #ifndef _SMBLDAP_H
22 #define _SMBLDAP_H
23
24 struct smbldap_state;
25
26 #include "include/smb_ldap.h"
27
28 #ifdef HAVE_LDAP
29
30 /* Function declarations -- not included in proto.h so we don't
31    have to worry about LDAP structure types */
32
33 NTSTATUS smbldap_init(TALLOC_CTX *mem_ctx,
34                       struct tevent_context *tevent_ctx,
35                       const char *location,
36                       bool anon,
37                       const char *bind_dn,
38                       const char *bind_secret,
39                       struct smbldap_state **smbldap_state);
40
41 void smbldap_set_mod (LDAPMod *** modlist, int modop, const char *attribute, const char *value);
42 void smbldap_set_mod_blob(LDAPMod *** modlist, int modop, const char *attribute, const DATA_BLOB *newblob);
43 void smbldap_make_mod(LDAP *ldap_struct, LDAPMessage *existing,
44                       LDAPMod ***mods,
45                       const char *attribute, const char *newval);
46 void smbldap_make_mod_blob(LDAP *ldap_struct, LDAPMessage *existing,
47                            LDAPMod ***mods,
48                            const char *attribute, const DATA_BLOB *newblob);
49 bool smbldap_get_single_attribute (LDAP * ldap_struct, LDAPMessage * entry,
50                                    const char *attribute, char *value,
51                                    int max_len);
52 int smbldap_modify(struct smbldap_state *ldap_state,
53                    const char *dn,
54                    LDAPMod *attrs[]);
55
56 /**
57  * Struct to keep the state for all the ldap stuff 
58  *
59  */
60
61 struct smbldap_state {
62         LDAP *ldap_struct;
63         pid_t pid;
64         time_t last_ping; /* monotonic */
65         /* retrive-once info */
66         const char *uri;
67
68         /* credentials */
69         bool anonymous;
70         char *bind_dn;
71         char *bind_secret;
72
73         bool paged_results;
74
75         unsigned int num_failures;
76
77         time_t last_use; /* monotonic */
78         struct tevent_context *tevent_context;
79         struct timed_event *idle_event;
80
81         struct timeval last_rebind; /* monotonic */
82 };
83
84 /* struct used by both pdb_ldap.c and pdb_nds.c */
85
86 struct ipasam_privates;
87
88 struct ldapsam_privates {
89         struct smbldap_state *smbldap_state;
90
91         /* Former statics */
92         LDAPMessage *result;
93         LDAPMessage *entry;
94         int index;
95
96         const char *domain_name;
97         struct dom_sid domain_sid;
98
99         /* configuration items */
100         int schema_ver;
101
102         char *domain_dn;
103
104         /* Is this NDS ldap? */
105         int is_nds_ldap;
106
107         /* Is this IPA ldap? */
108         int is_ipa_ldap;
109         struct ipasam_privates *ipasam_privates;
110
111         /* ldap server location parameter */
112         char *location;
113
114         struct {
115                 char *filter;
116                 LDAPMessage *result;
117         } search_cache;
118 };
119
120 /* The following definitions come from lib/smbldap.c  */
121
122 int smb_ldap_start_tls(LDAP *ldap_struct, int version);
123 int smb_ldap_setup_full_conn(LDAP **ldap_struct, const char *uri);
124 int smbldap_search(struct smbldap_state *ldap_state,
125                    const char *base, int scope, const char *filter,
126                    const char *attrs[], int attrsonly,
127                    LDAPMessage **res);
128 int smbldap_search_paged(struct smbldap_state *ldap_state,
129                          const char *base, int scope, const char *filter,
130                          const char **attrs, int attrsonly, int pagesize,
131                          LDAPMessage **res, void **cookie);
132 int smbldap_modify(struct smbldap_state *ldap_state, const char *dn, LDAPMod *attrs[]);
133 int smbldap_add(struct smbldap_state *ldap_state, const char *dn, LDAPMod *attrs[]);
134 int smbldap_delete(struct smbldap_state *ldap_state, const char *dn);
135 int smbldap_extended_operation(struct smbldap_state *ldap_state,
136                                LDAP_CONST char *reqoid, struct berval *reqdata,
137                                LDAPControl **serverctrls, LDAPControl **clientctrls,
138                                char **retoidp, struct berval **retdatap);
139 int smbldap_search_suffix (struct smbldap_state *ldap_state,
140                            const char *filter, const char **search_attr,
141                            LDAPMessage ** result);
142 void smbldap_free_struct(struct smbldap_state **ldap_state) ;
143 bool smbldap_has_control(LDAP *ld, const char *control);
144 bool smbldap_has_extension(LDAP *ld, const char *extension);
145 bool smbldap_has_naming_context(LDAP *ld, const char *naming_context);
146 bool smbldap_set_creds(struct smbldap_state *ldap_state, bool anon, const char *dn, const char *secret);
147 char * smbldap_talloc_single_attribute(LDAP *ldap_struct, LDAPMessage *entry,
148                                        const char *attribute,
149                                        TALLOC_CTX *mem_ctx);
150 char * smbldap_talloc_first_attribute(LDAP *ldap_struct, LDAPMessage *entry,
151                                       const char *attribute,
152                                       TALLOC_CTX *mem_ctx);
153 char * smbldap_talloc_smallest_attribute(LDAP *ldap_struct, LDAPMessage *entry,
154                                          const char *attribute,
155                                          TALLOC_CTX *mem_ctx);
156 bool smbldap_talloc_single_blob(TALLOC_CTX *mem_ctx, LDAP *ld,
157                                 LDAPMessage *msg, const char *attrib,
158                                 DATA_BLOB *blob);
159 bool smbldap_pull_sid(LDAP *ld, LDAPMessage *msg, const char *attrib,
160                       struct dom_sid *sid);
161 void talloc_autofree_ldapmsg(TALLOC_CTX *mem_ctx, LDAPMessage *result);
162 void talloc_autofree_ldapmod(TALLOC_CTX *mem_ctx, LDAPMod **mod);
163 char *smbldap_talloc_dn(TALLOC_CTX *mem_ctx, LDAP *ld,
164                               LDAPMessage *entry);
165
166 #endif  /* HAVE_LDAP */
167
168 #define LDAP_DEFAULT_TIMEOUT   15
169 #define LDAP_CONNECTION_DEFAULT_TIMEOUT 2
170 #define LDAP_PAGE_SIZE 1024
171
172 #define ADS_PAGE_CTL_OID        "1.2.840.113556.1.4.319"
173
174 /*
175  * Work around versions of the LDAP client libs that don't have the OIDs
176  * defined, or have them defined under the old name.
177  * This functionality is really a factor of the server, not the client
178  *
179  */
180
181 #if defined(LDAP_EXOP_X_MODIFY_PASSWD) && !defined(LDAP_EXOP_MODIFY_PASSWD)
182 #define LDAP_EXOP_MODIFY_PASSWD LDAP_EXOP_X_MODIFY_PASSWD
183 #elif !defined(LDAP_EXOP_MODIFY_PASSWD)
184 #define LDAP_EXOP_MODIFY_PASSWD "1.3.6.1.4.1.4203.1.11.1"
185 #endif
186
187 #if defined(LDAP_EXOP_X_MODIFY_PASSWD_ID) && !defined(LDAP_EXOP_MODIFY_PASSWD_ID)
188 #define LDAP_TAG_EXOP_MODIFY_PASSWD_ID LDAP_EXOP_X_MODIFY_PASSWD_ID
189 #elif !defined(LDAP_EXOP_MODIFY_PASSWD_ID)
190 #define LDAP_TAG_EXOP_MODIFY_PASSWD_ID        ((ber_tag_t) 0x80U)
191 #endif
192
193 #if defined(LDAP_EXOP_X_MODIFY_PASSWD_NEW) && !defined(LDAP_EXOP_MODIFY_PASSWD_NEW)
194 #define LDAP_TAG_EXOP_MODIFY_PASSWD_NEW LDAP_EXOP_X_MODIFY_PASSWD_NEW
195 #elif !defined(LDAP_EXOP_MODIFY_PASSWD_NEW)
196 #define LDAP_TAG_EXOP_MODIFY_PASSWD_NEW       ((ber_tag_t) 0x82U)
197 #endif
198
199 #endif  /* _SMBLDAP_H */