format-subunit: Hide reason if it is None.
[Samba/eduardoll.git] / source3 / include / ads.h
blobd0bae808454e424b58f005eac6d49d9dd6ebcd5e
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"
12 * This should be under the HAVE_KRB5 flag but since they're used
13 * in lp_kerberos_method(), they ned to be always available
15 #define KERBEROS_VERIFY_SECRETS 0
16 #define KERBEROS_VERIFY_SYSTEM_KEYTAB 1
17 #define KERBEROS_VERIFY_DEDICATED_KEYTAB 2
18 #define KERBEROS_VERIFY_SECRETS_AND_KEYTAB 3
21 * If you add any entries to the above, please modify the below expressions
22 * so they remain accurate.
24 #define USE_KERBEROS_KEYTAB (KERBEROS_VERIFY_SECRETS != lp_kerberos_method())
25 #define USE_SYSTEM_KEYTAB \
26 ((KERBEROS_VERIFY_SECRETS_AND_KEYTAB == lp_kerberos_method()) || \
27 (KERBEROS_VERIFY_SYSTEM_KEYTAB == lp_kerberos_method()))
29 #define TOK_ID_KRB_AP_REQ ((const uint8_t *)"\x01\x00")
30 #define TOK_ID_KRB_AP_REP ((const uint8_t *)"\x02\x00")
31 #define TOK_ID_KRB_ERROR ((const uint8_t *)"\x03\x00")
32 #define TOK_ID_GSS_GETMIC ((const uint8_t *)"\x01\x01")
33 #define TOK_ID_GSS_WRAP ((const uint8_t *)"\x02\x01")
35 enum wb_posix_mapping {
36 WB_POSIX_MAP_UNKNOWN = -1,
37 WB_POSIX_MAP_TEMPLATE = 0,
38 WB_POSIX_MAP_SFU = 1,
39 WB_POSIX_MAP_SFU20 = 2,
40 WB_POSIX_MAP_RFC2307 = 3,
41 WB_POSIX_MAP_UNIXINFO = 4
44 /* there are 5 possible types of errors the ads subsystem can produce */
45 enum ads_error_type {ENUM_ADS_ERROR_KRB5, ENUM_ADS_ERROR_GSS,
46 ENUM_ADS_ERROR_LDAP, ENUM_ADS_ERROR_SYSTEM, ENUM_ADS_ERROR_NT};
48 typedef struct {
49 enum ads_error_type error_type;
50 union err_state{
51 int rc;
52 NTSTATUS nt_status;
53 } err;
54 /* For error_type = ENUM_ADS_ERROR_GSS minor_status describe GSS API error */
55 /* Where rc represents major_status of GSS API error */
56 int minor_status;
57 } ADS_STATUS;
59 struct ads_struct;
61 struct ads_saslwrap_ops {
62 const char *name;
63 ADS_STATUS (*wrap)(struct ads_struct *, uint8 *buf, uint32 len);
64 ADS_STATUS (*unwrap)(struct ads_struct *);
65 void (*disconnect)(struct ads_struct *);
68 enum ads_saslwrap_type {
69 ADS_SASLWRAP_TYPE_PLAIN = 1,
70 ADS_SASLWRAP_TYPE_SIGN = 2,
71 ADS_SASLWRAP_TYPE_SEAL = 4
74 typedef struct ads_struct {
75 int is_mine; /* do I own this structure's memory? */
77 /* info needed to find the server */
78 struct {
79 char *realm;
80 char *workgroup;
81 char *ldap_server;
82 int foreign; /* set to 1 if connecting to a foreign
83 * realm */
84 bool gc; /* Is this a global catalog server? */
85 } server;
87 /* info needed to authenticate */
88 struct {
89 char *realm;
90 char *password;
91 char *user_name;
92 char *kdc_server;
93 unsigned flags;
94 int time_offset;
95 time_t tgt_expire;
96 time_t tgs_expire;
97 time_t renewable;
98 } auth;
100 /* info derived from the servers config */
101 struct {
102 uint32 flags; /* cldap flags identifying the services. */
103 char *realm;
104 char *bind_path;
105 char *ldap_server_name;
106 char *server_site_name;
107 char *client_site_name;
108 time_t current_time;
109 char *schema_path;
110 char *config_path;
111 } config;
113 /* info about the current LDAP connection */
114 #ifdef HAVE_LDAP
115 struct {
116 LDAP *ld;
117 struct sockaddr_storage ss; /* the ip of the active connection, if any */
118 time_t last_attempt; /* last attempt to reconnect */
119 int port;
121 enum ads_saslwrap_type wrap_type;
123 #ifdef HAVE_LDAP_SASL_WRAPPING
124 Sockbuf_IO_Desc *sbiod; /* lowlevel state for LDAP wrapping */
125 #endif /* HAVE_LDAP_SASL_WRAPPING */
126 TALLOC_CTX *mem_ctx;
127 const struct ads_saslwrap_ops *wrap_ops;
128 void *wrap_private_data;
129 struct {
130 uint32 ofs;
131 uint32 needed;
132 uint32 left;
133 #define ADS_SASL_WRAPPING_IN_MAX_WRAPPED 0x0FFFFFFF
134 uint32 max_wrapped;
135 uint32 min_wrapped;
136 uint32 size;
137 uint8 *buf;
138 } in;
139 struct {
140 uint32 ofs;
141 uint32 left;
142 #define ADS_SASL_WRAPPING_OUT_MAX_WRAPPED 0x00A00000
143 uint32 max_unwrapped;
144 uint32 sig_size;
145 uint32 size;
146 uint8 *buf;
147 } out;
148 } ldap;
149 #endif /* HAVE_LDAP */
150 } ADS_STRUCT;
152 /* used to remember the names of the posix attributes in AD */
153 /* see the rfc2307 & sfu nss backends */
155 struct posix_schema {
156 char *posix_homedir_attr;
157 char *posix_shell_attr;
158 char *posix_uidnumber_attr;
159 char *posix_gidnumber_attr;
160 char *posix_gecos_attr;
161 char *posix_uid_attr;
166 #ifdef HAVE_ADS
167 typedef LDAPMod **ADS_MODLIST;
168 #else
169 typedef void **ADS_MODLIST;
170 #endif
172 /* macros to simplify error returning */
173 #define ADS_ERROR(rc) ADS_ERROR_LDAP(rc)
174 #define ADS_ERROR_LDAP(rc) ads_build_error(ENUM_ADS_ERROR_LDAP, rc, 0)
175 #define ADS_ERROR_SYSTEM(rc) ads_build_error(ENUM_ADS_ERROR_SYSTEM, rc?rc:EINVAL, 0)
176 #define ADS_ERROR_KRB5(rc) ads_build_error(ENUM_ADS_ERROR_KRB5, rc, 0)
177 #define ADS_ERROR_GSS(rc, minor) ads_build_error(ENUM_ADS_ERROR_GSS, rc, minor)
178 #define ADS_ERROR_NT(rc) ads_build_nt_error(ENUM_ADS_ERROR_NT,rc)
180 #define ADS_ERR_OK(status) ((status.error_type == ENUM_ADS_ERROR_NT) ? NT_STATUS_IS_OK(status.err.nt_status):(status.err.rc == 0))
181 #define ADS_SUCCESS ADS_ERROR(0)
183 #define ADS_ERROR_HAVE_NO_MEMORY(x) do { \
184 if (!(x)) {\
185 return ADS_ERROR(LDAP_NO_MEMORY);\
187 } while (0)
190 /* time between reconnect attempts */
191 #define ADS_RECONNECT_TIME 5
193 /* ldap control oids */
194 #define ADS_PAGE_CTL_OID "1.2.840.113556.1.4.319"
195 #define ADS_NO_REFERRALS_OID "1.2.840.113556.1.4.1339"
196 #define ADS_SERVER_SORT_OID "1.2.840.113556.1.4.473"
197 #define ADS_PERMIT_MODIFY_OID "1.2.840.113556.1.4.1413"
198 #define ADS_ASQ_OID "1.2.840.113556.1.4.1504"
199 #define ADS_EXTENDED_DN_OID "1.2.840.113556.1.4.529"
200 #define ADS_SD_FLAGS_OID "1.2.840.113556.1.4.801"
202 /* ldap attribute oids (Services for Unix 3.0, 3.5) */
203 #define ADS_ATTR_SFU_UIDNUMBER_OID "1.2.840.113556.1.6.18.1.310"
204 #define ADS_ATTR_SFU_GIDNUMBER_OID "1.2.840.113556.1.6.18.1.311"
205 #define ADS_ATTR_SFU_HOMEDIR_OID "1.2.840.113556.1.6.18.1.344"
206 #define ADS_ATTR_SFU_SHELL_OID "1.2.840.113556.1.6.18.1.312"
207 #define ADS_ATTR_SFU_GECOS_OID "1.2.840.113556.1.6.18.1.337"
208 #define ADS_ATTR_SFU_UID_OID "1.2.840.113556.1.6.18.1.309"
210 /* ldap attribute oids (Services for Unix 2.0) */
211 #define ADS_ATTR_SFU20_UIDNUMBER_OID "1.2.840.113556.1.4.7000.187.70"
212 #define ADS_ATTR_SFU20_GIDNUMBER_OID "1.2.840.113556.1.4.7000.187.71"
213 #define ADS_ATTR_SFU20_HOMEDIR_OID "1.2.840.113556.1.4.7000.187.106"
214 #define ADS_ATTR_SFU20_SHELL_OID "1.2.840.113556.1.4.7000.187.72"
215 #define ADS_ATTR_SFU20_GECOS_OID "1.2.840.113556.1.4.7000.187.97"
216 #define ADS_ATTR_SFU20_UID_OID "1.2.840.113556.1.4.7000.187.102"
219 /* ldap attribute oids (RFC2307) */
220 #define ADS_ATTR_RFC2307_UIDNUMBER_OID "1.3.6.1.1.1.1.0"
221 #define ADS_ATTR_RFC2307_GIDNUMBER_OID "1.3.6.1.1.1.1.1"
222 #define ADS_ATTR_RFC2307_HOMEDIR_OID "1.3.6.1.1.1.1.3"
223 #define ADS_ATTR_RFC2307_SHELL_OID "1.3.6.1.1.1.1.4"
224 #define ADS_ATTR_RFC2307_GECOS_OID "1.3.6.1.1.1.1.2"
225 #define ADS_ATTR_RFC2307_UID_OID "0.9.2342.19200300.100.1.1"
227 /* ldap bitwise searches */
228 #define ADS_LDAP_MATCHING_RULE_BIT_AND "1.2.840.113556.1.4.803"
229 #define ADS_LDAP_MATCHING_RULE_BIT_OR "1.2.840.113556.1.4.804"
231 #define ADS_PINGS 0x0000FFFF /* Ping response */
233 /* ads auth control flags */
234 #define ADS_AUTH_DISABLE_KERBEROS 0x0001
235 #define ADS_AUTH_NO_BIND 0x0002
236 #define ADS_AUTH_ANON_BIND 0x0004
237 #define ADS_AUTH_SIMPLE_BIND 0x0008
238 #define ADS_AUTH_ALLOW_NTLMSSP 0x0010
239 #define ADS_AUTH_SASL_SIGN 0x0020
240 #define ADS_AUTH_SASL_SEAL 0x0040
241 #define ADS_AUTH_SASL_FORCE 0x0080
242 #define ADS_AUTH_USER_CREDS 0x0100
244 /* Kerberos environment variable names */
245 #define KRB5_ENV_CCNAME "KRB5CCNAME"
247 #define WELL_KNOWN_GUID_COMPUTERS "AA312825768811D1ADED00C04FD8D5CD"
248 #define WELL_KNOWN_GUID_USERS "A9D1CA15768811D1ADED00C04FD8D5CD"
250 enum ads_extended_dn_flags {
251 ADS_EXTENDED_DN_HEX_STRING = 0,
252 ADS_EXTENDED_DN_STRING = 1 /* not supported on win2k */
255 /* this is probably not very well suited to pass other controls generically but
256 * is good enough for the extended dn control where it is only used for atm */
258 typedef struct {
259 const char *control;
260 int val;
261 int critical;
262 } ads_control;
264 #define ADS_IGNORE_PRINCIPAL "not_defined_in_RFC4178@please_ignore"
266 #endif /* _INCLUDE_ADS_H_ */