bug 1195: add flag to ADS_STRUCT so we know who owns the main structure's memory...
[samba.git] / source3 / include / ads.h
1 /*
2   header for ads (active directory) library routines
3
4   basically this is a wrapper around ldap
5 */
6
7 typedef struct {
8         void *ld; /* the active ldap structure */
9         struct in_addr ldap_ip; /* the ip of the active connection, if any */
10         time_t last_attempt; /* last attempt to reconnect */
11         int ldap_port;
12         
13         int is_mine;    /* do I own this structure's memory? */
14         
15         /* info needed to find the server */
16         struct {
17                 char *realm;
18                 char *workgroup;
19                 char *ldap_server;
20                 char *ldap_uri;
21                 int foreign; /* set to 1 if connecting to a foreign realm */
22         } server;
23
24         /* info needed to authenticate */
25         struct {
26                 char *realm;
27                 char *password;
28                 char *user_name;
29                 char *kdc_server;
30                 unsigned flags;
31                 int time_offset;
32         } auth;
33
34         /* info derived from the servers config */
35         struct {
36                 char *realm;
37                 char *bind_path;
38                 char *ldap_server_name;
39                 time_t current_time;
40         } config;
41 } ADS_STRUCT;
42
43 /* there are 5 possible types of errors the ads subsystem can produce */
44 enum ads_error_type {ENUM_ADS_ERROR_KRB5, ENUM_ADS_ERROR_GSS, 
45                      ENUM_ADS_ERROR_LDAP, ENUM_ADS_ERROR_SYSTEM, ENUM_ADS_ERROR_NT};
46
47 typedef struct {
48         enum ads_error_type error_type;
49         union err_state{                
50                 int rc;
51                 NTSTATUS nt_status;
52         } err;
53         /* For error_type = ENUM_ADS_ERROR_GSS minor_status describe GSS API error */
54         /* Where rc represents major_status of GSS API error */
55         int minor_status;
56 } ADS_STATUS;
57
58 #ifdef HAVE_ADS
59 typedef LDAPMod **ADS_MODLIST;
60 #else
61 typedef void **ADS_MODLIST;
62 #endif
63
64 /* macros to simplify error returning */
65 #define ADS_ERROR(rc) ADS_ERROR_LDAP(rc)
66 #define ADS_ERROR_LDAP(rc) ads_build_error(ENUM_ADS_ERROR_LDAP, rc, 0)
67 #define ADS_ERROR_SYSTEM(rc) ads_build_error(ENUM_ADS_ERROR_SYSTEM, rc?rc:EINVAL, 0)
68 #define ADS_ERROR_KRB5(rc) ads_build_error(ENUM_ADS_ERROR_KRB5, rc, 0)
69 #define ADS_ERROR_GSS(rc, minor) ads_build_error(ENUM_ADS_ERROR_GSS, rc, minor)
70 #define ADS_ERROR_NT(rc) ads_build_nt_error(ENUM_ADS_ERROR_NT,rc)
71
72 #define ADS_ERR_OK(status) ((status.error_type == ENUM_ADS_ERROR_NT) ? NT_STATUS_IS_OK(status.err.nt_status):(status.err.rc == 0))
73 #define ADS_SUCCESS ADS_ERROR(0)
74
75 /* time between reconnect attempts */
76 #define ADS_RECONNECT_TIME 5
77
78 /* timeout on searches */
79 #define ADS_SEARCH_TIMEOUT 10
80
81 /* ldap control oids */
82 #define ADS_PAGE_CTL_OID "1.2.840.113556.1.4.319"
83 #define ADS_NO_REFERRALS_OID "1.2.840.113556.1.4.1339"
84 #define ADS_SERVER_SORT_OID "1.2.840.113556.1.4.473"
85 #define ADS_PERMIT_MODIFY_OID "1.2.840.113556.1.4.1413"
86
87 /* UserFlags for userAccountControl */
88 #define UF_SCRIPT                               0x00000001
89 #define UF_ACCOUNTDISABLE                       0x00000002
90 #define UF_UNUSED_1                             0x00000004
91 #define UF_HOMEDIR_REQUIRED                     0x00000008
92
93 #define UF_LOCKOUT                              0x00000010
94 #define UF_PASSWD_NOTREQD                       0x00000020
95 #define UF_PASSWD_CANT_CHANGE                   0x00000040
96 #define UF_ENCRYPTED_TEXT_PASSWORD_ALLOWED      0x00000080
97
98 #define UF_TEMP_DUPLICATE_ACCOUNT               0x00000100
99 #define UF_NORMAL_ACCOUNT                       0x00000200
100 #define UF_UNUSED_2                             0x00000400
101 #define UF_INTERDOMAIN_TRUST_ACCOUNT            0x00000800
102
103 #define UF_WORKSTATION_TRUST_ACCOUNT            0x00001000
104 #define UF_SERVER_TRUST_ACCOUNT                 0x00002000
105 #define UF_UNUSED_3                             0x00004000
106 #define UF_UNUSED_4                             0x00008000
107
108 #define UF_DONT_EXPIRE_PASSWD                   0x00010000
109 #define UF_MNS_LOGON_ACCOUNT                    0x00020000
110 #define UF_SMARTCARD_REQUIRED                   0x00040000
111 #define UF_TRUSTED_FOR_DELEGATION               0x00080000
112
113 #define UF_NOT_DELEGATED                        0x00100000
114 #define UF_USE_DES_KEY_ONLY                     0x00200000
115 #define UF_DONT_REQUIRE_PREAUTH                 0x00400000
116 #define UF_UNUSED_5                             0x00800000
117
118 #define UF_UNUSED_6                             0x01000000
119 #define UF_UNUSED_7                             0x02000000
120 #define UF_UNUSED_8                             0x04000000
121 #define UF_UNUSED_9                             0x08000000
122
123 #define UF_UNUSED_10                            0x10000000
124 #define UF_UNUSED_11                            0x20000000
125 #define UF_UNUSED_12                            0x40000000
126 #define UF_UNUSED_13                            0x80000000
127
128 #define UF_MACHINE_ACCOUNT_MASK (\
129                 UF_INTERDOMAIN_TRUST_ACCOUNT |\
130                 UF_WORKSTATION_TRUST_ACCOUNT |\
131                 UF_SERVER_TRUST_ACCOUNT \
132                 )
133
134 #define UF_ACCOUNT_TYPE_MASK (\
135                 UF_TEMP_DUPLICATE_ACCOUNT |\
136                 UF_NORMAL_ACCOUNT |\
137                 UF_INTERDOMAIN_TRUST_ACCOUNT |\
138                 UF_WORKSTATION_TRUST_ACCOUNT |\
139                 UF_SERVER_TRUST_ACCOUNT \
140                 )
141
142 #define UF_SETTABLE_BITS (\
143                 UF_SCRIPT |\
144                 UF_ACCOUNTDISABLE |\
145                 UF_HOMEDIR_REQUIRED  |\
146                 UF_LOCKOUT |\
147                 UF_PASSWD_NOTREQD |\
148                 UF_PASSWD_CANT_CHANGE |\
149                 UF_ACCOUNT_TYPE_MASK | \
150                 UF_DONT_EXPIRE_PASSWD | \
151                 UF_MNS_LOGON_ACCOUNT |\
152                 UF_ENCRYPTED_TEXT_PASSWORD_ALLOWED |\
153                 UF_SMARTCARD_REQUIRED |\
154                 UF_TRUSTED_FOR_DELEGATION |\
155                 UF_NOT_DELEGATED |\
156                 UF_USE_DES_KEY_ONLY  |\
157                 UF_DONT_REQUIRE_PREAUTH \
158                 )
159
160 /* sAMAccountType */
161 #define ATYPE_NORMAL_ACCOUNT                    0x30000000 /* 805306368 */
162 #define ATYPE_WORKSTATION_TRUST                 0x30000001 /* 805306369 */
163 #define ATYPE_INTERDOMAIN_TRUST                 0x30000002 /* 805306370 */ 
164 #define ATYPE_SECURITY_GLOBAL_GROUP             0x10000000 /* 268435456 */
165 #define ATYPE_DISTRIBUTION_GLOBAL_GROUP         0x10000001 /* 268435457 */
166 #define ATYPE_DISTRIBUTION_UNIVERSAL_GROUP      ATYPE_DISTRIBUTION_GLOBAL_GROUP
167 #define ATYPE_SECURITY_LOCAL_GROUP              0x20000000 /* 536870912 */
168 #define ATYPE_DISTRIBUTION_LOCAL_GROUP          0x20000001 /* 536870913 */
169
170 #define ATYPE_ACCOUNT           ATYPE_NORMAL_ACCOUNT            /* 0x30000000 805306368 */
171 #define ATYPE_GLOBAL_GROUP      ATYPE_SECURITY_GLOBAL_GROUP     /* 0x10000000 268435456 */
172 #define ATYPE_LOCAL_GROUP       ATYPE_SECURITY_LOCAL_GROUP      /* 0x20000000 536870912 */
173
174 /* groupType */
175 #define GTYPE_SECURITY_BUILTIN_LOCAL_GROUP      0x80000005      /* -2147483643 */
176 #define GTYPE_SECURITY_DOMAIN_LOCAL_GROUP       0x80000004      /* -2147483644 */
177 #define GTYPE_SECURITY_GLOBAL_GROUP             0x80000002      /* -2147483646 */
178 #define GTYPE_DISTRIBUTION_GLOBAL_GROUP         0x00000002      /* 2 */
179 #define GTYPE_DISTRIBUTION_DOMAIN_LOCAL_GROUP   0x00000004      /* 4 */
180 #define GTYPE_DISTRIBUTION_UNIVERSAL_GROUP      0x00000008      /* 8 */
181
182 /* Mailslot or cldap getdcname response flags */
183 #define ADS_PDC            0x00000001  /* DC is PDC */
184 #define ADS_GC             0x00000004  /* DC is a GC of forest */
185 #define ADS_LDAP           0x00000008  /* DC is an LDAP server */
186 #define ADS_DS             0x00000010  /* DC supports DS */
187 #define ADS_KDC            0x00000020  /* DC is running KDC */
188 #define ADS_TIMESERV       0x00000040  /* DC is running time services */
189 #define ADS_CLOSEST        0x00000080  /* DC is closest to client */
190 #define ADS_WRITABLE       0x00000100  /* DC has writable DS */
191 #define ADS_GOOD_TIMESERV  0x00000200  /* DC has hardware clock
192                                          (and running time) */
193 #define ADS_NDNC           0x00000400  /* DomainName is non-domain NC serviced
194                                          by LDAP server */
195 #define ADS_PINGS          0x0000FFFF  /* Ping response */
196 #define ADS_DNS_CONTROLLER 0x20000000  /* DomainControllerName is a DNS name*/
197 #define ADS_DNS_DOMAIN     0x40000000  /* DomainName is a DNS name */
198 #define ADS_DNS_FOREST     0x80000000  /* DnsForestName is a DNS name */
199
200 /* DomainCntrollerAddressType */
201 #define ADS_INET_ADDRESS      0x00000001
202 #define ADS_NETBIOS_ADDRESS   0x00000002
203
204
205 /* ads auth control flags */
206 #define ADS_AUTH_DISABLE_KERBEROS 0x01
207 #define ADS_AUTH_NO_BIND          0x02
208 #define ADS_AUTH_ANON_BIND        0x04
209 #define ADS_AUTH_SIMPLE_BIND      0x08
210 #define ADS_AUTH_ALLOW_NTLMSSP    0x10
211
212 /* Kerberos environment variable names */
213 #define KRB5_ENV_CCNAME "KRB5CCNAME"
214
215 /* Heimdal uses a slightly different name */
216 #if defined(HAVE_ENCTYPE_ARCFOUR_HMAC_MD5)
217 #define ENCTYPE_ARCFOUR_HMAC ENCTYPE_ARCFOUR_HMAC_MD5
218 #endif
219
220 /* The older versions of heimdal that don't have this
221    define don't seem to use it anyway.  I'm told they
222    always use a subkey */
223 #ifndef HAVE_AP_OPTS_USE_SUBKEY
224 #define AP_OPTS_USE_SUBKEY 0
225 #endif