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
struct ldb_context ;
struct ldb_module_ops ;
2008-02-20 04:57:07 +03:00
struct ldb_backend_ops ;
2008-09-12 02:33:16 +04:00
struct ldb_handle {
int status ;
enum ldb_state state ;
struct ldb_context * ldb ;
} ;
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 ;
} ;
2008-09-12 02:33:16 +04:00
/*
these function pointers define the operations that a ldb module can intercept
2004-11-16 12:00:52 +03:00
*/
struct ldb_module_ops {
const char * name ;
2006-03-02 19:32:53 +03:00
int ( * init_context ) ( struct ldb_module * ) ;
2006-05-29 05:30:02 +04:00
int ( * search ) ( struct ldb_module * , struct ldb_request * ) ; /* search */
int ( * add ) ( struct ldb_module * , struct ldb_request * ) ; /* add */
int ( * modify ) ( struct ldb_module * , struct ldb_request * ) ; /* modify */
int ( * del ) ( struct ldb_module * , struct ldb_request * ) ; /* delete */
int ( * rename ) ( struct ldb_module * , struct ldb_request * ) ; /* rename */
int ( * request ) ( struct ldb_module * , struct ldb_request * ) ; /* match any other operation */
2006-07-23 01:16:01 +04:00
int ( * extended ) ( struct ldb_module * , struct ldb_request * ) ; /* extended operations */
2005-09-17 23:25:50 +04:00
int ( * start_transaction ) ( struct ldb_module * ) ;
2005-09-24 19:42:15 +04:00
int ( * end_transaction ) ( struct ldb_module * ) ;
int ( * del_transaction ) ( struct ldb_module * ) ;
2006-06-08 01:03:38 +04:00
int ( * sequence_number ) ( struct ldb_module * , struct ldb_request * ) ;
2008-09-19 18:17:52 +04:00
void * private_data ;
2004-11-16 12:00:52 +03: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
/*
schema related information needed for matching rules
*/
struct ldb_schema {
/* attribute handling table */
2006-12-15 16:08:57 +03:00
unsigned num_attributes ;
struct ldb_schema_attribute * attributes ;
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
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
char * modules_dir ;
2008-06-14 19:24:17 +04:00
struct event_context * ev_ctx ;
2004-11-16 12:00:52 +03:00
} ;
2005-06-14 05:35:44 +04:00
# ifndef ARRAY_SIZE
# define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0]))
# endif
2005-06-18 11:42:21 +04:00
/*
simplify out of memory handling
*/
2005-10-17 15:27:03 +04:00
# define ldb_oom(ldb) ldb_debug_set(ldb, LDB_DEBUG_FATAL, "ldb out of memory at %s:%d\n", __FILE__, __LINE__)
2005-06-18 11:42:21 +04:00
2006-06-08 02:03:06 +04:00
/* The following definitions come from lib/ldb/common/ldb.c */
2006-07-12 08:59:41 +04:00
int ldb_connect_backend ( struct ldb_context * ldb , const char * url , const char * options [ ] ,
2006-06-08 02:03:06 +04:00
struct ldb_module * * backend_module ) ;
2007-01-14 16:43:09 +03:00
void ldb_set_default_dns ( struct ldb_context * ldb ) ;
2006-06-08 02:03:06 +04:00
2004-11-16 12:00:52 +03:00
/* The following definitions come from lib/ldb/common/ldb_debug.c */
void ldb_debug ( struct ldb_context * ldb , enum ldb_debug_level level , const char * fmt , . . . ) PRINTF_ATTRIBUTE ( 3 , 4 ) ;
2005-10-12 10:10:23 +04:00
void ldb_debug_set ( struct ldb_context * ldb , enum ldb_debug_level level ,
const char * fmt , . . . ) PRINTF_ATTRIBUTE ( 3 , 4 ) ;
2004-11-16 12:00:52 +03:00
/* The following definitions come from lib/ldb/common/ldb_ldif.c */
int ldb_should_b64_encode ( const struct ldb_val * val ) ;
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_operational_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
2005-08-18 19:02:01 +04:00
int ldb_match_msg ( struct ldb_context * ldb ,
2006-08-02 02:46:49 +04:00
const struct ldb_message * msg ,
const struct ldb_parse_tree * tree ,
2006-11-22 03:59:34 +03:00
struct ldb_dn * base ,
2005-07-12 16:04:54 +04:00
enum ldb_scope scope ) ;
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-12-14 13:03:21 +03:00
const struct ldb_schema_syntax * ldb_standard_syntax_by_name ( struct ldb_context * ldb ,
const char * syntax ) ;
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
2005-07-02 21:30:03 +04:00
/* The following definitions come from lib/ldb/common/ldb_attributes.c */
2006-12-15 16:08:57 +03:00
int ldb_schema_attribute_add_with_syntax ( struct ldb_context * ldb ,
const char * name ,
unsigned flags ,
const struct ldb_schema_syntax * syntax ) ;
int ldb_schema_attribute_add ( struct ldb_context * ldb ,
const char * name ,
unsigned flags ,
const char * syntax ) ;
void ldb_schema_attribute_remove ( struct ldb_context * ldb , const char * name ) ;
int ldb_setup_wellknown_attributes ( struct ldb_context * ldb ) ;
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
2005-07-02 21:30:03 +04:00
int ldb_handler_copy ( struct ldb_context * ldb , void * mem_ctx ,
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
const struct ldb_val * in , struct ldb_val * out ) ;
2005-07-02 21:30:03 +04:00
int ldb_comparison_binary ( struct ldb_context * ldb , void * mem_ctx ,
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
const struct ldb_val * v1 , const struct ldb_val * v2 ) ;
2006-01-06 07:01:23 +03:00
/* The following definitions come from lib/ldb/common/ldb_controls.c */
struct ldb_control * get_control_from_list ( struct ldb_control * * controls , const char * oid ) ;
int save_controls ( struct ldb_control * exclude , struct ldb_request * req , struct ldb_control * * * saver ) ;
int check_critical_controls ( struct ldb_control * * controls ) ;
2006-02-04 03:38:48 +03:00
/* The following definitions come from lib/ldb/common/ldb_utf8.c */
2008-08-22 11:36:56 +04:00
char * ldb_casefold_default ( void * context , void * mem_ctx , const char * s , size_t n ) ;
2006-09-21 10:44:12 +04:00
2006-11-16 12:16:17 +03:00
void ldb_msg_remove_element ( struct ldb_message * msg , struct ldb_message_element * el ) ;
2006-09-21 10:44:12 +04:00
/**
Obtain current / next database sequence number
*/
int ldb_sequence_number ( struct ldb_context * ldb , enum ldb_sequence_type type , uint64_t * seq_num ) ;
# define LDB_SEQ_GLOBAL_SEQUENCE 0x01
# define LDB_SEQ_TIMESTAMP_SEQUENCE 0x02
2008-09-12 02:33:16 +04:00
/* MODULES specific headers -- SSS */
/* 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_list ( struct ldb_context * ldb , const char * * module_list , struct ldb_module * backend , struct ldb_module * * out ) ;
int ldb_load_modules ( struct ldb_context * ldb , const char * options [ ] ) ;
int ldb_init_module_chain ( struct ldb_context * ldb , struct ldb_module * module ) ;
int ldb_next_request ( struct ldb_module * module , struct ldb_request * request ) ;
int ldb_next_start_trans ( struct ldb_module * module ) ;
int ldb_next_end_trans ( struct ldb_module * module ) ;
int ldb_next_del_trans ( struct ldb_module * module ) ;
int ldb_next_init ( struct ldb_module * module ) ;
void ldb_set_errstring ( struct ldb_context * ldb , const char * err_string ) ;
void ldb_asprintf_errstring ( struct ldb_context * ldb , const char * format , . . . ) PRINTF_ATTRIBUTE ( 2 , 3 ) ;
void ldb_reset_err_string ( struct ldb_context * ldb ) ;
const char * ldb_default_modules_dir ( void ) ;
int ldb_register_module ( const struct ldb_module_ops * ) ;
typedef int ( * ldb_connect_fn ) ( struct ldb_context * ldb , const char * url ,
unsigned int flags , const char * options [ ] ,
struct ldb_module * * module ) ;
struct ldb_backend_ops {
const char * name ;
ldb_connect_fn connect_fn ;
} ;
const char * ldb_default_modules_dir ( void ) ;
int ldb_register_backend ( const char * url_prefix , ldb_connect_fn ) ;
void * ldb_dso_load_symbol ( struct ldb_context * ldb , const char * name ,
const char * symbol ) ;
struct ldb_handle * ldb_handle_new ( TALLOC_CTX * mem_ctx , struct ldb_context * ldb ) ;
int ldb_module_send_entry ( struct ldb_request * req ,
struct ldb_message * msg ) ;
int ldb_module_send_referral ( struct ldb_request * req ,
char * ref ) ;
int ldb_module_done ( struct ldb_request * req ,
struct ldb_control * * ctrls ,
struct ldb_extended * response ,
int error ) ;
int ldb_mod_register_control ( struct ldb_module * module , const char * oid ) ;
2004-11-16 12:00:52 +03:00
# endif