2 Unix SMB/CIFS implementation.
6 Copyright (C) Andrew Tridgell 2005
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 2 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, write to the Free Software
20 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24 #include "lib/ldb/include/ldb.h"
25 #include "lib/ldb/include/ldb_errors.h"
26 #include "lib/ldb/include/ldb_private.h"
30 return 1 if a specific attribute has been requested
32 static int do_attribute(const char * const *attrs, const char *name)
34 return attrs == NULL ||
35 ldb_attr_in_list(attrs, name) ||
36 ldb_attr_in_list(attrs, "*");
40 add dynamically generated attributes to rootDSE result
42 static int rootdse_add_dynamic(struct ldb_module *module, struct ldb_request *req)
44 struct ldb_search *s = &req->op.search;
45 struct ldb_message *msg;
47 /* this is gross, and will be removed when I change ldb_result not
48 to be so pointer crazy :-) */
49 if (s->res[0][0].msgs == NULL) {
53 msg = s->res[0][0].msgs[0];
55 msg->dn = ldb_dn_explode(msg, "");
57 if (do_attribute(s->attrs, "currentTime")) {
58 if (ldb_msg_add_string(msg, "currentTime",
59 ldb_timestring(msg, time(NULL))) != 0) {
64 /* TODO: lots more dynamic attributes should be added here */
69 return LDB_ERR_OPERATIONS_ERROR;
73 handle search requests
75 static int rootdse_search_bytree(struct ldb_module *module, struct ldb_request *req)
77 // struct ldb_request r = *req;
78 struct ldb_search *s = &req->op.search;
82 /* see if its for the rootDSE */
83 if (s->scope != LDB_SCOPE_BASE ||
84 (s->base && s->base->comp_num != 0)) {
85 return ldb_next_request(module, req);
88 tmp_ctx = talloc_new(module);
90 /* in our db we store the rootDSE with a DN of cn=rootDSE */
91 s->base = ldb_dn_explode(tmp_ctx, "cn=rootDSE");
92 s->tree = ldb_parse_tree(tmp_ctx, "dn=*");
93 if (s->base == NULL || s->tree == NULL) {
96 return LDB_ERR_OPERATIONS_ERROR;
99 /* grab the static contents of the record */
100 ret = ldb_next_request(module, req);
102 req->op.search.res = s->res;
104 if (ret == LDB_SUCCESS) {
105 ret = rootdse_add_dynamic(module, req);
108 talloc_free(tmp_ctx);
114 static int rootdse_request(struct ldb_module *module, struct ldb_request *req)
116 switch (req->operation) {
118 return rootdse_search_bytree(module, req);
122 return ldb_next_request(module, req);
125 static const struct ldb_module_ops rootdse_ops = {
127 .request = rootdse_request
130 #ifdef HAVE_DLOPEN_DISABLED
131 struct ldb_module *init_module(struct ldb_context *ldb, const char *options[])
133 struct ldb_module *rootdse_module_init(struct ldb_context *ldb, const char *options[])
136 struct ldb_module *ctx;
138 ctx = talloc(ldb, struct ldb_module);
143 ctx->prev = ctx->next = NULL;
144 ctx->ops = &rootdse_ops;
145 ctx->private_data = NULL;