svn commit: samba r17427 - in branches/SOC/mkhl/ldb-map/modules: .
mkhl at samba.org
mkhl at samba.org
Sat Aug 5 17:54:52 GMT 2006
Author: mkhl
Date: 2006-08-05 17:54:52 +0000 (Sat, 05 Aug 2006)
New Revision: 17427
WebSVN: http://websvn.samba.org/cgi-bin/viewcvs.cgi?view=rev&root=samba&rev=17427
Log:
Change mapping type for "objectClass" into `generate'.
Add generator functions for "objectClass" elements, converting their
values as before but adding an objectClass of "extensibleObject" in
the remote partition.
Martin
Modified:
branches/SOC/mkhl/ldb-map/modules/ldb_map.c
Changeset:
Modified: branches/SOC/mkhl/ldb-map/modules/ldb_map.c
===================================================================
--- branches/SOC/mkhl/ldb-map/modules/ldb_map.c 2006-08-05 17:52:23 UTC (rev 17426)
+++ branches/SOC/mkhl/ldb-map/modules/ldb_map.c 2006-08-05 17:54:52 UTC (rev 17427)
@@ -1890,10 +1890,62 @@
return ldb_val_dup(mem_ctx, val);
}
+/* Generate a remote message with a mapped objectClass. */
+static
+void
+map_objectclass_generate_remote(struct ldb_module *module,
+ const char *local_attr,
+ const struct ldb_message *old,
+ struct ldb_message *remote,
+ struct ldb_message *local)
+{
+ struct ldb_message_element *el, *oc;
+ struct ldb_val val;
+ int i;
+
+ /* Find old local objectClass */
+ oc = ldb_msg_find_element(old, local_attr);
+ if (oc == NULL) {
+ return;
+ }
+
+ /* Prepare new element */
+ el = talloc_zero(remote, struct ldb_message_element);
+ if (el == NULL) {
+ ldb_oom(module->ldb);
+ return; /* TODO: fail? */
+ }
+
+ /* Copy local objectClass element, reverse space for an extra value */
+ el->num_values = oc->num_values + 1;
+ el->values = talloc_array(el, struct ldb_val, el->num_values);
+ if (el->values == NULL) {
+ talloc_free(el);
+ ldb_oom(module->ldb);
+ return; /* TODO: fail? */
+ }
+
+ /* Copy local element name "objectClass" */
+ el->name = talloc_strdup(el, local_attr);
+
+ /* Convert all local objectClasses */
+ for (i = 0; i < el->num_values - 1; i++) {
+ el->values[i] = map_objectclass_convert_local(module, el->values, &oc->values[i]);
+ }
+
+ val.data = (uint8_t *)talloc_strdup(el->values, "extensibleObject");
+ val.length = strlen((char *)val.data);
+
+ /* Append additional objectClass "extensibleObject" */
+ el->values[i] = val;
+
+ /* Add new objectClass to remote message */
+ ldb_msg_add(remote, el, 0);
+}
+
/* Map an objectClass into the local partition. */
static
-struct
-ldb_val
+struct ldb_val
map_objectclass_convert_remote(struct ldb_module *module,
void *mem_ctx,
const struct ldb_val *val)
@@ -1912,7 +1964,67 @@
return ldb_val_dup(mem_ctx, val);
}
+/* Generate a local message with a mapped objectClass. */
+static
+struct ldb_message_element *
+map_objectclass_generate_local(struct ldb_module *module,
+ void *mem_ctx,
+ const char *remote_attr,
+ const struct ldb_message *remote)
+{
+ struct ldb_message_element *el, *oc;
+ struct ldb_val val;
+ int i;
+ /* Find old remote objectClass */
+ oc = ldb_msg_find_element(remote, remote_attr);
+ if (oc == NULL) {
+ return NULL;
+ }
+
+ /* Prepare new element */
+ el = talloc_zero(mem_ctx, struct ldb_message_element);
+ if (el == NULL) {
+ ldb_oom(module->ldb);
+ return NULL;
+ }
+
+ /* Copy remote objectClass element */
+ el->num_values = oc->num_values;
+ el->values = talloc_array(el, struct ldb_val, el->num_values);
+ if (el->values == NULL) {
+ talloc_free(el);
+ ldb_oom(module->ldb);
+ return NULL;
+ }
+
+ /* Copy remote element name "objectClass" */
+ el->name = talloc_strdup(el, remote_attr);
+
+ /* Convert all remote objectClasses */
+ for (i = 0; i < el->num_values; i++) {
+ el->values[i] = map_objectclass_convert_remote(module, el->values, &oc->values[i]);
+ }
+
+ val.data = (uint8_t *)talloc_strdup(el->values, "extensibleObject");
+ val.length = strlen((char *)val.data);
+
+ /* Remove last value if it was "extensibleObject" */
+ if (ldb_val_equal_exact(&val, &el->values[i-1])) {
+ el->num_values--;
+ el->values = talloc_realloc(el, el->values, struct ldb_val, el->num_values);
+ if (el->values == NULL) {
+ talloc_free(el);
+ ldb_oom(module->ldb);
+ return NULL;
+ }
+ }
+
+ return el;
+}
+
+
+
/* Auxiliary request construction
* ============================== */
@@ -3099,12 +3211,12 @@
},
{
.local_name = "objectclass",
- .type = MAP_CONVERT,
+ .type = MAP_GENERATE,
.u = {
- .convert = {
- .remote_name = "objectclass",
- .convert_local = map_objectclass_convert_local,
- .convert_remote = map_objectclass_convert_remote,
+ .generate = {
+ .remote_names = { "objectclass", NULL },
+ .generate_local = map_objectclass_generate_local,
+ .generate_remote = map_objectclass_generate_remote,
},
},
},
More information about the samba-cvs
mailing list