Merge branch 'v3-2-test' of ssh://git.samba.org/data/git/samba into v3-2-test
[samba.git] / source3 / include / ads.h
1 #ifndef _INCLUDE_ADS_H_
2 #define _INCLUDE_ADS_H_
3 /*
4   header for ads (active directory) library routines
5
6   basically this is a wrapper around ldap
7 */
8
9 enum wb_posix_mapping {
10         WB_POSIX_MAP_UNKNOWN    = -1,
11         WB_POSIX_MAP_TEMPLATE   = 0, 
12         WB_POSIX_MAP_SFU        = 1, 
13         WB_POSIX_MAP_SFU20      = 2, 
14         WB_POSIX_MAP_RFC2307    = 3,
15         WB_POSIX_MAP_UNIXINFO   = 4
16 };
17
18 /* there are 5 possible types of errors the ads subsystem can produce */
19 enum ads_error_type {ENUM_ADS_ERROR_KRB5, ENUM_ADS_ERROR_GSS, 
20                      ENUM_ADS_ERROR_LDAP, ENUM_ADS_ERROR_SYSTEM, ENUM_ADS_ERROR_NT};
21
22 typedef struct {
23         enum ads_error_type error_type;
24         union err_state{                
25                 int rc;
26                 NTSTATUS nt_status;
27         } err;
28         /* For error_type = ENUM_ADS_ERROR_GSS minor_status describe GSS API error */
29         /* Where rc represents major_status of GSS API error */
30         int minor_status;
31 } ADS_STATUS;
32
33 struct ads_struct;
34
35 struct ads_saslwrap_ops {
36         const char *name;
37         ADS_STATUS (*wrap)(struct ads_struct *, uint8 *buf, uint32 len);
38         ADS_STATUS (*unwrap)(struct ads_struct *);
39         void (*disconnect)(struct ads_struct *);
40 };
41
42 enum ads_saslwrap_type {
43         ADS_SASLWRAP_TYPE_PLAIN = 1,
44         ADS_SASLWRAP_TYPE_SIGN = 2,
45         ADS_SASLWRAP_TYPE_SEAL = 4
46 };
47
48 typedef struct ads_struct {
49         int is_mine;    /* do I own this structure's memory? */
50         
51         /* info needed to find the server */
52         struct {
53                 char *realm;
54                 char *workgroup;
55                 char *ldap_server;
56                 int foreign; /* set to 1 if connecting to a foreign realm */
57         } server;
58
59         /* info needed to authenticate */
60         struct {
61                 char *realm;
62                 char *password;
63                 char *user_name;
64                 char *kdc_server;
65                 unsigned flags;
66                 int time_offset;
67                 time_t tgt_expire;
68                 time_t tgs_expire;
69                 time_t renewable;
70         } auth;
71
72         /* info derived from the servers config */
73         struct {
74                 uint32 flags; /* cldap flags identifying the services. */
75                 char *realm;
76                 char *bind_path;
77                 char *ldap_server_name;
78                 char *server_site_name;
79                 char *client_site_name;
80                 time_t current_time;
81                 int tried_closest_dc;
82                 char *schema_path;
83                 char *config_path;
84         } config;
85
86         /* info about the current LDAP connection */
87 #ifdef HAVE_LDAP
88         struct {
89                 LDAP *ld;
90                 struct sockaddr_storage ss; /* the ip of the active connection, if any */
91                 time_t last_attempt; /* last attempt to reconnect */
92                 int port;
93
94                 enum ads_saslwrap_type wrap_type;
95
96 #ifdef HAVE_LDAP_SASL_WRAPPING
97                 Sockbuf_IO_Desc *sbiod; /* lowlevel state for LDAP wrapping */
98 #endif /* HAVE_LDAP_SASL_WRAPPING */
99                 TALLOC_CTX *mem_ctx;
100                 const struct ads_saslwrap_ops *wrap_ops;
101                 void *wrap_private_data;
102                 struct {
103                         uint32 ofs;
104                         uint32 needed;
105                         uint32 left;
106 #define        ADS_SASL_WRAPPING_IN_MAX_WRAPPED        0x0FFFFFFF
107                         uint32 max_wrapped;
108                         uint32 min_wrapped;
109                         uint32 size;
110                         uint8 *buf;
111                 } in;
112                 struct {
113                         uint32 ofs;
114                         uint32 left;
115 #define        ADS_SASL_WRAPPING_OUT_MAX_WRAPPED       0x00A00000
116                         uint32 max_unwrapped;
117                         uint32 sig_size;
118                         uint32 size;
119                         uint8 *buf;
120                 } out;
121         } ldap;
122 #endif /* HAVE_LDAP */
123 } ADS_STRUCT;
124
125 /* used to remember the names of the posix attributes in AD */
126 /* see the rfc2307 & sfu nss backends */
127
128 struct posix_schema {
129         char *posix_homedir_attr;
130         char *posix_shell_attr;
131         char *posix_uidnumber_attr;
132         char *posix_gidnumber_attr;
133         char *posix_gecos_attr;
134 };
135
136
137
138 #ifdef HAVE_ADS
139 typedef LDAPMod **ADS_MODLIST;
140 #else
141 typedef void **ADS_MODLIST;
142 #endif
143
144 /* macros to simplify error returning */
145 #define ADS_ERROR(rc) ADS_ERROR_LDAP(rc)
146 #define ADS_ERROR_LDAP(rc) ads_build_error(ENUM_ADS_ERROR_LDAP, rc, 0)
147 #define ADS_ERROR_SYSTEM(rc) ads_build_error(ENUM_ADS_ERROR_SYSTEM, rc?rc:EINVAL, 0)
148 #define ADS_ERROR_KRB5(rc) ads_build_error(ENUM_ADS_ERROR_KRB5, rc, 0)
149 #define ADS_ERROR_GSS(rc, minor) ads_build_error(ENUM_ADS_ERROR_GSS, rc, minor)
150 #define ADS_ERROR_NT(rc) ads_build_nt_error(ENUM_ADS_ERROR_NT,rc)
151
152 #define ADS_ERR_OK(status) ((status.error_type == ENUM_ADS_ERROR_NT) ? NT_STATUS_IS_OK(status.err.nt_status):(status.err.rc == 0))
153 #define ADS_SUCCESS ADS_ERROR(0)
154
155 #define ADS_ERROR_HAVE_NO_MEMORY(x) do { \
156         if (!(x)) {\
157                 return ADS_ERROR(LDAP_NO_MEMORY);\
158         }\
159 } while (0)
160
161
162 /* time between reconnect attempts */
163 #define ADS_RECONNECT_TIME 5
164
165 /* ldap control oids */
166 #define ADS_PAGE_CTL_OID        "1.2.840.113556.1.4.319"
167 #define ADS_NO_REFERRALS_OID    "1.2.840.113556.1.4.1339"
168 #define ADS_SERVER_SORT_OID     "1.2.840.113556.1.4.473"
169 #define ADS_PERMIT_MODIFY_OID   "1.2.840.113556.1.4.1413"
170 #define ADS_ASQ_OID             "1.2.840.113556.1.4.1504"
171 #define ADS_EXTENDED_DN_OID     "1.2.840.113556.1.4.529"
172 #define ADS_SD_FLAGS_OID        "1.2.840.113556.1.4.801"
173
174 /* ldap attribute oids (Services for Unix 3.0, 3.5) */
175 #define ADS_ATTR_SFU_UIDNUMBER_OID      "1.2.840.113556.1.6.18.1.310"
176 #define ADS_ATTR_SFU_GIDNUMBER_OID      "1.2.840.113556.1.6.18.1.311"
177 #define ADS_ATTR_SFU_HOMEDIR_OID        "1.2.840.113556.1.6.18.1.344"
178 #define ADS_ATTR_SFU_SHELL_OID          "1.2.840.113556.1.6.18.1.312"
179 #define ADS_ATTR_SFU_GECOS_OID          "1.2.840.113556.1.6.18.1.337"
180
181 /* ldap attribute oids (Services for Unix 2.0) */
182 #define ADS_ATTR_SFU20_UIDNUMBER_OID    "1.2.840.113556.1.4.7000.187.70"
183 #define ADS_ATTR_SFU20_GIDNUMBER_OID    "1.2.840.113556.1.4.7000.187.71"
184 #define ADS_ATTR_SFU20_HOMEDIR_OID      "1.2.840.113556.1.4.7000.187.106"
185 #define ADS_ATTR_SFU20_SHELL_OID        "1.2.840.113556.1.4.7000.187.72"
186 #define ADS_ATTR_SFU20_GECOS_OID        "1.2.840.113556.1.4.7000.187.97"
187
188 /* ldap attribute oids (RFC2307) */
189 #define ADS_ATTR_RFC2307_UIDNUMBER_OID  "1.3.6.1.1.1.1.0"
190 #define ADS_ATTR_RFC2307_GIDNUMBER_OID  "1.3.6.1.1.1.1.1"
191 #define ADS_ATTR_RFC2307_HOMEDIR_OID    "1.3.6.1.1.1.1.3"
192 #define ADS_ATTR_RFC2307_SHELL_OID      "1.3.6.1.1.1.1.4"
193 #define ADS_ATTR_RFC2307_GECOS_OID      "1.3.6.1.1.1.1.2"
194
195 /* ldap bitwise searches */
196 #define ADS_LDAP_MATCHING_RULE_BIT_AND  "1.2.840.113556.1.4.803"
197 #define ADS_LDAP_MATCHING_RULE_BIT_OR   "1.2.840.113556.1.4.804"
198
199 /* UserFlags for userAccountControl */
200 #define UF_SCRIPT                               0x00000001
201 #define UF_ACCOUNTDISABLE                       0x00000002
202 #define UF_UNUSED_1                             0x00000004
203 #define UF_HOMEDIR_REQUIRED                     0x00000008
204
205 #define UF_LOCKOUT                              0x00000010
206 #define UF_PASSWD_NOTREQD                       0x00000020
207 #define UF_PASSWD_CANT_CHANGE                   0x00000040
208 #define UF_ENCRYPTED_TEXT_PASSWORD_ALLOWED      0x00000080
209
210 #define UF_TEMP_DUPLICATE_ACCOUNT               0x00000100
211 #define UF_NORMAL_ACCOUNT                       0x00000200
212 #define UF_UNUSED_2                             0x00000400
213 #define UF_INTERDOMAIN_TRUST_ACCOUNT            0x00000800
214
215 #define UF_WORKSTATION_TRUST_ACCOUNT            0x00001000
216 #define UF_SERVER_TRUST_ACCOUNT                 0x00002000
217 #define UF_UNUSED_3                             0x00004000
218 #define UF_UNUSED_4                             0x00008000
219
220 #define UF_DONT_EXPIRE_PASSWD                   0x00010000
221 #define UF_MNS_LOGON_ACCOUNT                    0x00020000
222 #define UF_SMARTCARD_REQUIRED                   0x00040000
223 #define UF_TRUSTED_FOR_DELEGATION               0x00080000
224
225 #define UF_NOT_DELEGATED                        0x00100000
226 #define UF_USE_DES_KEY_ONLY                     0x00200000
227 #define UF_DONT_REQUIRE_PREAUTH                 0x00400000
228 #define UF_PASSWORD_EXPIRED                     0x00800000
229
230 #define UF_TRUSTED_TO_AUTHENTICATE_FOR_DELEGATION 0x01000000
231 #define UF_NO_AUTH_DATA_REQUIRED                0x02000000
232 #define UF_UNUSED_8                             0x04000000
233 #define UF_UNUSED_9                             0x08000000
234
235 #define UF_UNUSED_10                            0x10000000
236 #define UF_UNUSED_11                            0x20000000
237 #define UF_UNUSED_12                            0x40000000
238 #define UF_UNUSED_13                            0x80000000
239
240 #define UF_MACHINE_ACCOUNT_MASK (\
241                 UF_INTERDOMAIN_TRUST_ACCOUNT |\
242                 UF_WORKSTATION_TRUST_ACCOUNT |\
243                 UF_SERVER_TRUST_ACCOUNT \
244                 )
245
246 #define UF_ACCOUNT_TYPE_MASK (\
247                 UF_TEMP_DUPLICATE_ACCOUNT |\
248                 UF_NORMAL_ACCOUNT |\
249                 UF_INTERDOMAIN_TRUST_ACCOUNT |\
250                 UF_WORKSTATION_TRUST_ACCOUNT |\
251                 UF_SERVER_TRUST_ACCOUNT \
252                 )
253
254 #define UF_SETTABLE_BITS (\
255                 UF_SCRIPT |\
256                 UF_ACCOUNTDISABLE |\
257                 UF_HOMEDIR_REQUIRED  |\
258                 UF_LOCKOUT |\
259                 UF_PASSWD_NOTREQD |\
260                 UF_PASSWD_CANT_CHANGE |\
261                 UF_ACCOUNT_TYPE_MASK | \
262                 UF_DONT_EXPIRE_PASSWD | \
263                 UF_MNS_LOGON_ACCOUNT |\
264                 UF_ENCRYPTED_TEXT_PASSWORD_ALLOWED |\
265                 UF_SMARTCARD_REQUIRED |\
266                 UF_TRUSTED_FOR_DELEGATION |\
267                 UF_NOT_DELEGATED |\
268                 UF_USE_DES_KEY_ONLY  |\
269                 UF_DONT_REQUIRE_PREAUTH \
270                 )
271
272 /* sAMAccountType */
273 #define ATYPE_NORMAL_ACCOUNT                    0x30000000 /* 805306368 */
274 #define ATYPE_WORKSTATION_TRUST                 0x30000001 /* 805306369 */
275 #define ATYPE_INTERDOMAIN_TRUST                 0x30000002 /* 805306370 */ 
276 #define ATYPE_SECURITY_GLOBAL_GROUP             0x10000000 /* 268435456 */
277 #define ATYPE_DISTRIBUTION_GLOBAL_GROUP         0x10000001 /* 268435457 */
278 #define ATYPE_DISTRIBUTION_UNIVERSAL_GROUP      ATYPE_DISTRIBUTION_GLOBAL_GROUP
279 #define ATYPE_SECURITY_LOCAL_GROUP              0x20000000 /* 536870912 */
280 #define ATYPE_DISTRIBUTION_LOCAL_GROUP          0x20000001 /* 536870913 */
281
282 #define ATYPE_ACCOUNT           ATYPE_NORMAL_ACCOUNT            /* 0x30000000 805306368 */
283 #define ATYPE_GLOBAL_GROUP      ATYPE_SECURITY_GLOBAL_GROUP     /* 0x10000000 268435456 */
284 #define ATYPE_LOCAL_GROUP       ATYPE_SECURITY_LOCAL_GROUP      /* 0x20000000 536870912 */
285
286 /* groupType */
287 #define GROUP_TYPE_BUILTIN_LOCAL_GROUP          0x00000001
288 #define GROUP_TYPE_ACCOUNT_GROUP                0x00000002
289 #define GROUP_TYPE_RESOURCE_GROUP               0x00000004
290 #define GROUP_TYPE_UNIVERSAL_GROUP              0x00000008
291 #define GROUP_TYPE_APP_BASIC_GROUP              0x00000010
292 #define GROUP_TYPE_APP_QUERY_GROUP              0x00000020
293 #define GROUP_TYPE_SECURITY_ENABLED             0x80000000
294
295 #define GTYPE_SECURITY_BUILTIN_LOCAL_GROUP (    /* 0x80000005 -2147483643 */ \
296                 GROUP_TYPE_BUILTIN_LOCAL_GROUP| \
297                 GROUP_TYPE_RESOURCE_GROUP| \
298                 GROUP_TYPE_SECURITY_ENABLED \
299                 )
300 #define GTYPE_SECURITY_DOMAIN_LOCAL_GROUP (     /* 0x80000004 -2147483644 */ \
301                 GROUP_TYPE_RESOURCE_GROUP| \
302                 GROUP_TYPE_SECURITY_ENABLED \
303                 )
304 #define GTYPE_SECURITY_GLOBAL_GROUP (           /* 0x80000002 -2147483646 */ \
305                 GROUP_TYPE_ACCOUNT_GROUP| \
306                 GROUP_TYPE_SECURITY_ENABLED \
307                 )
308 #define GTYPE_SECURITY_UNIVERSAL_GROUP (        /* 0x80000008 -2147483656 */ \
309                 GROUP_TYPE_UNIVERSAL_GROUP| \
310                 GROUP_TYPE_SECURITY_ENABLED \
311                 )
312
313 #define GTYPE_DISTRIBUTION_GLOBAL_GROUP         0x00000002      /* 2 */
314 #define GTYPE_DISTRIBUTION_DOMAIN_LOCAL_GROUP   0x00000004      /* 4 */
315 #define GTYPE_DISTRIBUTION_UNIVERSAL_GROUP      0x00000008      /* 8 */
316
317 #define ADS_PINGS          0x0000FFFF  /* Ping response */
318 #define ADS_DNS_CONTROLLER 0x20000000  /* DomainControllerName is a DNS name*/
319 #define ADS_DNS_DOMAIN     0x40000000  /* DomainName is a DNS name */
320 #define ADS_DNS_FOREST     0x80000000  /* DnsForestName is a DNS name */
321
322 /* DomainControllerAddressType */
323 #define ADS_INET_ADDRESS      0x00000001
324 #define ADS_NETBIOS_ADDRESS   0x00000002
325
326
327 /* ads auth control flags */
328 #define ADS_AUTH_DISABLE_KERBEROS 0x01
329 #define ADS_AUTH_NO_BIND          0x02
330 #define ADS_AUTH_ANON_BIND        0x04
331 #define ADS_AUTH_SIMPLE_BIND      0x08
332 #define ADS_AUTH_ALLOW_NTLMSSP    0x10
333 #define ADS_AUTH_SASL_SIGN        0x20
334 #define ADS_AUTH_SASL_SEAL        0x40
335 #define ADS_AUTH_SASL_FORCE       0x80
336
337 /* Kerberos environment variable names */
338 #define KRB5_ENV_CCNAME "KRB5CCNAME"
339
340 /* Heimdal uses a slightly different name */
341 #if defined(HAVE_ENCTYPE_ARCFOUR_HMAC_MD5)
342 #define ENCTYPE_ARCFOUR_HMAC ENCTYPE_ARCFOUR_HMAC_MD5
343 #endif
344
345 /* The older versions of heimdal that don't have this
346    define don't seem to use it anyway.  I'm told they
347    always use a subkey */
348 #ifndef HAVE_AP_OPTS_USE_SUBKEY
349 #define AP_OPTS_USE_SUBKEY 0
350 #endif
351
352 #define WELL_KNOWN_GUID_COMPUTERS       "AA312825768811D1ADED00C04FD8D5CD" 
353 #define WELL_KNOWN_GUID_USERS           "A9D1CA15768811D1ADED00C04FD8D5CD"
354
355 #ifndef KRB5_ADDR_NETBIOS
356 #define KRB5_ADDR_NETBIOS 0x14
357 #endif
358
359 #ifndef KRB5KRB_ERR_RESPONSE_TOO_BIG
360 #define KRB5KRB_ERR_RESPONSE_TOO_BIG (-1765328332L)
361 #endif
362
363 #ifdef HAVE_KRB5
364 typedef struct {
365         NTSTATUS ntstatus;
366         uint32 unknown1;
367         uint32 unknown2; /* 0x00000001 */
368 } KRB5_EDATA_NTSTATUS;
369
370 typedef struct {
371 #if defined(HAVE_MAGIC_IN_KRB5_ADDRESS) && defined(HAVE_ADDRTYPE_IN_KRB5_ADDRESS) /* MIT */
372         krb5_address **addrs;
373 #elif defined(HAVE_KRB5_ADDRESSES) /* Heimdal */
374         krb5_addresses *addrs;
375 #else
376 #error UNKNOWN_KRB5_ADDRESS_TYPE
377 #endif
378 } smb_krb5_addresses;
379 #endif
380
381 enum ads_extended_dn_flags {
382         ADS_EXTENDED_DN_HEX_STRING      = 0,
383         ADS_EXTENDED_DN_STRING          = 1 /* not supported on win2k */
384 };
385
386 /* this is probably not very well suited to pass other controls generically but
387  * is good enough for the extended dn control where it is only used for atm */
388
389 typedef struct {
390         const char *control;
391         int val;
392         int critical;
393 } ads_control;
394
395 #define ADS_EXTENDED_RIGHT_APPLY_GROUP_POLICY "edacfd8f-ffb3-11d1-b41d-00a0c968f939"
396
397 #define ADS_IGNORE_PRINCIPAL "not_defined_in_RFC4178@please_ignore"
398
399 /* Settings for the domainFunctionality attribute in the rootDSE */
400
401 #define DS_DOMAIN_FUNCTION_2000         0
402 #define DS_DOMAIN_FUCNTION_2003_MIXED   1
403 #define DS_DOMAIN_FUNCTION_2003         2
404 #define DS_DOMAIN_FUNCTION_2008         3
405
406 #endif  /* _INCLUDE_ADS_H_ */