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