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