Copyright (C) Andrew Tridgell 2004
Copyright (C) Stefan Metzmacher 2004
+ Copyright (C) Simo Sorce 2005
** NOTE! The following LGPL license applies to the ldb
** library. This does NOT imply that all of Samba is released
major restrictions as compared to tdb:
- no explicit locking calls
+ UPDATE: we have transactions now, better than locking --SSS.
*/
};
#endif
+/* internal ldb exploded dn structures */
+struct ldb_dn_component {
+ char *name;
+ struct ldb_val value;
+};
+struct ldb_dn {
+ int comp_num;
+ struct ldb_dn_component *components;
+};
+
/* these flags are used in ldd_message_element.flags fields. The
LDA_FLAGS_MOD_* flags are used in ldap_modify() calls to specify
whether attributes are being added, deleted or modified */
number of elements.
*/
struct ldb_message {
- char *dn;
+ struct ldb_dn *dn;
unsigned int num_elements;
struct ldb_message_element *elements;
void *private_data; /* private to the backend */
struct ldb_module;
+/* module initialisation function */
+typedef struct ldb_module *(*ldb_module_init_t)(struct ldb_context *, const char **);
+
+
/* debugging uses one of the following levels */
enum ldb_debug_level {LDB_DEBUG_FATAL, LDB_DEBUG_ERROR,
LDB_DEBUG_WARNING, LDB_DEBUG_TRACE};
};
#define LDB_FLG_RDONLY 1
+#define LDB_FLG_NOSYNC 2
#ifndef PRINTF_ATTRIBUTE
#define PRINTF_ATTRIBUTE(a,b)
#endif
-
-/* structues for ldb_parse_tree handling code */
-enum ldb_parse_op {LDB_OP_SIMPLE=1, LDB_OP_EXTENDED=2,
- LDB_OP_SUBSTRING=3, LDB_OP_PRESENT=4,
- LDB_OP_AND='&', LDB_OP_OR='|', LDB_OP_NOT='!'};
+/* structures for ldb_parse_tree handling code */
+enum ldb_parse_op { LDB_OP_AND=1, LDB_OP_OR=2, LDB_OP_NOT=3,
+ LDB_OP_EQUALITY=4, LDB_OP_SUBSTRING=5,
+ LDB_OP_GREATER=6, LDB_OP_LESS=7, LDB_OP_PRESENT=8,
+ LDB_OP_APPROX=9, LDB_OP_EXTENDED=10 };
struct ldb_parse_tree {
enum ldb_parse_op operation;
union {
struct {
- char *attr;
- struct ldb_val value;
- } simple;
+ struct ldb_parse_tree *child;
+ } isnot;
struct {
- char *attr;
- } present;
+ const char *attr;
+ struct ldb_val value;
+ } equality;
struct {
- char *attr;
+ const char *attr;
int start_with_wildcard;
int end_with_wildcard;
struct ldb_val **chunks;
} substring;
struct {
- char *attr;
+ const char *attr;
+ } present;
+ struct {
+ const char *attr;
+ struct ldb_val value;
+ } comparison;
+ struct {
+ const char *attr;
int dnAttributes;
char *rule_id;
struct ldb_val value;
unsigned int num_elements;
struct ldb_parse_tree **elements;
} list;
- struct {
- struct ldb_parse_tree *child;
- } not;
} u;
};
ldb_attr_comparison_t comparison_fn;
};
-#define LDB_ATTR_FLAG_HIDDEN (1<<0)
+#define LDB_ATTR_FLAG_HIDDEN (1<<0) /* the attribute is not returned by default */
+#define LDB_ATTR_FLAG_CONSTRUCTED (1<<1) /* the attribute is constructed from other attributes */
+#define LDB_ATTR_FLAG_CONSTRUCTED (1<<1) /* the attribute is constructed from other attributes */
+
/* well-known ldap attribute syntaxes - see rfc2252 section 4.3.2 */
#define LDB_SYNTAX_DN "1.3.6.1.4.1.1466.115.121.1.12"
use talloc_free to free the ldb_message returned
*/
int ldb_search(struct ldb_context *ldb,
- const char *base,
+ const struct ldb_dn *base,
enum ldb_scope scope,
const char *expression,
const char * const *attrs, struct ldb_message ***res);
like ldb_search() but takes a parse tree
*/
int ldb_search_bytree(struct ldb_context *ldb,
- const char *base,
+ const struct ldb_dn *base,
enum ldb_scope scope,
struct ldb_parse_tree *tree,
const char * const *attrs, struct ldb_message ***res);
/*
rename a record in the database
*/
-int ldb_rename(struct ldb_context *ldb, const char *olddn, const char *newdn);
+int ldb_rename(struct ldb_context *ldb, const struct ldb_dn *olddn, const struct ldb_dn *newdn);
/*
- create a named lock
+ delete a record from the database
*/
-int ldb_lock(struct ldb_context *ldb, const char *lockname);
+int ldb_delete(struct ldb_context *ldb, const struct ldb_dn *dn);
/*
- release a named lock
+ start a transaction
*/
-int ldb_unlock(struct ldb_context *ldb, const char *lockname);
+int ldb_transaction_start(struct ldb_context *ldb);
/*
- delete a record from the database
+ commit a transaction
+*/
+int ldb_transaction_commit(struct ldb_context *ldb);
+
+/*
+ cancel a transaction
*/
-int ldb_delete(struct ldb_context *ldb, const char *dn);
+int ldb_transaction_cancel(struct ldb_context *ldb);
/*
const struct ldb_attrib_handler *handlers,
unsigned num_handlers);
+/* The following definitions come from lib/ldb/common/ldb_dn.c */
+
+int ldb_dn_is_special(const struct ldb_dn *dn);
+int ldb_dn_check_special(const struct ldb_dn *dn, const char *check);
+char *ldb_dn_escape_value(void *mem_ctx, struct ldb_val value);
+struct ldb_dn *ldb_dn_new(void *mem_ctx);
+struct ldb_dn *ldb_dn_explode(void *mem_ctx, const char *dn);
+char *ldb_dn_linearize(void *mem_ctx, const struct ldb_dn *edn);
+char *ldb_dn_linearize_casefold(struct ldb_context *ldb, const struct ldb_dn *edn);
+int ldb_dn_compare_base(struct ldb_context *ldb, const struct ldb_dn *base, const struct ldb_dn *dn);
+int ldb_dn_compare(struct ldb_context *ldb, const struct ldb_dn *edn0, const struct ldb_dn *edn1);
+struct ldb_dn *ldb_dn_casefold(struct ldb_context *ldb, const struct ldb_dn *edn);
+struct ldb_dn *ldb_dn_explode_casefold(struct ldb_context *ldb, const char *dn);
+struct ldb_dn *ldb_dn_copy_partial(void *mem_ctx, const struct ldb_dn *dn, int num_el);
+struct ldb_dn *ldb_dn_copy(void *mem_ctx, const struct ldb_dn *dn);
+struct ldb_dn *ldb_dn_get_parent(void *mem_ctx, const struct ldb_dn *dn);
+struct ldb_dn_component *ldb_dn_build_component(void *mem_ctx, const char *attr,
+ const char *val);
+struct ldb_dn *ldb_dn_build_child(void *mem_ctx, const char *attr,
+ const char * value,
+ const struct ldb_dn *base);
+struct ldb_dn *ldb_dn_make_child(void *mem_ctx,
+ const struct ldb_dn_component *component,
+ const struct ldb_dn *base);
+struct ldb_dn *ldb_dn_compose(void *mem_ctx, const struct ldb_dn *dn1, const struct ldb_dn *dn2);
+struct ldb_dn *ldb_dn_string_compose(void *mem_ctx, const struct ldb_dn *base, const char *child_fmt, ...) PRINTF_ATTRIBUTE(3,4);
+struct ldb_dn_component *ldb_dn_get_rdn(void *mem_ctx, const struct ldb_dn *dn);
/* useful functions for ldb_message structure manipulation */
-
-int ldb_dn_cmp(const char *dn1, const char *dn2);
+int ldb_dn_cmp(struct ldb_context *ldb, const char *dn1, const char *dn2);
int ldb_attr_cmp(const char *dn1, const char *dn2);
-
-/* case-fold a DN */
-char *ldb_dn_fold(void * mem_ctx,
- const char * dn,
- void * user_data,
- int (* case_fold_attr_fn)(void * user_data, char * attr));
+char *ldb_dn_escape_value(void *mem_ctx, struct ldb_val value);
/* create an empty message */
struct ldb_message *ldb_msg_new(void *mem_ctx);
struct ldb_val *val);
/* add a new empty element to a ldb_message */
-int ldb_msg_add_empty(struct ldb_context *ldb,
- struct ldb_message *msg, const char *attr_name, int flags);
+int ldb_msg_add_empty(struct ldb_message *msg, const char *attr_name, int flags);
/* add a element to a ldb_message */
-int ldb_msg_add(struct ldb_context *ldb,
- struct ldb_message *msg,
+int ldb_msg_add(struct ldb_message *msg,
const struct ldb_message_element *el,
int flags);
-int ldb_msg_add_value(struct ldb_context *ldb,
- struct ldb_message *msg,
+int ldb_msg_add_value(struct ldb_message *msg,
const char *attr_name,
const struct ldb_val *val);
-int ldb_msg_add_string(struct ldb_context *ldb, struct ldb_message *msg,
+int ldb_msg_add_string(struct ldb_message *msg,
const char *attr_name, const char *str);
-int ldb_msg_add_fmt(struct ldb_context *ldb, struct ldb_message *msg,
- const char *attr_name, const char *fmt, ...) PRINTF_ATTRIBUTE(4,5);
+int ldb_msg_add_fmt(struct ldb_message *msg,
+ const char *attr_name, const char *fmt, ...) PRINTF_ATTRIBUTE(3,4);
/* compare two message elements - return 0 on match */
int ldb_msg_element_compare(struct ldb_message_element *el1,
void ldb_msg_sort_elements(struct ldb_message *msg);
-void ldb_msg_free(struct ldb_context *ldb, struct ldb_message *msg);
-
-struct ldb_message *ldb_msg_copy(struct ldb_context *ldb,
+struct ldb_message *ldb_msg_copy(void *mem_ctx,
const struct ldb_message *msg);
struct ldb_message *ldb_msg_canonicalize(struct ldb_context *ldb,
struct ldb_message *msg1,
struct ldb_message *msg2);
+int ldb_msg_sanity_check(const struct ldb_message *msg);
+
struct ldb_val ldb_val_dup(void *mem_ctx, const struct ldb_val *v);
/*
int ldb_set_opaque(struct ldb_context *ldb, const char *name, void *value);
void *ldb_get_opaque(struct ldb_context *ldb, const char *name);
+const struct ldb_attrib_handler *ldb_attrib_handler(struct ldb_context *ldb,
+ const char *attrib);
+
+
+const char **ldb_attr_list_copy(TALLOC_CTX *mem_ctx, const char * const *attrs);
+int ldb_attr_in_list(const char * const *attrs, const char *attr);
+
+
+void ldb_parse_tree_attr_replace(struct ldb_parse_tree *tree,
+ const char *attr,
+ const char *replace);
+
+void ldb_msg_rename_attr(struct ldb_message *msg, const char *attr, const char *replace);
+int ldb_msg_copy_attr(struct ldb_message *msg, const char *attr, const char *replace);
+
#endif