r12601: Syncronise both copies of dlinklist.h.
[kai/samba.git] / source4 / include / ads.h
1 /*
2    Unix SMB/CIFS implementation.
3    header for ads (active directory) library routines
4    basically this is a wrapper around ldap
5
6    Copyright (C) Andrew Tridgell 2001-2003
7
8    This program is free software; you can redistribute it and/or modify
9    it under the terms of the GNU General Public License as published by
10    the Free Software Foundation; either version 2 of the License, or
11    (at your option) any later version.
12
13    This program is distributed in the hope that it will be useful,
14    but WITHOUT ANY WARRANTY; without even the implied warranty of
15    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16    GNU General Public License for more details.
17
18    You should have received a copy of the GNU General Public License
19    along with this program; if not, write to the Free Software
20    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 */
22  
23 typedef struct ads_struct {
24         void *ld; /* the active ldap structure */
25         struct ipv4_addr ldap_ip; /* the ip of the active connection, if any */
26         time_t last_attempt; /* last attempt to reconnect */
27         int ldap_port;
28         
29         int is_mine;    /* do I own this structure's memory? */
30         
31         /* info needed to find the server */
32         struct {
33                 char *realm;
34                 char *workgroup;
35                 char *ldap_server;
36                 char *ldap_uri;
37                 int foreign; /* set to 1 if connecting to a foreign realm */
38         } server;
39
40         /* info needed to authenticate */
41         struct {
42                 char *realm;
43                 char *password;
44                 char *user_name;
45                 char *kdc_server;
46                 uint_t flags;
47                 int time_offset;
48                 time_t expire;
49         } auth;
50
51         /* info derived from the servers config */
52         struct {
53                 char *realm;
54                 char *bind_path;
55                 char *ldap_server_name;
56                 time_t current_time;
57         } config;
58 } ADS_STRUCT;
59
60 /* there are 5 possible types of errors the ads subsystem can produce */
61 enum ads_error_type {ENUM_ADS_ERROR_KRB5, ENUM_ADS_ERROR_GSS, 
62                      ENUM_ADS_ERROR_LDAP, ENUM_ADS_ERROR_SYSTEM, ENUM_ADS_ERROR_NT};
63
64 typedef struct {
65         enum ads_error_type error_type;
66         union err_state{                
67                 int rc;
68                 NTSTATUS nt_status;
69         } err;
70         /* For error_type = ENUM_ADS_ERROR_GSS minor_status describe GSS API error */
71         /* Where rc represents major_status of GSS API error */
72         int minor_status;
73 } ADS_STATUS;
74
75 typedef void **ADS_MODLIST;
76
77 /* macros to simplify error returning */
78 #define ADS_ERROR(rc) ADS_ERROR_LDAP(rc)
79 #define ADS_ERROR_LDAP(rc) ads_build_error(ENUM_ADS_ERROR_LDAP, rc, 0)
80 #define ADS_ERROR_SYSTEM(rc) ads_build_error(ENUM_ADS_ERROR_SYSTEM, rc?rc:EINVAL, 0)
81 #define ADS_ERROR_KRB5(rc) ads_build_error(ENUM_ADS_ERROR_KRB5, rc, 0)
82 #define ADS_ERROR_GSS(rc, minor) ads_build_error(ENUM_ADS_ERROR_GSS, rc, minor)
83 #define ADS_ERROR_NT(rc) ads_build_nt_error(ENUM_ADS_ERROR_NT,rc)
84
85 #define ADS_ERR_OK(status) ((status.error_type == ENUM_ADS_ERROR_NT) ? NT_STATUS_IS_OK(status.err.nt_status):(status.err.rc == 0))
86 #define ADS_SUCCESS ADS_ERROR(0)
87
88 /* time between reconnect attempts */
89 #define ADS_RECONNECT_TIME 5
90
91 /* timeout on searches */
92 #define ADS_SEARCH_TIMEOUT 10
93
94 /* ldap control oids */
95 #define ADS_PAGE_CTL_OID "1.2.840.113556.1.4.319"
96 #define ADS_NO_REFERRALS_OID "1.2.840.113556.1.4.1339"
97 #define ADS_SERVER_SORT_OID "1.2.840.113556.1.4.473"
98 #define ADS_PERMIT_MODIFY_OID "1.2.840.113556.1.4.1413"
99 /*
100 1.2.840.113556.1.4.319;
101 1.2.840.113556.1.4.801;
102 1.2.840.113556.1.4.473;
103 1.2.840.113556.1.4.528;
104 1.2.840.113556.1.4.417;
105 1.2.840.113556.1.4.619;
106 1.2.840.113556.1.4.841;
107 1.2.840.113556.1.4.529;
108 1.2.840.113556.1.4.805;
109 1.2.840.113556.1.4.521;
110 1.2.840.113556.1.4.970;
111 1.2.840.113556.1.4.1338;
112 1.2.840.113556.1.4.474;
113 1.2.840.113556.1.4.1339;
114 1.2.840.113556.1.4.1340;
115 1.2.840.113556.1.4.1413;
116 2.16.840.1.113730.3.4.9;
117 2.16.840.1.113730.3.4.10;
118 1.2.840.113556.1.4.1504;
119 1.2.840.113556.1.4.1852;
120 1.2.840.113556.1.4.802; 
121 */
122 /* UserFlags for userAccountControl */
123 #define UF_SCRIPT                               0x00000001
124 #define UF_ACCOUNTDISABLE                       0x00000002
125 #define UF_00000004                             0x00000004
126 #define UF_HOMEDIR_REQUIRED                     0x00000008
127
128 #define UF_LOCKOUT                              0x00000010
129 #define UF_PASSWD_NOTREQD                       0x00000020
130 #define UF_PASSWD_CANT_CHANGE                   0x00000040
131 #define UF_ENCRYPTED_TEXT_PASSWORD_ALLOWED      0x00000080
132
133 #define UF_TEMP_DUPLICATE_ACCOUNT               0x00000100
134 #define UF_NORMAL_ACCOUNT                       0x00000200
135 #define UF_00000400                             0x00000400
136 #define UF_INTERDOMAIN_TRUST_ACCOUNT            0x00000800
137
138 #define UF_WORKSTATION_TRUST_ACCOUNT            0x00001000
139 #define UF_SERVER_TRUST_ACCOUNT                 0x00002000
140 #define UF_00004000                             0x00004000
141 #define UF_00008000                             0x00008000
142
143 #define UF_DONT_EXPIRE_PASSWD                   0x00010000
144 #define UF_MNS_LOGON_ACCOUNT                    0x00020000
145 #define UF_SMARTCARD_REQUIRED                   0x00040000
146 #define UF_TRUSTED_FOR_DELEGATION               0x00080000
147
148 #define UF_NOT_DELEGATED                        0x00100000
149 #define UF_USE_DES_KEY_ONLY                     0x00200000
150 #define UF_DONT_REQUIRE_PREAUTH                 0x00400000
151 #define UF_UNUSED_5                             0x00800000
152
153 #define UF_UNUSED_6                             0x01000000
154 #define UF_NO_AUTH_DATA_REQUIRED                0x02000000
155 #define UF_UNUSED_8                             0x04000000
156 #define UF_UNUSED_9                             0x08000000
157
158 #define UF_UNUSED_10                            0x10000000
159 #define UF_UNUSED_11                            0x20000000
160 #define UF_UNUSED_12                            0x40000000
161 #define UF_UNUSED_13                            0x80000000
162
163 #define UF_MACHINE_ACCOUNT_MASK (\
164                 UF_INTERDOMAIN_TRUST_ACCOUNT |\
165                 UF_WORKSTATION_TRUST_ACCOUNT |\
166                 UF_SERVER_TRUST_ACCOUNT \
167                 )
168
169 #define UF_ACCOUNT_TYPE_MASK (\
170                 UF_TEMP_DUPLICATE_ACCOUNT |\
171                 UF_NORMAL_ACCOUNT |\
172                 UF_INTERDOMAIN_TRUST_ACCOUNT |\
173                 UF_WORKSTATION_TRUST_ACCOUNT |\
174                 UF_SERVER_TRUST_ACCOUNT \
175                 )
176
177 #define UF_SETTABLE_BITS (\
178                 UF_SCRIPT |\
179                 UF_ACCOUNTDISABLE |\
180                 UF_HOMEDIR_REQUIRED  |\
181                 UF_LOCKOUT |\
182                 UF_PASSWD_NOTREQD |\
183                 UF_PASSWD_CANT_CHANGE |\
184                 UF_ACCOUNT_TYPE_MASK | \
185                 UF_DONT_EXPIRE_PASSWD | \
186                 UF_MNS_LOGON_ACCOUNT |\
187                 UF_ENCRYPTED_TEXT_PASSWORD_ALLOWED |\
188                 UF_SMARTCARD_REQUIRED |\
189                 UF_TRUSTED_FOR_DELEGATION |\
190                 UF_NOT_DELEGATED |\
191                 UF_USE_DES_KEY_ONLY  |\
192                 UF_DONT_REQUIRE_PREAUTH \
193                 )
194
195 /* sAMAccountType */
196 #define ATYPE_NORMAL_ACCOUNT                    0x30000000 /* 805306368 */
197 #define ATYPE_WORKSTATION_TRUST                 0x30000001 /* 805306369 */
198 #define ATYPE_INTERDOMAIN_TRUST                 0x30000002 /* 805306370 */ 
199 #define ATYPE_SECURITY_GLOBAL_GROUP             0x10000000 /* 268435456 */
200 #define ATYPE_DISTRIBUTION_GLOBAL_GROUP         0x10000001 /* 268435457 */
201 #define ATYPE_DISTRIBUTION_UNIVERSAL_GROUP      ATYPE_DISTRIBUTION_GLOBAL_GROUP
202 #define ATYPE_SECURITY_LOCAL_GROUP              0x20000000 /* 536870912 */
203 #define ATYPE_DISTRIBUTION_LOCAL_GROUP          0x20000001 /* 536870913 */
204
205 #define ATYPE_ACCOUNT           ATYPE_NORMAL_ACCOUNT            /* 0x30000000 805306368 */
206 #define ATYPE_GLOBAL_GROUP      ATYPE_SECURITY_GLOBAL_GROUP     /* 0x10000000 268435456 */
207 #define ATYPE_LOCAL_GROUP       ATYPE_SECURITY_LOCAL_GROUP      /* 0x20000000 536870912 */
208
209 /* groupType */
210 #define GROUP_TYPE_BUILTIN_LOCAL_GROUP          0x00000001
211 #define GROUP_TYPE_ACCOUNT_GROUP                0x00000002
212 #define GROUP_TYPE_RESOURCE_GROUP               0x00000004
213 #define GROUP_TYPE_UNIVERSAL_GROUP              0x00000008
214 #define GROUP_TYPE_APP_BASIC_GROUP              0x00000010
215 #define GROUP_TYPE_APP_QUERY_GROUP              0x00000020
216 #define GROUP_TYPE_SECURITY_ENABLED             0x80000000
217
218 #define GTYPE_SECURITY_BUILTIN_LOCAL_GROUP ( \
219                 /* 0x80000005 -2147483643 */ \
220                 GROUP_TYPE_BUILTIN_LOCAL_GROUP| \
221                 GROUP_TYPE_RESOURCE_GROUP| \
222                 GROUP_TYPE_SECURITY_ENABLED \
223                 )
224 #define GTYPE_SECURITY_DOMAIN_LOCAL_GROUP ( \
225                 /* 0x80000004 -2147483644 */ \
226                 GROUP_TYPE_RESOURCE_GROUP| \
227                 GROUP_TYPE_SECURITY_ENABLED \
228                 )
229 #define GTYPE_SECURITY_GLOBAL_GROUP ( \
230                 /* 0x80000002 -2147483646 */ \
231                 GROUP_TYPE_ACCOUNT_GROUP| \
232                 GROUP_TYPE_SECURITY_ENABLED \
233                 )
234 #define GTYPE_DISTRIBUTION_GLOBAL_GROUP         0x00000002      /* 2 */
235 #define GTYPE_DISTRIBUTION_DOMAIN_LOCAL_GROUP   0x00000004      /* 4 */
236 #define GTYPE_DISTRIBUTION_UNIVERSAL_GROUP      0x00000008      /* 8 */
237
238 /* Mailslot or cldap getdcname response flags */
239 #define ADS_PDC            0x00000001  /* DC is PDC */
240 #define ADS_GC             0x00000004  /* DC is a GC of forest */
241 #define ADS_LDAP           0x00000008  /* DC is an LDAP server */
242 #define ADS_DS             0x00000010  /* DC supports DS */
243 #define ADS_KDC            0x00000020  /* DC is running KDC */
244 #define ADS_TIMESERV       0x00000040  /* DC is running time services */
245 #define ADS_CLOSEST        0x00000080  /* DC is closest to client */
246 #define ADS_WRITABLE       0x00000100  /* DC has writable DS */
247 #define ADS_GOOD_TIMESERV  0x00000200  /* DC has hardware clock
248                                          (and running time) */
249 #define ADS_NDNC           0x00000400  /* DomainName is non-domain NC serviced
250                                          by LDAP server */
251 #define ADS_PINGS          0x0000FFFF  /* Ping response */
252 #define ADS_DNS_CONTROLLER 0x20000000  /* DomainControllerName is a DNS name*/
253 #define ADS_DNS_DOMAIN     0x40000000  /* DomainName is a DNS name */
254 #define ADS_DNS_FOREST     0x80000000  /* DnsForestName is a DNS name */
255
256 /* DomainCntrollerAddressType */
257 #define ADS_INET_ADDRESS      0x00000001
258 #define ADS_NETBIOS_ADDRESS   0x00000002
259
260
261 /* ads auth control flags */
262 #define ADS_AUTH_DISABLE_KERBEROS 0x01
263 #define ADS_AUTH_NO_BIND          0x02
264 #define ADS_AUTH_ANON_BIND        0x04
265 #define ADS_AUTH_SIMPLE_BIND      0x08
266 #define ADS_AUTH_ALLOW_NTLMSSP    0x10
267
268 /* Kerberos environment variable names */
269 #define KRB5_ENV_CCNAME "KRB5CCNAME"
270
271 /* Heimdal uses a slightly different name */
272 #if defined(HAVE_ENCTYPE_ARCFOUR_HMAC_MD5)
273 #define ENCTYPE_ARCFOUR_HMAC ENCTYPE_ARCFOUR_HMAC_MD5
274 #endif
275
276 #define INSTANCE_TYPE_IS_NC_HEAD        0x00000001
277 #define INSTANCE_TYPE_UNINSTANT         0x00000002
278 #define INSTANCE_TYPE_WRITE             0x00000004
279 #define INSTANCE_TYPE_NC_ABOVE          0x00000008
280 #define INSTANCE_TYPE_NC_COMING         0x00000010
281 #define INSTANCE_TYPE_NC_GOING          0x00000020
282
283 #define SYSTEM_FLAG_CR_NTDS_NC                  0x00000001
284 #define SYSTEM_FLAG_CR_NTDS_DOMAIN              0x00000002
285 #define SYSTEM_FLAG_CR_NTDS_NOT_GC_REPLICATED   0x00000004
286 #define SYSTEM_FLAG_SCHEMA_BASE_OBJECT          0x00000010
287 #define SYSTEM_FLAG_DISALLOW_MOVE_ON_DELETE     0x02000000
288 #define SYSTEM_FLAG_DOMAIN_DISALLOW_MOVE        0x04000000
289 #define SYSTEM_FLAG_DOMAIN_DISALLOW_RENAME      0x08000000
290 #define SYSTEM_FLAG_CONFIG_ALLOW_LIMITED_MOVE   0x10000000
291 #define SYSTEM_FLAG_CONFIG_ALLOW_MOVE           0x20000000
292 #define SYSTEM_FLAG_CONFIG_ALLOW_ERNAME         0x20000000
293 #define SYSTEM_FLAG_DISALLOW_DELTE              0x80000000
294
295 #define DS_BEHAVIOR_WIN2000     0
296 #define DS_BEHAVIOR_WIN2003     2