[736] | 1 | #ifndef _INCLUDE_ADS_H_
|
---|
| 2 | #define _INCLUDE_ADS_H_
|
---|
| 3 | /*
|
---|
| 4 | header for ads (active directory) library routines
|
---|
| 5 |
|
---|
| 6 | basically this is a wrapper around ldap
|
---|
| 7 | */
|
---|
| 8 |
|
---|
| 9 | #include "../libds/common/flags.h"
|
---|
| 10 |
|
---|
| 11 | /*
|
---|
| 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
|
---|
| 14 | */
|
---|
| 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
|
---|
| 19 |
|
---|
| 20 | /*
|
---|
| 21 | * If you add any entries to the above, please modify the below expressions
|
---|
| 22 | * so they remain accurate.
|
---|
| 23 | */
|
---|
| 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()))
|
---|
| 28 |
|
---|
| 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")
|
---|
| 34 |
|
---|
| 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
|
---|
| 42 | };
|
---|
| 43 |
|
---|
| 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};
|
---|
| 47 |
|
---|
| 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;
|
---|
| 58 |
|
---|
| 59 | struct ads_struct;
|
---|
| 60 |
|
---|
| 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 *);
|
---|
| 66 | };
|
---|
| 67 |
|
---|
| 68 | enum ads_saslwrap_type {
|
---|
| 69 | ADS_SASLWRAP_TYPE_PLAIN = 1,
|
---|
| 70 | ADS_SASLWRAP_TYPE_SIGN = 2,
|
---|
| 71 | ADS_SASLWRAP_TYPE_SEAL = 4
|
---|
| 72 | };
|
---|
| 73 |
|
---|
| 74 | typedef struct ads_struct {
|
---|
| 75 | int is_mine; /* do I own this structure's memory? */
|
---|
| 76 |
|
---|
| 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;
|
---|
| 86 |
|
---|
| 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;
|
---|
| 99 |
|
---|
| 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 | int ldap_page_size;
|
---|
| 112 | } config;
|
---|
| 113 |
|
---|
| 114 | /* info about the current LDAP connection */
|
---|
| 115 | #ifdef HAVE_LDAP
|
---|
| 116 | struct {
|
---|
| 117 | LDAP *ld;
|
---|
| 118 | struct sockaddr_storage ss; /* the ip of the active connection, if any */
|
---|
| 119 | time_t last_attempt; /* last attempt to reconnect */
|
---|
| 120 | int port;
|
---|
| 121 |
|
---|
| 122 | enum ads_saslwrap_type wrap_type;
|
---|
| 123 |
|
---|
| 124 | #ifdef HAVE_LDAP_SASL_WRAPPING
|
---|
| 125 | Sockbuf_IO_Desc *sbiod; /* lowlevel state for LDAP wrapping */
|
---|
| 126 | #endif /* HAVE_LDAP_SASL_WRAPPING */
|
---|
| 127 | TALLOC_CTX *mem_ctx;
|
---|
| 128 | const struct ads_saslwrap_ops *wrap_ops;
|
---|
| 129 | void *wrap_private_data;
|
---|
| 130 | struct {
|
---|
| 131 | uint32 ofs;
|
---|
| 132 | uint32 needed;
|
---|
| 133 | uint32 left;
|
---|
| 134 | #define ADS_SASL_WRAPPING_IN_MAX_WRAPPED 0x0FFFFFFF
|
---|
| 135 | uint32 max_wrapped;
|
---|
| 136 | uint32 min_wrapped;
|
---|
| 137 | uint32 size;
|
---|
| 138 | uint8 *buf;
|
---|
| 139 | } in;
|
---|
| 140 | struct {
|
---|
| 141 | uint32 ofs;
|
---|
| 142 | uint32 left;
|
---|
| 143 | #define ADS_SASL_WRAPPING_OUT_MAX_WRAPPED 0x00A00000
|
---|
| 144 | uint32 max_unwrapped;
|
---|
| 145 | uint32 sig_size;
|
---|
| 146 | uint32 size;
|
---|
| 147 | uint8 *buf;
|
---|
| 148 | } out;
|
---|
| 149 | } ldap;
|
---|
| 150 | #endif /* HAVE_LDAP */
|
---|
| 151 | } ADS_STRUCT;
|
---|
| 152 |
|
---|
| 153 | /* used to remember the names of the posix attributes in AD */
|
---|
| 154 | /* see the rfc2307 & sfu nss backends */
|
---|
| 155 |
|
---|
| 156 | struct posix_schema {
|
---|
| 157 | char *posix_homedir_attr;
|
---|
| 158 | char *posix_shell_attr;
|
---|
| 159 | char *posix_uidnumber_attr;
|
---|
| 160 | char *posix_gidnumber_attr;
|
---|
| 161 | char *posix_gecos_attr;
|
---|
| 162 | char *posix_uid_attr;
|
---|
| 163 | };
|
---|
| 164 |
|
---|
| 165 |
|
---|
| 166 |
|
---|
| 167 | #ifdef HAVE_ADS
|
---|
| 168 | typedef LDAPMod **ADS_MODLIST;
|
---|
| 169 | #else
|
---|
| 170 | typedef void **ADS_MODLIST;
|
---|
| 171 | #endif
|
---|
| 172 |
|
---|
| 173 | /* macros to simplify error returning */
|
---|
| 174 | #define ADS_ERROR(rc) ADS_ERROR_LDAP(rc)
|
---|
| 175 | #define ADS_ERROR_LDAP(rc) ads_build_error(ENUM_ADS_ERROR_LDAP, rc, 0)
|
---|
| 176 | #define ADS_ERROR_SYSTEM(rc) ads_build_error(ENUM_ADS_ERROR_SYSTEM, rc?rc:EINVAL, 0)
|
---|
| 177 | #define ADS_ERROR_KRB5(rc) ads_build_error(ENUM_ADS_ERROR_KRB5, rc, 0)
|
---|
| 178 | #define ADS_ERROR_GSS(rc, minor) ads_build_error(ENUM_ADS_ERROR_GSS, rc, minor)
|
---|
| 179 | #define ADS_ERROR_NT(rc) ads_build_nt_error(ENUM_ADS_ERROR_NT,rc)
|
---|
| 180 |
|
---|
| 181 | #define ADS_ERR_OK(status) ((status.error_type == ENUM_ADS_ERROR_NT) ? NT_STATUS_IS_OK(status.err.nt_status):(status.err.rc == 0))
|
---|
| 182 | #define ADS_SUCCESS ADS_ERROR(0)
|
---|
| 183 |
|
---|
| 184 | #define ADS_ERROR_HAVE_NO_MEMORY(x) do { \
|
---|
| 185 | if (!(x)) {\
|
---|
| 186 | return ADS_ERROR(LDAP_NO_MEMORY);\
|
---|
| 187 | }\
|
---|
| 188 | } while (0)
|
---|
| 189 |
|
---|
| 190 |
|
---|
| 191 | /* time between reconnect attempts */
|
---|
| 192 | #define ADS_RECONNECT_TIME 5
|
---|
| 193 |
|
---|
| 194 | /* ldap control oids */
|
---|
| 195 | #define ADS_PAGE_CTL_OID "1.2.840.113556.1.4.319"
|
---|
| 196 | #define ADS_NO_REFERRALS_OID "1.2.840.113556.1.4.1339"
|
---|
| 197 | #define ADS_SERVER_SORT_OID "1.2.840.113556.1.4.473"
|
---|
| 198 | #define ADS_PERMIT_MODIFY_OID "1.2.840.113556.1.4.1413"
|
---|
| 199 | #define ADS_ASQ_OID "1.2.840.113556.1.4.1504"
|
---|
| 200 | #define ADS_EXTENDED_DN_OID "1.2.840.113556.1.4.529"
|
---|
| 201 | #define ADS_SD_FLAGS_OID "1.2.840.113556.1.4.801"
|
---|
| 202 |
|
---|
| 203 | /* ldap attribute oids (Services for Unix 3.0, 3.5) */
|
---|
| 204 | #define ADS_ATTR_SFU_UIDNUMBER_OID "1.2.840.113556.1.6.18.1.310"
|
---|
| 205 | #define ADS_ATTR_SFU_GIDNUMBER_OID "1.2.840.113556.1.6.18.1.311"
|
---|
| 206 | #define ADS_ATTR_SFU_HOMEDIR_OID "1.2.840.113556.1.6.18.1.344"
|
---|
| 207 | #define ADS_ATTR_SFU_SHELL_OID "1.2.840.113556.1.6.18.1.312"
|
---|
| 208 | #define ADS_ATTR_SFU_GECOS_OID "1.2.840.113556.1.6.18.1.337"
|
---|
| 209 | #define ADS_ATTR_SFU_UID_OID "1.2.840.113556.1.6.18.1.309"
|
---|
| 210 |
|
---|
| 211 | /* ldap attribute oids (Services for Unix 2.0) */
|
---|
| 212 | #define ADS_ATTR_SFU20_UIDNUMBER_OID "1.2.840.113556.1.4.7000.187.70"
|
---|
| 213 | #define ADS_ATTR_SFU20_GIDNUMBER_OID "1.2.840.113556.1.4.7000.187.71"
|
---|
| 214 | #define ADS_ATTR_SFU20_HOMEDIR_OID "1.2.840.113556.1.4.7000.187.106"
|
---|
| 215 | #define ADS_ATTR_SFU20_SHELL_OID "1.2.840.113556.1.4.7000.187.72"
|
---|
| 216 | #define ADS_ATTR_SFU20_GECOS_OID "1.2.840.113556.1.4.7000.187.97"
|
---|
| 217 | #define ADS_ATTR_SFU20_UID_OID "1.2.840.113556.1.4.7000.187.102"
|
---|
| 218 |
|
---|
| 219 |
|
---|
| 220 | /* ldap attribute oids (RFC2307) */
|
---|
| 221 | #define ADS_ATTR_RFC2307_UIDNUMBER_OID "1.3.6.1.1.1.1.0"
|
---|
| 222 | #define ADS_ATTR_RFC2307_GIDNUMBER_OID "1.3.6.1.1.1.1.1"
|
---|
| 223 | #define ADS_ATTR_RFC2307_HOMEDIR_OID "1.3.6.1.1.1.1.3"
|
---|
| 224 | #define ADS_ATTR_RFC2307_SHELL_OID "1.3.6.1.1.1.1.4"
|
---|
| 225 | #define ADS_ATTR_RFC2307_GECOS_OID "1.3.6.1.1.1.1.2"
|
---|
| 226 | #define ADS_ATTR_RFC2307_UID_OID "0.9.2342.19200300.100.1.1"
|
---|
| 227 |
|
---|
| 228 | /* ldap bitwise searches */
|
---|
| 229 | #define ADS_LDAP_MATCHING_RULE_BIT_AND "1.2.840.113556.1.4.803"
|
---|
| 230 | #define ADS_LDAP_MATCHING_RULE_BIT_OR "1.2.840.113556.1.4.804"
|
---|
| 231 |
|
---|
| 232 | #define ADS_PINGS 0x0000FFFF /* Ping response */
|
---|
| 233 | #define ADS_DNS_CONTROLLER 0x20000000 /* DomainControllerName is a DNS name*/
|
---|
| 234 | #define ADS_DNS_DOMAIN 0x40000000 /* DomainName is a DNS name */
|
---|
| 235 | #define ADS_DNS_FOREST 0x80000000 /* DnsForestName is a DNS name */
|
---|
| 236 |
|
---|
| 237 | /* ads auth control flags */
|
---|
| 238 | #define ADS_AUTH_DISABLE_KERBEROS 0x0001
|
---|
| 239 | #define ADS_AUTH_NO_BIND 0x0002
|
---|
| 240 | #define ADS_AUTH_ANON_BIND 0x0004
|
---|
| 241 | #define ADS_AUTH_SIMPLE_BIND 0x0008
|
---|
| 242 | #define ADS_AUTH_ALLOW_NTLMSSP 0x0010
|
---|
| 243 | #define ADS_AUTH_SASL_SIGN 0x0020
|
---|
| 244 | #define ADS_AUTH_SASL_SEAL 0x0040
|
---|
| 245 | #define ADS_AUTH_SASL_FORCE 0x0080
|
---|
| 246 | #define ADS_AUTH_USER_CREDS 0x0100
|
---|
| 247 |
|
---|
| 248 | /* Kerberos environment variable names */
|
---|
| 249 | #define KRB5_ENV_CCNAME "KRB5CCNAME"
|
---|
| 250 |
|
---|
| 251 | #define WELL_KNOWN_GUID_COMPUTERS "AA312825768811D1ADED00C04FD8D5CD"
|
---|
| 252 | #define WELL_KNOWN_GUID_USERS "A9D1CA15768811D1ADED00C04FD8D5CD"
|
---|
| 253 |
|
---|
| 254 | enum ads_extended_dn_flags {
|
---|
| 255 | ADS_EXTENDED_DN_HEX_STRING = 0,
|
---|
| 256 | ADS_EXTENDED_DN_STRING = 1 /* not supported on win2k */
|
---|
| 257 | };
|
---|
| 258 |
|
---|
| 259 | /* this is probably not very well suited to pass other controls generically but
|
---|
| 260 | * is good enough for the extended dn control where it is only used for atm */
|
---|
| 261 |
|
---|
| 262 | typedef struct {
|
---|
| 263 | const char *control;
|
---|
| 264 | int val;
|
---|
| 265 | int critical;
|
---|
| 266 | } ads_control;
|
---|
| 267 |
|
---|
| 268 | #define ADS_IGNORE_PRINCIPAL "not_defined_in_RFC4178@please_ignore"
|
---|
| 269 |
|
---|
| 270 | #endif /* _INCLUDE_ADS_H_ */
|
---|