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