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