diff options
author | Volker Lendecke <vl@samba.org> | 2008-03-28 11:53:00 +0100 |
---|---|---|
committer | Stefan Metzmacher <metze@samba.org> | 2008-04-01 14:04:22 +0200 |
commit | fcdfff1cc8c1214cbce1fdd863b1ede970234121 (patch) | |
tree | ad50b65a4882ebcb5187305c9b56d61e13eef360 /source3 | |
parent | d20f88c60302b9af21b3a04e1ebc536a0e0c0e36 (diff) | |
download | samba-fcdfff1cc8c1214cbce1fdd863b1ede970234121.tar.gz samba-fcdfff1cc8c1214cbce1fdd863b1ede970234121.tar.bz2 samba-fcdfff1cc8c1214cbce1fdd863b1ede970234121.zip |
Convert dbwrap_trans_store to NTSTATUS
Signed-off-by: Stefan Metzmacher <metze@samba.org>
(This used to be commit 5f4de856af1abe63b13059bbe1615cb5877770d0)
Diffstat (limited to 'source3')
-rw-r--r-- | source3/groupdb/mapping_tdb.c | 6 | ||||
-rw-r--r-- | source3/lib/dbwrap_util.c | 25 | ||||
-rw-r--r-- | source3/lib/sharesec.c | 9 | ||||
-rw-r--r-- | source3/passdb/secrets.c | 9 | ||||
-rw-r--r-- | source3/registry/reg_backend_db.c | 27 |
5 files changed, 43 insertions, 33 deletions
diff --git a/source3/groupdb/mapping_tdb.c b/source3/groupdb/mapping_tdb.c index e2aa06c8ff..718804b1e5 100644 --- a/source3/groupdb/mapping_tdb.c +++ b/source3/groupdb/mapping_tdb.c @@ -123,7 +123,7 @@ static bool add_mapping_entry(GROUP_MAP *map, int flag) { char *key, *buf; int len; - int res; + NTSTATUS status; key = group_mapping_key(talloc_tos(), &map->sid); if (key == NULL) { @@ -141,13 +141,13 @@ static bool add_mapping_entry(GROUP_MAP *map, int flag) len = tdb_pack((uint8 *)buf, len, "ddff", map->gid, map->sid_name_use, map->nt_name, map->comment); - res = dbwrap_trans_store( + status = dbwrap_trans_store( db, string_term_tdb_data(key), make_tdb_data((uint8_t *)buf, len), flag); TALLOC_FREE(key); - return (res == 0); + return NT_STATUS_IS_OK(status); } diff --git a/source3/lib/dbwrap_util.c b/source3/lib/dbwrap_util.c index 01d70556d8..1a636cc8a6 100644 --- a/source3/lib/dbwrap_util.c +++ b/source3/lib/dbwrap_util.c @@ -156,8 +156,8 @@ int32 dbwrap_change_int32_atomic(struct db_context *db, const char *keystr, return 0; } -int dbwrap_trans_store(struct db_context *db, TDB_DATA key, TDB_DATA dbuf, - int flag) +NTSTATUS dbwrap_trans_store(struct db_context *db, TDB_DATA key, TDB_DATA dbuf, + int flag) { int res; struct db_record *rec; @@ -166,12 +166,13 @@ int dbwrap_trans_store(struct db_context *db, TDB_DATA key, TDB_DATA dbuf, res = db->transaction_start(db); if (res != 0) { DEBUG(5, ("transaction_start failed\n")); - return res; + return NT_STATUS_INTERNAL_DB_CORRUPTION; } rec = db->fetch_locked(db, talloc_tos(), key); if (rec == NULL) { DEBUG(5, ("fetch_locked failed\n")); + status = NT_STATUS_NO_MEMORY; goto cancel; } @@ -186,15 +187,17 @@ int dbwrap_trans_store(struct db_context *db, TDB_DATA key, TDB_DATA dbuf, res = db->transaction_commit(db); if (res != 0) { DEBUG(5, ("tdb_transaction_commit failed\n")); + status = NT_STATUS_INTERNAL_DB_CORRUPTION; + goto cancel; } - return res; + return NT_STATUS_OK; cancel: if (db->transaction_cancel(db) != 0) { smb_panic("Cancelling transaction failed"); } - return -1; + return status; } int dbwrap_trans_delete(struct db_context *db, TDB_DATA key) @@ -237,17 +240,15 @@ int dbwrap_trans_delete(struct db_context *db, TDB_DATA key) return -1; } -int dbwrap_trans_store_int32(struct db_context *db, const char *keystr, int32_t v) +NTSTATUS dbwrap_trans_store_int32(struct db_context *db, const char *keystr, + int32_t v) { - int ret; int32 v_store; SIVAL(&v_store, 0, v); - ret = dbwrap_trans_store(db, string_term_tdb_data(keystr), - make_tdb_data((const uint8 *)&v_store, + return dbwrap_trans_store(db, string_term_tdb_data(keystr), + make_tdb_data((const uint8 *)&v_store, sizeof(v_store)), - TDB_REPLACE); - - return ret; + TDB_REPLACE); } diff --git a/source3/lib/sharesec.c b/source3/lib/sharesec.c index 3d9e608387..33141a9671 100644 --- a/source3/lib/sharesec.c +++ b/source3/lib/sharesec.c @@ -229,10 +229,11 @@ bool set_share_security(const char *share_name, SEC_DESC *psd) goto out; } - if (dbwrap_trans_store(share_db, string_term_tdb_data(key), blob, - TDB_REPLACE) == -1) { - DEBUG(1,("set_share_security: Failed to store secdesc for " - "%s\n", share_name )); + status = dbwrap_trans_store(share_db, string_term_tdb_data(key), blob, + TDB_REPLACE); + if (!NT_STATUS_IS_OK(status)) { + DEBUG(1, ("set_share_security: Failed to store secdesc for " + "%s: %s\n", share_name, nt_errstr(status))); goto out; } diff --git a/source3/passdb/secrets.c b/source3/passdb/secrets.c index 8d08d90dcf..71db81c0e4 100644 --- a/source3/passdb/secrets.c +++ b/source3/passdb/secrets.c @@ -140,13 +140,16 @@ void *secrets_fetch(const char *key, size_t *size) */ bool secrets_store(const char *key, const void *data, size_t size) { + NTSTATUS status; + if (!secrets_init()) { return false; } - return dbwrap_trans_store(db_ctx, string_tdb_data(key), - make_tdb_data((const uint8 *)data, size), - TDB_REPLACE) == 0; + status = dbwrap_trans_store(db_ctx, string_tdb_data(key), + make_tdb_data((const uint8 *)data, size), + TDB_REPLACE); + return NT_STATUS_IS_OK(status); } diff --git a/source3/registry/reg_backend_db.c b/source3/registry/reg_backend_db.c index 716207dbaa..4b8a4b4c37 100644 --- a/source3/registry/reg_backend_db.c +++ b/source3/registry/reg_backend_db.c @@ -349,12 +349,14 @@ bool regdb_init(void) vers_id = dbwrap_fetch_int32(regdb, vstring); if ( vers_id != REGVER_V1 ) { + NTSTATUS status; /* any upgrade code here if needed */ DEBUG(10, ("regdb_init: got %s = %d != %d\n", vstring, vers_id, REGVER_V1)); - if (dbwrap_trans_store_int32(regdb, vstring, REGVER_V1) != 0) { - DEBUG(0, ("regdb_init: error storing %s = %d\n", - vstring, REGVER_V1)); + status = dbwrap_trans_store_int32(regdb, vstring, REGVER_V1); + if (!NT_STATUS_IS_OK(status)) { + DEBUG(0, ("regdb_init: error storing %s = %d: %s\n", + vstring, REGVER_V1, nt_errstr(status))); return false; } else { DEBUG(10, ("regdb_init: stored %s = %d\n", @@ -881,7 +883,8 @@ bool regdb_store_values( const char *key, REGVAL_CTR *values ) TDB_DATA old_data, data; char *keystr = NULL; TALLOC_CTX *ctx = talloc_stackframe(); - int len, ret; + int len; + NTSTATUS status; bool result = false; DEBUG(10,("regdb_store_values: Looking for value of key [%s] \n", key)); @@ -920,9 +923,10 @@ bool regdb_store_values( const char *key, REGVAL_CTR *values ) goto done; } - ret = dbwrap_trans_store(regdb, string_term_tdb_data(keystr), data, - TDB_REPLACE); - result = (ret != -1); + status = dbwrap_trans_store(regdb, string_term_tdb_data(keystr), data, + TDB_REPLACE); + + result = NT_STATUS_IS_OK(status); done: TALLOC_FREE(ctx); @@ -972,6 +976,7 @@ static WERROR regdb_set_secdesc(const char *key, { TALLOC_CTX *mem_ctx = talloc_stackframe(); char *tdbkey; + NTSTATUS status; WERROR err = WERR_NOMEM; TDB_DATA tdbdata; int tdb_ret; @@ -1001,10 +1006,10 @@ static WERROR regdb_set_secdesc(const char *key, goto done; } - tdb_ret = dbwrap_trans_store(regdb, string_term_tdb_data(tdbkey), - tdbdata, 0); - if (tdb_ret != 0) { - err = ntstatus_to_werror(map_nt_error_from_unix(errno)); + status = dbwrap_trans_store(regdb, string_term_tdb_data(tdbkey), + tdbdata, 0); + if (!NT_STATUS_IS_OK(status)) { + err = ntstatus_to_werror(status); goto done; } |