4 LDAP semantics mapping module
6 Copyright (C) Jelmer Vernooij 2005
7 Copyright (C) Andrew Bartlett <abartlet@samba.org> 2006
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25 This module relies on ldb_map to do all the real work, but performs
26 some of the trivial mappings between AD semantics and that provided
27 by OpenLDAP and similar servers.
31 #include "ldb/include/ldb.h"
32 #include "ldb/include/ldb_private.h"
33 #include "ldb/include/ldb_errors.h"
34 #include "ldb/modules/ldb_map.h"
36 #include "librpc/gen_ndr/ndr_misc.h"
37 #include "librpc/ndr/libndr.h"
39 static struct ldb_val encode_guid(struct ldb_module *module, TALLOC_CTX *ctx, const struct ldb_val *val)
42 NTSTATUS status = GUID_from_string((char *)val->data, &guid);
43 struct ldb_val out = data_blob(NULL, 0);
45 if (!NT_STATUS_IS_OK(status)) {
48 status = ndr_push_struct_blob(&out, ctx, &guid,
49 (ndr_push_flags_fn_t)ndr_push_GUID);
50 if (!NT_STATUS_IS_OK(status)) {
57 static struct ldb_val decode_guid(struct ldb_module *module, TALLOC_CTX *ctx, const struct ldb_val *val)
61 struct ldb_val out = data_blob(NULL, 0);
63 guid = talloc(ctx, struct GUID);
67 status = ndr_pull_struct_blob(val, guid, guid,
68 (ndr_pull_flags_fn_t)ndr_pull_GUID);
69 if (!NT_STATUS_IS_OK(status)) {
73 out = data_blob_string_const(GUID_string(ctx, guid));
78 /* The backend holds binary sids, so just copy them back */
79 static struct ldb_val sid_copy(struct ldb_module *module, TALLOC_CTX *ctx, const struct ldb_val *val)
81 struct ldb_val out = data_blob(NULL, 0);
82 ldb_handler_copy(module->ldb, ctx, val, &out);
87 /* Ensure we always convert sids into binary, so the backend doesn't have to know about both forms */
88 static struct ldb_val sid_always_binary(struct ldb_module *module, TALLOC_CTX *ctx, const struct ldb_val *val)
90 struct ldb_val out = data_blob(NULL, 0);
91 const struct ldb_attrib_handler *handler = ldb_attrib_handler(module->ldb, "objectSid");
93 if (handler->canonicalise_fn(module->ldb, ctx, val, &out) != LDB_SUCCESS) {
94 return data_blob(NULL, 0);
100 const struct ldb_map_attribute entryUUID_attributes[] =
104 .local_name = "objectGUID",
108 .remote_name = "entryUUID",
109 .convert_local = decode_guid,
110 .convert_remote = encode_guid,
116 .local_name = "objectSid",
120 .remote_name = "objectSid",
121 .convert_local = sid_always_binary,
122 .convert_remote = sid_copy,
127 .local_name = "whenCreated",
131 .remote_name = "createTimestamp"
136 .local_name = "whenChanged",
140 .remote_name = "modifyTimestamp"
153 /* the context init function */
154 static int entryUUID_init(struct ldb_module *module)
158 ret = ldb_map_init(module, entryUUID_attributes, NULL, NULL);
159 if (ret != LDB_SUCCESS)
162 return ldb_next_init(module);
165 static struct ldb_module_ops entryUUID_ops = {
167 .init_context = entryUUID_init,
170 /* the init function */
171 int ldb_entryUUID_module_init(void)
173 struct ldb_module_ops ops = ldb_map_get_ops();
174 entryUUID_ops.add = ops.add;
175 entryUUID_ops.modify = ops.modify;
176 entryUUID_ops.del = ops.del;
177 entryUUID_ops.rename = ops.rename;
178 entryUUID_ops.search = ops.search;
179 entryUUID_ops.wait = ops.wait;
181 return ldb_register_module(&entryUUID_ops);