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/>.
30 /* specify schema versions between 2.2. and 3.0 */
32 #define SCHEMAVER_SAMBAACCOUNT 1
33 #define SCHEMAVER_SAMBASAMACCOUNT 2
35 /* objectclass names */
37 #define LDAP_OBJ_SAMBASAMACCOUNT "sambaSamAccount"
38 #define LDAP_OBJ_SAMBAACCOUNT "sambaAccount"
39 #define LDAP_OBJ_GROUPMAP "sambaGroupMapping"
40 #define LDAP_OBJ_DOMINFO "sambaDomain"
41 #define LDAP_OBJ_IDPOOL "sambaUnixIdPool"
42 #define LDAP_OBJ_IDMAP_ENTRY "sambaIdmapEntry"
43 #define LDAP_OBJ_SID_ENTRY "sambaSidEntry"
44 #define LDAP_OBJ_TRUST_PASSWORD "sambaTrustPassword"
45 #define LDAP_OBJ_TRUSTDOM_PASSWORD "sambaTrustedDomainPassword"
46 #define LDAP_OBJ_TRUSTED_DOMAIN "sambaTrustedDomain"
48 #define LDAP_OBJ_ACCOUNT "account"
49 #define LDAP_OBJ_POSIXACCOUNT "posixAccount"
50 #define LDAP_OBJ_POSIXGROUP "posixGroup"
51 #define LDAP_OBJ_OU "organizationalUnit"
53 /* some generic attributes that get reused a lot */
55 #define LDAP_ATTRIBUTE_SID "sambaSID"
56 #define LDAP_ATTRIBUTE_UIDNUMBER "uidNumber"
57 #define LDAP_ATTRIBUTE_GIDNUMBER "gidNumber"
58 #define LDAP_ATTRIBUTE_SID_LIST "sambaSIDList"
60 /* attribute map table indexes */
62 #define LDAP_ATTR_LIST_END 0
63 #define LDAP_ATTR_UID 1
64 #define LDAP_ATTR_UIDNUMBER 2
65 #define LDAP_ATTR_GIDNUMBER 3
66 #define LDAP_ATTR_UNIX_HOME 4
67 #define LDAP_ATTR_PWD_LAST_SET 5
68 #define LDAP_ATTR_PWD_CAN_CHANGE 6
69 #define LDAP_ATTR_PWD_MUST_CHANGE 7
70 #define LDAP_ATTR_LOGON_TIME 8
71 #define LDAP_ATTR_LOGOFF_TIME 9
72 #define LDAP_ATTR_KICKOFF_TIME 10
73 #define LDAP_ATTR_CN 11
74 #define LDAP_ATTR_DISPLAY_NAME 12
75 #define LDAP_ATTR_HOME_PATH 13
76 #define LDAP_ATTR_LOGON_SCRIPT 14
77 #define LDAP_ATTR_PROFILE_PATH 15
78 #define LDAP_ATTR_DESC 16
79 #define LDAP_ATTR_USER_WKS 17
80 #define LDAP_ATTR_USER_SID 18
81 #define LDAP_ATTR_USER_RID 18
82 #define LDAP_ATTR_PRIMARY_GROUP_SID 19
83 #define LDAP_ATTR_PRIMARY_GROUP_RID 20
84 #define LDAP_ATTR_LMPW 21
85 #define LDAP_ATTR_NTPW 22
86 #define LDAP_ATTR_DOMAIN 23
87 #define LDAP_ATTR_OBJCLASS 24
88 #define LDAP_ATTR_ACB_INFO 25
89 #define LDAP_ATTR_NEXT_USERRID 26
90 #define LDAP_ATTR_NEXT_GROUPRID 27
91 #define LDAP_ATTR_DOM_SID 28
92 #define LDAP_ATTR_HOME_DRIVE 29
93 #define LDAP_ATTR_GROUP_SID 30
94 #define LDAP_ATTR_GROUP_TYPE 31
95 #define LDAP_ATTR_SID 32
96 #define LDAP_ATTR_ALGORITHMIC_RID_BASE 33
97 #define LDAP_ATTR_NEXT_RID 34
98 #define LDAP_ATTR_BAD_PASSWORD_COUNT 35
99 #define LDAP_ATTR_LOGON_COUNT 36
100 #define LDAP_ATTR_MUNGED_DIAL 37
101 #define LDAP_ATTR_BAD_PASSWORD_TIME 38
102 #define LDAP_ATTR_PWD_HISTORY 39
103 #define LDAP_ATTR_SID_LIST 40
104 #define LDAP_ATTR_MOD_TIMESTAMP 41
105 #define LDAP_ATTR_LOGON_HOURS 42
106 #define LDAP_ATTR_TRUST_PASSWD_FLAGS 43
107 #define LDAP_ATTR_SN 44
110 typedef struct _attrib_map_entry
{
118 extern ATTRIB_MAP_ENTRY attrib_map_v22
[];
119 extern ATTRIB_MAP_ENTRY attrib_map_to_delete_v22
[];
120 extern ATTRIB_MAP_ENTRY attrib_map_v30
[];
121 extern ATTRIB_MAP_ENTRY attrib_map_to_delete_v30
[];
122 extern ATTRIB_MAP_ENTRY dominfo_attr_list
[];
123 extern ATTRIB_MAP_ENTRY groupmap_attr_list
[];
124 extern ATTRIB_MAP_ENTRY groupmap_attr_list_to_delete
[];
125 extern ATTRIB_MAP_ENTRY idpool_attr_list
[];
126 extern ATTRIB_MAP_ENTRY sidmap_attr_list
[];
127 extern ATTRIB_MAP_ENTRY trustpw_attr_list
[];
130 /* Function declarations -- not included in proto.h so we don't
131 have to worry about LDAP structure types */
133 NTSTATUS
smbldap_init(TALLOC_CTX
*mem_ctx
,
134 struct event_context
*event_ctx
,
135 const char *location
,
136 struct smbldap_state
**smbldap_state
);
138 const char* get_attr_key2string( ATTRIB_MAP_ENTRY table
[], int key
);
139 const char** get_attr_list( TALLOC_CTX
*mem_ctx
, ATTRIB_MAP_ENTRY table
[] );
140 void smbldap_set_mod (LDAPMod
*** modlist
, int modop
, const char *attribute
, const char *value
);
141 void smbldap_set_mod_blob(LDAPMod
*** modlist
, int modop
, const char *attribute
, const DATA_BLOB
*newblob
);
142 void smbldap_make_mod(LDAP
*ldap_struct
, LDAPMessage
*existing
,
144 const char *attribute
, const char *newval
);
145 void smbldap_make_mod_blob(LDAP
*ldap_struct
, LDAPMessage
*existing
,
147 const char *attribute
, const DATA_BLOB
*newblob
);
148 bool smbldap_get_single_attribute (LDAP
* ldap_struct
, LDAPMessage
* entry
,
149 const char *attribute
, char *value
,
151 int smbldap_modify(struct smbldap_state
*ldap_state
,
156 * Struct to keep the state for all the ldap stuff
160 struct smbldap_state
{
163 time_t last_ping
; /* monotonic */
164 /* retrive-once info */
174 unsigned int num_failures
;
176 time_t last_use
; /* monotonic */
177 struct event_context
*event_context
;
178 struct timed_event
*idle_event
;
180 struct timeval last_rebind
; /* monotonic */
183 /* struct used by both pdb_ldap.c and pdb_nds.c */
185 struct ipasam_privates
;
187 struct ldapsam_privates
{
188 struct smbldap_state
*smbldap_state
;
195 const char *domain_name
;
196 struct dom_sid domain_sid
;
198 /* configuration items */
203 /* Is this NDS ldap? */
206 /* Is this IPA ldap? */
208 struct ipasam_privates
*ipasam_privates
;
210 /* ldap server location parameter */
219 /* The following definitions come from lib/smbldap.c */
221 int smb_ldap_start_tls(LDAP
*ldap_struct
, int version
);
222 int smb_ldap_setup_full_conn(LDAP
**ldap_struct
, const char *uri
);
223 int smbldap_search(struct smbldap_state
*ldap_state
,
224 const char *base
, int scope
, const char *filter
,
225 const char *attrs
[], int attrsonly
,
227 int smbldap_search_paged(struct smbldap_state
*ldap_state
,
228 const char *base
, int scope
, const char *filter
,
229 const char **attrs
, int attrsonly
, int pagesize
,
230 LDAPMessage
**res
, void **cookie
);
231 int smbldap_modify(struct smbldap_state
*ldap_state
, const char *dn
, LDAPMod
*attrs
[]);
232 int smbldap_add(struct smbldap_state
*ldap_state
, const char *dn
, LDAPMod
*attrs
[]);
233 int smbldap_delete(struct smbldap_state
*ldap_state
, const char *dn
);
234 int smbldap_extended_operation(struct smbldap_state
*ldap_state
,
235 LDAP_CONST
char *reqoid
, struct berval
*reqdata
,
236 LDAPControl
**serverctrls
, LDAPControl
**clientctrls
,
237 char **retoidp
, struct berval
**retdatap
);
238 int smbldap_search_suffix (struct smbldap_state
*ldap_state
,
239 const char *filter
, const char **search_attr
,
240 LDAPMessage
** result
);
241 void smbldap_free_struct(struct smbldap_state
**ldap_state
) ;
242 NTSTATUS
smbldap_init(TALLOC_CTX
*mem_ctx
, struct event_context
*event_ctx
,
243 const char *location
,
244 struct smbldap_state
**smbldap_state
);
245 bool smbldap_has_control(LDAP
*ld
, const char *control
);
246 bool smbldap_has_extension(LDAP
*ld
, const char *extension
);
247 bool smbldap_has_naming_context(LDAP
*ld
, const char *naming_context
);
248 bool smbldap_set_creds(struct smbldap_state
*ldap_state
, bool anon
, const char *dn
, const char *secret
);
249 char * smbldap_talloc_single_attribute(LDAP
*ldap_struct
, LDAPMessage
*entry
,
250 const char *attribute
,
251 TALLOC_CTX
*mem_ctx
);
252 char * smbldap_talloc_first_attribute(LDAP
*ldap_struct
, LDAPMessage
*entry
,
253 const char *attribute
,
254 TALLOC_CTX
*mem_ctx
);
255 char * smbldap_talloc_smallest_attribute(LDAP
*ldap_struct
, LDAPMessage
*entry
,
256 const char *attribute
,
257 TALLOC_CTX
*mem_ctx
);
258 bool smbldap_talloc_single_blob(TALLOC_CTX
*mem_ctx
, LDAP
*ld
,
259 LDAPMessage
*msg
, const char *attrib
,
261 bool smbldap_pull_sid(LDAP
*ld
, LDAPMessage
*msg
, const char *attrib
,
262 struct dom_sid
*sid
);
263 void talloc_autofree_ldapmsg(TALLOC_CTX
*mem_ctx
, LDAPMessage
*result
);
264 void talloc_autofree_ldapmod(TALLOC_CTX
*mem_ctx
, LDAPMod
**mod
);
265 char *smbldap_talloc_dn(TALLOC_CTX
*mem_ctx
, LDAP
*ld
,
268 /* The following definitions come from lib/smbldap_util.c */
270 NTSTATUS
smbldap_search_domain_info(struct smbldap_state
*ldap_state
,
271 LDAPMessage
** result
, const char *domain_name
,
274 #endif /* HAVE_LDAP */
276 #define LDAP_DEFAULT_TIMEOUT 15
277 #define LDAP_CONNECTION_DEFAULT_TIMEOUT 2
278 #define LDAP_PAGE_SIZE 1024
280 #define ADS_PAGE_CTL_OID "1.2.840.113556.1.4.319"
283 * Work around versions of the LDAP client libs that don't have the OIDs
284 * defined, or have them defined under the old name.
285 * This functionality is really a factor of the server, not the client
289 #if defined(LDAP_EXOP_X_MODIFY_PASSWD) && !defined(LDAP_EXOP_MODIFY_PASSWD)
290 #define LDAP_EXOP_MODIFY_PASSWD LDAP_EXOP_X_MODIFY_PASSWD
291 #elif !defined(LDAP_EXOP_MODIFY_PASSWD)
292 #define LDAP_EXOP_MODIFY_PASSWD "1.3.6.1.4.1.4203.1.11.1"
295 #if defined(LDAP_EXOP_X_MODIFY_PASSWD_ID) && !defined(LDAP_EXOP_MODIFY_PASSWD_ID)
296 #define LDAP_TAG_EXOP_MODIFY_PASSWD_ID LDAP_EXOP_X_MODIFY_PASSWD_ID
297 #elif !defined(LDAP_EXOP_MODIFY_PASSWD_ID)
298 #define LDAP_TAG_EXOP_MODIFY_PASSWD_ID ((ber_tag_t) 0x80U)
301 #if defined(LDAP_EXOP_X_MODIFY_PASSWD_NEW) && !defined(LDAP_EXOP_MODIFY_PASSWD_NEW)
302 #define LDAP_TAG_EXOP_MODIFY_PASSWD_NEW LDAP_EXOP_X_MODIFY_PASSWD_NEW
303 #elif !defined(LDAP_EXOP_MODIFY_PASSWD_NEW)
304 #define LDAP_TAG_EXOP_MODIFY_PASSWD_NEW ((ber_tag_t) 0x82U)
307 #endif /* _SMBLDAP_H */