r7994: This adds support in Winbindd's "security = ads"-mode to retrieve the POSIX
[kai/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                 time_t expire;
33         } auth;
34
35         /* info derived from the servers config */
36         struct {
37                 char *realm;
38                 char *bind_path;
39                 char *schema_path;
40                 char *ldap_server_name;
41                 time_t current_time;
42         } config;
43
44         /* info derived from the servers schema */
45         struct {
46                 char *sfu_homedir_attr;
47                 char *sfu_shell_attr;
48                 char *sfu_uidnumber_attr;
49                 char *sfu_gidnumber_attr;
50         } schema;
51
52 } ADS_STRUCT;
53
54 /* there are 5 possible types of errors the ads subsystem can produce */
55 enum ads_error_type {ENUM_ADS_ERROR_KRB5, ENUM_ADS_ERROR_GSS, 
56                      ENUM_ADS_ERROR_LDAP, ENUM_ADS_ERROR_SYSTEM, ENUM_ADS_ERROR_NT};
57
58 typedef struct {
59         enum ads_error_type error_type;
60         union err_state{                
61                 int rc;
62                 NTSTATUS nt_status;
63         } err;
64         /* For error_type = ENUM_ADS_ERROR_GSS minor_status describe GSS API error */
65         /* Where rc represents major_status of GSS API error */
66         int minor_status;
67 } ADS_STATUS;
68
69 #ifdef HAVE_ADS
70 typedef LDAPMod **ADS_MODLIST;
71 #else
72 typedef void **ADS_MODLIST;
73 #endif
74
75 /* macros to simplify error returning */
76 #define ADS_ERROR(rc) ADS_ERROR_LDAP(rc)
77 #define ADS_ERROR_LDAP(rc) ads_build_error(ENUM_ADS_ERROR_LDAP, rc, 0)
78 #define ADS_ERROR_SYSTEM(rc) ads_build_error(ENUM_ADS_ERROR_SYSTEM, rc?rc:EINVAL, 0)
79 #define ADS_ERROR_KRB5(rc) ads_build_error(ENUM_ADS_ERROR_KRB5, rc, 0)
80 #define ADS_ERROR_GSS(rc, minor) ads_build_error(ENUM_ADS_ERROR_GSS, rc, minor)
81 #define ADS_ERROR_NT(rc) ads_build_nt_error(ENUM_ADS_ERROR_NT,rc)
82
83 #define ADS_ERR_OK(status) ((status.error_type == ENUM_ADS_ERROR_NT) ? NT_STATUS_IS_OK(status.err.nt_status):(status.err.rc == 0))
84 #define ADS_SUCCESS ADS_ERROR(0)
85
86 /* time between reconnect attempts */
87 #define ADS_RECONNECT_TIME 5
88
89 /* ldap control oids */
90 #define ADS_PAGE_CTL_OID        "1.2.840.113556.1.4.319"
91 #define ADS_NO_REFERRALS_OID    "1.2.840.113556.1.4.1339"
92 #define ADS_SERVER_SORT_OID     "1.2.840.113556.1.4.473"
93 #define ADS_PERMIT_MODIFY_OID   "1.2.840.113556.1.4.1413"
94
95 /* ldap attribute oids (Services for Unix) */
96 #define ADS_ATTR_SFU_UIDNUMBER_OID      "1.2.840.113556.1.6.18.1.310"
97 #define ADS_ATTR_SFU_GIDNUMBER_OID      "1.2.840.113556.1.6.18.1.311"
98 #define ADS_ATTR_SFU_HOMEDIR_OID        "1.2.840.113556.1.6.18.1.344"
99 #define ADS_ATTR_SFU_SHELL_OID          "1.2.840.113556.1.6.18.1.312"
100
101 /* UserFlags for userAccountControl */
102 #define UF_SCRIPT                               0x00000001
103 #define UF_ACCOUNTDISABLE                       0x00000002
104 #define UF_UNUSED_1                             0x00000004
105 #define UF_HOMEDIR_REQUIRED                     0x00000008
106
107 #define UF_LOCKOUT                              0x00000010
108 #define UF_PASSWD_NOTREQD                       0x00000020
109 #define UF_PASSWD_CANT_CHANGE                   0x00000040
110 #define UF_ENCRYPTED_TEXT_PASSWORD_ALLOWED      0x00000080
111
112 #define UF_TEMP_DUPLICATE_ACCOUNT               0x00000100
113 #define UF_NORMAL_ACCOUNT                       0x00000200
114 #define UF_UNUSED_2                             0x00000400
115 #define UF_INTERDOMAIN_TRUST_ACCOUNT            0x00000800
116
117 #define UF_WORKSTATION_TRUST_ACCOUNT            0x00001000
118 #define UF_SERVER_TRUST_ACCOUNT                 0x00002000
119 #define UF_UNUSED_3                             0x00004000
120 #define UF_UNUSED_4                             0x00008000
121
122 #define UF_DONT_EXPIRE_PASSWD                   0x00010000
123 #define UF_MNS_LOGON_ACCOUNT                    0x00020000
124 #define UF_SMARTCARD_REQUIRED                   0x00040000
125 #define UF_TRUSTED_FOR_DELEGATION               0x00080000
126
127 #define UF_NOT_DELEGATED                        0x00100000
128 #define UF_USE_DES_KEY_ONLY                     0x00200000
129 #define UF_DONT_REQUIRE_PREAUTH                 0x00400000
130 #define UF_UNUSED_5                             0x00800000
131
132 #define UF_UNUSED_6                             0x01000000
133 #define UF_UNUSED_7                             0x02000000
134 #define UF_UNUSED_8                             0x04000000
135 #define UF_UNUSED_9                             0x08000000
136
137 #define UF_UNUSED_10                            0x10000000
138 #define UF_UNUSED_11                            0x20000000
139 #define UF_UNUSED_12                            0x40000000
140 #define UF_UNUSED_13                            0x80000000
141
142 #define UF_MACHINE_ACCOUNT_MASK (\
143                 UF_INTERDOMAIN_TRUST_ACCOUNT |\
144                 UF_WORKSTATION_TRUST_ACCOUNT |\
145                 UF_SERVER_TRUST_ACCOUNT \
146                 )
147
148 #define UF_ACCOUNT_TYPE_MASK (\
149                 UF_TEMP_DUPLICATE_ACCOUNT |\
150                 UF_NORMAL_ACCOUNT |\
151                 UF_INTERDOMAIN_TRUST_ACCOUNT |\
152                 UF_WORKSTATION_TRUST_ACCOUNT |\
153                 UF_SERVER_TRUST_ACCOUNT \
154                 )
155
156 #define UF_SETTABLE_BITS (\
157                 UF_SCRIPT |\
158                 UF_ACCOUNTDISABLE |\
159                 UF_HOMEDIR_REQUIRED  |\
160                 UF_LOCKOUT |\
161                 UF_PASSWD_NOTREQD |\
162                 UF_PASSWD_CANT_CHANGE |\
163                 UF_ACCOUNT_TYPE_MASK | \
164                 UF_DONT_EXPIRE_PASSWD | \
165                 UF_MNS_LOGON_ACCOUNT |\
166                 UF_ENCRYPTED_TEXT_PASSWORD_ALLOWED |\
167                 UF_SMARTCARD_REQUIRED |\
168                 UF_TRUSTED_FOR_DELEGATION |\
169                 UF_NOT_DELEGATED |\
170                 UF_USE_DES_KEY_ONLY  |\
171                 UF_DONT_REQUIRE_PREAUTH \
172                 )
173
174 /* sAMAccountType */
175 #define ATYPE_NORMAL_ACCOUNT                    0x30000000 /* 805306368 */
176 #define ATYPE_WORKSTATION_TRUST                 0x30000001 /* 805306369 */
177 #define ATYPE_INTERDOMAIN_TRUST                 0x30000002 /* 805306370 */ 
178 #define ATYPE_SECURITY_GLOBAL_GROUP             0x10000000 /* 268435456 */
179 #define ATYPE_DISTRIBUTION_GLOBAL_GROUP         0x10000001 /* 268435457 */
180 #define ATYPE_DISTRIBUTION_UNIVERSAL_GROUP      ATYPE_DISTRIBUTION_GLOBAL_GROUP
181 #define ATYPE_SECURITY_LOCAL_GROUP              0x20000000 /* 536870912 */
182 #define ATYPE_DISTRIBUTION_LOCAL_GROUP          0x20000001 /* 536870913 */
183
184 #define ATYPE_ACCOUNT           ATYPE_NORMAL_ACCOUNT            /* 0x30000000 805306368 */
185 #define ATYPE_GLOBAL_GROUP      ATYPE_SECURITY_GLOBAL_GROUP     /* 0x10000000 268435456 */
186 #define ATYPE_LOCAL_GROUP       ATYPE_SECURITY_LOCAL_GROUP      /* 0x20000000 536870912 */
187
188 /* groupType */
189 #define GTYPE_SECURITY_BUILTIN_LOCAL_GROUP      0x80000005      /* -2147483643 */
190 #define GTYPE_SECURITY_DOMAIN_LOCAL_GROUP       0x80000004      /* -2147483644 */
191 #define GTYPE_SECURITY_GLOBAL_GROUP             0x80000002      /* -2147483646 */
192 #define GTYPE_DISTRIBUTION_GLOBAL_GROUP         0x00000002      /* 2 */
193 #define GTYPE_DISTRIBUTION_DOMAIN_LOCAL_GROUP   0x00000004      /* 4 */
194 #define GTYPE_DISTRIBUTION_UNIVERSAL_GROUP      0x00000008      /* 8 */
195
196 /* Mailslot or cldap getdcname response flags */
197 #define ADS_PDC            0x00000001  /* DC is PDC */
198 #define ADS_GC             0x00000004  /* DC is a GC of forest */
199 #define ADS_LDAP           0x00000008  /* DC is an LDAP server */
200 #define ADS_DS             0x00000010  /* DC supports DS */
201 #define ADS_KDC            0x00000020  /* DC is running KDC */
202 #define ADS_TIMESERV       0x00000040  /* DC is running time services */
203 #define ADS_CLOSEST        0x00000080  /* DC is closest to client */
204 #define ADS_WRITABLE       0x00000100  /* DC has writable DS */
205 #define ADS_GOOD_TIMESERV  0x00000200  /* DC has hardware clock
206                                          (and running time) */
207 #define ADS_NDNC           0x00000400  /* DomainName is non-domain NC serviced
208                                          by LDAP server */
209 #define ADS_PINGS          0x0000FFFF  /* Ping response */
210 #define ADS_DNS_CONTROLLER 0x20000000  /* DomainControllerName is a DNS name*/
211 #define ADS_DNS_DOMAIN     0x40000000  /* DomainName is a DNS name */
212 #define ADS_DNS_FOREST     0x80000000  /* DnsForestName is a DNS name */
213
214 /* DomainCntrollerAddressType */
215 #define ADS_INET_ADDRESS      0x00000001
216 #define ADS_NETBIOS_ADDRESS   0x00000002
217
218
219 /* ads auth control flags */
220 #define ADS_AUTH_DISABLE_KERBEROS 0x01
221 #define ADS_AUTH_NO_BIND          0x02
222 #define ADS_AUTH_ANON_BIND        0x04
223 #define ADS_AUTH_SIMPLE_BIND      0x08
224 #define ADS_AUTH_ALLOW_NTLMSSP    0x10
225
226 /* Kerberos environment variable names */
227 #define KRB5_ENV_CCNAME "KRB5CCNAME"
228
229 /* Heimdal uses a slightly different name */
230 #if defined(HAVE_ENCTYPE_ARCFOUR_HMAC_MD5)
231 #define ENCTYPE_ARCFOUR_HMAC ENCTYPE_ARCFOUR_HMAC_MD5
232 #endif
233
234 /* The older versions of heimdal that don't have this
235    define don't seem to use it anyway.  I'm told they
236    always use a subkey */
237 #ifndef HAVE_AP_OPTS_USE_SUBKEY
238 #define AP_OPTS_USE_SUBKEY 0
239 #endif
240
241 #define WELL_KNOWN_GUID_COMPUTERS       "AA312825768811D1ADED00C04FD8D5CD" 
242 #define WELL_KNOWN_GUID_USERS           "A9D1CA15768811D1ADED00C04FD8D5CD"