2 Unix SMB/CIFS implementation.
3 header for ads (active directory) library routines
4 basically this is a wrapper around ldap
6 Copyright (C) Andrew Tridgell 2001-2003
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
27 void *ld; /* the active ldap structure */
28 struct in_addr ldap_ip; /* the ip of the active connection, if any */
29 time_t last_attempt; /* last attempt to reconnect */
32 /* info needed to find the server */
38 int foreign; /* set to 1 if connecting to a foreign realm */
41 /* info needed to authenticate */
51 /* info derived from the servers config */
55 char *ldap_server_name;
60 /* there are 5 possible types of errors the ads subsystem can produce */
61 enum ads_error_type {ENUM_ADS_ERROR_KRB5, ENUM_ADS_ERROR_GSS,
62 ENUM_ADS_ERROR_LDAP, ENUM_ADS_ERROR_SYSTEM, ENUM_ADS_ERROR_NT};
65 enum ads_error_type error_type;
70 /* For error_type = ENUM_ADS_ERROR_GSS minor_status describe GSS API error */
71 /* Where rc represents major_status of GSS API error */
76 typedef LDAPMod **ADS_MODLIST;
78 typedef void **ADS_MODLIST;
81 /* macros to simplify error returning */
82 #define ADS_ERROR(rc) ADS_ERROR_LDAP(rc)
83 #define ADS_ERROR_LDAP(rc) ads_build_error(ENUM_ADS_ERROR_LDAP, rc, 0)
84 #define ADS_ERROR_SYSTEM(rc) ads_build_error(ENUM_ADS_ERROR_SYSTEM, rc?rc:EINVAL, 0)
85 #define ADS_ERROR_KRB5(rc) ads_build_error(ENUM_ADS_ERROR_KRB5, rc, 0)
86 #define ADS_ERROR_GSS(rc, minor) ads_build_error(ENUM_ADS_ERROR_GSS, rc, minor)
87 #define ADS_ERROR_NT(rc) ads_build_nt_error(ENUM_ADS_ERROR_NT,rc)
89 #define ADS_ERR_OK(status) ((status.error_type == ENUM_ADS_ERROR_NT) ? NT_STATUS_IS_OK(status.err.nt_status):(status.err.rc == 0))
90 #define ADS_SUCCESS ADS_ERROR(0)
92 /* time between reconnect attempts */
93 #define ADS_RECONNECT_TIME 5
95 /* timeout on searches */
96 #define ADS_SEARCH_TIMEOUT 10
98 /* ldap control oids */
99 #define ADS_PAGE_CTL_OID "1.2.840.113556.1.4.319"
100 #define ADS_NO_REFERRALS_OID "1.2.840.113556.1.4.1339"
101 #define ADS_SERVER_SORT_OID "1.2.840.113556.1.4.473"
102 #define ADS_PERMIT_MODIFY_OID "1.2.840.113556.1.4.1413"
104 /* UserFlags for userAccountControl */
105 #define UF_SCRIPT 0x00000001
106 #define UF_ACCOUNTDISABLE 0x00000002
107 #define UF_UNUSED_1 0x00000004
108 #define UF_HOMEDIR_REQUIRED 0x00000008
110 #define UF_LOCKOUT 0x00000010
111 #define UF_PASSWD_NOTREQD 0x00000020
112 #define UF_PASSWD_CANT_CHANGE 0x00000040
113 #define UF_ENCRYPTED_TEXT_PASSWORD_ALLOWED 0x00000080
115 #define UF_TEMP_DUPLICATE_ACCOUNT 0x00000100
116 #define UF_NORMAL_ACCOUNT 0x00000200
117 #define UF_UNUSED_2 0x00000400
118 #define UF_INTERDOMAIN_TRUST_ACCOUNT 0x00000800
120 #define UF_WORKSTATION_TRUST_ACCOUNT 0x00001000
121 #define UF_SERVER_TRUST_ACCOUNT 0x00002000
122 #define UF_UNUSED_3 0x00004000
123 #define UF_UNUSED_4 0x00008000
125 #define UF_DONT_EXPIRE_PASSWD 0x00010000
126 #define UF_MNS_LOGON_ACCOUNT 0x00020000
127 #define UF_SMARTCARD_REQUIRED 0x00040000
128 #define UF_TRUSTED_FOR_DELEGATION 0x00080000
130 #define UF_NOT_DELEGATED 0x00100000
131 #define UF_USE_DES_KEY_ONLY 0x00200000
132 #define UF_DONT_REQUIRE_PREAUTH 0x00400000
133 #define UF_UNUSED_5 0x00800000
135 #define UF_UNUSED_6 0x01000000
136 #define UF_UNUSED_7 0x02000000
137 #define UF_UNUSED_8 0x04000000
138 #define UF_UNUSED_9 0x08000000
140 #define UF_UNUSED_10 0x10000000
141 #define UF_UNUSED_11 0x20000000
142 #define UF_UNUSED_12 0x40000000
143 #define UF_UNUSED_13 0x80000000
145 #define UF_MACHINE_ACCOUNT_MASK (\
146 UF_INTERDOMAIN_TRUST_ACCOUNT |\
147 UF_WORKSTATION_TRUST_ACCOUNT |\
148 UF_SERVER_TRUST_ACCOUNT \
151 #define UF_ACCOUNT_TYPE_MASK (\
152 UF_TEMP_DUPLICATE_ACCOUNT |\
154 UF_INTERDOMAIN_TRUST_ACCOUNT |\
155 UF_WORKSTATION_TRUST_ACCOUNT |\
156 UF_SERVER_TRUST_ACCOUNT \
159 #define UF_SETTABLE_BITS (\
162 UF_HOMEDIR_REQUIRED |\
165 UF_PASSWD_CANT_CHANGE |\
166 UF_ACCOUNT_TYPE_MASK | \
167 UF_DONT_EXPIRE_PASSWD | \
168 UF_MNS_LOGON_ACCOUNT |\
169 UF_ENCRYPTED_TEXT_PASSWORD_ALLOWED |\
170 UF_SMARTCARD_REQUIRED |\
171 UF_TRUSTED_FOR_DELEGATION |\
173 UF_USE_DES_KEY_ONLY |\
174 UF_DONT_REQUIRE_PREAUTH \
178 #define ATYPE_NORMAL_ACCOUNT 0x30000000 /* 805306368 */
179 #define ATYPE_WORKSTATION_TRUST 0x30000001 /* 805306369 */
180 #define ATYPE_INTERDOMAIN_TRUST 0x30000002 /* 805306370 */
181 #define ATYPE_SECURITY_GLOBAL_GROUP 0x10000000 /* 268435456 */
182 #define ATYPE_DISTRIBUTION_GLOBAL_GROUP 0x10000001 /* 268435457 */
183 #define ATYPE_DISTRIBUTION_UNIVERSAL_GROUP ATYPE_DISTRIBUTION_GLOBAL_GROUP
184 #define ATYPE_SECURITY_LOCAL_GROUP 0x20000000 /* 536870912 */
185 #define ATYPE_DISTRIBUTION_LOCAL_GROUP 0x20000001 /* 536870913 */
187 #define ATYPE_ACCOUNT ATYPE_NORMAL_ACCOUNT /* 0x30000000 805306368 */
188 #define ATYPE_GLOBAL_GROUP ATYPE_SECURITY_GLOBAL_GROUP /* 0x10000000 268435456 */
189 #define ATYPE_LOCAL_GROUP ATYPE_SECURITY_LOCAL_GROUP /* 0x20000000 536870912 */
192 #define GTYPE_SECURITY_BUILTIN_LOCAL_GROUP 0x80000005 /* -2147483643 */
193 #define GTYPE_SECURITY_DOMAIN_LOCAL_GROUP 0x80000004 /* -2147483644 */
194 #define GTYPE_SECURITY_GLOBAL_GROUP 0x80000002 /* -2147483646 */
195 #define GTYPE_DISTRIBUTION_GLOBAL_GROUP 0x00000002 /* 2 */
196 #define GTYPE_DISTRIBUTION_DOMAIN_LOCAL_GROUP 0x00000004 /* 4 */
197 #define GTYPE_DISTRIBUTION_UNIVERSAL_GROUP 0x00000008 /* 8 */
199 /* Mailslot or cldap getdcname response flags */
200 #define ADS_PDC 0x00000001 /* DC is PDC */
201 #define ADS_GC 0x00000004 /* DC is a GC of forest */
202 #define ADS_LDAP 0x00000008 /* DC is an LDAP server */
203 #define ADS_DS 0x00000010 /* DC supports DS */
204 #define ADS_KDC 0x00000020 /* DC is running KDC */
205 #define ADS_TIMESERV 0x00000040 /* DC is running time services */
206 #define ADS_CLOSEST 0x00000080 /* DC is closest to client */
207 #define ADS_WRITABLE 0x00000100 /* DC has writable DS */
208 #define ADS_GOOD_TIMESERV 0x00000200 /* DC has hardware clock
209 (and running time) */
210 #define ADS_NDNC 0x00000400 /* DomainName is non-domain NC serviced
212 #define ADS_PINGS 0x0000FFFF /* Ping response */
213 #define ADS_DNS_CONTROLLER 0x20000000 /* DomainControllerName is a DNS name*/
214 #define ADS_DNS_DOMAIN 0x40000000 /* DomainName is a DNS name */
215 #define ADS_DNS_FOREST 0x80000000 /* DnsForestName is a DNS name */
217 /* DomainCntrollerAddressType */
218 #define ADS_INET_ADDRESS 0x00000001
219 #define ADS_NETBIOS_ADDRESS 0x00000002
222 /* ads auth control flags */
223 #define ADS_AUTH_DISABLE_KERBEROS 0x01
224 #define ADS_AUTH_NO_BIND 0x02
225 #define ADS_AUTH_ANON_BIND 0x04
226 #define ADS_AUTH_SIMPLE_BIND 0x08
227 #define ADS_AUTH_ALLOW_NTLMSSP 0x10
229 /***************************************
230 Some krb5 compat stuff
231 ***************************************/
232 /* Kerberos environment variable names */
233 #define KRB5_ENV_CCNAME "KRB5CCNAME"
235 /* Heimdal uses a slightly different name */
236 #if defined(HAVE_ENCTYPE_ARCFOUR_HMAC_MD5)
237 #define ENCTYPE_ARCFOUR_HMAC ENCTYPE_ARCFOUR_HMAC_MD5
240 /* The older versions of heimdal that don't have this
241 define don't seem to use it anyway. I'm told they
242 always use a subkey */
243 #ifndef HAVE_AP_OPTS_USE_SUBKEY
244 #define AP_OPTS_USE_SUBKEY 0
246 #if defined(HAVE_KRB5)
248 #ifndef HAVE_KRB5_SET_REAL_TIME
249 krb5_error_code krb5_set_real_time(krb5_context context, int32_t seconds, int32_t microseconds);
252 #ifndef HAVE_KRB5_SET_DEFAULT_TGS_KTYPES
253 krb5_error_code krb5_set_default_tgs_ktypes(krb5_context ctx, const krb5_enctype *enc);
256 #if defined(HAVE_KRB5_AUTH_CON_SETKEY) && !defined(HAVE_KRB5_AUTH_CON_SETUSERUSERKEY)
257 krb5_error_code krb5_auth_con_setuseruserkey(krb5_context context, krb5_auth_context auth_context, krb5_keyblock *keyblock);
260 /* Samba wrapper function for krb5 functionality. */
261 void setup_kaddr( krb5_address *pkaddr, struct sockaddr *paddr);
262 int create_kerberos_key_from_string(krb5_context context, krb5_principal host_princ, krb5_data *password, krb5_keyblock *key, krb5_enctype enctype);
263 void get_auth_data_from_tkt(DATA_BLOB *auth_data, krb5_ticket *tkt);
264 krb5_const_principal get_principal_from_tkt(krb5_ticket *tkt);
265 krb5_error_code krb5_locate_kdc(krb5_context ctx, const krb5_data *realm, struct sockaddr **addr_pp, int *naddrs, int get_masters);
266 krb5_error_code get_kerberos_allowed_etypes(krb5_context context, krb5_enctype **enctypes);
267 void free_kerberos_etypes(krb5_context context, krb5_enctype *enctypes);
268 BOOL get_krb5_smb_session_key(krb5_context context, krb5_auth_context auth_context, DATA_BLOB *session_key, BOOL remote);
269 #endif /* HAVE_KRB5 */