s3-smbldap: improve smbldap.h readability and rearrange some defines.
[Samba/vl.git] / source3 / include / smbldap.h
blobef09c4c3c28c5fc8337cb1b8b40a0a0e4a69a318
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 /**
29 * Struct to keep the state for all the ldap stuff
33 struct smbldap_state {
34 LDAP *ldap_struct;
35 pid_t pid;
36 time_t last_ping; /* monotonic */
37 /* retrive-once info */
38 const char *uri;
40 /* credentials */
41 bool anonymous;
42 char *bind_dn;
43 char *bind_secret;
45 bool paged_results;
47 unsigned int num_failures;
49 time_t last_use; /* monotonic */
50 struct tevent_context *tevent_context;
51 struct timed_event *idle_event;
53 struct timeval last_rebind; /* monotonic */
56 /* struct used by both pdb_ldap.c and pdb_nds.c */
58 struct ipasam_privates;
60 struct ldapsam_privates {
61 struct smbldap_state *smbldap_state;
63 /* Former statics */
64 LDAPMessage *result;
65 LDAPMessage *entry;
66 int index;
68 const char *domain_name;
69 struct dom_sid domain_sid;
71 /* configuration items */
72 int schema_ver;
74 char *domain_dn;
76 /* Is this NDS ldap? */
77 int is_nds_ldap;
79 /* Is this IPA ldap? */
80 int is_ipa_ldap;
81 struct ipasam_privates *ipasam_privates;
83 /* ldap server location parameter */
84 char *location;
86 struct {
87 char *filter;
88 LDAPMessage *result;
89 } search_cache;
92 /* The following definitions come from lib/smbldap.c */
94 NTSTATUS smbldap_init(TALLOC_CTX *mem_ctx,
95 struct tevent_context *tevent_ctx,
96 const char *location,
97 bool anon,
98 const char *bind_dn,
99 const char *bind_secret,
100 struct smbldap_state **smbldap_state);
102 void smbldap_set_mod (LDAPMod *** modlist, int modop, const char *attribute, const char *value);
103 void smbldap_set_mod_blob(LDAPMod *** modlist, int modop, const char *attribute, const DATA_BLOB *newblob);
104 void smbldap_make_mod(LDAP *ldap_struct, LDAPMessage *existing,
105 LDAPMod ***mods,
106 const char *attribute, const char *newval);
107 void smbldap_make_mod_blob(LDAP *ldap_struct, LDAPMessage *existing,
108 LDAPMod ***mods,
109 const char *attribute, const DATA_BLOB *newblob);
110 bool smbldap_get_single_attribute (LDAP * ldap_struct, LDAPMessage * entry,
111 const char *attribute, char *value,
112 int max_len);
113 int smbldap_modify(struct smbldap_state *ldap_state,
114 const char *dn,
115 LDAPMod *attrs[]);
116 int smb_ldap_start_tls(LDAP *ldap_struct, int version);
117 int smb_ldap_setup_full_conn(LDAP **ldap_struct, const char *uri);
118 int smbldap_search(struct smbldap_state *ldap_state,
119 const char *base, int scope, const char *filter,
120 const char *attrs[], int attrsonly,
121 LDAPMessage **res);
122 int smbldap_search_paged(struct smbldap_state *ldap_state,
123 const char *base, int scope, const char *filter,
124 const char **attrs, int attrsonly, int pagesize,
125 LDAPMessage **res, void **cookie);
126 int smbldap_modify(struct smbldap_state *ldap_state, const char *dn, LDAPMod *attrs[]);
127 int smbldap_add(struct smbldap_state *ldap_state, const char *dn, LDAPMod *attrs[]);
128 int smbldap_delete(struct smbldap_state *ldap_state, const char *dn);
129 int smbldap_extended_operation(struct smbldap_state *ldap_state,
130 LDAP_CONST char *reqoid, struct berval *reqdata,
131 LDAPControl **serverctrls, LDAPControl **clientctrls,
132 char **retoidp, struct berval **retdatap);
133 int smbldap_search_suffix (struct smbldap_state *ldap_state,
134 const char *filter, const char **search_attr,
135 LDAPMessage ** result);
136 void smbldap_free_struct(struct smbldap_state **ldap_state) ;
137 bool smbldap_has_control(LDAP *ld, const char *control);
138 bool smbldap_has_extension(LDAP *ld, const char *extension);
139 bool smbldap_has_naming_context(LDAP *ld, const char *naming_context);
140 bool smbldap_set_creds(struct smbldap_state *ldap_state, bool anon, const char *dn, const char *secret);
141 char * smbldap_talloc_single_attribute(LDAP *ldap_struct, LDAPMessage *entry,
142 const char *attribute,
143 TALLOC_CTX *mem_ctx);
144 char * smbldap_talloc_first_attribute(LDAP *ldap_struct, LDAPMessage *entry,
145 const char *attribute,
146 TALLOC_CTX *mem_ctx);
147 char * smbldap_talloc_smallest_attribute(LDAP *ldap_struct, LDAPMessage *entry,
148 const char *attribute,
149 TALLOC_CTX *mem_ctx);
150 bool smbldap_talloc_single_blob(TALLOC_CTX *mem_ctx, LDAP *ld,
151 LDAPMessage *msg, const char *attrib,
152 DATA_BLOB *blob);
153 bool smbldap_pull_sid(LDAP *ld, LDAPMessage *msg, const char *attrib,
154 struct dom_sid *sid);
155 void talloc_autofree_ldapmsg(TALLOC_CTX *mem_ctx, LDAPMessage *result);
156 void talloc_autofree_ldapmod(TALLOC_CTX *mem_ctx, LDAPMod **mod);
157 char *smbldap_talloc_dn(TALLOC_CTX *mem_ctx, LDAP *ld,
158 LDAPMessage *entry);
160 #endif /* HAVE_LDAP */
162 #endif /* _SMBLDAP_H */