2010-11-01 15:36:42 +03:00
# include "replace.h"
# include "system/filesys.h"
# include "system/time.h"
2012-06-19 07:13:10 +04:00
# include "tdb.h"
2009-01-30 02:39:30 +03:00
# include "ldb_module.h"
2017-01-10 09:05:40 +03:00
struct ltdb_private ;
struct kv_db_ops {
int ( * store ) ( struct ltdb_private * ltdb , TDB_DATA key , TDB_DATA data , int flags ) ;
int ( * delete ) ( struct ltdb_private * ltdb , TDB_DATA key ) ;
int ( * lock_read ) ( struct ldb_module * ) ;
int ( * unlock_read ) ( struct ldb_module * ) ;
2017-01-10 11:44:11 +03:00
int ( * begin_write ) ( struct ltdb_private * ) ;
int ( * prepare_write ) ( struct ltdb_private * ) ;
int ( * abort_write ) ( struct ltdb_private * ) ;
int ( * finish_write ) ( struct ltdb_private * ) ;
2017-01-10 09:05:40 +03:00
int ( * error ) ( struct ltdb_private * ltdb ) ;
const char * ( * name ) ( struct ltdb_private * ltdb ) ;
} ;
2004-03-31 10:45:39 +04:00
/* this private structure is used by the ltdb backend in the
ldb_context */
struct ltdb_private {
2017-01-10 09:05:40 +03:00
const struct kv_db_ops * kv_ops ;
2004-03-31 10:45:39 +04:00
TDB_CONTEXT * tdb ;
unsigned int connect_flags ;
2004-05-01 13:45:56 +04:00
2006-09-21 10:44:12 +04:00
unsigned long long sequence_number ;
2004-05-01 13:45:56 +04:00
2006-10-19 01:45:46 +04:00
/* the low level tdb seqnum - used to avoid loading BASEINFO when
possible */
int tdb_seqnum ;
2005-01-02 10:49:29 +03:00
struct ltdb_cache {
struct ldb_message * indexlist ;
2009-10-21 15:21:26 +04:00
bool one_level_indexes ;
bool attribute_indexes ;
2017-08-10 08:13:48 +03:00
const char * GUID_index_attribute ;
2017-08-14 07:13:42 +03:00
const char * GUID_index_dn_component ;
2005-01-02 10:49:29 +03:00
} * cache ;
2007-10-18 04:03:21 +04:00
int in_transaction ;
2007-11-15 03:53:44 +03:00
bool check_base ;
2011-10-26 11:47:35 +04:00
bool disallow_dn_filter ;
2008-12-16 10:45:28 +03:00
struct ltdb_idxptr * idxptr ;
2009-03-31 08:07:54 +04:00
bool prepared_commit ;
2009-12-09 06:37:26 +03:00
int read_lock_count ;
2010-11-23 12:19:49 +03:00
bool warn_unindexed ;
2013-01-02 08:57:25 +04:00
bool warn_reindex ;
2017-09-18 01:43:32 +03:00
bool read_only ;
2017-08-16 01:42:40 +03:00
const struct ldb_schema_syntax * GUID_index_syntax ;
2018-02-21 05:20:17 +03:00
/*
* Maximum index key length . If non zero keys longer than this length
* will be truncated for non unique indexes . Keys for unique indexes
* greater than this length will be rejected .
*/
unsigned max_key_length ;
2004-03-31 10:45:39 +04:00
} ;
2006-07-22 20:56:33 +04:00
struct ltdb_context {
2006-03-03 20:44:03 +03:00
struct ldb_module * module ;
2008-09-12 02:34:11 +04:00
struct ldb_request * req ;
2009-03-10 01:04:38 +03:00
bool request_terminated ;
struct ltdb_req_spy * spy ;
2006-03-03 20:44:03 +03:00
/* search stuff */
2006-08-22 22:09:49 +04:00
const struct ldb_parse_tree * tree ;
2006-11-22 03:59:34 +03:00
struct ldb_dn * base ;
2006-03-03 20:44:03 +03:00
enum ldb_scope scope ;
const char * const * attrs ;
2008-12-29 22:24:57 +03:00
struct tevent_timer * timeout_event ;
2015-12-03 06:30:59 +03:00
/* error handling */
int error ;
2006-03-03 20:44:03 +03:00
} ;
2004-05-01 13:45:56 +04:00
/* special record types */
# define LTDB_INDEX "@INDEX"
# define LTDB_INDEXLIST "@INDEXLIST"
# define LTDB_IDX "@IDX"
2009-10-21 15:21:26 +04:00
# define LTDB_IDXVERSION "@IDXVERSION"
2004-05-01 13:45:56 +04:00
# define LTDB_IDXATTR "@IDXATTR"
2006-12-11 18:49:39 +03:00
# define LTDB_IDXONE "@IDXONE"
2017-08-11 03:25:42 +03:00
# define LTDB_IDXDN "@IDXDN"
2017-08-15 06:33:24 +03:00
# define LTDB_IDXGUID "@IDXGUID"
# define LTDB_IDX_DN_GUID "@IDX_DN_GUID"
2004-05-01 13:45:56 +04:00
# define LTDB_BASEINFO "@BASEINFO"
2007-11-15 03:53:44 +03:00
# define LTDB_OPTIONS "@OPTIONS"
2004-05-01 13:45:56 +04:00
# define LTDB_ATTRIBUTES "@ATTRIBUTES"
/* special attribute types */
# define LTDB_SEQUENCE_NUMBER "sequenceNumber"
2007-11-15 03:53:44 +03:00
# define LTDB_CHECK_BASE "checkBaseOnSearch"
2011-10-26 11:47:35 +04:00
# define LTDB_DISALLOW_DN_FILTER "disallowDNFilter"
2006-09-21 10:44:12 +04:00
# define LTDB_MOD_TIMESTAMP "whenChanged"
2004-05-01 13:45:56 +04:00
# define LTDB_OBJECTCLASS "objectClass"
2017-09-01 11:04:43 +03:00
/* DB keys */
# define LTDB_GUID_KEY_PREFIX "GUID="
# define LTDB_GUID_SIZE 16
2017-09-01 11:06:15 +03:00
# define LTDB_GUID_KEY_SIZE (LTDB_GUID_SIZE + sizeof(LTDB_GUID_KEY_PREFIX) - 1)
2017-09-01 11:04:43 +03:00
2004-11-16 12:00:52 +03:00
/* The following definitions come from lib/ldb/ldb_tdb/ldb_cache.c */
2005-01-02 10:49:29 +03:00
int ltdb_cache_reload ( struct ldb_module * module ) ;
2004-11-16 12:00:52 +03:00
int ltdb_cache_load ( struct ldb_module * module ) ;
int ltdb_increase_sequence_number ( struct ldb_module * module ) ;
2005-05-18 01:43:47 +04:00
int ltdb_check_at_attributes_values ( const struct ldb_val * value ) ;
2004-11-16 12:00:52 +03:00
/* The following definitions come from lib/ldb/ldb_tdb/ldb_index.c */
struct ldb_parse_tree ;
2009-09-15 21:00:24 +04:00
int ltdb_search_indexed ( struct ltdb_context * ctx , uint32_t * ) ;
2017-08-10 07:23:33 +03:00
int ltdb_index_add_new ( struct ldb_module * module ,
struct ltdb_private * ltdb ,
const struct ldb_message * msg ) ;
2009-10-21 15:21:26 +04:00
int ltdb_index_delete ( struct ldb_module * module , const struct ldb_message * msg ) ;
2017-08-10 07:23:33 +03:00
int ltdb_index_del_element ( struct ldb_module * module ,
struct ltdb_private * ltdb ,
2017-08-15 04:08:42 +03:00
const struct ldb_message * msg ,
2009-11-18 12:44:56 +03:00
struct ldb_message_element * el ) ;
2017-08-10 07:23:33 +03:00
int ltdb_index_add_element ( struct ldb_module * module ,
struct ltdb_private * ltdb ,
2017-08-15 04:08:42 +03:00
const struct ldb_message * msg ,
2009-10-21 15:21:26 +04:00
struct ldb_message_element * el ) ;
2017-08-10 07:23:33 +03:00
int ltdb_index_del_value ( struct ldb_module * module ,
struct ltdb_private * ltdb ,
2017-08-15 04:08:42 +03:00
const struct ldb_message * msg ,
2009-11-06 20:35:17 +03:00
struct ldb_message_element * el , unsigned int v_idx ) ;
2004-11-16 12:00:52 +03:00
int ltdb_reindex ( struct ldb_module * module ) ;
2008-12-16 10:45:28 +03:00
int ltdb_index_transaction_start ( struct ldb_module * module ) ;
int ltdb_index_transaction_commit ( struct ldb_module * module ) ;
int ltdb_index_transaction_cancel ( struct ldb_module * module ) ;
2017-08-11 09:09:01 +03:00
int ltdb_key_dn_from_idx ( struct ldb_module * module ,
struct ltdb_private * ltdb ,
TALLOC_CTX * mem_ctx ,
struct ldb_dn * dn ,
TDB_DATA * tdb_key ) ;
2004-11-16 12:00:52 +03:00
/* The following definitions come from lib/ldb/ldb_tdb/ldb_search.c */
int ltdb_has_wildcard ( struct ldb_module * module , const char * attr_name ,
const struct ldb_val * val ) ;
void ltdb_search_dn1_free ( struct ldb_module * module , struct ldb_message * msg ) ;
2016-07-26 15:20:27 +03:00
int ltdb_search_dn1 ( struct ldb_module * module , struct ldb_dn * dn , struct ldb_message * msg ,
unsigned int unpack_flags ) ;
2017-08-28 06:37:28 +03:00
int ltdb_search_base ( struct ldb_module * module ,
TALLOC_CTX * mem_ctx ,
struct ldb_dn * dn ,
struct ldb_dn * * ret_dn ) ;
2017-08-10 07:06:08 +03:00
int ltdb_search_key ( struct ldb_module * module , struct ltdb_private * ltdb ,
struct TDB_DATA tdb_key ,
struct ldb_message * msg ,
unsigned int unpack_flags ) ;
2016-08-26 00:58:38 +03:00
int ltdb_filter_attrs ( TALLOC_CTX * mem_ctx ,
const struct ldb_message * msg , const char * const * attrs ,
struct ldb_message * * filtered_msg ) ;
2008-09-12 02:34:11 +04:00
int ltdb_search ( struct ltdb_context * ctx ) ;
2004-11-16 12:00:52 +03:00
/* The following definitions come from lib/ldb/ldb_tdb/ldb_tdb.c */
2008-10-15 22:03:20 +04:00
int ltdb_lock_read ( struct ldb_module * module ) ;
int ltdb_unlock_read ( struct ldb_module * module ) ;
2017-09-01 05:35:08 +03:00
/*
* Determine if this key could hold a record . We allow the new GUID
* index , the old DN index and a possible future ID =
*/
bool ltdb_key_is_record ( TDB_DATA key ) ;
2017-08-14 06:47:15 +03:00
TDB_DATA ltdb_key_dn ( struct ldb_module * module , TALLOC_CTX * mem_ctx ,
struct ldb_dn * dn ) ;
TDB_DATA ltdb_key_msg ( struct ldb_module * module , TALLOC_CTX * mem_ctx ,
const struct ldb_message * msg ) ;
2017-09-01 11:06:15 +03:00
int ltdb_guid_to_key ( struct ldb_module * module ,
struct ltdb_private * ltdb ,
const struct ldb_val * GUID_val ,
TDB_DATA * key ) ;
int ltdb_idx_to_key ( struct ldb_module * module ,
struct ltdb_private * ltdb ,
TALLOC_CTX * mem_ctx ,
const struct ldb_val * idx_val ,
TDB_DATA * key ) ;
2004-11-16 12:00:52 +03:00
int ltdb_store ( struct ldb_module * module , const struct ldb_message * msg , int flgs ) ;
2009-12-19 12:55:11 +03:00
int ltdb_modify_internal ( struct ldb_module * module , const struct ldb_message * msg , struct ldb_request * req ) ;
2017-08-17 00:08:34 +03:00
int ltdb_delete_noindex ( struct ldb_module * module ,
const struct ldb_message * msg ) ;
2009-10-22 04:06:33 +04:00
int ltdb_err_map ( enum TDB_ERROR tdb_code ) ;
2004-11-16 12:00:52 +03:00
2005-07-20 04:59:38 +04:00
struct tdb_context * ltdb_wrap_open ( TALLOC_CTX * mem_ctx ,
const char * path , int hash_size , int tdb_flags ,
2006-07-03 10:40:56 +04:00
int open_flags , mode_t mode ,
struct ldb_context * ldb ) ;