29
29
#include "includes.h"
30
#include "ldb/include/ldb_module.h"
30
#include <ldb_module.h>
31
31
#include "ldb/ldb_map/ldb_map.h"
33
33
#include "librpc/gen_ndr/ndr_misc.h"
34
34
#include "librpc/ndr/libndr.h"
35
35
#include "dsdb/samdb/samdb.h"
36
#include <ldb_handlers.h>
37
38
struct entryuuid_private {
38
39
struct ldb_context *ldb;
45
46
NTSTATUS status = GUID_from_data_blob(val, &guid);
46
enum ndr_err_code ndr_err;
47
47
struct ldb_val out = data_blob(NULL, 0);
49
49
if (!NT_STATUS_IS_OK(status)) {
52
ndr_err = ndr_push_struct_blob(&out, ctx, NULL, &guid,
53
(ndr_push_flags_fn_t)ndr_push_GUID);
54
if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
52
status = GUID_to_ndr_blob(&guid, ctx, &out);
53
if (!NT_STATUS_IS_OK(status)) {
54
return data_blob(NULL, 0);
75
74
NTSTATUS status = NS_GUID_from_string((char *)val->data, &guid);
76
enum ndr_err_code ndr_err;
77
75
struct ldb_val out = data_blob(NULL, 0);
79
77
if (!NT_STATUS_IS_OK(status)) {
82
ndr_err = ndr_push_struct_blob(&out, ctx, NULL, &guid,
83
(ndr_push_flags_fn_t)ndr_push_GUID);
84
if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
80
status = GUID_to_ndr_blob(&guid, ctx, &out);
81
if (!NT_STATUS_IS_OK(status)) {
82
return data_blob(NULL, 0);
122
/* Ensure we always convert sids into string, so the backend doesn't have to know about both forms */
123
static struct ldb_val sid_always_string(struct ldb_module *module, TALLOC_CTX *ctx, const struct ldb_val *val)
125
struct ldb_context *ldb = ldb_module_get_ctx(module);
126
struct ldb_val out = data_blob(NULL, 0);
128
if (ldif_comparision_objectSid_isString(val)) {
129
if (ldb_handler_copy(ldb, ctx, val, &out) != LDB_SUCCESS) {
130
return data_blob(NULL, 0);
134
if (ldif_write_objectSid(ldb, ctx, val, &out) != LDB_SUCCESS) {
135
return data_blob(NULL, 0);
125
141
/* Ensure we always convert objectCategory into a DN */
126
142
static struct ldb_val objectCategory_always_dn(struct ldb_module *module, TALLOC_CTX *ctx, const struct ldb_val *val)
131
147
const struct ldb_schema_attribute *a = ldb_schema_attribute_by_name(ldb, "objectCategory");
133
149
dn = ldb_dn_from_ldb_val(ctx, ldb, val);
134
if (dn && ldb_dn_validate(dn)) {
150
if (ldb_dn_validate(dn)) {
136
152
return val_copy(module, ctx, val);
166
182
static unsigned long long entryCSN_to_usn_int(TALLOC_CTX *ctx, const struct ldb_val *val)
168
char *entryCSN = talloc_strdup(ctx, (const char *)val->data);
184
char *entryCSN = talloc_strndup(ctx, (const char *)val->data, val->length);
169
185
char *mod_per_sec;
171
187
unsigned long long usn;
216
232
static struct ldb_val timestamp_to_usn(struct ldb_module *module, TALLOC_CTX *ctx, const struct ldb_val *val)
218
234
struct ldb_val out;
220
236
unsigned long long usn;
222
t = ldb_string_to_time((const char *)val->data);
238
ldb_val_to_time(val, &t);
224
240
usn = ((unsigned long long)t <<24);
285
/* securityIdentifier */
287
.local_name = "securityIdentifier",
288
.type = LDB_MAP_CONVERT,
291
.remote_name = "securityIdentifier",
292
.convert_local = sid_always_binary,
293
.convert_remote = val_copy,
270
298
.local_name = "name",
299
.type = LDB_MAP_RENAME,
274
.remote_name = "samba4RDN"
302
.remote_name = "rdnValue"
279
307
.local_name = "whenCreated",
308
.type = LDB_MAP_RENAME,
283
311
.remote_name = "createTimestamp"
469
497
.local_name = "objectSid",
473
.remote_name = "objectSid",
498
.type = LDB_MAP_CONVERT,
501
.remote_name = "sambaSID",
502
.convert_local = sid_always_string,
503
.convert_remote = sid_always_binary,
507
/* securityIdentifier */
509
.local_name = "securityIdentifier",
510
.type = LDB_MAP_CONVERT,
513
.remote_name = "securityIdentifier",
474
514
.convert_local = sid_always_binary,
475
515
.convert_remote = val_copy,
480
520
.local_name = "whenCreated",
521
.type = LDB_MAP_RENAME,
484
524
.remote_name = "createTimestamp"
529
569
.local_name = "groupType",
570
.type = LDB_MAP_CONVERT,
533
.remote_name = "groupType",
573
.remote_name = "sambaGroupType",
534
574
.convert_local = normalise_to_signed32,
535
575
.convert_remote = val_copy,
635
.local_name = "pwdLastSet",
636
.type = LDB_MAP_RENAME,
639
.remote_name = "sambaPwdLastSet"
644
.local_name = "lastLogon",
645
.type = LDB_MAP_RENAME,
648
.remote_name = "sambaLogonTime"
653
.local_name = "lastLogoff",
654
.type = LDB_MAP_RENAME,
657
.remote_name = "sambaLogoffTime"
662
.local_name = "badPwdCount",
663
.type = LDB_MAP_RENAME,
666
.remote_name = "sambaBadPasswordCount"
671
.local_name = "logonHours",
672
.type = LDB_MAP_RENAME,
675
.remote_name = "sambaLogonHours"
680
.local_name = "homeDrive",
681
.type = LDB_MAP_RENAME,
684
.remote_name = "sambaHomeDrive"
689
.local_name = "scriptPath",
690
.type = LDB_MAP_RENAME,
693
.remote_name = "sambaLogonScript"
698
.local_name = "profilePath",
699
.type = LDB_MAP_RENAME,
702
.remote_name = "sambaProfilePath"
707
.local_name = "userWorkstations",
708
.type = LDB_MAP_RENAME,
711
.remote_name = "sambaUserWorkstations"
716
.local_name = "homeDirectory",
717
.type = LDB_MAP_RENAME,
720
.remote_name = "sambaHomePath"
725
.local_name = "nextRid",
726
.type = LDB_MAP_RENAME,
729
.remote_name = "sambaNextRid"
734
.local_name = "privilegeDisplayName",
735
.type = LDB_MAP_RENAME,
738
.remote_name = "sambaPrivName"
595
743
.local_name = "*",
744
.type = LDB_MAP_KEEP,
599
747
.local_name = NULL,
751
/* This objectClass conflicts with builtin classes on FDS */
752
const struct ldb_map_objectclass nsuniqueid_objectclasses[] =
603
759
/* These things do not show up in wildcard searches in OpenLDAP, but
604
760
* we need them to show up in the AD-like view */
605
761
static const char * const nsuniqueid_wildcard_attributes[] = {
626
782
static int nsuniqueid_init(struct ldb_module *module)
629
ret = ldb_map_init(module, nsuniqueid_attributes, NULL, nsuniqueid_wildcard_attributes, "extensibleObject", NULL);
785
ret = ldb_map_init(module, nsuniqueid_attributes, nsuniqueid_objectclasses, nsuniqueid_wildcard_attributes, "extensibleObject", NULL);
630
786
if (ret != LDB_SUCCESS)
692
848
partition_ctrl = ldb_request_get_control(req, DSDB_CONTROL_CURRENT_PARTITION_OID);
693
849
if (!partition_ctrl) {
694
850
ldb_debug_set(ldb, LDB_DEBUG_FATAL,
695
"entryuuid_sequence_number: no current partition control found");
696
return LDB_ERR_CONSTRAINT_VIOLATION;
851
"entryuuid_sequence_number: no current partition control found!");
852
return LDB_ERR_PROTOCOL_ERROR;
699
855
partition = talloc_get_type(partition_ctrl->data,
700
856
struct dsdb_control_current_partition);
701
SMB_ASSERT(partition && partition->version == DSDB_CONTROL_CURRENT_PARTITION_VERSION);
857
if ((partition == NULL) || (partition->version != DSDB_CONTROL_CURRENT_PARTITION_VERSION)) {
858
ldb_debug_set(ldb, LDB_DEBUG_FATAL,
859
"entryuuid_sequence_number: current partition control with wrong data!");
860
return LDB_ERR_PROTOCOL_ERROR;
703
863
ret = ldb_build_search_req(&search_req, ldb, req,
704
864
partition->dn, LDB_SCOPE_BASE,
705
865
NULL, contextCSN_attr, NULL,
706
866
&seq_num, get_seq_callback,
868
LDB_REQ_SET_LOCATION(search_req);
708
869
if (ret != LDB_SUCCESS) {
723
884
ext = talloc_zero(req, struct ldb_extended);
725
return LDB_ERR_OPERATIONS_ERROR;
727
888
seqr = talloc_zero(req, struct ldb_seqnum_result);
728
889
if (seqr == NULL) {
729
890
talloc_free(ext);
730
return LDB_ERR_OPERATIONS_ERROR;
732
893
ext->oid = LDB_EXTENDED_SEQUENCE_NUMBER;
733
894
ext->data = seqr;
763
924
return ldb_next_request(module, req);
766
_PUBLIC_ const struct ldb_module_ops ldb_entryuuid_module_ops = {
927
static const struct ldb_module_ops ldb_entryuuid_module_ops = {
767
928
.name = "entryuuid",
768
929
.init_context = entryuuid_init,
769
930
.extended = entryuuid_extended,
773
_PUBLIC_ const struct ldb_module_ops ldb_nsuniqueid_module_ops = {
934
static const struct ldb_module_ops ldb_nsuniqueid_module_ops = {
774
935
.name = "nsuniqueid",
775
936
.init_context = nsuniqueid_init,
776
937
.extended = entryuuid_extended,
942
initialise the module
944
_PUBLIC_ int ldb_simple_ldap_map_module_init(const char *version)
947
LDB_MODULE_CHECK_VERSION(version);
948
ret = ldb_register_module(&ldb_entryuuid_module_ops);
949
if (ret != LDB_SUCCESS) {
952
ret = ldb_register_module(&ldb_nsuniqueid_module_ops);
953
if (ret != LDB_SUCCESS) {