2 ldb database library utility
4 Copyright (C) Matthieu Patou 2009
6 ** NOTE! The following LGPL license applies to the ldb
7 ** library. This does NOT imply that all of Samba is released
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 3 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, see <http://www.gnu.org/licenses/>.
27 * Description: Common function used by ldb_add/ldb_modify/ldb_delete
29 * Author: Matthieu Patou
33 #include "ldb_module.h"
35 /* autostarts a transacion if none active */
36 static int ldb_do_autotransaction(struct ldb_context *ldb,
37 struct ldb_request *req)
41 ret = ldb_transaction_start(ldb);
42 if (ret != LDB_SUCCESS) {
46 ret = ldb_request(ldb, req);
47 if (ret == LDB_SUCCESS) {
48 ret = ldb_wait(req->handle, LDB_WAIT_ALL);
51 if (ret == LDB_SUCCESS) {
52 return ldb_transaction_commit(ldb);
54 ldb_transaction_cancel(ldb);
56 if (ldb_errstring(ldb) == NULL) {
57 /* no error string was setup by the backend */
58 ldb_asprintf_errstring(ldb, "%s (%d)", ldb_strerror(ret), ret);
64 Same as ldb_add but accept control
66 int ldb_add_ctrl(struct ldb_context *ldb,
67 const struct ldb_message *message,
68 struct ldb_control **controls)
70 struct ldb_request *req;
73 ret = ldb_msg_sanity_check(ldb, message);
74 if (ret != LDB_SUCCESS) {
78 ret = ldb_build_add_req(&req, ldb, ldb,
82 ldb_op_default_callback,
85 if (ret != LDB_SUCCESS) return ret;
87 /* do request and autostart a transaction */
88 ret = ldb_do_autotransaction(ldb, req);
95 same as ldb_delete but accept control
97 int ldb_delete_ctrl(struct ldb_context *ldb, struct ldb_dn *dn,
98 struct ldb_control **controls)
100 struct ldb_request *req;
103 ret = ldb_build_del_req(&req, ldb, ldb,
107 ldb_op_default_callback,
110 if (ret != LDB_SUCCESS) return ret;
112 /* do request and autostart a transaction */
113 ret = ldb_do_autotransaction(ldb, req);
121 same as ldb_modify, but accepts controls
123 int ldb_modify_ctrl(struct ldb_context *ldb,
124 const struct ldb_message *message,
125 struct ldb_control **controls)
127 struct ldb_request *req;
130 ret = ldb_msg_sanity_check(ldb, message);
131 if (ret != LDB_SUCCESS) {
135 ret = ldb_build_mod_req(&req, ldb, ldb,
139 ldb_op_default_callback,
142 if (ret != LDB_SUCCESS) return ret;
144 /* do request and autostart a transaction */
145 ret = ldb_do_autotransaction(ldb, req);