r17580: Add a new tools to convert back from AD-like schema to OpenLDAP.
[kamenim/samba.git] / source4 / lib / ldb / include / ldb.h
index 0e192c2e31635cb989d959e6ed6a8ab0845fd8a4..2e659b5307928ec6144431c8cadd92f1cae9c01e 100644 (file)
@@ -233,6 +233,15 @@ struct ldb_utf8_fns {
 */
 #define LDB_FLG_NOSYNC 2
 
+/**
+   Flag value to specify autoreconnect mode.
+
+   If LDB_FLG_RECONNECT is used in ldb_connect, then the backend will
+   be opened in a way that makes it try to auto reconnect if the
+   connection is dropped (actually make sense only with ldap).
+*/
+#define LDB_FLG_RECONNECT 4
+
 /*! \cond DOXYGEN_IGNORE */
 #ifndef PRINTF_ATTRIBUTE
 #define PRINTF_ATTRIBUTE(a,b)
@@ -413,6 +422,27 @@ typedef int (*ldb_qsort_cmp_fn_t) (void *v1, void *v2, void *opaque);
 */
 #define LDB_CONTROL_PAGED_RESULTS_OID  "1.2.840.113556.1.4.319"
 
+/**
+   OID for specifying the returned elements of the ntSecurityDescriptor
+
+   \sa <a href="http://msdn.microsoft.com/library/default.asp?url=/library/en-us/ldap/ldap/ldap_server_sd_flags_oid.asp">Microsoft documentation of this OID</a>
+*/
+#define LDB_CONTROL_SD_FLAGS_OID       "1.2.840.113556.1.4.801"
+
+/**
+   OID for specifying an advanced scope for the search (one partition)
+
+   \sa <a href="http://msdn.microsoft.com/library/default.asp?url=/library/en-us/ldap/ldap/ldap_server_domain_scope_oid.asp">Microsoft documentation of this OID</a>
+*/
+#define LDB_CONTROL_DOMAIN_SCOPE_OID   "1.2.840.113556.1.4.1339"
+
+/**
+   OID for specifying an advanced scope for a search
+
+   \sa <a href="http://msdn.microsoft.com/library/default.asp?url=/library/en-us/ldap/ldap/ldap_server_search_options_oid.asp">Microsoft documentation of this OID</a>
+*/
+#define LDB_CONTROL_SEARCH_OPTIONS_OID "1.2.840.113556.1.4.1340"
+
 /**
    OID for notification
 
@@ -420,6 +450,13 @@ typedef int (*ldb_qsort_cmp_fn_t) (void *v1, void *v2, void *opaque);
 */
 #define LDB_CONTROL_NOTIFICATION_OID   "1.2.840.113556.1.4.528"
 
+/**
+   OID for getting deleted objects
+
+   \sa <a href="http://msdn.microsoft.com/library/default.asp?url=/library/en-us/ldap/ldap/ldap_server_show_deleted_oid.asp">Microsoft documentation of this OID</a>
+*/
+#define LDB_CONTROL_SHOW_DELETED_OID   "1.2.840.113556.1.4.417"
+
 /**
    OID for extended DN
 
@@ -455,20 +492,95 @@ typedef int (*ldb_qsort_cmp_fn_t) (void *v1, void *v2, void *opaque);
 /**
    OID for LDAP Attribute Scoped Query extension.
 
-   This control is include in SearchRequest or SearchResponse
+   This control is included in SearchRequest or SearchResponse
    messages as part of the controls field of the LDAPMessage.
 */
 #define LDB_CONTROL_ASQ_OID            "1.2.840.113556.1.4.1504"
 
 /**
-   OID for LDAPrectory Sync extension. 
+   OID for LDAP Directory Sync extension. 
 
-   This control is include in SearchRequest or SearchResponse
+   This control is included in SearchRequest or SearchResponse
    messages as part of the controls field of the LDAPMessage.
 */
 #define LDB_CONTROL_DIRSYNC_OID                "1.2.840.113556.1.4.841"
 
 
+/**
+   OID for LDAP Virtual List View Request extension.
+
+   This control is included in SearchRequest messages
+   as part of the controls field of the LDAPMessage.
+*/
+#define LDB_CONTROL_VLV_REQ_OID                "2.16.840.1.113730.3.4.9"
+
+/**
+   OID for LDAP Virtual List View Response extension.
+
+   This control is included in SearchResponse messages
+   as part of the controls field of the LDAPMessage.
+*/
+#define LDB_CONTROL_VLV_RESP_OID       "2.16.840.1.113730.3.4.10"
+
+/**
+   OID to let modifies don't give an error when adding an existing
+   attribute with the same value or deleting an nonexisting one attribute
+
+   \sa <a href="http://msdn.microsoft.com/library/default.asp?url=/library/en-us/ldap/ldap/ldap_server_permissive_modify_oid.asp">Microsoft documentation of this OID</a>
+*/
+#define LDB_CONTROL_PERMISSIVE_MODIFY_OID      "1.2.840.113556.1.4.1413"
+
+/**
+   OID for LDAP Extended Operation START_TLS.
+
+   This Extended operation is used to start a new TLS
+   channel on top of a clear text channel.
+*/
+#define LDB_EXTENDED_START_TLS_OID     "1.3.6.1.4.1.1466.20037"
+
+/**
+   OID for LDAP Extended Operation START_TLS.
+
+   This Extended operation is used to start a new TLS
+   channel on top of a clear text channel.
+*/
+#define LDB_EXTENDED_DYNAMIC_OID       "1.3.6.1.4.1.1466.101.119.1"
+
+/**
+   OID for LDAP Extended Operation START_TLS.
+
+   This Extended operation is used to start a new TLS
+   channel on top of a clear text channel.
+*/
+#define LDB_EXTENDED_FAST_BIND_OID     "1.2.840.113556.1.4.1781"
+
+struct ldb_sd_flags_control {
+       /*
+        * request the owner    0x00000001
+        * request the group    0x00000002
+        * request the DACL     0x00000004
+        * request the SACL     0x00000008
+        */
+       unsigned secinfo_flags;
+};
+
+struct ldb_search_options_control {
+       /*
+        * DOMAIN_SCOPE         0x00000001
+        * this limits the search to one partition,
+        * and no referrals will be returned.
+        * (Note this doesn't limit the entries by there
+        *  objectSid belonging to a domain! Builtin and Foreign Sids
+        *  are still returned)
+        *
+        * PHANTOM_ROOT         0x00000002
+        * this search on the whole tree on a domain controller
+        * over multiple partitions without referrals.
+        * (This is the default behavior on the Global Catalog Port)
+        */
+       unsigned search_options;
+};
+
 struct ldb_paged_control {
        int size;
        int cookie_len;
@@ -504,33 +616,100 @@ struct ldb_dirsync_control {
        char *cookie;
 };
 
+struct ldb_vlv_req_control {
+       int beforeCount;
+       int afterCount;
+       int type;
+       union {
+               struct {
+                       int offset;
+                       int contentCount;
+               } byOffset;
+               struct {
+                       int value_len;
+                       char *value;
+               } gtOrEq;
+       } match;
+       int ctxid_len;
+       char *contextId;
+};
+
+struct ldb_vlv_resp_control {
+       int targetPosition;
+       int contentCount;
+       int vlv_result;
+       int ctxid_len;
+       char *contextId;
+};
+
 struct ldb_control {
        const char *oid;
        int critical;
        void *data;
 };
 
-struct ldb_credentials;
-
 enum ldb_request_type {
-       LDB_REQ_SEARCH,
-       LDB_REQ_ADD,
-       LDB_REQ_MODIFY,
-       LDB_REQ_DELETE,
-       LDB_REQ_RENAME,
-       LDB_REQ_REGISTER
+       LDB_SEARCH,
+       LDB_ADD,
+       LDB_MODIFY,
+       LDB_DELETE,
+       LDB_RENAME,
+       LDB_EXTENDED,
+       LDB_REQ_REGISTER_CONTROL,
+       LDB_REQ_REGISTER_PARTITION,
+       LDB_SEQUENCE_NUMBER
+};
+
+enum ldb_reply_type {
+       LDB_REPLY_ENTRY,
+       LDB_REPLY_REFERRAL,
+       LDB_REPLY_EXTENDED,
+       LDB_REPLY_DONE
+};
+
+enum ldb_wait_type {
+       LDB_WAIT_ALL,
+       LDB_WAIT_NONE
+};
+
+enum ldb_state {
+       LDB_ASYNC_INIT,
+       LDB_ASYNC_PENDING,
+       LDB_ASYNC_DONE
 };
 
 struct ldb_result {
        unsigned int count;
        struct ldb_message **msgs;
+       char **refs;
+       struct ldb_control **controls;
+};
+
+struct ldb_extended {
+       const char *oid;
+       const char *value;
+       int value_len;
+};
+
+struct ldb_reply {
+       enum ldb_reply_type type;
+       struct ldb_message *message;
+       struct ldb_extended *response;
+       char *referral;
        struct ldb_control **controls;
 };
 
+struct ldb_handle {
+       int status;
+       enum ldb_state state;
+       void *private_data;
+       struct ldb_module *module;
+};
+
 struct ldb_search {
        const struct ldb_dn *base;
        enum ldb_scope scope;
-       struct ldb_parse_tree *tree;
+       const struct ldb_parse_tree *tree;
        const char * const *attrs;
        struct ldb_result *res;
 };
@@ -556,9 +735,17 @@ struct ldb_register_control {
        const char *oid;
 };
 
+struct ldb_register_partition {
+       const struct ldb_dn *dn;
+};
+
+struct ldb_sequence_number {
+       uint64_t seq_num;
+};
+
 struct ldb_request {
 
-       int operation;
+       enum ldb_request_type operation;
 
        union {
                struct ldb_search search;
@@ -566,15 +753,37 @@ struct ldb_request {
                struct ldb_modify mod;
                struct ldb_delete del;
                struct ldb_rename rename;
-               struct ldb_register_control reg;
+               struct ldb_register_control reg_control;
+               struct ldb_register_partition reg_partition;
+               struct ldb_sequence_number seq_num;
        } op;
 
        struct ldb_control **controls;
-       struct ldb_credentials *creds;
+
+       void *context;
+       int (*callback)(struct ldb_context *, void *, struct ldb_reply *);
+
+       int timeout;
+       time_t starttime;
+       struct ldb_handle *handle;
 };
 
 int ldb_request(struct ldb_context *ldb, struct ldb_request *request);
 
+int ldb_wait(struct ldb_handle *handle, enum ldb_wait_type type);
+
+int ldb_set_timeout(struct ldb_context *ldb, struct ldb_request *req, int timeout);
+int ldb_set_timeout_from_prev_req(struct ldb_context *ldb, struct ldb_request *oldreq, struct ldb_request *newreq);
+
+/**
+  Initialise ldbs' global information
+
+  This is required before any other LDB call
+
+  \return 0 if initialisation succeeded, -1 otherwise
+*/
+int ldb_global_init(void);
+
 /**
   Initialise an ldb context
 
@@ -706,6 +915,11 @@ int ldb_rename(struct ldb_context *ldb, const struct ldb_dn *olddn, const struct
 */
 int ldb_delete(struct ldb_context *ldb, const struct ldb_dn *dn);
 
+/**
+  Obtain current database sequence number
+*/
+int ldb_sequence_number(struct ldb_context *ldb, uint64_t *seq_num);
+
 /**
   start a transaction
 */
@@ -727,6 +941,11 @@ int ldb_transaction_cancel(struct ldb_context *ldb);
 */
 const char *ldb_errstring(struct ldb_context *ldb);
 
+/**
+  return a string explaining what a ldb error constant meancs
+*/
+const char *ldb_strerror(int ldb_err);
+
 /**
   setup the default utf8 functions
   FIXME: these functions do not yet handle utf8
@@ -954,8 +1173,8 @@ int ldb_dn_cmp(struct ldb_context *ldb, const char *dn1, const char *dn2);
    case; non-zero if there are any differences
 */
 int ldb_attr_cmp(const char *attr1, const char *attr2);
+char *ldb_attr_casefold(void *mem_ctx, const char *s);
 int ldb_attr_dn(const char *attr);
-char *ldb_dn_escape_value(void *mem_ctx, struct ldb_val value);
 
 /**
    Create an empty message
@@ -1007,6 +1226,11 @@ int ldb_msg_add(struct ldb_message *msg,
 int ldb_msg_add_value(struct ldb_message *msg, 
                      const char *attr_name,
                      const struct ldb_val *val);
+int ldb_msg_add_steal_value(struct ldb_message *msg, 
+                     const char *attr_name,
+                     struct ldb_val *val);
+int ldb_msg_add_steal_string(struct ldb_message *msg, 
+                            const char *attr_name, char *str);
 int ldb_msg_add_string(struct ldb_message *msg, 
                       const char *attr_name, const char *str);
 int ldb_msg_add_fmt(struct ldb_message *msg, 
@@ -1026,24 +1250,31 @@ int ldb_msg_element_compare(struct ldb_message_element *el1,
    single valued.
 */
 const struct ldb_val *ldb_msg_find_ldb_val(const struct ldb_message *msg, const char *attr_name);
-int ldb_msg_find_int(const struct ldb_message *msg, 
-                    const char *attr_name,
-                    int default_value);
-unsigned int ldb_msg_find_uint(const struct ldb_message *msg, 
-                              const char *attr_name,
-                              unsigned int default_value);
-int64_t ldb_msg_find_int64(const struct ldb_message *msg, 
-                          const char *attr_name,
-                          int64_t default_value);
-uint64_t ldb_msg_find_uint64(const struct ldb_message *msg, 
+int ldb_msg_find_attr_as_int(const struct ldb_message *msg, 
                             const char *attr_name,
-                            uint64_t default_value);
-double ldb_msg_find_double(const struct ldb_message *msg, 
-                          const char *attr_name,
-                          double default_value);
-const char *ldb_msg_find_string(const struct ldb_message *msg, 
-                               const char *attr_name,
-                               const char *default_value);
+                            int default_value);
+unsigned int ldb_msg_find_attr_as_uint(const struct ldb_message *msg, 
+                                      const char *attr_name,
+                                      unsigned int default_value);
+int64_t ldb_msg_find_attr_as_int64(const struct ldb_message *msg, 
+                                  const char *attr_name,
+                                  int64_t default_value);
+uint64_t ldb_msg_find_attr_as_uint64(const struct ldb_message *msg, 
+                                    const char *attr_name,
+                                    uint64_t default_value);
+double ldb_msg_find_attr_as_double(const struct ldb_message *msg, 
+                                  const char *attr_name,
+                                  double default_value);
+int ldb_msg_find_attr_as_bool(const struct ldb_message *msg, 
+                             const char *attr_name,
+                             int default_value);
+const char *ldb_msg_find_attr_as_string(const struct ldb_message *msg, 
+                                       const char *attr_name,
+                                       const char *default_value);
+
+struct ldb_dn *ldb_msg_find_attr_as_dn(void *mem_ctx,
+                                      const struct ldb_message *msg,
+                                       const char *attr_name);
 
 void ldb_msg_sort_elements(struct ldb_message *msg);
 
@@ -1060,6 +1291,10 @@ struct ldb_message *ldb_msg_diff(struct ldb_context *ldb,
                                 struct ldb_message *msg1,
                                 struct ldb_message *msg2);
 
+int ldb_msg_check_string_attribute(const struct ldb_message *msg,
+                                  const char *name,
+                                  const char *value);
+
 /**
    Integrity check an ldb_message
 
@@ -1073,7 +1308,8 @@ struct ldb_message *ldb_msg_diff(struct ldb_context *ldb,
    LDB_ERR_INVALID_ATTRIBUTE_SYNTAX) if there is a problem with a
    message.
 */
-int ldb_msg_sanity_check(const struct ldb_message *msg);
+int ldb_msg_sanity_check(struct ldb_context *ldb,
+                        const struct ldb_message *msg);
 
 /**
    Duplicate an ldb_val structure
@@ -1117,6 +1353,7 @@ const struct ldb_attrib_handler *ldb_attrib_handler(struct ldb_context *ldb,
 
 
 const char **ldb_attr_list_copy(void *mem_ctx, const char * const *attrs);
+const char **ldb_attr_list_copy_add(void *mem_ctx, const char * const *attrs, const char *new_attr);
 int ldb_attr_in_list(const char * const *attrs, const char *attr);