r141: A number of changes to get things working on FreeBSD and reduce the breakage
[Samba/gebeck_regimport.git] / source4 / lib / ldb / common / ldb.c
blob3ba4434e071b351b29de14085aa9c86f8aa43221
1 /*
2 ldb database library
4 Copyright (C) Andrew Tridgell 2004
6 ** NOTE! The following LGPL license applies to the ldb
7 ** library. This does NOT imply that all of Samba is released
8 ** under the LGPL
10 This library is free software; you can redistribute it and/or
11 modify it under the terms of the GNU Lesser General Public
12 License as published by the Free Software Foundation; either
13 version 2 of the License, or (at your option) any later version.
15 This library is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 Lesser General Public License for more details.
20 You should have received a copy of the GNU Lesser General Public
21 License along with this library; if not, write to the Free Software
22 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
26 * Name: ldb
28 * Component: ldb core API
30 * Description: core API routines interfacing to ldb backends
32 * Author: Andrew Tridgell
35 #include "includes.h"
37 /*
38 connect to a database. The URL can either be one of the following forms
39 ldb://path
40 ldapi://path
42 flags is made up of LDB_FLG_*
44 the options are passed uninterpreted to the backend, and are
45 backend specific
47 struct ldb_context *ldb_connect(const char *url, unsigned int flags,
48 const char *options[])
51 if (strncmp(url, "tdb:", 4) == 0) {
52 return ltdb_connect(url, flags, options);
55 #ifdef HAVE_LDAP
56 if (strncmp(url, "ldap", 4) == 0) {
57 return lldb_connect(url, flags, options);
59 #endif /*HAVE_LDAP*/
61 errno = EINVAL;
62 return NULL;
66 close the connection to the database
68 int ldb_close(struct ldb_context *ldb)
70 return ldb->ops->close(ldb);
75 search the database given a LDAP-like search expression
77 return the number of records found, or -1 on error
79 int ldb_search(struct ldb_context *ldb,
80 const char *base,
81 enum ldb_scope scope,
82 const char *expression,
83 const char *attrs[], struct ldb_message ***res)
85 return ldb->ops->search(ldb, base, scope, expression, attrs, res);
88 /*
89 free a set of messages returned by ldb_search
91 int ldb_search_free(struct ldb_context *ldb, struct ldb_message **msgs)
93 return ldb->ops->search_free(ldb, msgs);
98 add a record to the database. Will fail if a record with the given class and key
99 already exists
101 int ldb_add(struct ldb_context *ldb,
102 const struct ldb_message *message)
104 return ldb->ops->add(ldb, message);
108 modify the specified attributes of a record
110 int ldb_modify(struct ldb_context *ldb,
111 const struct ldb_message *message)
113 return ldb->ops->modify(ldb, message);
118 delete a record from the database
120 int ldb_delete(struct ldb_context *ldb, const char *dn)
122 return ldb->ops->delete(ldb, dn);
126 return extended error information
128 const char *ldb_errstring(struct ldb_context *ldb)
130 return ldb->ops->errstring(ldb);