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