r9621: Bunch of bug fixes. Add 'format' option to samba3dump (text,summary,ldif)
[sfrench/samba-autobuild/.git] / source4 / lib / ldb / include / ldb.h
index 5773e39fa9ee329e42372e381ab8501e23e7b757..46b359b8ba48dd906143c77d3877b66d2d4e3fa7 100644 (file)
   sensible, but it can be to anything you like, including binary data
   blobs of arbitrary size.
 */
+#ifndef ldb_val
 struct ldb_val {
-       unsigned int length;
-       void *data;
+       uint8_t *data;
+       size_t length;
+};
+#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
@@ -71,12 +83,18 @@ struct ldb_val {
 #define LDB_FLAG_MOD_DELETE  3
 
 
+/*
+  well known object IDs
+*/
+#define LDB_OID_COMPARATOR_AND  "1.2.840.113556.1.4.803"
+#define LDB_OID_COMPARATOR_OR   "1.2.840.113556.1.4.804"
+
 /*
   results are given back as arrays of ldb_message_element
 */
 struct ldb_message_element {
        unsigned int flags;
-       char *name;
+       const char *name;
        unsigned int num_values;
        struct ldb_val *values;
 };
@@ -87,7 +105,7 @@ struct ldb_message_element {
   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 */
@@ -144,18 +162,35 @@ struct ldb_debug_ops {
 #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_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 {
+                       struct ldb_parse_tree *child;
+               } isnot;
                struct {
                        char *attr;
                        struct ldb_val value;
-               } simple;
+               } equality;
+               struct {
+                       char *attr;
+                       int start_with_wildcard;
+                       int end_with_wildcard;
+                       struct ldb_val **chunks;
+               } substring;
+               struct {
+                       char *attr;
+               } present;
+               struct {
+                       char *attr;
+                       struct ldb_val value;
+               } comparison;
                struct {
                        char *attr;
                        int dnAttributes;
@@ -166,9 +201,6 @@ struct ldb_parse_tree {
                        unsigned int num_elements;
                        struct ldb_parse_tree **elements;
                } list;
-               struct {
-                       struct ldb_parse_tree *child;
-               } not;
        } u;
 };
 
@@ -177,6 +209,45 @@ char *ldb_filter_from_tree(void *mem_ctx, struct ldb_parse_tree *tree);
 char *ldb_binary_encode(void *ctx, struct ldb_val val);
 
 
+/*
+  functions for controlling attribute handling
+*/
+typedef int (*ldb_attr_handler_t)(struct ldb_context *, void *mem_ctx, const struct ldb_val *, struct ldb_val *);
+typedef int (*ldb_attr_comparison_t)(struct ldb_context *, void *mem_ctx, const struct ldb_val *, const struct ldb_val *);
+
+struct ldb_attrib_handler {
+       const char *attr;
+
+       /* LDB_ATTR_FLAG_* */
+       unsigned flags;
+
+       /* convert from ldif to binary format */
+       ldb_attr_handler_t ldif_read_fn;
+
+       /* convert from binary to ldif format */
+       ldb_attr_handler_t ldif_write_fn;
+       
+       /* canonicalise a value, for use by indexing and dn construction */
+       ldb_attr_handler_t canonicalise_fn;
+
+       /* compare two values */
+       ldb_attr_comparison_t comparison_fn;
+};
+
+#define LDB_ATTR_FLAG_HIDDEN     (1<<0)
+
+/* 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"
+#define LDB_SYNTAX_DIRECTORY_STRING     "1.3.6.1.4.1.1466.115.121.1.15"
+#define LDB_SYNTAX_INTEGER              "1.3.6.1.4.1.1466.115.121.1.27"
+#define LDB_SYNTAX_OCTET_STRING         "1.3.6.1.4.1.1466.115.121.1.40"
+#define LDB_SYNTAX_OBJECTCLASS          "LDB_SYNTAX_OBJECTCLASS"
+
+/*
+  initialise a ldb context
+*/
+struct ldb_context *ldb_init(void *mem_ctx);
+
 /* 
  connect to a database. The URL can either be one of the following forms
    ldb://path
@@ -187,8 +258,7 @@ char *ldb_binary_encode(void *ctx, struct ldb_val val);
    the options are passed uninterpreted to the backend, and are
    backend specific
 */
-struct ldb_context *ldb_connect(const char *url, unsigned int flags,
-                               const char *options[]);
+int ldb_connect(struct ldb_context *ldb, const char *url, unsigned int flags, const char *options[]);
 
 /*
   search the database given a LDAP-like search expression
@@ -198,7 +268,7 @@ struct ldb_context *ldb_connect(const char *url, unsigned int flags,
   use talloc_free to free the ldb_message returned
 */
 int ldb_search(struct ldb_context *ldb, 
-              const char *base,
+              const const struct ldb_dn *base,
               enum ldb_scope scope,
               const char *expression,
               const char * const *attrs, struct ldb_message ***res);
@@ -207,7 +277,7 @@ int ldb_search(struct ldb_context *ldb,
   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);
@@ -228,12 +298,22 @@ int ldb_modify(struct ldb_context *ldb,
 /*
   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
+*/
+int ldb_lock(struct ldb_context *ldb, const char *lockname);
+
+/*
+  release a named lock
+*/
+int ldb_unlock(struct ldb_context *ldb, const char *lockname);
 
 /*
   delete a record from the database
 */
-int ldb_delete(struct ldb_context *ldb, const char *dn);
+int ldb_delete(struct ldb_context *ldb, const struct ldb_dn *dn);
 
 
 /*
@@ -245,6 +325,7 @@ const char *ldb_errstring(struct ldb_context *ldb);
   casefold a string (should be UTF8, but at the moment it isn't)
 */
 char *ldb_casefold(void *mem_ctx, const char *s);
+int ldb_caseless_cmp(const char *s1, const char *s2);
 
 /*
   ldif manipulation functions
@@ -257,17 +338,46 @@ void ldb_ldif_read_free(struct ldb_context *ldb, struct ldb_ldif *);
 struct ldb_ldif *ldb_ldif_read(struct ldb_context *ldb, 
                               int (*fgetc_fn)(void *), void *private_data);
 struct ldb_ldif *ldb_ldif_read_file(struct ldb_context *ldb, FILE *f);
-struct ldb_ldif *ldb_ldif_read_string(struct ldb_context *ldb, const char *s);
+struct ldb_ldif *ldb_ldif_read_string(struct ldb_context *ldb, const char **s);
 int ldb_ldif_write_file(struct ldb_context *ldb, FILE *f, const struct ldb_ldif *msg);
-
+char *ldb_base64_encode(void *mem_ctx, const char *buf, int len);
+int ldb_base64_decode(char *s);
+int ldb_attrib_add_handlers(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, ...);
+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(struct ldb_module *module, const char *dn, int (*case_fold_attr_fn)(struct ldb_module * module, 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);
@@ -330,9 +440,7 @@ const char *ldb_msg_find_string(const struct ldb_message *msg,
 
 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, 
@@ -356,4 +464,11 @@ int ldb_set_debug(struct ldb_context *ldb,
 /* this sets up debug to print messages on stderr */
 int ldb_set_debug_stderr(struct ldb_context *ldb);
 
+/* control backend specific opaque values */
+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);
+
 #endif