Author: mkhl Date: 2006-06-24 19:29:10 +0000 (Sat, 24 Jun 2006) New Revision: 16500
WebSVN: http://websvn.samba.org/cgi-bin/viewcvs.cgi?view=rev&root=samba&rev=16500 Log: So the sorting was a dumb idea and needed forward declarations. Bah. Fix other compilation issues. 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-06-24 17:19:09 UTC (rev 16499) +++ branches/SOC/mkhl/ldb-map/modules/ldb_map.c 2006-06-24 19:29:10 UTC (rev 16500) @@ -327,7 +327,7 @@ int i; for (i = 0; i < msg->num_elements; i++) { - map = find_attr_local(data, msg->elements[i]); + map = find_attr_local(data, msg->elements[i].name); if (map && map->type != MAP_IGNORE) return 1; } @@ -1612,6 +1612,23 @@ /* } */ +/* Add the local record */ +static +int +map_add_do_local(struct ldb_async_handle *handle) +{ + struct map_async_context *ac; + + ac = talloc_get_type(handle->private_data, struct map_async_context); + + ldb_set_timeout_from_prev_req(ac->module->ldb, + ac->orig_req, ac->local_req); + + ac->step = MAP_DO_ADD_LOCAL; + + return ldb_next_request(ac->module, ac->local_req); +} + /* Add a record */ static int @@ -1707,10 +1724,12 @@ return LDB_ERR_OPERATIONS_ERROR; } -/* Add the local record */ + + +/* Modify the local record */ static int -map_add_do_local(struct ldb_async_handle *handle) +map_modify_do_local(struct ldb_async_handle *handle) { struct map_async_context *ac; @@ -1719,12 +1738,50 @@ ldb_set_timeout_from_prev_req(ac->module->ldb, ac->orig_req, ac->local_req); - ac->step = MAP_DO_ADD_LOCAL; + ac->step = MAP_DO_MODIFY_LOCAL; return ldb_next_request(ac->module, ac->local_req); } +/* Modify the remote record */ +static +int +map_modify_do_remote(struct ldb_async_handle *handle) +{ + struct map_async_context *ac; + struct ldb_message *msg; + char *dn; + ac = talloc_get_type(handle->private_data, struct map_async_context); + + /* no remote record, add it instead */ + if (ac->remote_dn == NULL) { + /* turn request into 'add' */ + msg = discard_const_p(struct ldb_message, + ac->remote_req->op.mod.message); + ac->remote_req->operation = LDB_ADD; + ac->remote_req->op.add.message = msg; + /* TODO: Could I just leave msg in there? I think so, + but it looks clearer this way. */ + + /* update local 'IS_MAPPED' */ + msg = discard_const_p(struct ldb_message, + ac->local_req->op.mod.message); + dn = ldb_dn_linearize(msg, ac->remote_dn); + if (ldb_msg_add_empty(msg, IS_MAPPED, LDB_FLAG_MOD_ADD) != 0) + return LDB_ERR_OPERATIONS_ERROR; + if (ldb_msg_add_string(msg, IS_MAPPED, dn) != 0) + return LDB_ERR_OPERATIONS_ERROR; + } + + ldb_set_timeout_from_prev_req(ac->module->ldb, + ac->orig_req, ac->remote_req); + + ac->step = MAP_DO_MODIFY_REMOTE; + + return ldb_next_remote_request(ac->module, ac->remote_req); +} + /* Modify a record */ static int @@ -1817,97 +1874,35 @@ return LDB_ERR_OPERATIONS_ERROR; } -/* Modify the remote record */ + +/* Delete the local record */ static int -map_modify_do_remote(struct ldb_async_handle *handle) +map_delete_do_local(struct ldb_async_handle *handle) { struct map_async_context *ac; - struct ldb_message *msg; - char *dn; ac = talloc_get_type(handle->private_data, struct map_async_context); - /* no remote record, add it instead */ - if (ac->remote_dn == NULL) { - /* turn request into 'add' */ - msg = discard_const_p(struct ldb_message, - ac->remote_req->op.mod.message); - ac->remote_req->operation = LDB_ADD; - ac->remote_req->op.add.message = msg; - /* TODO: Could I just leave msg in there? I think so, - but it looks clearer this way. */ - - /* update local 'IS_MAPPED' */ - msg = discard_const_p(struct ldb_message, - ac->local_req->op.mod.message); - dn = ldb_dn_linearize(msg, ac->remote_dn); - if (ldb_msg_add_empty(msg, IS_MAPPED, LDB_FLAG_MOD_ADD) != 0) - return LDB_ERR_OPERATIONS_ERROR; - if (ldb_msg_add_string(msg, IS_MAPPED, dn) != 0) - return LDB_ERR_OPERATIONS_ERROR; + /* prepare the local operation */ + ac->local_req = talloc_zero(ac, struct ldb_request); + if (ac->local_req == NULL) { + ldb_oom(ac->module->ldb); + return LDB_ERR_OPERATIONS_ERROR; } - ldb_set_timeout_from_prev_req(ac->module->ldb, - ac->orig_req, ac->remote_req); + *(ac->local_req) = *(ac->orig_req); /* copy the request */ - ac->step = MAP_DO_MODIFY_REMOTE; - - return ldb_next_remote_request(ac->module, ac->remote_req); -} - -/* Modify the local record */ -static -int -map_modify_do_local(struct ldb_async_handle *handle) -{ - struct map_async_context *ac; - - ac = talloc_get_type(handle->private_data, struct map_async_context); - + ac->local_req->async.context = NULL; + ac->local_req->async.callback = NULL; ldb_set_timeout_from_prev_req(ac->module->ldb, ac->orig_req, ac->local_req); - ac->step = MAP_DO_MODIFY_LOCAL; + ac->step = MAP_DO_DELETE_LOCAL; return ldb_next_request(ac->module, ac->local_req); } - -/* Delete a record */ -static -int -map_delete(struct ldb_module *module, - struct ldb_request *req) -{ - struct ldb_async_handle *h; - struct map_async_context *ac; - - /* do not manipulate our control entries */ - if (ldb_dn_is_special(req->op.del.dn)) - return ldb_next_request(module, req); - - /* TODO: check that DN is under the local baseDN */ - - /* prepare async context and handle */ - h = map_init_handle(req, module); - if (h == NULL) - return LDB_ERR_OPERATIONS_ERROR; - ac = talloc_get_type(h->private_data, struct map_async_context); - - /* return or own handle to deal with this call */ - req->async.handle = h; - - /* prepare the search operation */ - ac->search_req = build_self_req(ac, req->op.del.dn); - if (ac->search_req == NULL) - return LDB_ERR_OPERATIONS_ERROR; - - ac->step = MAP_SEARCH_SELF_DELETE; - - return ldb_next_request(module, ac->search_req); -} - /* Delete the remote record */ static int @@ -1943,46 +1938,17 @@ return ldb_next_remote_request(ac->module, ac->remote_req); } -/* Delete the local record */ +/* Delete a record */ static int -map_delete_do_local(struct ldb_async_handle *handle) -{ - struct map_async_context *ac; - - ac = talloc_get_type(handle->private_data, struct map_async_context); - - /* prepare the local operation */ - ac->local_req = talloc_zero(ac, struct ldb_request); - if (ac->local_req == NULL) { - ldb_oom(ac->module->ldb); - return LDB_ERR_OPERATIONS_ERROR; - } - - *(ac->local_req) = *(ac->orig_req); /* copy the request */ - - ac->local_req->async.context = NULL; - ac->local_req->async.callback = NULL; - ldb_set_timeout_from_prev_req(ac->module->ldb, - ac->orig_req, ac->local_req); - - ac->step = MAP_DO_DELETE_LOCAL; - - return ldb_next_request(ac->module, ac->local_req); -} - - -/* Rename a record */ -static -int -map_rename(struct ldb_module *module, +map_delete(struct ldb_module *module, struct ldb_request *req) { struct ldb_async_handle *h; struct map_async_context *ac; /* do not manipulate our control entries */ - if (ldb_dn_is_special(req->op.rename.olddn)) + if (ldb_dn_is_special(req->op.del.dn)) return ldb_next_request(module, req); /* TODO: check that DN is under the local baseDN */ @@ -1997,51 +1963,42 @@ req->async.handle = h; /* prepare the search operation */ - ac->search_req = build_self_req(ac, req->op.rename.olddn); + ac->search_req = build_self_req(ac, req->op.del.dn); if (ac->search_req == NULL) return LDB_ERR_OPERATIONS_ERROR; - ac->step = MAP_SEARCH_SELF_RENAME; + ac->step = MAP_SEARCH_SELF_DELETE; return ldb_next_request(module, ac->search_req); } -/* Rename the remote record */ + +/* Rename the local record */ static int -map_rename_do_remote(struct ldb_async_handle *handle) +map_rename_do_local(struct ldb_async_handle *handle) { struct map_async_context *ac; ac = talloc_get_type(handle->private_data, struct map_async_context); - /* no remote record, continue locally */ - if (ac->remote_dn == NULL) - return map_rename_do_local(handle); - - /* prepare the remote operation */ - ac->remote_req = talloc_zero(ac, struct ldb_request); - if (ac->remote_req == NULL) { + /* prepare the local operation */ + ac->local_req = talloc_zero(ac, struct ldb_request); + if (ac->local_req == NULL) { ldb_oom(ac->module->ldb); return LDB_ERR_OPERATIONS_ERROR; } - *(ac->remote_req) = *(ac->orig_req); /* copy the request */ + *(ac->local_req) = *(ac->orig_req); /* copy the request */ - ac->remote_req->async.context = NULL; - ac->remote_req->async.callback = NULL; + ac->local_req->async.context = NULL; + ac->local_req->async.callback = NULL; ldb_set_timeout_from_prev_req(ac->module->ldb, - ac->orig_req, ac->remote_req); + ac->orig_req, ac->local_req); - /* operate on remote record */ - ac->remote_req->op.rename.olddn = ac->remote_dn; - ac->remote_req->op.rename.newdn - = map_local_dn(ac->module, ac->remote_req, - ac->orig_req->op.rename.newdn); + ac->step = MAP_DO_RENAME_LOCAL; - ac->step = MAP_DO_RENAME_REMOTE; - - return ldb_next_remote_request(ac->module, ac->remote_req); + return ldb_next_request(ac->module, ac->local_req); } /* Update the local 'IS_MAPPED' attribute */ @@ -2096,38 +2053,82 @@ return LDB_ERR_OPERATIONS_ERROR; } -/* Rename the local record */ +/* Rename the remote record */ static int -map_rename_do_local(struct ldb_async_handle *handle) +map_rename_do_remote(struct ldb_async_handle *handle) { struct map_async_context *ac; ac = talloc_get_type(handle->private_data, struct map_async_context); - /* prepare the local operation */ - ac->local_req = talloc_zero(ac, struct ldb_request); - if (ac->local_req == NULL) { + /* no remote record, continue locally */ + if (ac->remote_dn == NULL) + return map_rename_do_local(handle); + + /* prepare the remote operation */ + ac->remote_req = talloc_zero(ac, struct ldb_request); + if (ac->remote_req == NULL) { ldb_oom(ac->module->ldb); return LDB_ERR_OPERATIONS_ERROR; } - *(ac->local_req) = *(ac->orig_req); /* copy the request */ + *(ac->remote_req) = *(ac->orig_req); /* copy the request */ - ac->local_req->async.context = NULL; - ac->local_req->async.callback = NULL; + ac->remote_req->async.context = NULL; + ac->remote_req->async.callback = NULL; ldb_set_timeout_from_prev_req(ac->module->ldb, - ac->orig_req, ac->local_req); + ac->orig_req, ac->remote_req); - ac->step = MAP_DO_RENAME_LOCAL; + /* operate on remote record */ + ac->remote_req->op.rename.olddn = ac->remote_dn; + ac->remote_req->op.rename.newdn + = map_local_dn(ac->module, ac->remote_req, + ac->orig_req->op.rename.newdn); - return ldb_next_request(ac->module, ac->local_req); + ac->step = MAP_DO_RENAME_REMOTE; + + return ldb_next_remote_request(ac->module, ac->remote_req); } +/* Rename a record */ +static +int +map_rename(struct ldb_module *module, + struct ldb_request *req) +{ + struct ldb_async_handle *h; + struct map_async_context *ac; + /* do not manipulate our control entries */ + if (ldb_dn_is_special(req->op.rename.olddn)) + return ldb_next_request(module, req); + + /* TODO: check that DN is under the local baseDN */ + + /* prepare async context and handle */ + h = map_init_handle(req, module); + if (h == NULL) + return LDB_ERR_OPERATIONS_ERROR; + ac = talloc_get_type(h->private_data, struct map_async_context); + + /* return or own handle to deal with this call */ + req->async.handle = h; + + /* prepare the search operation */ + ac->search_req = build_self_req(ac, req->op.rename.olddn); + if (ac->search_req == NULL) + return LDB_ERR_OPERATIONS_ERROR; + + ac->step = MAP_SEARCH_SELF_RENAME; + + return ldb_next_request(module, ac->search_req); +} + + /* Asynchronism */ -/* last request was run for the current step */ +/* last request that was run for the current step */ static struct ldb_request * map_async_get_req(struct map_async_context *ac) @@ -2210,8 +2211,7 @@ /* Async trampoline */ static int -map_async_wait(struct ldb_async_handle *handle, - enum ldb_async_wait_type type) +mp_async_wait(struct ldb_async_handle *handle) { struct map_async_context *ac; struct ldb_request *req; @@ -2349,7 +2349,7 @@ if (dn == NULL) { ldb_debug(module->ldb, LDB_DEBUG_ERROR, "ldb_map: " "Failed to construct the '%s' DN!\n", MAP_DN_NAME); - goto failed; + return LDB_ERR_OPERATIONS_ERROR; } ret = ldb_search(module->ldb, dn, LDB_SCOPE_BASE, NULL, attrs, &res); @@ -2362,7 +2362,7 @@ "No results for '%s=%s'!\n", MAP_DN_NAME, name); return LDB_ERR_CONSTRAINT_VIOLATION; } - if (result->count > 1) { + if (res->count > 1) { ldb_debug(module->ldb, LDB_DEBUG_ERROR, "ldb_map: " "Too many results for '%s=%s'!\n", MAP_DN_NAME, name); return LDB_ERR_CONSTRAINT_VIOLATION; @@ -2398,31 +2398,31 @@ /* specified ones go first */ for (i = 0; attrs[i].local_name; i++) { - data->context.attribute_maps + data->attribute_maps = talloc_realloc(data, data->attribute_maps, struct ldb_map_attribute, last+1); - data->context.attribute_maps[last] = attrs[i]; + data->attribute_maps[last] = attrs[i]; last++; } /* built-in ones go last */ for (i = 0; builtin_attribute_maps[i].local_name; i++) { - data->context.attribute_maps + data->attribute_maps = talloc_realloc(data, data->attribute_maps, struct ldb_map_attribute, last+1); - data->context.attribute_maps[last] = builtin_attribute_maps[i]; + data->attribute_maps[last] = builtin_attribute_maps[i]; last++; } /* ensure 'local_name == NULL' for the last entry */ - data->context.attribute_maps - = talloc_realloc(data, data->context.attribute_maps, + data->attribute_maps + = talloc_realloc(data, data->attribute_maps, struct ldb_map_attribute, last+1); - memset(&data->context.attribute_maps[last], 0, + memset(&data->attribute_maps[last], 0, sizeof(struct ldb_map_attribute)); /* store list of objectClass maps */ - data->context.objectclass_maps = ocls; + data->objectclass_maps = ocls; }