1 #ifndef _INCLUDE_ADS_H_
2 #define _INCLUDE_ADS_H_
4 header for ads (active directory) library routines
6 basically this is a wrapper around ldap
9 #include "../libds/common/flags.h"
11 #define TOK_ID_KRB_AP_REQ ((const uint8_t *)"\x01\x00")
12 #define TOK_ID_KRB_AP_REP ((const uint8_t *)"\x02\x00")
13 #define TOK_ID_KRB_ERROR ((const uint8_t *)"\x03\x00")
14 #define TOK_ID_GSS_GETMIC ((const uint8_t *)"\x01\x01")
15 #define TOK_ID_GSS_WRAP ((const uint8_t *)"\x02\x01")
17 enum wb_posix_mapping
{
18 WB_POSIX_MAP_UNKNOWN
= -1,
19 WB_POSIX_MAP_TEMPLATE
= 0,
21 WB_POSIX_MAP_SFU20
= 2,
22 WB_POSIX_MAP_RFC2307
= 3,
23 WB_POSIX_MAP_UNIXINFO
= 4
26 /* there are 5 possible types of errors the ads subsystem can produce */
27 enum ads_error_type
{ENUM_ADS_ERROR_KRB5
, ENUM_ADS_ERROR_GSS
,
28 ENUM_ADS_ERROR_LDAP
, ENUM_ADS_ERROR_SYSTEM
, ENUM_ADS_ERROR_NT
};
31 enum ads_error_type error_type
;
36 /* For error_type = ENUM_ADS_ERROR_GSS minor_status describe GSS API error */
37 /* Where rc represents major_status of GSS API error */
43 struct ads_saslwrap_ops
{
45 ADS_STATUS (*wrap
)(struct ads_struct
*, uint8
*buf
, uint32 len
);
46 ADS_STATUS (*unwrap
)(struct ads_struct
*);
47 void (*disconnect
)(struct ads_struct
*);
50 enum ads_saslwrap_type
{
51 ADS_SASLWRAP_TYPE_PLAIN
= 1,
52 ADS_SASLWRAP_TYPE_SIGN
= 2,
53 ADS_SASLWRAP_TYPE_SEAL
= 4
56 typedef struct ads_struct
{
57 int is_mine
; /* do I own this structure's memory? */
59 /* info needed to find the server */
64 int foreign
; /* set to 1 if connecting to a foreign
66 bool gc
; /* Is this a global catalog server? */
69 /* info needed to authenticate */
82 /* info derived from the servers config */
84 uint32 flags
; /* cldap flags identifying the services. */
87 char *ldap_server_name
;
88 char *server_site_name
;
89 char *client_site_name
;
95 /* info about the current LDAP connection */
99 struct sockaddr_storage ss
; /* the ip of the active connection, if any */
100 time_t last_attempt
; /* last attempt to reconnect */
103 enum ads_saslwrap_type wrap_type
;
105 #ifdef HAVE_LDAP_SASL_WRAPPING
106 Sockbuf_IO_Desc
*sbiod
; /* lowlevel state for LDAP wrapping */
107 #endif /* HAVE_LDAP_SASL_WRAPPING */
109 const struct ads_saslwrap_ops
*wrap_ops
;
110 void *wrap_private_data
;
115 #define ADS_SASL_WRAPPING_IN_MAX_WRAPPED 0x0FFFFFFF
124 #define ADS_SASL_WRAPPING_OUT_MAX_WRAPPED 0x00A00000
125 uint32 max_unwrapped
;
131 #endif /* HAVE_LDAP */
134 /* used to remember the names of the posix attributes in AD */
135 /* see the rfc2307 & sfu nss backends */
137 struct posix_schema
{
138 char *posix_homedir_attr
;
139 char *posix_shell_attr
;
140 char *posix_uidnumber_attr
;
141 char *posix_gidnumber_attr
;
142 char *posix_gecos_attr
;
143 char *posix_uid_attr
;
149 typedef LDAPMod
**ADS_MODLIST
;
151 typedef void **ADS_MODLIST
;
154 /* macros to simplify error returning */
155 #define ADS_ERROR(rc) ADS_ERROR_LDAP(rc)
156 #define ADS_ERROR_LDAP(rc) ads_build_error(ENUM_ADS_ERROR_LDAP, rc, 0)
157 #define ADS_ERROR_SYSTEM(rc) ads_build_error(ENUM_ADS_ERROR_SYSTEM, rc?rc:EINVAL, 0)
158 #define ADS_ERROR_KRB5(rc) ads_build_error(ENUM_ADS_ERROR_KRB5, rc, 0)
159 #define ADS_ERROR_GSS(rc, minor) ads_build_error(ENUM_ADS_ERROR_GSS, rc, minor)
160 #define ADS_ERROR_NT(rc) ads_build_nt_error(ENUM_ADS_ERROR_NT,rc)
162 #define ADS_ERR_OK(status) ((status.error_type == ENUM_ADS_ERROR_NT) ? NT_STATUS_IS_OK(status.err.nt_status):(status.err.rc == 0))
163 #define ADS_SUCCESS ADS_ERROR(0)
165 #define ADS_ERROR_HAVE_NO_MEMORY(x) do { \
167 return ADS_ERROR(LDAP_NO_MEMORY);\
172 /* time between reconnect attempts */
173 #define ADS_RECONNECT_TIME 5
175 /* ldap control oids */
176 #define ADS_PAGE_CTL_OID "1.2.840.113556.1.4.319"
177 #define ADS_NO_REFERRALS_OID "1.2.840.113556.1.4.1339"
178 #define ADS_SERVER_SORT_OID "1.2.840.113556.1.4.473"
179 #define ADS_PERMIT_MODIFY_OID "1.2.840.113556.1.4.1413"
180 #define ADS_ASQ_OID "1.2.840.113556.1.4.1504"
181 #define ADS_EXTENDED_DN_OID "1.2.840.113556.1.4.529"
182 #define ADS_SD_FLAGS_OID "1.2.840.113556.1.4.801"
184 /* ldap attribute oids (Services for Unix 3.0, 3.5) */
185 #define ADS_ATTR_SFU_UIDNUMBER_OID "1.2.840.113556.1.6.18.1.310"
186 #define ADS_ATTR_SFU_GIDNUMBER_OID "1.2.840.113556.1.6.18.1.311"
187 #define ADS_ATTR_SFU_HOMEDIR_OID "1.2.840.113556.1.6.18.1.344"
188 #define ADS_ATTR_SFU_SHELL_OID "1.2.840.113556.1.6.18.1.312"
189 #define ADS_ATTR_SFU_GECOS_OID "1.2.840.113556.1.6.18.1.337"
190 #define ADS_ATTR_SFU_UID_OID "1.2.840.113556.1.6.18.1.309"
192 /* ldap attribute oids (Services for Unix 2.0) */
193 #define ADS_ATTR_SFU20_UIDNUMBER_OID "1.2.840.113556.1.4.7000.187.70"
194 #define ADS_ATTR_SFU20_GIDNUMBER_OID "1.2.840.113556.1.4.7000.187.71"
195 #define ADS_ATTR_SFU20_HOMEDIR_OID "1.2.840.113556.1.4.7000.187.106"
196 #define ADS_ATTR_SFU20_SHELL_OID "1.2.840.113556.1.4.7000.187.72"
197 #define ADS_ATTR_SFU20_GECOS_OID "1.2.840.113556.1.4.7000.187.97"
198 #define ADS_ATTR_SFU20_UID_OID "1.2.840.113556.1.4.7000.187.102"
201 /* ldap attribute oids (RFC2307) */
202 #define ADS_ATTR_RFC2307_UIDNUMBER_OID "1.3.6.1.1.1.1.0"
203 #define ADS_ATTR_RFC2307_GIDNUMBER_OID "1.3.6.1.1.1.1.1"
204 #define ADS_ATTR_RFC2307_HOMEDIR_OID "1.3.6.1.1.1.1.3"
205 #define ADS_ATTR_RFC2307_SHELL_OID "1.3.6.1.1.1.1.4"
206 #define ADS_ATTR_RFC2307_GECOS_OID "1.3.6.1.1.1.1.2"
207 #define ADS_ATTR_RFC2307_UID_OID "0.9.2342.19200300.100.1.1"
209 /* ldap bitwise searches */
210 #define ADS_LDAP_MATCHING_RULE_BIT_AND "1.2.840.113556.1.4.803"
211 #define ADS_LDAP_MATCHING_RULE_BIT_OR "1.2.840.113556.1.4.804"
213 #define ADS_PINGS 0x0000FFFF /* Ping response */
214 #define ADS_DNS_CONTROLLER 0x20000000 /* DomainControllerName is a DNS name*/
215 #define ADS_DNS_DOMAIN 0x40000000 /* DomainName is a DNS name */
216 #define ADS_DNS_FOREST 0x80000000 /* DnsForestName is a DNS name */
218 /* ads auth control flags */
219 #define ADS_AUTH_DISABLE_KERBEROS 0x0001
220 #define ADS_AUTH_NO_BIND 0x0002
221 #define ADS_AUTH_ANON_BIND 0x0004
222 #define ADS_AUTH_SIMPLE_BIND 0x0008
223 #define ADS_AUTH_ALLOW_NTLMSSP 0x0010
224 #define ADS_AUTH_SASL_SIGN 0x0020
225 #define ADS_AUTH_SASL_SEAL 0x0040
226 #define ADS_AUTH_SASL_FORCE 0x0080
227 #define ADS_AUTH_USER_CREDS 0x0100
229 /* Kerberos environment variable names */
230 #define KRB5_ENV_CCNAME "KRB5CCNAME"
232 /* Heimdal uses a slightly different name */
233 #if defined(HAVE_ENCTYPE_ARCFOUR_HMAC_MD5)
234 #define ENCTYPE_ARCFOUR_HMAC ENCTYPE_ARCFOUR_HMAC_MD5
237 /* The older versions of heimdal that don't have this
238 define don't seem to use it anyway. I'm told they
239 always use a subkey */
240 #ifndef HAVE_AP_OPTS_USE_SUBKEY
241 #define AP_OPTS_USE_SUBKEY 0
244 #define WELL_KNOWN_GUID_COMPUTERS "AA312825768811D1ADED00C04FD8D5CD"
245 #define WELL_KNOWN_GUID_USERS "A9D1CA15768811D1ADED00C04FD8D5CD"
247 #ifndef KRB5_ADDR_NETBIOS
248 #define KRB5_ADDR_NETBIOS 0x14
251 #ifndef KRB5KRB_ERR_RESPONSE_TOO_BIG
252 #define KRB5KRB_ERR_RESPONSE_TOO_BIG (-1765328332L)
257 #if defined(HAVE_MAGIC_IN_KRB5_ADDRESS) && defined(HAVE_ADDRTYPE_IN_KRB5_ADDRESS) /* MIT */
258 krb5_address
**addrs
;
259 #elif defined(HAVE_KRB5_ADDRESSES) /* Heimdal */
260 krb5_addresses
*addrs
;
262 #error UNKNOWN_KRB5_ADDRESS_TYPE
263 #endif /* defined(HAVE_MAGIC_IN_KRB5_ADDRESS) && defined(HAVE_ADDRTYPE_IN_KRB5_ADDRESS) */
264 } smb_krb5_addresses
;
266 #ifdef HAVE_KRB5_KEYBLOCK_KEYVALUE /* Heimdal */
267 #define KRB5_KEY_TYPE(k) ((k)->keytype)
268 #define KRB5_KEY_LENGTH(k) ((k)->keyvalue.length)
269 #define KRB5_KEY_DATA(k) ((k)->keyvalue.data)
270 #define KRB5_KEY_DATA_CAST void
272 #define KRB5_KEY_TYPE(k) ((k)->enctype)
273 #define KRB5_KEY_LENGTH(k) ((k)->length)
274 #define KRB5_KEY_DATA(k) ((k)->contents)
275 #define KRB5_KEY_DATA_CAST krb5_octet
276 #endif /* HAVE_KRB5_KEYBLOCK_KEYVALUE */
278 #ifdef HAVE_KRB5_KEYTAB_ENTRY_KEY /* MIT */
279 #define KRB5_KT_KEY(k) (&(k)->key)
280 #elif HAVE_KRB5_KEYTAB_ENTRY_KEYBLOCK /* Heimdal */
281 #define KRB5_KT_KEY(k) (&(k)->keyblock)
283 #error krb5_keytab_entry has no key or keyblock member
284 #endif /* HAVE_KRB5_KEYTAB_ENTRY_KEY */
286 #endif /* HAVE_KRB5 */
288 enum ads_extended_dn_flags
{
289 ADS_EXTENDED_DN_HEX_STRING
= 0,
290 ADS_EXTENDED_DN_STRING
= 1 /* not supported on win2k */
293 /* this is probably not very well suited to pass other controls generically but
294 * is good enough for the extended dn control where it is only used for atm */
302 #define ADS_IGNORE_PRINCIPAL "not_defined_in_RFC4178@please_ignore"
304 #endif /* _INCLUDE_ADS_H_ */