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