r14170: Paranioa fix for sesssetup.
[Samba/nascimento.git] / source3 / include / smbldap.h
blob6cfde13f4a9df19a9aaefea0784886c19b6bbccd
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 2 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, write to the Free Software
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 #ifndef _SMBLDAP_H
23 #define _SMBLDAP_H
25 struct smbldap_state;
27 #ifdef HAVE_LDAP
29 /* specify schema versions between 2.2. and 3.0 */
31 #define SCHEMAVER_SAMBAACCOUNT 1
32 #define SCHEMAVER_SAMBASAMACCOUNT 2
34 /* objectclass names */
36 #define LDAP_OBJ_SAMBASAMACCOUNT "sambaSamAccount"
37 #define LDAP_OBJ_SAMBAACCOUNT "sambaAccount"
38 #define LDAP_OBJ_GROUPMAP "sambaGroupMapping"
39 #define LDAP_OBJ_DOMINFO "sambaDomain"
40 #define LDAP_OBJ_IDPOOL "sambaUnixIdPool"
41 #define LDAP_OBJ_IDMAP_ENTRY "sambaIdmapEntry"
42 #define LDAP_OBJ_SID_ENTRY "sambaSidEntry"
43 #define LDAP_OBJ_TRUST_PASSWORD "sambaTrustPassword"
45 #define LDAP_OBJ_ACCOUNT "account"
46 #define LDAP_OBJ_POSIXACCOUNT "posixAccount"
47 #define LDAP_OBJ_POSIXGROUP "posixGroup"
48 #define LDAP_OBJ_OU "organizationalUnit"
50 /* some generic attributes that get reused a lot */
52 #define LDAP_ATTRIBUTE_SID "sambaSID"
53 #define LDAP_ATTRIBUTE_UIDNUMBER "uidNumber"
54 #define LDAP_ATTRIBUTE_GIDNUMBER "gidNumber"
55 #define LDAP_ATTRIBUTE_SID_LIST "sambaSIDList"
57 /* attribute map table indexes */
59 #define LDAP_ATTR_LIST_END 0
60 #define LDAP_ATTR_UID 1
61 #define LDAP_ATTR_UIDNUMBER 2
62 #define LDAP_ATTR_GIDNUMBER 3
63 #define LDAP_ATTR_UNIX_HOME 4
64 #define LDAP_ATTR_PWD_LAST_SET 5
65 #define LDAP_ATTR_PWD_CAN_CHANGE 6
66 #define LDAP_ATTR_PWD_MUST_CHANGE 7
67 #define LDAP_ATTR_LOGON_TIME 8
68 #define LDAP_ATTR_LOGOFF_TIME 9
69 #define LDAP_ATTR_KICKOFF_TIME 10
70 #define LDAP_ATTR_CN 11
71 #define LDAP_ATTR_DISPLAY_NAME 12
72 #define LDAP_ATTR_HOME_PATH 13
73 #define LDAP_ATTR_LOGON_SCRIPT 14
74 #define LDAP_ATTR_PROFILE_PATH 15
75 #define LDAP_ATTR_DESC 16
76 #define LDAP_ATTR_USER_WKS 17
77 #define LDAP_ATTR_USER_SID 18
78 #define LDAP_ATTR_USER_RID 18
79 #define LDAP_ATTR_PRIMARY_GROUP_SID 19
80 #define LDAP_ATTR_PRIMARY_GROUP_RID 20
81 #define LDAP_ATTR_LMPW 21
82 #define LDAP_ATTR_NTPW 22
83 #define LDAP_ATTR_DOMAIN 23
84 #define LDAP_ATTR_OBJCLASS 24
85 #define LDAP_ATTR_ACB_INFO 25
86 #define LDAP_ATTR_NEXT_USERRID 26
87 #define LDAP_ATTR_NEXT_GROUPRID 27
88 #define LDAP_ATTR_DOM_SID 28
89 #define LDAP_ATTR_HOME_DRIVE 29
90 #define LDAP_ATTR_GROUP_SID 30
91 #define LDAP_ATTR_GROUP_TYPE 31
92 #define LDAP_ATTR_SID 32
93 #define LDAP_ATTR_ALGORITHMIC_RID_BASE 33
94 #define LDAP_ATTR_NEXT_RID 34
95 #define LDAP_ATTR_BAD_PASSWORD_COUNT 35
96 #define LDAP_ATTR_LOGON_COUNT 36
97 #define LDAP_ATTR_MUNGED_DIAL 37
98 #define LDAP_ATTR_BAD_PASSWORD_TIME 38
99 #define LDAP_ATTR_PWD_HISTORY 39
100 #define LDAP_ATTR_SID_LIST 40
101 #define LDAP_ATTR_MOD_TIMESTAMP 41
102 #define LDAP_ATTR_LOGON_HOURS 42
103 #define LDAP_ATTR_TRUST_PASSWD_FLAGS 43
106 typedef struct _attrib_map_entry {
107 int attrib;
108 const char *name;
109 } ATTRIB_MAP_ENTRY;
112 /* structures */
114 extern ATTRIB_MAP_ENTRY attrib_map_v22[];
115 extern ATTRIB_MAP_ENTRY attrib_map_to_delete_v22[];
116 extern ATTRIB_MAP_ENTRY attrib_map_v30[];
117 extern ATTRIB_MAP_ENTRY attrib_map_to_delete_v30[];
118 extern ATTRIB_MAP_ENTRY dominfo_attr_list[];
119 extern ATTRIB_MAP_ENTRY groupmap_attr_list[];
120 extern ATTRIB_MAP_ENTRY groupmap_attr_list_to_delete[];
121 extern ATTRIB_MAP_ENTRY idpool_attr_list[];
122 extern ATTRIB_MAP_ENTRY sidmap_attr_list[];
123 extern ATTRIB_MAP_ENTRY trustpw_attr_list[];
126 /* Function declarations -- not included in proto.h so we don't
127 have to worry about LDAP structure types */
129 NTSTATUS smbldap_init(TALLOC_CTX *mem_ctx,
130 const char *location,
131 struct smbldap_state **smbldap_state);
133 const char* get_attr_key2string( ATTRIB_MAP_ENTRY table[], int key );
134 const char** get_attr_list( TALLOC_CTX *mem_ctx, ATTRIB_MAP_ENTRY table[] );
135 void smbldap_set_mod (LDAPMod *** modlist, int modop, const char *attribute, const char *value);
136 void smbldap_make_mod(LDAP *ldap_struct, LDAPMessage *existing,
137 LDAPMod ***mods,
138 const char *attribute, const char *newval);
139 BOOL smbldap_get_single_attribute (LDAP * ldap_struct, LDAPMessage * entry,
140 const char *attribute, char *value,
141 int max_len);
142 BOOL smbldap_get_single_pstring (LDAP * ldap_struct, LDAPMessage * entry,
143 const char *attribute, pstring value);
144 char *smbldap_get_dn(LDAP *ld, LDAPMessage *entry);
145 int smbldap_modify(struct smbldap_state *ldap_state,
146 const char *dn,
147 LDAPMod *attrs[]);
150 * Struct to keep the state for all the ldap stuff
154 struct smbldap_state {
155 LDAP *ldap_struct;
156 pid_t pid;
157 time_t last_ping;
158 /* retrive-once info */
159 const char *uri;
160 char *bind_dn;
161 char *bind_secret;
162 BOOL paged_results;
164 unsigned int num_failures;
166 time_t last_use;
167 smb_event_id_t event_id;
169 struct timeval last_rebind;
172 /* struct used by both pdb_ldap.c and pdb_nds.c */
174 struct ldapsam_privates {
175 struct smbldap_state *smbldap_state;
177 /* Former statics */
178 LDAPMessage *result;
179 LDAPMessage *entry;
180 int index;
182 const char *domain_name;
183 DOM_SID domain_sid;
185 /* configuration items */
186 int schema_ver;
188 char *domain_dn;
190 /* Is this NDS ldap? */
191 int is_nds_ldap;
193 /* ldap server location parameter */
194 char *location;
197 /* Functions shared between pdb_ldap.c and pdb_nds.c. */
198 NTSTATUS pdb_init_ldapsam_compat( struct pdb_methods **pdb_method, const char *location);
199 void private_data_free_fn(void **result);
200 int ldapsam_search_suffix_by_name(struct ldapsam_privates *ldap_state,
201 const char *user,
202 LDAPMessage ** result,
203 const char **attr);
204 NTSTATUS pdb_init_ldapsam( struct pdb_methods **pdb_method, const char *location);
205 const char** get_userattr_list( TALLOC_CTX *mem_ctx, int schema_ver );
207 char * smbldap_talloc_single_attribute(LDAP *ldap_struct, LDAPMessage *entry,
208 const char *attribute,
209 TALLOC_CTX *mem_ctx);
210 void talloc_autofree_ldapmsg(TALLOC_CTX *mem_ctx, LDAPMessage *result);
211 void talloc_autofree_ldapmod(TALLOC_CTX *mem_ctx, LDAPMod **mod);
212 const char *smbldap_talloc_dn(TALLOC_CTX *mem_ctx, LDAP *ld,
213 LDAPMessage *entry);
216 #endif /* HAVE_LDAP */
218 #define LDAP_CONNECT_DEFAULT_TIMEOUT 15
219 #define LDAP_PAGE_SIZE 1024
221 #endif /* _SMBLDAP_H */