diff options
author | Andrew Tridgell <tridge@samba.org> | 2010-02-16 14:45:16 +1100 |
---|---|---|
committer | Andrew Tridgell <tridge@samba.org> | 2010-02-16 21:10:50 +1100 |
commit | 90203f87e7da3346ae9236e4d30c93b95a2ddad9 (patch) | |
tree | 5eb2caa2f160e9a9f69c6d9eb673ff128fa66352 /source4/dsdb | |
parent | c6d85d67f9b52e4071c84749a1f55de646a5451c (diff) | |
download | samba-90203f87e7da3346ae9236e4d30c93b95a2ddad9.tar.gz samba-90203f87e7da3346ae9236e4d30c93b95a2ddad9.tar.bz2 samba-90203f87e7da3346ae9236e4d30c93b95a2ddad9.zip |
s4-dsdb: change samdb_replace() to dsdb_replace() and allow for dsdb_flags
This allows for controls to be added easily where they are needed.
Diffstat (limited to 'source4/dsdb')
-rw-r--r-- | source4/dsdb/common/util.c | 99 | ||||
-rw-r--r-- | source4/dsdb/common/util.h | 1 | ||||
-rw-r--r-- | source4/dsdb/schema/schema_init.c | 5 | ||||
-rw-r--r-- | source4/dsdb/schema/schema_set.c | 4 |
4 files changed, 33 insertions, 76 deletions
diff --git a/source4/dsdb/common/util.c b/source4/dsdb/common/util.c index 12185f999d..5178253ae1 100644 --- a/source4/dsdb/common/util.c +++ b/source4/dsdb/common/util.c @@ -783,7 +783,7 @@ int samdb_msg_add_delete(struct ldb_context *sam_ldb, TALLOC_CTX *mem_ctx, struc const char *attr_name) { /* we use an empty replace rather than a delete, as it allows for - samdb_replace() to be used everywhere */ + dsdb_replace() to be used everywhere */ return ldb_msg_add_empty(msg, attr_name, LDB_FLAG_MOD_REPLACE, NULL); } @@ -981,26 +981,10 @@ int samdb_msg_set_string(struct ldb_context *sam_ldb, TALLOC_CTX *mem_ctx, struc } /* - replace elements in a record -*/ -int samdb_replace(struct ldb_context *sam_ldb, TALLOC_CTX *mem_ctx, struct ldb_message *msg) -{ - int i; - - /* mark all the message elements as LDB_FLAG_MOD_REPLACE */ - for (i=0;i<msg->num_elements;i++) { - msg->elements[i].flags = LDB_FLAG_MOD_REPLACE; - } - - /* modify the samdb record */ - return ldb_modify(sam_ldb, msg); -} - -/* * Handle ldb_request in transaction */ static int dsdb_autotransaction_request(struct ldb_context *sam_ldb, - struct ldb_request *req) + struct ldb_request *req) { int ret; @@ -1023,55 +1007,6 @@ static int dsdb_autotransaction_request(struct ldb_context *sam_ldb, } /* - * replace elements in a record using LDB_CONTROL_AS_SYSTEM - * used to skip access checks on operations - * that are performed by the system - */ -int samdb_replace_as_system(struct ldb_context *sam_ldb, - TALLOC_CTX *mem_ctx, - struct ldb_message *msg) -{ - int i; - int ldb_ret; - struct ldb_request *req = NULL; - - /* mark all the message elements as LDB_FLAG_MOD_REPLACE */ - for (i=0;i<msg->num_elements;i++) { - msg->elements[i].flags = LDB_FLAG_MOD_REPLACE; - } - - - ldb_ret = ldb_msg_sanity_check(sam_ldb, msg); - if (ldb_ret != LDB_SUCCESS) { - return ldb_ret; - } - - ldb_ret = ldb_build_mod_req(&req, sam_ldb, mem_ctx, - msg, - NULL, - NULL, - ldb_op_default_callback, - NULL); - - if (ldb_ret != LDB_SUCCESS) { - talloc_free(req); - return ldb_ret; - } - - ldb_ret = ldb_request_add_control(req, LDB_CONTROL_AS_SYSTEM_OID, false, NULL); - if (ldb_ret != LDB_SUCCESS) { - talloc_free(req); - return ldb_ret; - } - - /* do request and auto start a transaction */ - ldb_ret = dsdb_autotransaction_request(sam_ldb, req); - - talloc_free(req); - return ldb_ret; -} - -/* return a default security descriptor */ struct security_descriptor *samdb_default_security_descriptor(TALLOC_CTX *mem_ctx) @@ -2119,7 +2054,7 @@ NTSTATUS samdb_set_password_sid(struct ldb_context *ldb, TALLOC_CTX *mem_ctx, } /* modify the samdb record */ - ret = samdb_replace(ldb, mem_ctx, msg); + ret = dsdb_replace(ldb, msg, 0); if (ret != LDB_SUCCESS) { ldb_transaction_cancel(ldb); talloc_free(user_dn); @@ -3434,6 +3369,13 @@ int dsdb_request_add_controls(struct ldb_request *req, uint32_t dsdb_flags) } } + if (dsdb_flags & DSDB_FLAG_AS_SYSTEM) { + ret = ldb_request_add_control(req, LDB_CONTROL_AS_SYSTEM_OID, false, NULL); + if (ret != LDB_SUCCESS) { + return ret; + } + } + return LDB_SUCCESS; } @@ -3461,11 +3403,24 @@ int dsdb_modify(struct ldb_context *ldb, const struct ldb_message *message, return ret; } - ret = ldb_request(ldb, req); - if (ret == LDB_SUCCESS) { - ret = ldb_wait(req->handle, LDB_WAIT_ALL); - } + ret = dsdb_autotransaction_request(ldb, req); talloc_free(req); return ret; } + +/* + like dsdb_modify() but set all the element flags to + LDB_FLAG_MOD_REPLACE + */ +int dsdb_replace(struct ldb_context *ldb, struct ldb_message *msg, uint32_t dsdb_flags) +{ + int i; + + /* mark all the message elements as LDB_FLAG_MOD_REPLACE */ + for (i=0;i<msg->num_elements;i++) { + msg->elements[i].flags = LDB_FLAG_MOD_REPLACE; + } + + return dsdb_modify(ldb, msg, dsdb_flags); +} diff --git a/source4/dsdb/common/util.h b/source4/dsdb/common/util.h index 590653acc2..e80fdd8216 100644 --- a/source4/dsdb/common/util.h +++ b/source4/dsdb/common/util.h @@ -30,3 +30,4 @@ #define DSDB_SEARCH_SHOW_EXTENDED_DN 0x0010 #define DSDB_MODIFY_RELAX 0x0020 #define DSDB_MODIFY_PERMISSIVE 0x0040 +#define DSDB_FLAG_AS_SYSTEM 0x0080 diff --git a/source4/dsdb/schema/schema_init.c b/source4/dsdb/schema/schema_init.c index 77b4e2a473..c369d57fa9 100644 --- a/source4/dsdb/schema/schema_init.c +++ b/source4/dsdb/schema/schema_init.c @@ -22,6 +22,7 @@ #include "includes.h" #include "dsdb/samdb/samdb.h" +#include "dsdb/common/util.h" #include "lib/ldb/include/ldb_errors.h" #include "../lib/util/dlinklist.h" #include "librpc/gen_ndr/ndr_misc.h" @@ -310,12 +311,12 @@ WERROR dsdb_write_prefixes_from_schema_to_ldb(TALLOC_CTX *mem_ctx, struct ldb_co return WERR_NOMEM; } - ldb_ret = samdb_replace_as_system(ldb, temp_ctx, msg); + ldb_ret = dsdb_replace(ldb, msg, DSDB_FLAG_AS_SYSTEM); talloc_free(temp_ctx); if (ldb_ret != 0) { - DEBUG(0,("dsdb_write_prefixes_from_schema_to_ldb: samdb_replace failed\n")); + DEBUG(0,("dsdb_write_prefixes_from_schema_to_ldb: dsdb_replace failed\n")); return WERR_FOOBAR; } diff --git a/source4/dsdb/schema/schema_set.c b/source4/dsdb/schema/schema_set.c index 99b26f6b9d..3dace04304 100644 --- a/source4/dsdb/schema/schema_set.c +++ b/source4/dsdb/schema/schema_set.c @@ -138,7 +138,7 @@ static int dsdb_schema_set_attributes(struct ldb_context *ldb, struct dsdb_schem mod_msg = ldb_msg_diff(ldb, res->msgs[0], msg); if (mod_msg->num_elements > 0) { - ret = samdb_replace(ldb, mem_ctx, mod_msg); + ret = dsdb_replace(ldb, mod_msg, 0); } } @@ -166,7 +166,7 @@ static int dsdb_schema_set_attributes(struct ldb_context *ldb, struct dsdb_schem mod_msg = ldb_msg_diff(ldb, res_idx->msgs[0], msg_idx); if (mod_msg->num_elements > 0) { - ret = samdb_replace(ldb, mem_ctx, mod_msg); + ret = dsdb_replace(ldb, mod_msg, 0); } } if (ret == LDB_ERR_OPERATIONS_ERROR || ret == LDB_ERR_INSUFFICIENT_ACCESS_RIGHTS || ret == LDB_ERR_INVALID_DN_SYNTAX) { |