Revert "Fix bug 8196 - Many (newer) header files don't have copyright / GPL header...
[ddiss/samba.git] / source4 / 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                 struct ldb_message *attributes;
22                 bool one_level_indexes;
23                 bool attribute_indexes;
24
25                 struct {
26                         char *name;
27                         int flags;
28                 } last_attribute;
29         } *cache;
30
31         int in_transaction;
32
33         bool check_base;
34         struct ltdb_idxptr *idxptr;
35         bool prepared_commit;
36         int read_lock_count;
37
38         bool warn_unindexed;
39 };
40
41 /*
42   the async local context
43   holds also internal search state during a full db search
44 */
45 struct ltdb_req_spy {
46         struct ltdb_context *ctx;
47 };
48
49 struct ltdb_context {
50         struct ldb_module *module;
51         struct ldb_request *req;
52
53         bool request_terminated;
54         struct ltdb_req_spy *spy;
55
56         /* search stuff */
57         const struct ldb_parse_tree *tree;
58         struct ldb_dn *base;
59         enum ldb_scope scope;
60         const char * const *attrs;
61         struct tevent_timer *timeout_event;
62 };
63
64 /* special record types */
65 #define LTDB_INDEX      "@INDEX"
66 #define LTDB_INDEXLIST  "@INDEXLIST"
67 #define LTDB_IDX        "@IDX"
68 #define LTDB_IDXVERSION "@IDXVERSION"
69 #define LTDB_IDXATTR    "@IDXATTR"
70 #define LTDB_IDXONE     "@IDXONE"
71 #define LTDB_BASEINFO   "@BASEINFO"
72 #define LTDB_OPTIONS    "@OPTIONS"
73 #define LTDB_ATTRIBUTES "@ATTRIBUTES"
74
75 /* special attribute types */
76 #define LTDB_SEQUENCE_NUMBER "sequenceNumber"
77 #define LTDB_CHECK_BASE "checkBaseOnSearch"
78 #define LTDB_MOD_TIMESTAMP "whenChanged"
79 #define LTDB_OBJECTCLASS "objectClass"
80
81 /* The following definitions come from lib/ldb/ldb_tdb/ldb_cache.c  */
82
83 int ltdb_cache_reload(struct ldb_module *module);
84 int ltdb_cache_load(struct ldb_module *module);
85 int ltdb_increase_sequence_number(struct ldb_module *module);
86 int ltdb_check_at_attributes_values(const struct ldb_val *value);
87
88 /* The following definitions come from lib/ldb/ldb_tdb/ldb_index.c  */
89
90 struct ldb_parse_tree;
91
92 int ltdb_search_indexed(struct ltdb_context *ctx, uint32_t *);
93 int ltdb_index_add_new(struct ldb_module *module, const struct ldb_message *msg);
94 int ltdb_index_delete(struct ldb_module *module, const struct ldb_message *msg);
95 int ltdb_index_del_element(struct ldb_module *module, struct ldb_dn *dn,
96                            struct ldb_message_element *el);
97 int ltdb_index_add_element(struct ldb_module *module, struct ldb_dn *dn, 
98                            struct ldb_message_element *el);
99 int ltdb_index_del_value(struct ldb_module *module, struct ldb_dn *dn,
100                          struct ldb_message_element *el, unsigned int v_idx);
101 int ltdb_reindex(struct ldb_module *module);
102 int ltdb_index_transaction_start(struct ldb_module *module);
103 int ltdb_index_transaction_commit(struct ldb_module *module);
104 int ltdb_index_transaction_cancel(struct ldb_module *module);
105
106 /* The following definitions come from lib/ldb/ldb_tdb/ldb_pack.c  */
107
108 int ltdb_pack_data(struct ldb_module *module,
109                    const struct ldb_message *message,
110                    struct TDB_DATA *data);
111 void ltdb_unpack_data_free(struct ldb_module *module,
112                            struct ldb_message *message);
113 int ltdb_unpack_data(struct ldb_module *module,
114                      const struct TDB_DATA *data,
115                      struct ldb_message *message);
116
117 /* The following definitions come from lib/ldb/ldb_tdb/ldb_search.c  */
118
119 int ltdb_has_wildcard(struct ldb_module *module, const char *attr_name, 
120                       const struct ldb_val *val);
121 void ltdb_search_dn1_free(struct ldb_module *module, struct ldb_message *msg);
122 int ltdb_search_dn1(struct ldb_module *module, struct ldb_dn *dn, struct ldb_message *msg);
123 int ltdb_add_attr_results(struct ldb_module *module,
124                           TALLOC_CTX *mem_ctx, 
125                           struct ldb_message *msg,
126                           const char * const attrs[], 
127                           unsigned int *count, 
128                           struct ldb_message ***res);
129 int ltdb_filter_attrs(struct ldb_message *msg, const char * const *attrs);
130 int ltdb_search(struct ltdb_context *ctx);
131
132 /* The following definitions come from lib/ldb/ldb_tdb/ldb_tdb.c  */
133 int ltdb_lock_read(struct ldb_module *module);
134 int ltdb_unlock_read(struct ldb_module *module);
135 struct TDB_DATA ltdb_key(struct ldb_module *module, struct ldb_dn *dn);
136 int ltdb_store(struct ldb_module *module, const struct ldb_message *msg, int flgs);
137 int ltdb_modify_internal(struct ldb_module *module, const struct ldb_message *msg, struct ldb_request *req);
138 int ltdb_delete_noindex(struct ldb_module *module, struct ldb_dn *dn);
139 int ltdb_err_map(enum TDB_ERROR tdb_code);
140
141 struct tdb_context *ltdb_wrap_open(TALLOC_CTX *mem_ctx,
142                                    const char *path, int hash_size, int tdb_flags,
143                                    int open_flags, mode_t mode,
144                                    struct ldb_context *ldb);