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 enum wb_posix_mapping
{
12 WB_POSIX_MAP_UNKNOWN
= -1,
13 WB_POSIX_MAP_TEMPLATE
= 0,
15 WB_POSIX_MAP_SFU20
= 2,
16 WB_POSIX_MAP_RFC2307
= 3,
17 WB_POSIX_MAP_UNIXINFO
= 4
20 /* there are 5 possible types of errors the ads subsystem can produce */
21 enum ads_error_type
{ENUM_ADS_ERROR_KRB5
, ENUM_ADS_ERROR_GSS
,
22 ENUM_ADS_ERROR_LDAP
, ENUM_ADS_ERROR_SYSTEM
, ENUM_ADS_ERROR_NT
};
25 enum ads_error_type error_type
;
30 /* For error_type = ENUM_ADS_ERROR_GSS minor_status describe GSS API error */
31 /* Where rc represents major_status of GSS API error */
37 struct ads_saslwrap_ops
{
39 ADS_STATUS (*wrap
)(struct ads_struct
*, uint8
*buf
, uint32 len
);
40 ADS_STATUS (*unwrap
)(struct ads_struct
*);
41 void (*disconnect
)(struct ads_struct
*);
44 enum ads_saslwrap_type
{
45 ADS_SASLWRAP_TYPE_PLAIN
= 1,
46 ADS_SASLWRAP_TYPE_SIGN
= 2,
47 ADS_SASLWRAP_TYPE_SEAL
= 4
50 typedef struct ads_struct
{
51 int is_mine
; /* do I own this structure's memory? */
53 /* info needed to find the server */
58 int foreign
; /* set to 1 if connecting to a foreign
60 bool gc
; /* Is this a global catalog server? */
63 /* info needed to authenticate */
76 /* info derived from the servers config */
78 uint32 flags
; /* cldap flags identifying the services. */
81 char *ldap_server_name
;
82 char *server_site_name
;
83 char *client_site_name
;
89 /* info about the current LDAP connection */
93 struct sockaddr_storage ss
; /* the ip of the active connection, if any */
94 time_t last_attempt
; /* last attempt to reconnect */
97 enum ads_saslwrap_type wrap_type
;
99 #ifdef HAVE_LDAP_SASL_WRAPPING
100 Sockbuf_IO_Desc
*sbiod
; /* lowlevel state for LDAP wrapping */
101 #endif /* HAVE_LDAP_SASL_WRAPPING */
103 const struct ads_saslwrap_ops
*wrap_ops
;
104 void *wrap_private_data
;
109 #define ADS_SASL_WRAPPING_IN_MAX_WRAPPED 0x0FFFFFFF
118 #define ADS_SASL_WRAPPING_OUT_MAX_WRAPPED 0x00A00000
119 uint32 max_unwrapped
;
125 #endif /* HAVE_LDAP */
128 /* used to remember the names of the posix attributes in AD */
129 /* see the rfc2307 & sfu nss backends */
131 struct posix_schema
{
132 char *posix_homedir_attr
;
133 char *posix_shell_attr
;
134 char *posix_uidnumber_attr
;
135 char *posix_gidnumber_attr
;
136 char *posix_gecos_attr
;
137 char *posix_uid_attr
;
143 typedef LDAPMod
**ADS_MODLIST
;
145 typedef void **ADS_MODLIST
;
148 /* macros to simplify error returning */
149 #define ADS_ERROR(rc) ADS_ERROR_LDAP(rc)
150 #define ADS_ERROR_LDAP(rc) ads_build_error(ENUM_ADS_ERROR_LDAP, rc, 0)
151 #define ADS_ERROR_SYSTEM(rc) ads_build_error(ENUM_ADS_ERROR_SYSTEM, rc?rc:EINVAL, 0)
152 #define ADS_ERROR_KRB5(rc) ads_build_error(ENUM_ADS_ERROR_KRB5, rc, 0)
153 #define ADS_ERROR_GSS(rc, minor) ads_build_error(ENUM_ADS_ERROR_GSS, rc, minor)
154 #define ADS_ERROR_NT(rc) ads_build_nt_error(ENUM_ADS_ERROR_NT,rc)
156 #define ADS_ERR_OK(status) ((status.error_type == ENUM_ADS_ERROR_NT) ? NT_STATUS_IS_OK(status.err.nt_status):(status.err.rc == 0))
157 #define ADS_SUCCESS ADS_ERROR(0)
159 #define ADS_ERROR_HAVE_NO_MEMORY(x) do { \
161 return ADS_ERROR(LDAP_NO_MEMORY);\
166 /* time between reconnect attempts */
167 #define ADS_RECONNECT_TIME 5
169 /* ldap control oids */
170 #define ADS_PAGE_CTL_OID "1.2.840.113556.1.4.319"
171 #define ADS_NO_REFERRALS_OID "1.2.840.113556.1.4.1339"
172 #define ADS_SERVER_SORT_OID "1.2.840.113556.1.4.473"
173 #define ADS_PERMIT_MODIFY_OID "1.2.840.113556.1.4.1413"
174 #define ADS_ASQ_OID "1.2.840.113556.1.4.1504"
175 #define ADS_EXTENDED_DN_OID "1.2.840.113556.1.4.529"
176 #define ADS_SD_FLAGS_OID "1.2.840.113556.1.4.801"
178 /* ldap attribute oids (Services for Unix 3.0, 3.5) */
179 #define ADS_ATTR_SFU_UIDNUMBER_OID "1.2.840.113556.1.6.18.1.310"
180 #define ADS_ATTR_SFU_GIDNUMBER_OID "1.2.840.113556.1.6.18.1.311"
181 #define ADS_ATTR_SFU_HOMEDIR_OID "1.2.840.113556.1.6.18.1.344"
182 #define ADS_ATTR_SFU_SHELL_OID "1.2.840.113556.1.6.18.1.312"
183 #define ADS_ATTR_SFU_GECOS_OID "1.2.840.113556.1.6.18.1.337"
184 #define ADS_ATTR_SFU_UID_OID "1.2.840.113556.1.6.18.1.309"
186 /* ldap attribute oids (Services for Unix 2.0) */
187 #define ADS_ATTR_SFU20_UIDNUMBER_OID "1.2.840.113556.1.4.7000.187.70"
188 #define ADS_ATTR_SFU20_GIDNUMBER_OID "1.2.840.113556.1.4.7000.187.71"
189 #define ADS_ATTR_SFU20_HOMEDIR_OID "1.2.840.113556.1.4.7000.187.106"
190 #define ADS_ATTR_SFU20_SHELL_OID "1.2.840.113556.1.4.7000.187.72"
191 #define ADS_ATTR_SFU20_GECOS_OID "1.2.840.113556.1.4.7000.187.97"
192 #define ADS_ATTR_SFU20_UID_OID "1.2.840.113556.1.4.7000.187.102"
195 /* ldap attribute oids (RFC2307) */
196 #define ADS_ATTR_RFC2307_UIDNUMBER_OID "1.3.6.1.1.1.1.0"
197 #define ADS_ATTR_RFC2307_GIDNUMBER_OID "1.3.6.1.1.1.1.1"
198 #define ADS_ATTR_RFC2307_HOMEDIR_OID "1.3.6.1.1.1.1.3"
199 #define ADS_ATTR_RFC2307_SHELL_OID "1.3.6.1.1.1.1.4"
200 #define ADS_ATTR_RFC2307_GECOS_OID "1.3.6.1.1.1.1.2"
201 #define ADS_ATTR_RFC2307_UID_OID "0.9.2342.19200300.100.1.1"
203 /* ldap bitwise searches */
204 #define ADS_LDAP_MATCHING_RULE_BIT_AND "1.2.840.113556.1.4.803"
205 #define ADS_LDAP_MATCHING_RULE_BIT_OR "1.2.840.113556.1.4.804"
207 #define ADS_PINGS 0x0000FFFF /* Ping response */
208 #define ADS_DNS_CONTROLLER 0x20000000 /* DomainControllerName is a DNS name*/
209 #define ADS_DNS_DOMAIN 0x40000000 /* DomainName is a DNS name */
210 #define ADS_DNS_FOREST 0x80000000 /* DnsForestName is a DNS name */
212 /* ads auth control flags */
213 #define ADS_AUTH_DISABLE_KERBEROS 0x0001
214 #define ADS_AUTH_NO_BIND 0x0002
215 #define ADS_AUTH_ANON_BIND 0x0004
216 #define ADS_AUTH_SIMPLE_BIND 0x0008
217 #define ADS_AUTH_ALLOW_NTLMSSP 0x0010
218 #define ADS_AUTH_SASL_SIGN 0x0020
219 #define ADS_AUTH_SASL_SEAL 0x0040
220 #define ADS_AUTH_SASL_FORCE 0x0080
221 #define ADS_AUTH_USER_CREDS 0x0100
223 /* Kerberos environment variable names */
224 #define KRB5_ENV_CCNAME "KRB5CCNAME"
226 /* Heimdal uses a slightly different name */
227 #if defined(HAVE_ENCTYPE_ARCFOUR_HMAC_MD5)
228 #define ENCTYPE_ARCFOUR_HMAC ENCTYPE_ARCFOUR_HMAC_MD5
231 /* The older versions of heimdal that don't have this
232 define don't seem to use it anyway. I'm told they
233 always use a subkey */
234 #ifndef HAVE_AP_OPTS_USE_SUBKEY
235 #define AP_OPTS_USE_SUBKEY 0
238 #define WELL_KNOWN_GUID_COMPUTERS "AA312825768811D1ADED00C04FD8D5CD"
239 #define WELL_KNOWN_GUID_USERS "A9D1CA15768811D1ADED00C04FD8D5CD"
241 #ifndef KRB5_ADDR_NETBIOS
242 #define KRB5_ADDR_NETBIOS 0x14
245 #ifndef KRB5KRB_ERR_RESPONSE_TOO_BIG
246 #define KRB5KRB_ERR_RESPONSE_TOO_BIG (-1765328332L)
251 #if defined(HAVE_MAGIC_IN_KRB5_ADDRESS) && defined(HAVE_ADDRTYPE_IN_KRB5_ADDRESS) /* MIT */
252 krb5_address
**addrs
;
253 #elif defined(HAVE_KRB5_ADDRESSES) /* Heimdal */
254 krb5_addresses
*addrs
;
256 #error UNKNOWN_KRB5_ADDRESS_TYPE
257 #endif /* defined(HAVE_MAGIC_IN_KRB5_ADDRESS) && defined(HAVE_ADDRTYPE_IN_KRB5_ADDRESS) */
258 } smb_krb5_addresses
;
260 #ifdef HAVE_KRB5_KEYBLOCK_KEYVALUE /* Heimdal */
261 #define KRB5_KEY_TYPE(k) ((k)->keytype)
262 #define KRB5_KEY_LENGTH(k) ((k)->keyvalue.length)
263 #define KRB5_KEY_DATA(k) ((k)->keyvalue.data)
264 #define KRB5_KEY_DATA_CAST void
266 #define KRB5_KEY_TYPE(k) ((k)->enctype)
267 #define KRB5_KEY_LENGTH(k) ((k)->length)
268 #define KRB5_KEY_DATA(k) ((k)->contents)
269 #define KRB5_KEY_DATA_CAST krb5_octet
270 #endif /* HAVE_KRB5_KEYBLOCK_KEYVALUE */
272 #ifdef HAVE_KRB5_KEYTAB_ENTRY_KEY /* MIT */
273 #define KRB5_KT_KEY(k) (&(k)->key)
274 #elif HAVE_KRB5_KEYTAB_ENTRY_KEYBLOCK /* Heimdal */
275 #define KRB5_KT_KEY(k) (&(k)->keyblock)
277 #error krb5_keytab_entry has no key or keyblock member
278 #endif /* HAVE_KRB5_KEYTAB_ENTRY_KEY */
280 #endif /* HAVE_KRB5 */
282 enum ads_extended_dn_flags
{
283 ADS_EXTENDED_DN_HEX_STRING
= 0,
284 ADS_EXTENDED_DN_STRING
= 1 /* not supported on win2k */
287 /* this is probably not very well suited to pass other controls generically but
288 * is good enough for the extended dn control where it is only used for atm */
296 #define ADS_IGNORE_PRINCIPAL "not_defined_in_RFC4178@please_ignore"
298 #endif /* _INCLUDE_ADS_H_ */