s4-ldb: cope better with corruption of tdb records
[ira/wip.git] / source4 / lib / ldb / ldb_tdb / ldb_tdb.h
1 #include "ldb_includes.h"
2 #include "tdb.h"
3 #include "ldb_module.h"
4
5 /* this private structure is used by the ltdb backend in the
6    ldb_context */
7 struct ltdb_private {
8         TDB_CONTEXT *tdb;
9         unsigned int connect_flags;
10         
11         unsigned long long sequence_number;
12
13         /* the low level tdb seqnum - used to avoid loading BASEINFO when
14            possible */
15         int tdb_seqnum;
16
17         struct ltdb_cache {
18                 struct ldb_message *indexlist;
19                 struct ldb_message *attributes;
20
21                 struct {
22                         char *name;
23                         int flags;
24                 } last_attribute;
25         } *cache;
26
27         int in_transaction;
28
29         bool check_base;
30         struct ltdb_idxptr *idxptr;
31         bool prepared_commit;
32 };
33
34 /*
35   the async local context
36   holds also internal search state during a full db search
37 */
38 struct ltdb_req_spy {
39         struct ltdb_context *ctx;
40 };
41
42 struct ltdb_context {
43         struct ldb_module *module;
44         struct ldb_request *req;
45
46         bool request_terminated;
47         struct ltdb_req_spy *spy;
48
49         /* search stuff */
50         const struct ldb_parse_tree *tree;
51         struct ldb_dn *base;
52         enum ldb_scope scope;
53         const char * const *attrs;
54         struct tevent_timer *timeout_event;
55 };
56
57 /* special record types */
58 #define LTDB_INDEX      "@INDEX"
59 #define LTDB_INDEXLIST  "@INDEXLIST"
60 #define LTDB_IDX        "@IDX"
61 #define LTDB_IDXPTR     "@IDXPTR"
62 #define LTDB_IDXATTR    "@IDXATTR"
63 #define LTDB_IDXONE     "@IDXONE"
64 #define LTDB_BASEINFO   "@BASEINFO"
65 #define LTDB_OPTIONS    "@OPTIONS"
66 #define LTDB_ATTRIBUTES "@ATTRIBUTES"
67
68 /* special attribute types */
69 #define LTDB_SEQUENCE_NUMBER "sequenceNumber"
70 #define LTDB_CHECK_BASE "checkBaseOnSearch"
71 #define LTDB_MOD_TIMESTAMP "whenChanged"
72 #define LTDB_OBJECTCLASS "objectClass"
73
74 /* The following definitions come from lib/ldb/ldb_tdb/ldb_cache.c  */
75
76 int ltdb_cache_reload(struct ldb_module *module);
77 int ltdb_cache_load(struct ldb_module *module);
78 int ltdb_increase_sequence_number(struct ldb_module *module);
79 int ltdb_check_at_attributes_values(const struct ldb_val *value);
80
81 /* The following definitions come from lib/ldb/ldb_tdb/ldb_index.c  */
82
83 struct ldb_parse_tree;
84
85 int ltdb_search_indexed(struct ltdb_context *ctx, uint32_t *);
86 int ltdb_index_add(struct ldb_module *module, const struct ldb_message *msg);
87 int ltdb_index_del(struct ldb_module *module, const struct ldb_message *msg);
88 int ltdb_index_one(struct ldb_module *module, const struct ldb_message *msg, int add);
89 int ltdb_reindex(struct ldb_module *module);
90 int ltdb_index_transaction_start(struct ldb_module *module);
91 int ltdb_index_transaction_commit(struct ldb_module *module);
92 int ltdb_index_transaction_cancel(struct ldb_module *module);
93
94 /* The following definitions come from lib/ldb/ldb_tdb/ldb_pack.c  */
95
96 int ltdb_pack_data(struct ldb_module *module,
97                    const struct ldb_message *message,
98                    struct TDB_DATA *data);
99 void ltdb_unpack_data_free(struct ldb_module *module,
100                            struct ldb_message *message);
101 int ltdb_unpack_data(struct ldb_module *module,
102                      const struct TDB_DATA *data,
103                      struct ldb_message *message);
104
105 /* The following definitions come from lib/ldb/ldb_tdb/ldb_search.c  */
106
107 int ltdb_has_wildcard(struct ldb_module *module, const char *attr_name, 
108                       const struct ldb_val *val);
109 void ltdb_search_dn1_free(struct ldb_module *module, struct ldb_message *msg);
110 int ltdb_search_dn1(struct ldb_module *module, struct ldb_dn *dn, struct ldb_message *msg);
111 int ltdb_add_attr_results(struct ldb_module *module,
112                           TALLOC_CTX *mem_ctx, 
113                           struct ldb_message *msg,
114                           const char * const attrs[], 
115                           unsigned int *count, 
116                           struct ldb_message ***res);
117 int ltdb_filter_attrs(struct ldb_message *msg, const char * const *attrs);
118 int ltdb_search(struct ltdb_context *ctx);
119
120 /* The following definitions come from lib/ldb/ldb_tdb/ldb_tdb.c  */
121 int ltdb_lock_read(struct ldb_module *module);
122 int ltdb_unlock_read(struct ldb_module *module);
123 struct TDB_DATA ltdb_key(struct ldb_module *module, struct ldb_dn *dn);
124 int ltdb_store(struct ldb_module *module, const struct ldb_message *msg, int flgs);
125 int ltdb_delete_noindex(struct ldb_module *module, struct ldb_dn *dn);
126 int ltdb_modify_internal(struct ldb_module *module, const struct ldb_message *msg);
127
128 int ltdb_index_del_value(struct ldb_module *module, const char *dn, 
129                          struct ldb_message_element *el, int v_idx);
130
131 struct tdb_context *ltdb_wrap_open(TALLOC_CTX *mem_ctx,
132                                    const char *path, int hash_size, int tdb_flags,
133                                    int open_flags, mode_t mode,
134                                    struct ldb_context *ldb);