r17580: Add a new tools to convert back from AD-like schema to OpenLDAP.
[kamenim/samba.git] / source4 / lib / ldb / include / ldb.h
index 13e69282cada252fc6d5765c90f1000463bfc0d5..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
 
@@ -485,6 +522,65 @@ typedef int (*ldb_qsort_cmp_fn_t) (void *v1, void *v2, void *opaque);
 */
 #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;
@@ -552,36 +648,31 @@ struct ldb_control {
        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_ASYNC_SEARCH,
-       LDB_ASYNC_ADD,
-       LDB_ASYNC_MODIFY,
-       LDB_ASYNC_DELETE,
-       LDB_ASYNC_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_async_wait_type {
+enum ldb_wait_type {
        LDB_WAIT_ALL,
-       LDB_WAIT_ONCE,
        LDB_WAIT_NONE
 };
 
-enum ldb_async_state {
+enum ldb_state {
        LDB_ASYNC_INIT,
        LDB_ASYNC_PENDING,
        LDB_ASYNC_DONE
@@ -594,23 +685,31 @@ struct ldb_result {
        struct ldb_control **controls;
 };
 
-struct ldb_async_result {
+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_async_handle {
+struct ldb_handle {
        int status;
-       enum ldb_async_state state;
+       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;
 };
@@ -636,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;
@@ -646,24 +753,27 @@ 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;
 
-       struct {
-               void *context;
-               int (*callback)(struct ldb_context *, void *, struct ldb_async_result *);
+       void *context;
+       int (*callback)(struct ldb_context *, void *, struct ldb_reply *);
 
-               int timeout;
-               struct ldb_async_handle *handle;
-       } async;
+       int timeout;
+       time_t starttime;
+       struct ldb_handle *handle;
 };
 
 int ldb_request(struct ldb_context *ldb, struct ldb_request *request);
 
-int ldb_async_wait(struct ldb_context *ldb, struct ldb_async_handle *handle, enum ldb_async_wait_type type);
+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
@@ -805,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
 */
@@ -826,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
@@ -1055,7 +1175,6 @@ int ldb_dn_cmp(struct ldb_context *ldb, const char *dn1, const char *dn2);
 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
@@ -1131,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);
 
@@ -1165,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
 
@@ -1178,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
@@ -1222,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);