s3 net: i18n support for net time
[Samba.git] / source3 / include / ads.h
blob9761d54086652f953260cd5298fbaa71d4bd4195
1 #ifndef _INCLUDE_ADS_H_
2 #define _INCLUDE_ADS_H_
3 /*
4 header for ads (active directory) library routines
6 basically this is a wrapper around ldap
7 */
9 #include "../libds/common/flags.h"
11 enum wb_posix_mapping {
12 WB_POSIX_MAP_UNKNOWN = -1,
13 WB_POSIX_MAP_TEMPLATE = 0,
14 WB_POSIX_MAP_SFU = 1,
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};
24 typedef struct {
25 enum ads_error_type error_type;
26 union err_state{
27 int rc;
28 NTSTATUS nt_status;
29 } err;
30 /* For error_type = ENUM_ADS_ERROR_GSS minor_status describe GSS API error */
31 /* Where rc represents major_status of GSS API error */
32 int minor_status;
33 } ADS_STATUS;
35 struct ads_struct;
37 struct ads_saslwrap_ops {
38 const char *name;
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 */
54 struct {
55 char *realm;
56 char *workgroup;
57 char *ldap_server;
58 int foreign; /* set to 1 if connecting to a foreign
59 * realm */
60 bool gc; /* Is this a global catalog server? */
61 } server;
63 /* info needed to authenticate */
64 struct {
65 char *realm;
66 char *password;
67 char *user_name;
68 char *kdc_server;
69 unsigned flags;
70 int time_offset;
71 time_t tgt_expire;
72 time_t tgs_expire;
73 time_t renewable;
74 } auth;
76 /* info derived from the servers config */
77 struct {
78 uint32 flags; /* cldap flags identifying the services. */
79 char *realm;
80 char *bind_path;
81 char *ldap_server_name;
82 char *server_site_name;
83 char *client_site_name;
84 time_t current_time;
85 char *schema_path;
86 char *config_path;
87 } config;
89 /* info about the current LDAP connection */
90 #ifdef HAVE_LDAP
91 struct {
92 LDAP *ld;
93 struct sockaddr_storage ss; /* the ip of the active connection, if any */
94 time_t last_attempt; /* last attempt to reconnect */
95 int port;
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 */
102 TALLOC_CTX *mem_ctx;
103 const struct ads_saslwrap_ops *wrap_ops;
104 void *wrap_private_data;
105 struct {
106 uint32 ofs;
107 uint32 needed;
108 uint32 left;
109 #define ADS_SASL_WRAPPING_IN_MAX_WRAPPED 0x0FFFFFFF
110 uint32 max_wrapped;
111 uint32 min_wrapped;
112 uint32 size;
113 uint8 *buf;
114 } in;
115 struct {
116 uint32 ofs;
117 uint32 left;
118 #define ADS_SASL_WRAPPING_OUT_MAX_WRAPPED 0x00A00000
119 uint32 max_unwrapped;
120 uint32 sig_size;
121 uint32 size;
122 uint8 *buf;
123 } out;
124 } ldap;
125 #endif /* HAVE_LDAP */
126 } ADS_STRUCT;
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;
142 #ifdef HAVE_ADS
143 typedef LDAPMod **ADS_MODLIST;
144 #else
145 typedef void **ADS_MODLIST;
146 #endif
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 { \
160 if (!(x)) {\
161 return ADS_ERROR(LDAP_NO_MEMORY);\
163 } while (0)
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
229 #endif
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
236 #endif
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
243 #endif
245 #ifndef KRB5KRB_ERR_RESPONSE_TOO_BIG
246 #define KRB5KRB_ERR_RESPONSE_TOO_BIG (-1765328332L)
247 #endif
249 #ifdef HAVE_KRB5
250 typedef struct {
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;
255 #else
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
265 #else /* MIT */
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)
276 #else
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 */
290 typedef struct {
291 const char *control;
292 int val;
293 int critical;
294 } ads_control;
296 #define ADS_IGNORE_PRINCIPAL "not_defined_in_RFC4178@please_ignore"
298 #endif /* _INCLUDE_ADS_H_ */