*/
#include "includes.h"
-#include "ldb/include/ldb_module.h"
+#include <ldb_module.h>
#include "ldb/ldb_map/ldb_map.h"
#include "librpc/gen_ndr/ndr_misc.h"
#include "librpc/ndr/libndr.h"
#include "dsdb/samdb/samdb.h"
+#include "dsdb/common/util.h"
+#include <ldb_handlers.h>
struct entryuuid_private {
struct ldb_context *ldb;
{
struct GUID guid;
NTSTATUS status = GUID_from_data_blob(val, &guid);
- enum ndr_err_code ndr_err;
struct ldb_val out = data_blob(NULL, 0);
if (!NT_STATUS_IS_OK(status)) {
return out;
}
- ndr_err = ndr_push_struct_blob(&out, ctx, NULL, &guid,
- (ndr_push_flags_fn_t)ndr_push_GUID);
- if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
- return out;
+ status = GUID_to_ndr_blob(&guid, ctx, &out);
+ if (!NT_STATUS_IS_OK(status)) {
+ return data_blob(NULL, 0);
}
return out;
{
struct GUID guid;
NTSTATUS status = NS_GUID_from_string((char *)val->data, &guid);
- enum ndr_err_code ndr_err;
struct ldb_val out = data_blob(NULL, 0);
if (!NT_STATUS_IS_OK(status)) {
return out;
}
- ndr_err = ndr_push_struct_blob(&out, ctx, NULL, &guid,
- (ndr_push_flags_fn_t)ndr_push_GUID);
- if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
- return out;
+ status = GUID_to_ndr_blob(&guid, ctx, &out);
+ if (!NT_STATUS_IS_OK(status)) {
+ return data_blob(NULL, 0);
}
return out;
return out;
}
+/* Ensure we always convert sids into string, so the backend doesn't have to know about both forms */
+static struct ldb_val sid_always_string(struct ldb_module *module, TALLOC_CTX *ctx, const struct ldb_val *val)
+{
+ struct ldb_context *ldb = ldb_module_get_ctx(module);
+ struct ldb_val out = data_blob(NULL, 0);
+
+ if (ldif_comparision_objectSid_isString(val)) {
+ if (ldb_handler_copy(ldb, ctx, val, &out) != LDB_SUCCESS) {
+ return data_blob(NULL, 0);
+ }
+
+ } else {
+ if (ldif_write_objectSid(ldb, ctx, val, &out) != LDB_SUCCESS) {
+ return data_blob(NULL, 0);
+ }
+ }
+ return out;
+}
+
/* Ensure we always convert objectCategory into a DN */
static struct ldb_val objectCategory_always_dn(struct ldb_module *module, TALLOC_CTX *ctx, const struct ldb_val *val)
{
const struct ldb_schema_attribute *a = ldb_schema_attribute_by_name(ldb, "objectCategory");
dn = ldb_dn_from_ldb_val(ctx, ldb, val);
- if (dn && ldb_dn_validate(dn)) {
+ if (ldb_dn_validate(dn)) {
talloc_free(dn);
return val_copy(module, ctx, val);
}
static unsigned long long entryCSN_to_usn_int(TALLOC_CTX *ctx, const struct ldb_val *val)
{
- char *entryCSN = talloc_strdup(ctx, (const char *)val->data);
+ char *entryCSN = talloc_strndup(ctx, (const char *)val->data, val->length);
char *mod_per_sec;
time_t t;
unsigned long long usn;
static struct ldb_val timestamp_to_usn(struct ldb_module *module, TALLOC_CTX *ctx, const struct ldb_val *val)
{
struct ldb_val out;
- time_t t;
+ time_t t=0;
unsigned long long usn;
- t = ldb_string_to_time((const char *)val->data);
+ ldb_val_to_time(val, &t);
usn = ((unsigned long long)t <<24);
},
},
},
+ /* securityIdentifier */
+ {
+ .local_name = "securityIdentifier",
+ .type = LDB_MAP_CONVERT,
+ .u = {
+ .convert = {
+ .remote_name = "securityIdentifier",
+ .convert_local = sid_always_binary,
+ .convert_remote = val_copy,
+ },
+ },
+ },
{
.local_name = "name",
.type = LDB_MAP_RENAME,
.u = {
.rename = {
- .remote_name = "samba4RDN"
+ .remote_name = "rdnValue"
}
}
},
.type = LDB_MAP_CONVERT,
.u = {
.convert = {
- .remote_name = "objectSid",
- .convert_local = sid_always_binary,
- .convert_remote = val_copy,
+ .remote_name = "sambaSID",
+ .convert_local = sid_always_string,
+ .convert_remote = sid_always_binary,
}
}
},
+ /* securityIdentifier */
+ {
+ .local_name = "securityIdentifier",
+ .type = LDB_MAP_CONVERT,
+ .u = {
+ .convert = {
+ .remote_name = "securityIdentifier",
+ .convert_local = sid_always_binary,
+ .convert_remote = val_copy,
+ },
+ },
+ },
{
.local_name = "whenCreated",
.type = LDB_MAP_RENAME,
}
}
},
- {
- .local_name = "unixHomeDirectory",
- .type = MAP_RENAME,
- .u = {
- .rename = {
- .remote_name = "homeDirectory"
- }
- }
- },
{
.local_name = "pwdLastSet",
- .type = MAP_RENAME,
+ .type = LDB_MAP_RENAME,
.u = {
.rename = {
.remote_name = "sambaPwdLastSet"
},
{
.local_name = "lastLogon",
- .type = MAP_RENAME,
+ .type = LDB_MAP_RENAME,
.u = {
.rename = {
.remote_name = "sambaLogonTime"
},
{
.local_name = "lastLogoff",
- .type = MAP_RENAME,
+ .type = LDB_MAP_RENAME,
.u = {
.rename = {
.remote_name = "sambaLogoffTime"
},
{
.local_name = "badPwdCount",
- .type = MAP_RENAME,
+ .type = LDB_MAP_RENAME,
.u = {
.rename = {
.remote_name = "sambaBadPasswordCount"
},
{
.local_name = "logonHours",
- .type = MAP_RENAME,
+ .type = LDB_MAP_RENAME,
.u = {
.rename = {
.remote_name = "sambaLogonHours"
},
{
.local_name = "homeDrive",
- .type = MAP_RENAME,
+ .type = LDB_MAP_RENAME,
.u = {
.rename = {
.remote_name = "sambaHomeDrive"
},
{
.local_name = "scriptPath",
- .type = MAP_RENAME,
+ .type = LDB_MAP_RENAME,
.u = {
.rename = {
.remote_name = "sambaLogonScript"
},
{
.local_name = "profilePath",
- .type = MAP_RENAME,
+ .type = LDB_MAP_RENAME,
.u = {
.rename = {
.remote_name = "sambaProfilePath"
},
{
.local_name = "userWorkstations",
- .type = MAP_RENAME,
+ .type = LDB_MAP_RENAME,
.u = {
.rename = {
.remote_name = "sambaUserWorkstations"
},
{
.local_name = "homeDirectory",
- .type = MAP_RENAME,
+ .type = LDB_MAP_RENAME,
.u = {
.rename = {
.remote_name = "sambaHomePath"
},
{
.local_name = "nextRid",
- .type = MAP_RENAME,
+ .type = LDB_MAP_RENAME,
.u = {
.rename = {
.remote_name = "sambaNextRid"
},
{
.local_name = "privilegeDisplayName",
- .type = MAP_RENAME,
+ .type = LDB_MAP_RENAME,
.u = {
.rename = {
.remote_name = "sambaPrivName"
/* This objectClass conflicts with builtin classes on FDS */
const struct ldb_map_objectclass nsuniqueid_objectclasses[] =
{
- {
- .local_name = "domain",
- .remote_name = "samba4Domain"
- },
- {
- .local_name = "rFC822LocalPart",
- .remote_name = "samba4RFC822LocalPart"
- },
- {
- .local_name = "mailRecipient",
- .remote_name = "samba4MailRecipient"
- },
- {
- .local_name = "nisMap",
- .remote_name = "samba4NisMap"
- },
- {
- .local_name = "person",
- .remote_name = "samba4Person"
- },
- {
- .local_name = "organizationalPerson",
- .remote_name = "samba4OrganizationalPerson"
- },
- {
- .local_name = "residentialPerson",
- .remote_name = "samba4ResidentialPerson"
- },
- {
- .local_name = "inetOrgPerson",
- .remote_name = "samba4InetOrgPerson"
- },
{
.local_name = NULL
}
struct ldb_context *ldb;
int ret;
struct map_private *map_private;
- struct entryuuid_private *entryuuid_private;
unsigned long long seq_num = 0;
struct ldb_request *search_req;
map_private = talloc_get_type(ldb_module_get_private(module), struct map_private);
- entryuuid_private = talloc_get_type(map_private->caller_private, struct entryuuid_private);
-
/* All this to get the DN of the parition, so we can search the right thing */
partition_ctrl = ldb_request_get_control(req, DSDB_CONTROL_CURRENT_PARTITION_OID);
if (!partition_ctrl) {
ldb_debug_set(ldb, LDB_DEBUG_FATAL,
- "entryuuid_sequence_number: no current partition control found");
- return LDB_ERR_CONSTRAINT_VIOLATION;
+ "entryuuid_sequence_number: no current partition control found!");
+ return LDB_ERR_PROTOCOL_ERROR;
}
partition = talloc_get_type(partition_ctrl->data,
struct dsdb_control_current_partition);
- SMB_ASSERT(partition && partition->version == DSDB_CONTROL_CURRENT_PARTITION_VERSION);
+ if ((partition == NULL) || (partition->version != DSDB_CONTROL_CURRENT_PARTITION_VERSION)) {
+ ldb_debug_set(ldb, LDB_DEBUG_FATAL,
+ "entryuuid_sequence_number: current partition control with wrong data!");
+ return LDB_ERR_PROTOCOL_ERROR;
+ }
ret = ldb_build_search_req(&search_req, ldb, req,
partition->dn, LDB_SCOPE_BASE,
NULL, contextCSN_attr, NULL,
&seq_num, get_seq_callback,
NULL);
+ LDB_REQ_SET_LOCATION(search_req);
if (ret != LDB_SUCCESS) {
return ret;
}
ext = talloc_zero(req, struct ldb_extended);
if (!ext) {
- return LDB_ERR_OPERATIONS_ERROR;
+ return ldb_oom(ldb);
}
seqr = talloc_zero(req, struct ldb_seqnum_result);
if (seqr == NULL) {
talloc_free(ext);
- return LDB_ERR_OPERATIONS_ERROR;
+ return ldb_oom(ldb);
}
ext->oid = LDB_EXTENDED_SEQUENCE_NUMBER;
ext->data = seqr;
seqr->seq_num++;
break;
case LDB_SEQ_HIGHEST_TIMESTAMP:
- {
- seqr->seq_num = (seq_num >> 24);
- break;
- }
+ return ldb_module_error(module, LDB_ERR_OPERATIONS_ERROR, "LDB_SEQ_HIGHEST_TIMESTAMP not supported");
}
+
seqr->flags = 0;
- seqr->flags |= LDB_SEQ_TIMESTAMP_SEQUENCE;
seqr->flags |= LDB_SEQ_GLOBAL_SEQUENCE;
/* send request done */
return ldb_next_request(module, req);
}
-_PUBLIC_ const struct ldb_module_ops ldb_entryuuid_module_ops = {
+static const struct ldb_module_ops ldb_entryuuid_module_ops = {
.name = "entryuuid",
.init_context = entryuuid_init,
.extended = entryuuid_extended,
LDB_MAP_OPS
};
-_PUBLIC_ const struct ldb_module_ops ldb_nsuniqueid_module_ops = {
+static const struct ldb_module_ops ldb_nsuniqueid_module_ops = {
.name = "nsuniqueid",
.init_context = nsuniqueid_init,
.extended = entryuuid_extended,
LDB_MAP_OPS
};
+
+/*
+ initialise the module
+ */
+_PUBLIC_ int ldb_simple_ldap_map_module_init(const char *version)
+{
+ int ret;
+ LDB_MODULE_CHECK_VERSION(version);
+ ret = ldb_register_module(&ldb_entryuuid_module_ops);
+ if (ret != LDB_SUCCESS) {
+ return ret;
+ }
+ ret = ldb_register_module(&ldb_nsuniqueid_module_ops);
+ if (ret != LDB_SUCCESS) {
+ return ret;
+ }
+ return LDB_SUCCESS;
+}