Re: svn commit: samba r25781 - in branches/SAMBA_4_0: source/dsdb/samdb/ldb_modules testprogs/ejs

2007-11-01 Thread Stefan (metze) Metzmacher
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

> WebSVN: 
> http://websvn.samba.org/cgi-bin/viewcvs.cgi?view=rev&root=samba&rev=25781
> 
> Log:
> Handle and test linked attribute renames.  

Hi Andrew,

please also commit dsdb_linked_attribute_lDAPDisplayName_list()

metze
-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.5 (GNU/Linux)
Comment: Using GnuPG with SUSE - http://enigmail.mozdev.org

iD8DBQFHKdB3m70gjA5TCD8RAvFSAKCr4NH831xbf8GpwIkvNYMuXjAa9QCgmOQq
7m5caqhs02Dx76343G4DcLY=
=vmP7
-END PGP SIGNATURE-


svn commit: samba r25781 - in branches/SAMBA_4_0: source/dsdb/samdb/ldb_modules testprogs/ejs

2007-11-01 Thread abartlet
Author: abartlet
Date: 2007-11-01 12:34:06 + (Thu, 01 Nov 2007)
New Revision: 25781

WebSVN: 
http://websvn.samba.org/cgi-bin/viewcvs.cgi?view=rev&root=samba&rev=25781

Log:
Handle and test linked attribute renames.  

Andrew Bartlett

Modified:
   branches/SAMBA_4_0/source/dsdb/samdb/ldb_modules/linked_attributes.c
   branches/SAMBA_4_0/testprogs/ejs/ldap.js


Changeset:
Modified: branches/SAMBA_4_0/source/dsdb/samdb/ldb_modules/linked_attributes.c
===
--- branches/SAMBA_4_0/source/dsdb/samdb/ldb_modules/linked_attributes.c
2007-11-01 11:43:00 UTC (rev 25780)
+++ branches/SAMBA_4_0/source/dsdb/samdb/ldb_modules/linked_attributes.c
2007-11-01 12:34:06 UTC (rev 25781)
@@ -41,6 +41,8 @@
struct ldb_request **down_req;
int num_requests;
int finished_requests;
+
+   const char **linked_attrs;
 };
 
 static struct linked_attributes_context *linked_attributes_init_handle(struct 
ldb_request *req, 
@@ -369,22 +371,323 @@
return ret;
 }
 
-/* delete */
-static int linked_attributes_delete(struct ldb_module *module, struct 
ldb_request *req)
+static int setup_modifies(struct ldb_context *ldb, TALLOC_CTX *mem_ctx, 
+ struct linked_attributes_context *ac,
+ struct ldb_message *msg, 
+ struct ldb_dn *olddn, struct ldb_dn *newdn) 
 {
-   /* Look up list of linked attributes */
-   /* Search to see if any linked attributes are in this entry */
-   return ldb_next_request(module, req);
+   int i, j, ret = LDB_SUCCESS;
+   const struct dsdb_schema *schema = dsdb_get_schema(ldb);
+   /* Look up each of the returned attributes */
+   /* Find their schema */
+   /* And it is an actual entry: now create a series of modify requests */
+   for (i=0; i < msg->num_elements; i++) {
+   int otherid;
+   const struct dsdb_attribute *target_attr;
+   const struct ldb_message_element *el = &msg->elements[i];
+   const struct dsdb_attribute *schema_attr
+   = dsdb_attribute_by_lDAPDisplayName(schema, el->name);
+   if (!schema_attr) {
+   ldb_asprintf_errstring(ldb, 
+  "attribute %s is not a valid 
attribute in schema", el->name);
+   return LDB_ERR_OBJECT_CLASS_VIOLATION;  
+   }
+   /* We have a valid attribute, but if it's not linked they maybe 
we just got an extra return on our search... */
+   if (schema_attr->linkID == 0) {
+   continue;
+   }
+   
+   /* Depending on which direction this link is in, we need to 
find it's partner */
+   if ((schema_attr->linkID & 1) == 1) {
+   otherid = schema_attr->linkID - 1;
+   } else {
+   otherid = schema_attr->linkID + 1;
+   }
+   
+   /* Now find the target attribute */
+   target_attr = dsdb_attribute_by_linkID(schema, otherid);
+   if (!target_attr) {
+   ldb_asprintf_errstring(ldb, 
+  "attribute %s does not have 
valid link target", el->name);
+   return LDB_ERR_OBJECT_CLASS_VIOLATION;  
+   }
+   
+   /* For each value being moded, we need to setup the modify */
+   for (j=0; j < el->num_values; j++) {
+   struct ldb_message_element *ret_el;
+   struct ldb_request *new_req;
+   /* Create the modify request */
+   struct ldb_message *new_msg = ldb_msg_new(ac->down_req);
+   if (!new_msg) {
+   ldb_oom(ldb);
+   return LDB_ERR_OPERATIONS_ERROR;
+   }
+   new_msg->dn = ldb_dn_new(new_msg, ldb, (char 
*)el->values[j].data);
+   if (!new_msg->dn) {
+   ldb_asprintf_errstring(ldb, 
+  "attribute %s value %s 
was not a valid DN", msg->elements[i].name,
+  el->values[j].data);
+   return LDB_ERR_INVALID_ATTRIBUTE_SYNTAX;
+   }
+   
+   if (olddn) {
+   ret = ldb_msg_add_empty(new_msg, 
target_attr->lDAPDisplayName, 
+   LDB_FLAG_MOD_DELETE, 
&ret_el);
+   if (ret != LDB_SUCCESS) {
+   return ret;
+   }   
+