Re: svn commit: samba r17526 - in branches/SAMBA_4_0/source: dsdb/samdb/ldb_modules lib/ldb/modules setup

2006-08-14 Thread simo
Andrew,
I do not think this is the right way to do what you aim for.

I'd like you to revert the change and instead build a module, to be used
with the ldap backend, that will remove or change these attributes. This
will make it work even if someone sets them by hands with an explicit
add/modify operation and will leave the rest of code simpler (as it is
now).
I may integrate the operational/objectguid functionality in the schema
module later on, so you would need to change this code anyway.

Simo.

On Mon, 2006-08-14 at 00:59 +, [EMAIL PROTECTED] wrote:
 Author: abartlet
 Date: 2006-08-14 00:59:57 + (Mon, 14 Aug 2006)
 New Revision: 17526
 
 WebSVN: 
 http://websvn.samba.org/cgi-bin/viewcvs.cgi?view=revroot=sambarev=17526
 
 Log:
 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
 
 Modified:
branches/SAMBA_4_0/source/dsdb/samdb/ldb_modules/objectguid.c
branches/SAMBA_4_0/source/lib/ldb/modules/operational.c
branches/SAMBA_4_0/source/setup/provision
branches/SAMBA_4_0/source/setup/provision_partitions.ldif
 
 
 Changeset:
 Modified: branches/SAMBA_4_0/source/dsdb/samdb/ldb_modules/objectguid.c
 ===
 --- branches/SAMBA_4_0/source/dsdb/samdb/ldb_modules/objectguid.c 
 2006-08-13 23:58:04 UTC (rev 17525)
 +++ branches/SAMBA_4_0/source/dsdb/samdb/ldb_modules/objectguid.c 
 2006-08-14 00:59:57 UTC (rev 17526)
 @@ -50,6 +50,35 @@
   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 @@
   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 @@
   /* 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,22 @@
   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 */
 @@ -113,6 +152,54 @@
   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);
 

svn commit: samba r17526 - in branches/SAMBA_4_0/source: dsdb/samdb/ldb_modules lib/ldb/modules setup

2006-08-13 Thread abartlet
Author: abartlet
Date: 2006-08-14 00:59:57 + (Mon, 14 Aug 2006)
New Revision: 17526

WebSVN: 
http://websvn.samba.org/cgi-bin/viewcvs.cgi?view=revroot=sambarev=17526

Log:
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

Modified:
   branches/SAMBA_4_0/source/dsdb/samdb/ldb_modules/objectguid.c
   branches/SAMBA_4_0/source/lib/ldb/modules/operational.c
   branches/SAMBA_4_0/source/setup/provision
   branches/SAMBA_4_0/source/setup/provision_partitions.ldif


Changeset:
Modified: branches/SAMBA_4_0/source/dsdb/samdb/ldb_modules/objectguid.c
===
--- branches/SAMBA_4_0/source/dsdb/samdb/ldb_modules/objectguid.c   
2006-08-13 23:58:04 UTC (rev 17525)
+++ branches/SAMBA_4_0/source/dsdb/samdb/ldb_modules/objectguid.c   
2006-08-14 00:59:57 UTC (rev 17526)
@@ -50,6 +50,35 @@
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 @@
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 @@
/* 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,22 @@
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 */
@@ -113,6 +152,54 @@
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 */
+   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;
+}
+
 static const struct ldb_module_ops objectguid_ops = {
.name  = objectguid,
.add   = objectguid_add,

Modified: branches/SAMBA_4_0/source/lib/ldb/modules/operational.c