ldb_tdb: Prepare to handle rename with GUID index by using ltdb_search_base()
[samba.git] / lib / ldb / ldb_tdb / ldb_tdb.h
1 #include "replace.h"
2 #include "system/filesys.h"
3 #include "system/time.h"
4 #include "tdb.h"
5 #include "ldb_module.h"
6
7 /* this private structure is used by the ltdb backend in the
8    ldb_context */
9 struct ltdb_private {
10         TDB_CONTEXT *tdb;
11         unsigned int connect_flags;
12         
13         unsigned long long sequence_number;
14
15         /* the low level tdb seqnum - used to avoid loading BASEINFO when
16            possible */
17         int tdb_seqnum;
18
19         struct ltdb_cache {
20                 struct ldb_message *indexlist;
21                 bool one_level_indexes;
22                 bool attribute_indexes;
23                 const char *GUID_index_attribute;
24         } *cache;
25
26         int in_transaction;
27
28         bool check_base;
29         bool disallow_dn_filter;
30         struct ltdb_idxptr *idxptr;
31         bool prepared_commit;
32         int read_lock_count;
33
34         bool warn_unindexed;
35         bool warn_reindex;
36
37         bool read_only;
38 };
39
40 struct ltdb_context {
41         struct ldb_module *module;
42         struct ldb_request *req;
43
44         bool request_terminated;
45         struct ltdb_req_spy *spy;
46
47         /* search stuff */
48         const struct ldb_parse_tree *tree;
49         struct ldb_dn *base;
50         enum ldb_scope scope;
51         const char * const *attrs;
52         struct tevent_timer *timeout_event;
53
54         /* error handling */
55         int error;
56 };
57
58 /* special record types */
59 #define LTDB_INDEX      "@INDEX"
60 #define LTDB_INDEXLIST  "@INDEXLIST"
61 #define LTDB_IDX        "@IDX"
62 #define LTDB_IDXVERSION "@IDXVERSION"
63 #define LTDB_IDXATTR    "@IDXATTR"
64 #define LTDB_IDXONE     "@IDXONE"
65 #define LTDB_BASEINFO   "@BASEINFO"
66 #define LTDB_OPTIONS    "@OPTIONS"
67 #define LTDB_ATTRIBUTES "@ATTRIBUTES"
68
69 /* special attribute types */
70 #define LTDB_SEQUENCE_NUMBER "sequenceNumber"
71 #define LTDB_CHECK_BASE "checkBaseOnSearch"
72 #define LTDB_DISALLOW_DN_FILTER "disallowDNFilter"
73 #define LTDB_MOD_TIMESTAMP "whenChanged"
74 #define LTDB_OBJECTCLASS "objectClass"
75
76 /* DB keys */
77 #define LTDB_GUID_KEY_PREFIX "GUID="
78 #define LTDB_GUID_SIZE 16
79
80 /* The following definitions come from lib/ldb/ldb_tdb/ldb_cache.c  */
81
82 int ltdb_cache_reload(struct ldb_module *module);
83 int ltdb_cache_load(struct ldb_module *module);
84 int ltdb_increase_sequence_number(struct ldb_module *module);
85 int ltdb_check_at_attributes_values(const struct ldb_val *value);
86
87 /* The following definitions come from lib/ldb/ldb_tdb/ldb_index.c  */
88
89 struct ldb_parse_tree;
90
91 int ltdb_search_indexed(struct ltdb_context *ctx, uint32_t *);
92 int ltdb_index_add_new(struct ldb_module *module,
93                        struct ltdb_private *ltdb,
94                        const struct ldb_message *msg);
95 int ltdb_index_delete(struct ldb_module *module, const struct ldb_message *msg);
96 int ltdb_index_del_element(struct ldb_module *module,
97                            struct ltdb_private *ltdb,
98                            const struct ldb_message *msg,
99                            struct ldb_message_element *el);
100 int ltdb_index_add_element(struct ldb_module *module,
101                            struct ltdb_private *ltdb,
102                            const struct ldb_message *msg,
103                            struct ldb_message_element *el);
104 int ltdb_index_del_value(struct ldb_module *module,
105                          struct ltdb_private *ltdb,
106                          const struct ldb_message *msg,
107                          struct ldb_message_element *el, unsigned int v_idx);
108 int ltdb_reindex(struct ldb_module *module);
109 int ltdb_index_transaction_start(struct ldb_module *module);
110 int ltdb_index_transaction_commit(struct ldb_module *module);
111 int ltdb_index_transaction_cancel(struct ldb_module *module);
112
113 /* The following definitions come from lib/ldb/ldb_tdb/ldb_search.c  */
114
115 int ltdb_has_wildcard(struct ldb_module *module, const char *attr_name, 
116                       const struct ldb_val *val);
117 void ltdb_search_dn1_free(struct ldb_module *module, struct ldb_message *msg);
118 int ltdb_search_dn1(struct ldb_module *module, struct ldb_dn *dn, struct ldb_message *msg,
119                     unsigned int unpack_flags);
120 int ltdb_search_base(struct ldb_module *module, struct ldb_dn *dn);
121 int ltdb_search_key(struct ldb_module *module, struct ltdb_private *ltdb,
122                     struct TDB_DATA tdb_key,
123                     struct ldb_message *msg,
124                     unsigned int unpack_flags);
125 int ltdb_filter_attrs(TALLOC_CTX *mem_ctx,
126                       const struct ldb_message *msg, const char * const *attrs,
127                       struct ldb_message **filtered_msg);
128 int ltdb_search(struct ltdb_context *ctx);
129
130 /* The following definitions come from lib/ldb/ldb_tdb/ldb_tdb.c  */
131 int ltdb_lock_read(struct ldb_module *module);
132 int ltdb_unlock_read(struct ldb_module *module);
133 /* 
134  * Determine if this key could hold a record.  We allow the new GUID
135  * index, the old DN index and a possible future ID=
136  */
137 bool ltdb_key_is_record(TDB_DATA key);
138 TDB_DATA ltdb_key_dn(struct ldb_module *module, struct ldb_dn *dn);
139 TDB_DATA ltdb_key_msg(struct ldb_module *module, const struct ldb_message *msg);
140 int ltdb_store(struct ldb_module *module, const struct ldb_message *msg, int flgs);
141 int ltdb_modify_internal(struct ldb_module *module, const struct ldb_message *msg, struct ldb_request *req);
142 int ltdb_delete_noindex(struct ldb_module *module,
143                         const struct ldb_message *msg);
144 int ltdb_err_map(enum TDB_ERROR tdb_code);
145
146 struct tdb_context *ltdb_wrap_open(TALLOC_CTX *mem_ctx,
147                                    const char *path, int hash_size, int tdb_flags,
148                                    int open_flags, mode_t mode,
149                                    struct ldb_context *ldb);