lib/util: inline lib/util/util_runcmd.h again
[Samba.git] / lib / ldb / tests / sample_module.c
blob6ba9ed28b656711e2a7de660a51b3782754b92a6
1 /*
2 Unix SMB/CIFS implementation.
3 Samba utility functions
4 Copyright (C) Jelmer Vernooij <jelmer@samba.org> 2007
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 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/>.
24 #include "replace.h"
25 #include "ldb_module.h"
27 static int sample_add_callback(struct ldb_request *down_req,
28 struct ldb_reply *ares)
30 struct ldb_request *req =
31 talloc_get_type_abort(down_req->context,
32 struct ldb_request);
34 if (ares == NULL) {
35 return ldb_module_done(req, NULL, NULL,
36 LDB_ERR_OPERATIONS_ERROR);
39 if (ares->type == LDB_REPLY_REFERRAL) {
40 return ldb_module_send_referral(req, ares->referral);
43 if (ares->error != LDB_SUCCESS) {
44 return ldb_module_done(req, ares->controls,
45 ares->response, ares->error);
48 if (ares->type != LDB_REPLY_DONE) {
49 return ldb_module_done(req, NULL, NULL,
50 LDB_ERR_OPERATIONS_ERROR);
53 return ldb_module_done(req, ares->controls,
54 ares->response, LDB_SUCCESS);
57 static int sample_add(struct ldb_module *mod, struct ldb_request *req)
59 struct ldb_context *ldb = ldb_module_get_ctx(mod);
60 struct ldb_control *control = NULL;
61 struct ldb_message *msg = NULL;
62 struct ldb_request *down_req = NULL;
63 int ret;
65 /* check if there's a relax control */
66 control = ldb_request_get_control(req, LDB_CONTROL_RELAX_OID);
67 if (control != NULL) {
68 return LDB_ERR_UNWILLING_TO_PERFORM;
71 msg = ldb_msg_copy_shallow(req, req->op.add.message);
72 if (msg == NULL) {
73 return LDB_ERR_OPERATIONS_ERROR;
76 ret = ldb_msg_add_fmt(msg, "touchedBy", "sample");
77 if (ret != LDB_SUCCESS) {
78 return ret;
81 ret = ldb_build_add_req(&down_req, ldb, req,
82 msg,
83 req->controls,
84 req, sample_add_callback,
85 req);
86 if (ret != LDB_SUCCESS) {
87 return ret;
90 talloc_steal(down_req, msg);
92 /* go on with the call chain */
93 return ldb_next_request(mod, down_req);
96 static int sample_modify(struct ldb_module *mod, struct ldb_request *req)
98 struct ldb_control *control;
100 /* check if there's a relax control */
101 control = ldb_request_get_control(req, LDB_CONTROL_RELAX_OID);
102 if (control != NULL) {
103 return LDB_ERR_UNWILLING_TO_PERFORM;
106 /* not found go on */
107 return ldb_next_request(mod, req);
111 static struct ldb_module_ops ldb_sample_module_ops = {
112 .name = "sample",
113 .add = sample_add,
114 .del = sample_modify,
115 .modify = sample_modify,
118 int ldb_sample_init(const char *version)
120 LDB_MODULE_CHECK_VERSION(version);
121 return ldb_register_module(&ldb_sample_module_ops);