This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2 of the License, or
+ the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-#ifndef _SMB_LDAP_H
-#define _SMB_LDAP_H
+#ifndef _SMB_LDAP_H_
+#define _SMB_LDAP_H_
+#include "libcli/ldap/ldap_errors.h"
#include "lib/ldb/include/ldb.h"
+#include "librpc/gen_ndr/misc.h"
enum ldap_request_tag {
LDAP_TAG_BindRequest = 0,
LDAP_AUTH_MECH_SASL = 3
};
-enum ldap_result_code {
- LDAP_SUCCESS = 0,
- LDAP_OPERATIONS_ERROR = 1,
- LDAP_PROTOCOL_ERROR = 2,
- LDAP_TIME_LIMIT_EXCEEDED = 3,
- LDAP_SIZE_LIMIT_EXCEEDED = 4,
- LDAP_COMPARE_FALSE = 5,
- LDAP_COMPARE_TRUE = 6,
- LDAP_AUTH_METHOD_NOT_SUPPORTED = 7,
- LDAP_STRONG_AUTH_REQUIRED = 8,
- LDAP_REFERRAL = 10,
- LDAP_ADMIN_LIMIT_EXCEEDED = 11,
- LDAP_UNAVAILABLE_CRITICAL_EXTENSION = 12,
- LDAP_CONFIDENTIALITY_REQUIRED = 13,
- LDAP_SASL_BIND_IN_PROGRESS = 14,
- LDAP_NO_SUCH_ATTRIBUTE = 16,
- LDAP_UNDEFINED_ATTRIBUTE_TYPE = 17,
- LDAP_INAPPROPRIATE_MATCHING = 18,
- LDAP_CONSTRAINT_VIOLATION = 19,
- LDAP_ATTRIBUTE_OR_VALUE_EXISTS = 20,
- LDAP_INVALID_ATTRIBUTE_SYNTAX = 21,
- LDAP_NO_SUCH_OBJECT = 32,
- LDAP_ALIAS_PROBLEM = 33,
- LDAP_INVALID_DN_SYNTAX = 34,
- LDAP_ALIAS_DEREFERENCING_PROBLEM = 36,
- LDAP_INAPPROPRIATE_AUTHENTICATION = 48,
- LDAP_INVALID_CREDENTIALS = 49,
- LDAP_INSUFFICIENT_ACCESS_RIGHTs = 50,
- LDAP_BUSY = 51,
- LDAP_UNAVAILABLE = 52,
- LDAP_UNWILLING_TO_PERFORM = 53,
- LDAP_LOOP_DETECT = 54,
- LDAP_NAMING_VIOLATION = 64,
- LDAP_OBJECT_CLASS_VIOLATION = 65,
- LDAP_NOT_ALLOWED_ON_NON_LEAF = 66,
- LDAP_NOT_ALLOWED_ON_RDN = 67,
- LDAP_ENTRY_ALREADY_EXISTS = 68,
- LDAP_OBJECT_CLASS_MODS_PROHIBITED = 69,
- LDAP_AFFECTS_MULTIPLE_DSAS = 71,
- LDAP_OTHER = 80
-};
-
struct ldap_Result {
int resultcode;
const char *dn;
const char *referral;
};
-struct ldap_attribute {
- const char *name;
- int num_values;
- DATA_BLOB *values;
-};
-
struct ldap_BindRequest {
int version;
const char *dn;
const char *password;
struct {
const char *mechanism;
- DATA_BLOB secblob;
+ DATA_BLOB *secblob;/* optional */
} SASL;
} creds;
};
struct ldap_BindResponse {
struct ldap_Result response;
union {
- DATA_BLOB secblob;
+ DATA_BLOB *secblob;/* optional */
} SASL;
};
enum ldap_deref deref;
uint32_t timelimit;
uint32_t sizelimit;
- BOOL attributesonly;
+ bool attributesonly;
struct ldb_parse_tree *tree;
int num_attributes;
const char **attributes;
struct ldap_SearchResEntry {
const char *dn;
int num_attributes;
- struct ldap_attribute *attributes;
+ struct ldb_message_element *attributes;
};
struct ldap_SearchResRef {
struct ldap_mod {
enum ldap_modify_type type;
- struct ldap_attribute attrib;
+ struct ldb_message_element attrib;
};
struct ldap_ModifyRequest {
struct ldap_AddRequest {
const char *dn;
int num_attributes;
- struct ldap_attribute *attributes;
+ struct ldb_message_element *attributes;
};
struct ldap_DelRequest {
struct ldap_ModifyDNRequest {
const char *dn;
const char *newrdn;
- BOOL deleteolddn;
- const char *newsuperior;
+ bool deleteolddn;
+ const char *newsuperior;/* optional */
};
struct ldap_CompareRequest {
struct ldap_ExtendedRequest {
const char *oid;
- DATA_BLOB value;
+ DATA_BLOB *value;/* optional */
};
struct ldap_ExtendedResponse {
struct ldap_Result response;
- const char *name;
- DATA_BLOB value;
+ const char *oid;/* optional */
+ DATA_BLOB *value;/* optional */
};
union ldap_Request {
+ struct ldap_Result GeneralResult;
struct ldap_BindRequest BindRequest;
struct ldap_BindResponse BindResponse;
struct ldap_UnbindRequest UnbindRequest;
struct ldap_ExtendedResponse ExtendedResponse;
};
-struct ldap_Control {
- const char *oid;
- BOOL critical;
- DATA_BLOB value;
-};
struct ldap_message {
- uint32_t messageid;
+ int messageid;
enum ldap_request_tag type;
union ldap_Request r;
- int num_controls;
- struct ldap_Control *controls;
-};
-
-struct ldap_queue_entry {
- struct ldap_queue_entry *next, *prev;
- int msgid;
- struct ldap_message *msg;
-};
-
-struct ldap_connection {
- int sock;
- int next_msgid;
- char *host;
- uint16_t port;
- BOOL ldaps;
-
- const char *auth_dn;
- const char *simple_pw;
-
- /* Current outstanding search entry */
- int searchid;
-
- /* List for incoming search entries */
- struct ldap_queue_entry *search_entries;
-
- /* Outstanding LDAP requests that have not yet been replied to */
- struct ldap_queue_entry *outstanding;
-
- /* Let's support SASL */
- struct gensec_security *gensec;
+ struct ldb_control **controls;
+ bool *controls_decoded;
};
-#define LDAP_CONNECTION_TIMEOUT 10000
-
-/* The following definitions come from libcli/ldap/ldap.c */
+struct tevent_context;
+struct cli_credentials;
+struct dom_sid;
+struct asn1_data;
-BOOL ldap_encode(struct ldap_message *msg, DATA_BLOB *result);
-BOOL ldap_decode(struct asn1_data *data, struct ldap_message *msg);
-BOOL ldap_parse_basic_url(TALLOC_CTX *mem_ctx, const char *url,
- char **host, uint16_t *port, BOOL *ldaps);
-
-/* The following definitions come from libcli/ldap/ldap_client.c */
-
-struct ldap_connection *ldap_connect(TALLOC_CTX *mem_ctx, const char *url);
struct ldap_message *new_ldap_message(TALLOC_CTX *mem_ctx);
-BOOL ldap_send_msg(struct ldap_connection *conn, struct ldap_message *msg,
- const struct timeval *endtime);
-BOOL ldap_receive_msg(struct ldap_connection *conn, struct ldap_message *msg,
- const struct timeval *endtime);
-struct ldap_message *ldap_receive(struct ldap_connection *conn, int msgid,
- const struct timeval *endtime);
-struct ldap_message *ldap_transaction(struct ldap_connection *conn,
- struct ldap_message *request);
-int ldap_bind_simple(struct ldap_connection *conn, const char *userdn, const char *password);
-int ldap_bind_sasl(struct ldap_connection *conn, struct cli_credentials *creds);
-struct ldap_connection *ldap_setup_connection(TALLOC_CTX *mem_ctx, const char *url,
- const char *userdn, const char *password);
-struct ldap_connection *ldap_setup_connection_with_sasl(TALLOC_CTX *mem_ctx, const char *url,
- struct cli_credentials *creds);
-BOOL ldap_abandon_message(struct ldap_connection *conn, int msgid,
- const struct timeval *endtime);
-BOOL ldap_setsearchent(struct ldap_connection *conn, struct ldap_message *msg,
- const struct timeval *endtime);
-struct ldap_message *ldap_getsearchent(struct ldap_connection *conn,
- const struct timeval *endtime);
-void ldap_endsearchent(struct ldap_connection *conn,
- const struct timeval *endtime);
-struct ldap_message *ldap_searchone(struct ldap_connection *conn,
- struct ldap_message *msg,
- const struct timeval *endtime);
-BOOL ldap_find_single_value(struct ldap_message *msg, const char *attr,
- DATA_BLOB *value);
-BOOL ldap_find_single_string(struct ldap_message *msg, const char *attr,
- TALLOC_CTX *mem_ctx, char **value);
-BOOL ldap_find_single_int(struct ldap_message *msg, const char *attr,
- int *value);
-int ldap_error(struct ldap_connection *conn);
-NTSTATUS ldap2nterror(int ldaperror);
-
-/* The following definitions come from libcli/ldap/ldap_ldif.c */
-
-BOOL add_value_to_attrib(TALLOC_CTX *mem_ctx, struct ldb_val *value,
- struct ldap_attribute *attrib);
-BOOL add_attrib_to_array_talloc(TALLOC_CTX *mem_ctx,
- const struct ldap_attribute *attrib,
- struct ldap_attribute **attribs,
- int *num_attribs);
-BOOL add_mod_to_array_talloc(TALLOC_CTX *mem_ctx,
- struct ldap_mod *mod,
- struct ldap_mod **mods,
- int *num_mods);
-struct ldap_message *ldap_ldif2msg(TALLOC_CTX *mem_ctx, const char *s);
-
-/* The following definitions come from libcli/ldap/ldap_ndr.c */
-
-const char *ldap_encode_ndr_uint32(TALLOC_CTX *mem_ctx, uint32_t value);
-const char *ldap_encode_ndr_dom_sid(TALLOC_CTX *mem_ctx, struct dom_sid *sid);
-const char *ldap_encode_ndr_GUID(TALLOC_CTX *mem_ctx, struct GUID *guid);
-NTSTATUS ldap_decode_ndr_GUID(TALLOC_CTX *mem_ctx, struct ldb_val val, struct GUID *guid);
+NTSTATUS ldap_decode(struct asn1_data *data, struct ldap_message *msg);
+bool ldap_encode(struct ldap_message *msg, DATA_BLOB *result, TALLOC_CTX *mem_ctx);
-#endif
+#endif