2004-11-16 12:00:52 +03:00
/*
ldb database library
2005-07-02 21:30:03 +04:00
Copyright ( C ) Andrew Tridgell 2004
2004-11-16 12:00:52 +03:00
Copyright ( C ) Stefan Metzmacher 2004
2005-09-18 14:47:03 +04:00
Copyright ( C ) Simo Sorce 2004 - 2005
2004-11-16 12:00:52 +03:00
* * NOTE ! The following LGPL license applies to the ldb
* * library . This does NOT imply that all of Samba is released
* * under the LGPL
This library is free software ; you can redistribute it and / or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation ; either
2007-07-10 06:46:15 +04:00
version 3 of the License , or ( at your option ) any later version .
2004-11-16 12:00:52 +03:00
This library is distributed in the hope that it will be useful ,
but WITHOUT ANY WARRANTY ; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the GNU
Lesser General Public License for more details .
You should have received a copy of the GNU Lesser General Public
2007-07-10 07:42:26 +04:00
License along with this library ; if not , see < http : //www.gnu.org/licenses/>.
2004-11-16 12:00:52 +03:00
*/
/*
* Name : ldb
*
* Component : ldb private header
*
2006-01-11 19:29:02 +03:00
* Description : defines internal ldb structures used by the subsystem and modules
2004-11-16 12:00:52 +03:00
*
* Author : Andrew Tridgell
* Author : Stefan Metzmacher
*/
# ifndef _LDB_PRIVATE_H_
# define _LDB_PRIVATE_H_ 1
2010-11-01 15:36:42 +03:00
# include "replace.h"
# include "system/filesys.h"
# include "system/time.h"
2009-01-30 02:39:30 +03:00
# include "ldb.h"
# include "ldb_module.h"
2004-11-16 12:00:52 +03:00
struct ldb_context ;
struct ldb_module_ops ;
2008-02-20 04:57:07 +03:00
struct ldb_backend_ops ;
2009-09-04 11:22:20 +04:00
# define LDB_HANDLE_FLAG_DONE_CALLED 1
2010-10-19 04:17:53 +04:00
/* call is from an untrusted source - eg. over ldap:// */
# define LDB_HANDLE_FLAG_UNTRUSTED 2
2009-09-04 11:22:20 +04:00
2008-09-12 02:33:16 +04:00
struct ldb_handle {
int status ;
enum ldb_state state ;
struct ldb_context * ldb ;
2009-09-04 11:22:20 +04:00
unsigned flags ;
2011-04-20 20:26:47 +04:00
/* flags dedicated to be set by application using ldb */
uint32_t custom_flags ;
2009-09-22 05:15:19 +04:00
unsigned nesting ;
2010-09-24 23:07:16 +04:00
2017-05-04 12:39:21 +03:00
/* Private event context (if not NULL) */
struct tevent_context * event_context ;
2010-09-24 23:07:16 +04:00
/* used for debugging */
struct ldb_request * parent ;
const char * location ;
2008-09-12 02:33:16 +04:00
} ;
2004-11-16 12:00:52 +03:00
/* basic module structure */
struct ldb_module {
struct ldb_module * prev , * next ;
struct ldb_context * ldb ;
void * private_data ;
const struct ldb_module_ops * ops ;
} ;
r8037: a fairly major update to the internals of ldb. Changes are:
- moved the knowledge of attribute types out of ldb_tdb and into the
generic ldb code. This allows the ldb_match() message match logic
to be generic, so it can be used by other backend
- added the generic ability to load attribute handlers, for
canonicalisation, compare, ldif read and ldif write. In the future
this will be used by the schema module to allow us to correctly
obey the attributetype schema elements
- added attribute handlers for some of the core ldap attribute types,
Integer, DirectoryString, DN, ObjectClass etc
- added automatic registration of attribute handlers for well-known
attribute names 'cn', 'dc', 'dn', 'ou' and 'objectClass'
- converted the objectSid special handlers for Samba to the new system
- added more correct handling of indexing in tdb backend based on the
attribute canonicalisation function
- added generic support for subclasses, moving it out of the tdb
backend. This will be used in future by the schema module
- fixed several bugs in the dn_explode code. It still needs more
work, but doesn't corrupt ldb dbs any more.
(This used to be commit 944c5844ab441b96d8e5d7b2d151982139d1fab9)
2005-07-01 10:21:26 +04:00
/*
schema related information needed for matching rules
*/
struct ldb_schema {
2009-04-02 09:42:21 +04:00
void * attribute_handler_override_private ;
ldb_attribute_handler_override_fn_t attribute_handler_override ;
r8037: a fairly major update to the internals of ldb. Changes are:
- moved the knowledge of attribute types out of ldb_tdb and into the
generic ldb code. This allows the ldb_match() message match logic
to be generic, so it can be used by other backend
- added the generic ability to load attribute handlers, for
canonicalisation, compare, ldif read and ldif write. In the future
this will be used by the schema module to allow us to correctly
obey the attributetype schema elements
- added attribute handlers for some of the core ldap attribute types,
Integer, DirectoryString, DN, ObjectClass etc
- added automatic registration of attribute handlers for well-known
attribute names 'cn', 'dc', 'dn', 'ou' and 'objectClass'
- converted the objectSid special handlers for Samba to the new system
- added more correct handling of indexing in tdb backend based on the
attribute canonicalisation function
- added generic support for subclasses, moving it out of the tdb
backend. This will be used in future by the schema module
- fixed several bugs in the dn_explode code. It still needs more
work, but doesn't corrupt ldb dbs any more.
(This used to be commit 944c5844ab441b96d8e5d7b2d151982139d1fab9)
2005-07-01 10:21:26 +04:00
/* attribute handling table */
2006-12-15 16:08:57 +03:00
unsigned num_attributes ;
struct ldb_schema_attribute * attributes ;
2008-12-16 10:19:07 +03:00
unsigned num_dn_extended_syntax ;
struct ldb_dn_extended_syntax * dn_extended_syntax ;
2017-03-30 03:23:44 +03:00
/*
* If set , the attribute_handler_override has the details of
* what attributes have an index
*/
bool index_handler_override ;
bool one_level_indexes ;
2017-08-15 06:57:57 +03:00
const char * GUID_index_attribute ;
const char * GUID_index_dn_component ;
r8037: a fairly major update to the internals of ldb. Changes are:
- moved the knowledge of attribute types out of ldb_tdb and into the
generic ldb code. This allows the ldb_match() message match logic
to be generic, so it can be used by other backend
- added the generic ability to load attribute handlers, for
canonicalisation, compare, ldif read and ldif write. In the future
this will be used by the schema module to allow us to correctly
obey the attributetype schema elements
- added attribute handlers for some of the core ldap attribute types,
Integer, DirectoryString, DN, ObjectClass etc
- added automatic registration of attribute handlers for well-known
attribute names 'cn', 'dc', 'dn', 'ou' and 'objectClass'
- converted the objectSid special handlers for Samba to the new system
- added more correct handling of indexing in tdb backend based on the
attribute canonicalisation function
- added generic support for subclasses, moving it out of the tdb
backend. This will be used in future by the schema module
- fixed several bugs in the dn_explode code. It still needs more
work, but doesn't corrupt ldb dbs any more.
(This used to be commit 944c5844ab441b96d8e5d7b2d151982139d1fab9)
2005-07-01 10:21:26 +04:00
} ;
2004-11-16 12:00:52 +03:00
/*
every ldb connection is started by establishing a ldb_context
*/
struct ldb_context {
/* the operations provided by the backend */
struct ldb_module * modules ;
2005-01-02 10:49:29 +03:00
/* debugging operations */
2004-11-16 12:00:52 +03:00
struct ldb_debug_ops debug_ops ;
2005-06-20 08:56:43 +04:00
2014-11-05 13:02:25 +03:00
/* extended matching rules */
struct ldb_extended_match_entry {
const struct ldb_extended_match_rule * rule ;
struct ldb_extended_match_entry * prev , * next ;
} * extended_match_rules ;
2006-02-04 03:38:48 +03:00
/* custom utf8 functions */
struct ldb_utf8_fns utf8_fns ;
2005-06-20 08:56:43 +04:00
/* backend specific opaque parameters */
struct ldb_opaque {
struct ldb_opaque * next ;
const char * name ;
void * value ;
} * opaque ;
2005-06-21 10:35:55 +04:00
r8037: a fairly major update to the internals of ldb. Changes are:
- moved the knowledge of attribute types out of ldb_tdb and into the
generic ldb code. This allows the ldb_match() message match logic
to be generic, so it can be used by other backend
- added the generic ability to load attribute handlers, for
canonicalisation, compare, ldif read and ldif write. In the future
this will be used by the schema module to allow us to correctly
obey the attributetype schema elements
- added attribute handlers for some of the core ldap attribute types,
Integer, DirectoryString, DN, ObjectClass etc
- added automatic registration of attribute handlers for well-known
attribute names 'cn', 'dc', 'dn', 'ou' and 'objectClass'
- converted the objectSid special handlers for Samba to the new system
- added more correct handling of indexing in tdb backend based on the
attribute canonicalisation function
- added generic support for subclasses, moving it out of the tdb
backend. This will be used in future by the schema module
- fixed several bugs in the dn_explode code. It still needs more
work, but doesn't corrupt ldb dbs any more.
(This used to be commit 944c5844ab441b96d8e5d7b2d151982139d1fab9)
2005-07-01 10:21:26 +04:00
struct ldb_schema schema ;
2005-09-18 22:49:06 +04:00
char * err_string ;
2005-09-24 19:42:15 +04:00
int transaction_active ;
2006-02-22 04:31:35 +03:00
2006-06-04 09:28:13 +04:00
int default_timeout ;
2006-07-12 08:59:41 +04:00
unsigned int flags ;
2006-09-27 09:57:41 +04:00
unsigned int create_perms ;
2007-09-11 19:42:19 +04:00
2008-12-29 22:24:57 +03:00
struct tevent_context * ev_ctx ;
2009-09-16 01:07:06 +04:00
2017-05-12 03:21:28 +03:00
/*
* If the backend holds locks , we must not use a global event
* context , so this flag will be set and ldb_handle_new ( ) will
* build a new event context
*/
bool require_private_event_context ;
2009-09-16 01:07:06 +04:00
bool prepare_commit_done ;
2009-09-22 04:52:21 +04:00
char * partial_debug ;
2010-11-01 07:41:07 +03:00
struct poptOption * popt_options ;
2004-11-16 12:00:52 +03:00
} ;
2006-06-08 02:03:06 +04:00
/* The following definitions come from lib/ldb/common/ldb.c */
2008-02-20 04:57:07 +03:00
extern const struct ldb_module_ops ldb_objectclass_module_ops ;
extern const struct ldb_module_ops ldb_paged_results_module_ops ;
extern const struct ldb_module_ops ldb_rdn_name_module_ops ;
extern const struct ldb_module_ops ldb_schema_module_ops ;
extern const struct ldb_module_ops ldb_asq_module_ops ;
2008-02-25 22:40:37 +03:00
extern const struct ldb_module_ops ldb_server_sort_module_ops ;
2008-02-20 04:57:07 +03:00
extern const struct ldb_module_ops ldb_ldap_module_ops ;
extern const struct ldb_module_ops ldb_ildap_module_ops ;
2008-02-26 03:20:55 +03:00
extern const struct ldb_module_ops ldb_paged_searches_module_ops ;
2008-02-20 04:57:07 +03:00
extern const struct ldb_module_ops ldb_tdb_module_ops ;
2008-02-26 03:20:55 +03:00
extern const struct ldb_module_ops ldb_skel_module_ops ;
extern const struct ldb_module_ops ldb_subtree_rename_module_ops ;
extern const struct ldb_module_ops ldb_subtree_delete_module_ops ;
2008-02-20 04:57:07 +03:00
extern const struct ldb_module_ops ldb_sqlite3_module_ops ;
2008-02-25 22:40:37 +03:00
extern const struct ldb_module_ops ldb_wins_ldb_module_ops ;
extern const struct ldb_module_ops ldb_ranged_results_module_ops ;
2008-02-20 04:57:07 +03:00
extern const struct ldb_backend_ops ldb_tdb_backend_ops ;
extern const struct ldb_backend_ops ldb_sqlite3_backend_ops ;
extern const struct ldb_backend_ops ldb_ldap_backend_ops ;
2008-03-18 16:29:13 +03:00
extern const struct ldb_backend_ops ldb_ldapi_backend_ops ;
2008-02-20 04:57:07 +03:00
extern const struct ldb_backend_ops ldb_ldaps_backend_ops ;
2004-11-16 12:00:52 +03:00
2006-12-15 16:08:57 +03:00
int ldb_setup_wellknown_attributes ( struct ldb_context * ldb ) ;
2016-10-20 06:04:04 +03:00
/*
remove attributes with a specified flag ( eg LDB_ATTR_FLAG_FROM_DB ) for this ldb context
This is to permit correct reloads
*/
void ldb_schema_attribute_remove_flagged ( struct ldb_context * ldb , unsigned int flag ) ;
2016-10-20 06:01:42 +03:00
int ldb_schema_attribute_fill_with_syntax ( struct ldb_context * ldb ,
TALLOC_CTX * mem_ctx ,
const char * attribute ,
unsigned flags ,
const struct ldb_schema_syntax * syntax ,
struct ldb_schema_attribute * a ) ;
2006-12-15 16:08:57 +03:00
2006-08-17 05:52:24 +04:00
const char * * ldb_subclass_list ( struct ldb_context * ldb , const char * classname ) ;
void ldb_subclass_remove ( struct ldb_context * ldb , const char * classname ) ;
int ldb_subclass_add ( struct ldb_context * ldb , const char * classname , const char * subclass ) ;
r8037: a fairly major update to the internals of ldb. Changes are:
- moved the knowledge of attribute types out of ldb_tdb and into the
generic ldb code. This allows the ldb_match() message match logic
to be generic, so it can be used by other backend
- added the generic ability to load attribute handlers, for
canonicalisation, compare, ldif read and ldif write. In the future
this will be used by the schema module to allow us to correctly
obey the attributetype schema elements
- added attribute handlers for some of the core ldap attribute types,
Integer, DirectoryString, DN, ObjectClass etc
- added automatic registration of attribute handlers for well-known
attribute names 'cn', 'dc', 'dn', 'ou' and 'objectClass'
- converted the objectSid special handlers for Samba to the new system
- added more correct handling of indexing in tdb backend based on the
attribute canonicalisation function
- added generic support for subclasses, moving it out of the tdb
backend. This will be used in future by the schema module
- fixed several bugs in the dn_explode code. It still needs more
work, but doesn't corrupt ldb dbs any more.
(This used to be commit 944c5844ab441b96d8e5d7b2d151982139d1fab9)
2005-07-01 10:21:26 +04:00
2006-02-04 03:38:48 +03:00
/* The following definitions come from lib/ldb/common/ldb_utf8.c */
2010-07-13 03:37:58 +04:00
char * ldb_casefold_default ( void * context , TALLOC_CTX * mem_ctx , const char * s , size_t n ) ;
2006-09-21 10:44:12 +04:00
2008-10-20 20:59:51 +04:00
void ldb_dump_results ( struct ldb_context * ldb , struct ldb_result * result , FILE * f ) ;
2006-09-21 10:44:12 +04:00
2008-09-12 02:33:16 +04:00
/* The following definitions come from lib/ldb/common/ldb_modules.c */
const char * * ldb_modules_list_from_string ( struct ldb_context * ldb , TALLOC_CTX * mem_ctx , const char * string ) ;
int ldb_load_modules ( struct ldb_context * ldb , const char * options [ ] ) ;
2008-10-20 20:59:51 +04:00
2010-07-13 03:37:58 +04:00
struct ldb_val ldb_binary_decode ( TALLOC_CTX * mem_ctx , const char * str ) ;
2008-10-20 20:59:51 +04:00
2010-07-06 09:35:16 +04:00
/* The following definitions come from lib/ldb/common/ldb_options.c */
const char * ldb_options_find ( struct ldb_context * ldb , const char * options [ ] ,
const char * option_name ) ;
2012-08-29 05:29:44 +04:00
/* The following definitions come from lib/ldb/common/ldb_ldif.c */
2012-04-10 11:29:11 +04:00
struct ldif_read_file_state {
FILE * f ;
size_t line_no ;
} ;
struct ldb_ldif * ldb_ldif_read_file_state ( struct ldb_context * ldb ,
struct ldif_read_file_state * state ) ;
2012-08-29 05:29:44 +04:00
char * ldb_ldif_write_redacted_trace_string ( struct ldb_context * ldb , TALLOC_CTX * mem_ctx ,
const struct ldb_ldif * ldif ) ;
2015-10-14 03:49:01 +03:00
/*
* Get the LDB context in use on an LDB DN .
*
* This is helpful to the python LDB code , which may use as part of
* adding base and child components to an existing DN .
*/
struct ldb_context * ldb_dn_get_ldb_context ( struct ldb_dn * dn ) ;
2017-06-15 02:30:33 +03:00
# define LDB_MSG_FIND_COMMON_REMOVE_DUPLICATES 1
/**
Determine whether any values in an element are also in another element ,
and optionally fix that .
\ param ldb an ldb context
\ param mem_ctx a talloc context
\ param el an element
\ param other_el another element
\ param options flags controlling the function behaviour
Without the LDB_MSG_FIND_COMMON_REMOVE_DUPLICATES flag , return
LDB_ERR_ATTRIBUTE_OR_VALUE_EXISTS if the elements share values , and
LDB_SUCCESS if they don ' t . That is , determine whether there is an
intersection without changing anything .
With the LDB_MSG_FIND_COMMON_REMOVE_DUPLICATES flag , any values in common
are removed from the first element and LDB_SUCCESS is returned .
LDB_ERR_OPERATIONS_ERROR indicates an allocation failure or an unknown option .
LDB_ERR_INAPPROPRIATE_MATCHING means the elements differ in name .
*/
int ldb_msg_find_common_values ( struct ldb_context * ldb ,
TALLOC_CTX * mem_ctx ,
struct ldb_message_element * el ,
struct ldb_message_element * other_el ,
uint32_t options ) ;
/**
Detect whether an element contains duplicate values
\ param ldb a currently unused ldb_context struct
\ param mem_ctx a talloc context
\ param el the element to search
\ param duplicate will point to a duplicate value if there are duplicates ,
or NULL otherwise .
\ param options is a flags field . All values are reserved .
\ return an ldb error code . LDB_ERR_OPERATIONS_ERROR indicates an allocation
failure or an unknown option flag . Otherwise LDB_SUCCESS .
\ note This search is case sensitive
*/
int ldb_msg_find_duplicate_val ( struct ldb_context * ldb ,
TALLOC_CTX * mem_ctx ,
const struct ldb_message_element * el ,
struct ldb_val * * duplicate ,
uint32_t options ) ;
2017-08-28 05:55:00 +03:00
/**
Check if a particular message will match the given filter
\ param ldb an ldb context
\ param msg the message to be checked
\ param tree the filter tree to check against
\ param scope the scope to match against
( to avoid matching special DNs except on a base search )
\ param matched a pointer to a boolean set true if it matches ,
false otherwise
returns LDB_SUCCESS or an error
\ note this is a recursive function , and does short - circuit evaluation
*/
int ldb_match_message ( struct ldb_context * ldb ,
const struct ldb_message * msg ,
const struct ldb_parse_tree * tree ,
enum ldb_scope scope , bool * matched ) ;
2017-06-15 02:30:33 +03:00
2004-11-16 12:00:52 +03:00
# endif