summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Bartlett <abartlet@samba.org>2006-08-14 00:59:57 +0000
committerGerald (Jerry) Carter <jerry@samba.org>2007-10-10 14:15:33 -0500
commit8f42f1292c2f1f1002b8446dc8b5351eb633d5ce (patch)
tree93ea15acce51657b8dd95bdc429b450db63313b5
parent027583e6de2a6981d1c0e8959e1e37bf758be8f9 (diff)
downloadsamba-8f42f1292c2f1f1002b8446dc8b5351eb633d5ce.tar.gz
samba-8f42f1292c2f1f1002b8446dc8b5351eb633d5ce.tar.bz2
samba-8f42f1292c2f1f1002b8446dc8b5351eb633d5ce.zip
r17526: Move timestamp generation into the objectGUID module. It probably
needs to be renamed (operation_add?). This allows me to match the behaviour and substitute with the entryUUID module for remote LDAP connections. Andrew Bartlett (This used to be commit af02b4d7c631bb15bf5a5f73f9fdc23075d50f60)
-rw-r--r--source4/dsdb/samdb/ldb_modules/objectguid.c89
-rw-r--r--source4/lib/ldb/modules/operational.c41
-rwxr-xr-xsource4/setup/provision6
-rw-r--r--source4/setup/provision_partitions.ldif5
4 files changed, 98 insertions, 43 deletions
diff --git a/source4/dsdb/samdb/ldb_modules/objectguid.c b/source4/dsdb/samdb/ldb_modules/objectguid.c
index 1f18f0e603..ca27f17d71 100644
--- a/source4/dsdb/samdb/ldb_modules/objectguid.c
+++ b/source4/dsdb/samdb/ldb_modules/objectguid.c
@@ -50,6 +50,35 @@ static struct ldb_message_element *objectguid_find_attribute(const struct ldb_me
return NULL;
}
+/*
+ add a time element to a record
+*/
+static int add_time_element(struct ldb_message *msg, const char *attr, time_t t)
+{
+ struct ldb_message_element *el;
+ char *s;
+
+ if (ldb_msg_find_element(msg, attr) != NULL) {
+ return 0;
+ }
+
+ s = ldb_timestring(msg, t);
+ if (s == NULL) {
+ return -1;
+ }
+
+ if (ldb_msg_add_string(msg, attr, s) != 0) {
+ return -1;
+ }
+
+ el = ldb_msg_find_element(msg, attr);
+ /* always set as replace. This works because on add ops, the flag
+ is ignored */
+ el->flags = LDB_FLAG_MOD_REPLACE;
+
+ return 0;
+}
+
/* add_record: add objectGUID attribute */
static int objectguid_add(struct ldb_module *module, struct ldb_request *req)
{
@@ -60,6 +89,7 @@ static int objectguid_add(struct ldb_module *module, struct ldb_request *req)
struct GUID guid;
NTSTATUS nt_status;
int ret;
+ time_t t = time(NULL);
ldb_debug(module->ldb, LDB_DEBUG_TRACE, "objectguid_add_record\n");
@@ -82,6 +112,7 @@ static int objectguid_add(struct ldb_module *module, struct ldb_request *req)
/* we have to copy the message as the caller might have it as a const */
down_req->op.add.message = msg = ldb_msg_copy_shallow(down_req, req->op.add.message);
if (msg == NULL) {
+ talloc_free(down_req);
return LDB_ERR_OPERATIONS_ERROR;
}
@@ -91,14 +122,70 @@ static int objectguid_add(struct ldb_module *module, struct ldb_request *req)
nt_status = ndr_push_struct_blob(&v, msg, &guid,
(ndr_push_flags_fn_t)ndr_push_GUID);
if (!NT_STATUS_IS_OK(nt_status)) {
- return -1;
+ talloc_free(down_req);
+ return LDB_ERR_OPERATIONS_ERROR;
}
ret = ldb_msg_add_value(msg, "objectGUID", &v);
if (ret) {
+ talloc_free(down_req);
return ret;
}
+ if (add_time_element(msg, "whenCreated", t) != 0 ||
+ add_time_element(msg, "whenChanged", t) != 0) {
+ talloc_free(down_req);
+ return LDB_ERR_OPERATIONS_ERROR;
+ }
+
+ ldb_set_timeout_from_prev_req(module->ldb, req, down_req);
+
+ /* go on with the call chain */
+ ret = ldb_next_request(module, down_req);
+
+ /* do not free down_req as the call results may be linked to it,
+ * it will be freed when the upper level request get freed */
+ if (ret == LDB_SUCCESS) {
+ req->handle = down_req->handle;
+ }
+
+ return ret;
+}
+
+/* modify_record: update timestamps */
+static int objectguid_modify(struct ldb_module *module, struct ldb_request *req)
+{
+ struct ldb_request *down_req;
+ struct ldb_message *msg;
+ int ret;
+ time_t t = time(NULL);
+
+ ldb_debug(module->ldb, LDB_DEBUG_TRACE, "objectguid_add_record\n");
+
+ /* do not manipulate our control entries */
+ if (ldb_dn_is_special(req->op.add.message->dn)) {
+ return ldb_next_request(module, req);
+ }
+
+ down_req = talloc(req, struct ldb_request);
+ if (down_req == NULL) {
+ return LDB_ERR_OPERATIONS_ERROR;
+ }
+
+ *down_req = *req;
+
+ /* we have to copy the message as the caller might have it as a const */
+ down_req->op.mod.message = msg = ldb_msg_copy_shallow(down_req, req->op.mod.message);
+ if (msg == NULL) {
+ talloc_free(down_req);
+ return LDB_ERR_OPERATIONS_ERROR;
+ }
+
+ if (add_time_element(msg, "whenChanged", t) != 0) {
+ talloc_free(down_req);
+ return LDB_ERR_OPERATIONS_ERROR;
+ }
+
ldb_set_timeout_from_prev_req(module->ldb, req, down_req);
/* go on with the call chain */
diff --git a/source4/lib/ldb/modules/operational.c b/source4/lib/ldb/modules/operational.c
index 934622eccd..b14d552e83 100644
--- a/source4/lib/ldb/modules/operational.c
+++ b/source4/lib/ldb/modules/operational.c
@@ -170,35 +170,6 @@ failed:
}
/*
- add a time element to a record
-*/
-static int add_time_element(struct ldb_message *msg, const char *attr, time_t t)
-{
- struct ldb_message_element *el;
- char *s;
-
- if (ldb_msg_find_element(msg, attr) != NULL) {
- return 0;
- }
-
- s = ldb_timestring(msg, t);
- if (s == NULL) {
- return -1;
- }
-
- if (ldb_msg_add_string(msg, attr, s) != 0) {
- return -1;
- }
-
- el = ldb_msg_find_element(msg, attr);
- /* always set as replace. This works because on add ops, the flag
- is ignored */
- el->flags = LDB_FLAG_MOD_REPLACE;
-
- return 0;
-}
-
-/*
add a uint64_t element to a record
*/
static int add_uint64_element(struct ldb_message *msg, const char *attr, uint64_t v)
@@ -348,7 +319,6 @@ static int operational_add(struct ldb_module *module, struct ldb_request *req)
{
struct ldb_request *down_req;
struct ldb_message *msg;
- time_t t = time(NULL);
uint64_t seq_num;
int ret;
@@ -368,11 +338,6 @@ static int operational_add(struct ldb_module *module, struct ldb_request *req)
if (msg == NULL) {
return LDB_ERR_OPERATIONS_ERROR;
}
- if (add_time_element(msg, "whenCreated", t) != 0 ||
- add_time_element(msg, "whenChanged", t) != 0) {
- talloc_free(down_req);
- return LDB_ERR_OPERATIONS_ERROR;
- }
/* Get a sequence number from the backend */
ret = ldb_sequence_number(module->ldb, &seq_num);
@@ -405,7 +370,6 @@ static int operational_modify(struct ldb_module *module, struct ldb_request *req
{
struct ldb_request *down_req;
struct ldb_message *msg;
- time_t t = time(NULL);
uint64_t seq_num;
int ret;
@@ -425,11 +389,6 @@ static int operational_modify(struct ldb_module *module, struct ldb_request *req
if (msg == NULL) {
return LDB_ERR_OPERATIONS_ERROR;
}
- if (add_time_element(msg, "whenChanged", t) != 0) {
- talloc_free(down_req);
- return LDB_ERR_OPERATIONS_ERROR;
- }
-
/* Get a sequence number from the backend */
ret = ldb_sequence_number(module->ldb, &seq_num);
if (ret == LDB_SUCCESS) {
diff --git a/source4/setup/provision b/source4/setup/provision
index a58f4a5dce..4d4716ee1a 100755
--- a/source4/setup/provision
+++ b/source4/setup/provision
@@ -111,6 +111,12 @@ for (r in options) {
subobj[key] = options[r];
}
+if (options["ldap-backend"] != undefined) {
+ subobj["LDAPMODULES"] = "entryUUID";
+} else {
+ subobj["LDAPMODULES"] = "objectguid";
+}
+
var blank = (options["blank"] != undefined);
var ldapbase = (options["ldap-base"] != undefined);
diff --git a/source4/setup/provision_partitions.ldif b/source4/setup/provision_partitions.ldif
index 14e077eca1..e9a273795a 100644
--- a/source4/setup/provision_partitions.ldif
+++ b/source4/setup/provision_partitions.ldif
@@ -5,6 +5,9 @@ partition: ${BASEDN}:${LDAPBACKEND}
replicateEntries: @SUBCLASSES
replicateEntries: @ATTRIBUTES
replicateEntries: @INDEXLIST
+modules:CN=Schema,CN=Configuration,${BASEDN}:objectguid
+modules:CN=Configuration,${BASEDN}:objectguid
+modules:${BASEDN}:${LDAPMODULES}
#Add modules to the list to activate them by default
#beware often order is important
@@ -15,4 +18,4 @@ replicateEntries: @INDEXLIST
# - partition must be last
dn: @MODULES
-@LIST: rootdse,kludge_acl,paged_results,server_sort,extended_dn,asq,samldb,objectguid,password_hash,operational,objectclass,rdn_name,partition
+@LIST: rootdse,kludge_acl,paged_results,server_sort,extended_dn,asq,samldb,password_hash,operational,objectclass,rdn_name,partition