2 Unix SMB/CIFS implementation.
3 Samba utility functions
5 Copyright (C) Andrew Tridgell 2009
6 Copyright (C) Andrew Bartlett <abartlet@samba.org> 2009
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program. If not, see <http://www.gnu.org/licenses/>.
23 #include "ldb_module.h"
26 search for attrs on one DN, in the modules below
28 int dsdb_module_search_dn(struct ldb_module *module,
30 struct ldb_result **_res,
31 struct ldb_dn *basedn,
32 const char * const *attrs)
35 struct ldb_request *req;
37 struct ldb_result *res;
39 tmp_ctx = talloc_new(mem_ctx);
41 res = talloc_zero(tmp_ctx, struct ldb_result);
43 return LDB_ERR_OPERATIONS_ERROR;
46 ret = ldb_build_search_req(&req, ldb_module_get_ctx(module), tmp_ctx,
53 ldb_search_default_callback,
55 if (ret != LDB_SUCCESS) {
60 ret = ldb_next_request(module, req);
61 if (ret == LDB_SUCCESS) {
62 ret = ldb_wait(req->handle, LDB_WAIT_ALL);
65 if (ret != LDB_SUCCESS) {
70 if (res->count != 1) {
71 /* we may be reading a DB that does not have the 'check base on search' option... */
72 ret = LDB_ERR_NO_SUCH_OBJECT;
73 ldb_asprintf_errstring(ldb_module_get_ctx(module),
74 "dsdb_module_search_dn: did not find base dn %s (%d results)",
75 ldb_dn_get_linearized(basedn), res->count);
77 *_res = talloc_steal(mem_ctx, res);
84 search for attrs in the modules below
86 int dsdb_module_search(struct ldb_module *module,
88 struct ldb_result **_res,
89 struct ldb_dn *basedn, enum ldb_scope scope,
90 const char * const *attrs,
91 const char *expression)
94 struct ldb_request *req;
96 struct ldb_result *res;
98 tmp_ctx = talloc_new(mem_ctx);
100 res = talloc_zero(tmp_ctx, struct ldb_result);
102 return LDB_ERR_OPERATIONS_ERROR;
105 ret = ldb_build_search_req(&req, ldb_module_get_ctx(module), tmp_ctx,
112 ldb_search_default_callback,
114 if (ret != LDB_SUCCESS) {
115 talloc_free(tmp_ctx);
119 ret = ldb_next_request(module, req);
120 if (ret == LDB_SUCCESS) {
121 ret = ldb_wait(req->handle, LDB_WAIT_ALL);
125 if (ret == LDB_SUCCESS) {
126 *_res = talloc_steal(mem_ctx, res);
128 talloc_free(tmp_ctx);