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 +0000, [EMAIL PROTECTED] wrote:
> Author: abartlet
> Date: 2006-08-14 00:59:57 +0000 (Mon, 14 Aug 2006)
> New Revision: 17526
> 
> WebSVN: 
> http://websvn.samba.org/cgi-bin/viewcvs.cgi?view=rev&root=samba&rev=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
> ===================================================================
> --- branches/SAMBA_4_0/source/lib/ldb/modules/operational.c   2006-08-13 
> 23:58:04 UTC (rev 17525)
> +++ branches/SAMBA_4_0/source/lib/ldb/modules/operational.c   2006-08-14 
> 00:59:57 UTC (rev 17526)
> @@ -170,35 +170,6 @@
>  }
>  
>  /*
> -  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 @@
>  {
>       struct ldb_request *down_req;
>       struct ldb_message *msg;
> -     time_t t = time(NULL);
>       uint64_t seq_num;
>       int ret;
>  
> @@ -368,11 +338,6 @@
>       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 @@
>  {
>       struct ldb_request *down_req;
>       struct ldb_message *msg;
> -     time_t t = time(NULL);
>       uint64_t seq_num;
>       int ret;
>  
> @@ -425,11 +389,6 @@
>       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) {
> 
> Modified: branches/SAMBA_4_0/source/setup/provision
> ===================================================================
> --- branches/SAMBA_4_0/source/setup/provision 2006-08-13 23:58:04 UTC (rev 
> 17525)
> +++ branches/SAMBA_4_0/source/setup/provision 2006-08-14 00:59:57 UTC (rev 
> 17526)
> @@ -111,6 +111,12 @@
>       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);
>  
> 
> Modified: branches/SAMBA_4_0/source/setup/provision_partitions.ldif
> ===================================================================
> --- branches/SAMBA_4_0/source/setup/provision_partitions.ldif 2006-08-13 
> 23:58:04 UTC (rev 17525)
> +++ branches/SAMBA_4_0/source/setup/provision_partitions.ldif 2006-08-14 
> 00:59:57 UTC (rev 17526)
> @@ -5,6 +5,9 @@
>  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 @@
>  # - partition must be last
>  
>  dn: @MODULES
> [EMAIL PROTECTED]: 
> rootdse,kludge_acl,paged_results,server_sort,extended_dn,asq,samldb,objectguid,password_hash,operational,objectclass,rdn_name,partition
> [EMAIL PROTECTED]: 
> rootdse,kludge_acl,paged_results,server_sort,extended_dn,asq,samldb,password_hash,operational,objectclass,rdn_name,partition
-- 
Simo Sorce
Samba Team GPL Compliance Officer
email: [EMAIL PROTECTED]
http://samba.org

Reply via email to