mirror of
https://github.com/samba-team/samba.git
synced 2025-08-09 17:49:29 +03:00
tdb_compat: Higher level API fixes.
My previous patches fixed up all direct TDB callers, but there are a few utility functions and the db_context functions which are still using the old -1 / 0 return codes. It's clearer to fix up all the callers of these too, so everywhere is consistent: non-zero means an error. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
@ -57,7 +57,7 @@ TDB_DATA string_term_tdb_data(const char *string)
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
Lock a chain by string. Return -1 if lock failed.
|
||||
Lock a chain by string. Return non-zero if lock failed.
|
||||
****************************************************************************/
|
||||
|
||||
int tdb_lock_bystring(struct tdb_context *tdb, const char *keyval)
|
||||
@ -79,7 +79,7 @@ void tdb_unlock_bystring(struct tdb_context *tdb, const char *keyval)
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
Read lock a chain by string. Return -1 if lock failed.
|
||||
Read lock a chain by string. Return non-zero if lock failed.
|
||||
****************************************************************************/
|
||||
|
||||
int tdb_read_lock_bystring(struct tdb_context *tdb, const char *keyval)
|
||||
@ -263,7 +263,7 @@ int32_t tdb_change_int32_atomic(struct tdb_context *tdb, const char *keystr, int
|
||||
int32_t val;
|
||||
int32_t ret = -1;
|
||||
|
||||
if (tdb_lock_bystring(tdb, keystr) == -1)
|
||||
if (tdb_lock_bystring(tdb, keystr) != 0)
|
||||
return -1;
|
||||
|
||||
if ((val = tdb_fetch_int32(tdb, keystr)) == -1) {
|
||||
@ -304,7 +304,7 @@ bool tdb_change_uint32_atomic(struct tdb_context *tdb, const char *keystr, uint3
|
||||
uint32_t val;
|
||||
bool ret = false;
|
||||
|
||||
if (tdb_lock_bystring(tdb, keystr) == -1)
|
||||
if (tdb_lock_bystring(tdb, keystr) != 0)
|
||||
return false;
|
||||
|
||||
if (!tdb_fetch_uint32(tdb, keystr, &val)) {
|
||||
|
@ -31,7 +31,7 @@ TDB_DATA string_tdb_data(const char *string);
|
||||
TDB_DATA string_term_tdb_data(const char *string);
|
||||
|
||||
/****************************************************************************
|
||||
Lock a chain by string. Return -1 if lock failed.
|
||||
Lock a chain by string. Return non-zero if lock failed.
|
||||
****************************************************************************/
|
||||
int tdb_lock_bystring(struct tdb_context *tdb, const char *keyval);
|
||||
|
||||
@ -41,7 +41,7 @@ int tdb_lock_bystring(struct tdb_context *tdb, const char *keyval);
|
||||
void tdb_unlock_bystring(struct tdb_context *tdb, const char *keyval);
|
||||
|
||||
/****************************************************************************
|
||||
Read lock a chain by string. Return -1 if lock failed.
|
||||
Read lock a chain by string. Return non-zero if lock failed.
|
||||
****************************************************************************/
|
||||
int tdb_read_lock_bystring(struct tdb_context *tdb, const char *keyval);
|
||||
|
||||
|
@ -183,7 +183,7 @@ static int db_tdb_parse(struct db_context *db, TDB_DATA key,
|
||||
struct db_tdb_ctx *ctx = talloc_get_type_abort(
|
||||
db->private_data, struct db_tdb_ctx);
|
||||
|
||||
return tdb_parse_record(ctx->wtdb->tdb, key, parser, private_data) ? -1 : 0;
|
||||
return tdb_parse_record(ctx->wtdb->tdb, key, parser, private_data);
|
||||
}
|
||||
|
||||
static NTSTATUS db_tdb_store(struct db_record *rec, TDB_DATA data, int flag)
|
||||
@ -320,7 +320,7 @@ static int db_tdb_transaction_commit(struct db_context *db)
|
||||
{
|
||||
struct db_tdb_ctx *db_ctx =
|
||||
talloc_get_type_abort(db->private_data, struct db_tdb_ctx);
|
||||
return tdb_transaction_commit(db_ctx->wtdb->tdb) == 0 ? 0 : -1;
|
||||
return tdb_transaction_commit(db_ctx->wtdb->tdb);
|
||||
}
|
||||
|
||||
static int db_tdb_transaction_cancel(struct db_context *db)
|
||||
|
@ -492,7 +492,7 @@ TDB_DATA dbwrap_fetch(struct db_context *db, TALLOC_CTX *mem_ctx,
|
||||
{
|
||||
TDB_DATA result;
|
||||
|
||||
if (db->fetch(db, mem_ctx, key, &result) == -1) {
|
||||
if (db->fetch(db, mem_ctx, key, &result) != 0) {
|
||||
return make_tdb_data(NULL, 0);
|
||||
}
|
||||
|
||||
|
@ -781,7 +781,7 @@ NTSTATUS evlog_push_record_tdb(TALLOC_CTX *mem_ctx,
|
||||
|
||||
/* lock */
|
||||
ret = tdb_lock_bystring_with_timeout(tdb, EVT_NEXT_RECORD, 1);
|
||||
if (ret == -1) {
|
||||
if (ret != 0) {
|
||||
return NT_STATUS_LOCK_NOT_GRANTED;
|
||||
}
|
||||
|
||||
|
@ -70,7 +70,7 @@ struct named_mutex *grab_named_mutex(TALLOC_CTX *mem_ctx, const char *name,
|
||||
}
|
||||
|
||||
if (tdb_lock_bystring_with_timeout(result->tdb->tdb, name,
|
||||
timeout) == -1) {
|
||||
timeout) != 0) {
|
||||
DEBUG(1, ("Could not get the lock for %s\n", name));
|
||||
TALLOC_FREE(result);
|
||||
return NULL;
|
||||
|
@ -250,7 +250,7 @@ bool serverid_exists(const struct server_id *id)
|
||||
state.id = id;
|
||||
state.exists = false;
|
||||
|
||||
if (db->parse_record(db, tdbkey, server_exists_parse, &state) == -1) {
|
||||
if (db->parse_record(db, tdbkey, server_exists_parse, &state) != 0) {
|
||||
return false;
|
||||
}
|
||||
return state.exists;
|
||||
|
@ -51,7 +51,7 @@ static int tdb_validate_child(struct tdb_context *tdb,
|
||||
* but I don't want to change all the callers...
|
||||
*/
|
||||
ret = tdb_check(tdb, NULL, NULL);
|
||||
if (ret == -1) {
|
||||
if (ret != 0) {
|
||||
v_status.tdb_error = True;
|
||||
v_status.success = False;
|
||||
goto out;
|
||||
|
@ -406,7 +406,7 @@ NTSTATUS reinit_after_fork(struct messaging_context *msg_ctx,
|
||||
set_need_random_reseed();
|
||||
|
||||
/* tdb needs special fork handling */
|
||||
if (tdb_reopen_all(parent_longlived ? 1 : 0) == -1) {
|
||||
if (tdb_reopen_all(parent_longlived ? 1 : 0) != 0) {
|
||||
DEBUG(0,("tdb_reopen_all failed.\n"));
|
||||
status = NT_STATUS_OPEN_FAILED;
|
||||
goto done;
|
||||
|
@ -67,7 +67,7 @@ static int tdb_chainlock_with_timeout_internal( TDB_CONTEXT *tdb, TDB_DATA key,
|
||||
alarm(0);
|
||||
tdb_setalarm_sigptr(tdb, NULL);
|
||||
CatchSignal(SIGALRM, SIG_IGN);
|
||||
if (gotalarm && (ret == -1)) {
|
||||
if (gotalarm && (ret != 0)) {
|
||||
DEBUG(0,("tdb_chainlock_with_timeout_internal: alarm (%u) timed out for key %s in tdb %s\n",
|
||||
timeout, key.dptr, tdb_name(tdb)));
|
||||
/* TODO: If we time out waiting for a lock, it might
|
||||
@ -82,7 +82,7 @@ static int tdb_chainlock_with_timeout_internal( TDB_CONTEXT *tdb, TDB_DATA key,
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
Write lock a chain. Return -1 if timeout or lock failed.
|
||||
Write lock a chain. Return non-zero if timeout or lock failed.
|
||||
****************************************************************************/
|
||||
|
||||
int tdb_chainlock_with_timeout( TDB_CONTEXT *tdb, TDB_DATA key, unsigned int timeout)
|
||||
@ -99,7 +99,7 @@ int tdb_lock_bystring_with_timeout(TDB_CONTEXT *tdb, const char *keyval,
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
Read lock a chain by string. Return -1 if timeout or lock failed.
|
||||
Read lock a chain by string. Return non-zero if timeout or lock failed.
|
||||
****************************************************************************/
|
||||
|
||||
int tdb_read_lock_bystring_with_timeout(TDB_CONTEXT *tdb, const char *keyval, unsigned int timeout)
|
||||
|
@ -1845,7 +1845,7 @@ static struct byte_range_lock *brl_get_locks_internal(TALLOC_CTX *mem_ctx,
|
||||
}
|
||||
|
||||
if (do_read_only) {
|
||||
if (brlock_db->fetch(brlock_db, br_lck, key, &data) == -1) {
|
||||
if (brlock_db->fetch(brlock_db, br_lck, key, &data) != 0) {
|
||||
DEBUG(3, ("Could not fetch byte range lock record\n"));
|
||||
TALLOC_FREE(br_lck);
|
||||
return NULL;
|
||||
|
@ -1009,7 +1009,7 @@ struct share_mode_lock *fetch_share_mode_unlocked(TALLOC_CTX *mem_ctx,
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (lock_db->fetch(lock_db, lck, key, &data) == -1) {
|
||||
if (lock_db->fetch(lock_db, lck, key, &data) != 0) {
|
||||
DEBUG(3, ("Could not fetch share entry\n"));
|
||||
TALLOC_FREE(lck);
|
||||
return NULL;
|
||||
|
@ -574,7 +574,7 @@ static bool nfs4_map_sid(smbacl4_vfs_params *params, const struct dom_sid *src,
|
||||
|
||||
if (mapping_db->fetch(mapping_db, NULL,
|
||||
string_term_tdb_data(sid_string_tos(src)),
|
||||
&data) == -1) {
|
||||
&data) != 0) {
|
||||
DEBUG(10, ("could not find mapping for SID %s\n",
|
||||
sid_string_dbg(src)));
|
||||
return False;
|
||||
|
@ -177,7 +177,7 @@ static NTSTATUS get_acl_blob(TALLOC_CTX *ctx,
|
||||
if (db->fetch(db,
|
||||
ctx,
|
||||
make_tdb_data(id_buf, sizeof(id_buf)),
|
||||
&data) == -1) {
|
||||
&data) != 0) {
|
||||
return NT_STATUS_INTERNAL_DB_CORRUPTION;
|
||||
}
|
||||
|
||||
|
@ -108,7 +108,7 @@ static NTSTATUS xattr_tdb_load_attrs(TALLOC_CTX *mem_ctx,
|
||||
|
||||
if (db_ctx->fetch(db_ctx, mem_ctx,
|
||||
make_tdb_data(id_buf, sizeof(id_buf)),
|
||||
&data) == -1) {
|
||||
&data) != 0) {
|
||||
return NT_STATUS_INTERNAL_DB_CORRUPTION;
|
||||
}
|
||||
|
||||
|
@ -59,10 +59,10 @@ bool login_cache_init(void)
|
||||
|
||||
bool login_cache_shutdown(void)
|
||||
{
|
||||
/* tdb_close routine returns -1 on error */
|
||||
/* tdb_close routine returns non-zero on error */
|
||||
if (!cache) return False;
|
||||
DEBUG(5, ("Closing cache file\n"));
|
||||
return tdb_close(cache) != -1;
|
||||
return tdb_close(cache) == 0;
|
||||
}
|
||||
|
||||
/* if we can't read the cache, oh well, no need to return anything */
|
||||
|
@ -632,7 +632,7 @@ static bool print_notify_pid_list(const char *printername, TALLOC_CTX *mem_ctx,
|
||||
return False;
|
||||
tdb = pdb->tdb;
|
||||
|
||||
if (tdb_read_lock_bystring_with_timeout(tdb, NOTIFY_PID_LIST_KEY, 10) == -1) {
|
||||
if (tdb_read_lock_bystring_with_timeout(tdb, NOTIFY_PID_LIST_KEY, 10) != 0) {
|
||||
DEBUG(0,("print_notify_pid_list: Failed to lock printer %s database\n",
|
||||
printername));
|
||||
if (pdb)
|
||||
|
@ -208,7 +208,7 @@ bool print_backend_init(struct messaging_context *msg_ctx)
|
||||
pdb = get_print_db_byname(lp_const_servicename(snum));
|
||||
if (!pdb)
|
||||
continue;
|
||||
if (tdb_lock_bystring(pdb->tdb, sversion) == -1) {
|
||||
if (tdb_lock_bystring(pdb->tdb, sversion) != 0) {
|
||||
DEBUG(0,("print_backend_init: Failed to open printer %s database\n", lp_const_servicename(snum) ));
|
||||
release_print_db(pdb);
|
||||
return False;
|
||||
@ -1516,7 +1516,7 @@ static void print_queue_update_with_lock( struct tevent_context *ev,
|
||||
|
||||
slprintf(keystr, sizeof(keystr) - 1, "LOCK/%s", sharename);
|
||||
/* Only wait 10 seconds for this. */
|
||||
if (tdb_lock_bystring_with_timeout(pdb->tdb, keystr, 10) == -1) {
|
||||
if (tdb_lock_bystring_with_timeout(pdb->tdb, keystr, 10) != 0) {
|
||||
DEBUG(0,("print_queue_update_with_lock: Failed to lock printer %s database\n", sharename));
|
||||
release_print_db(pdb);
|
||||
return;
|
||||
@ -1885,7 +1885,7 @@ bool print_notify_register_pid(int snum)
|
||||
tdb = pdb->tdb;
|
||||
}
|
||||
|
||||
if (tdb_lock_bystring_with_timeout(tdb, NOTIFY_PID_LIST_KEY, 10) == -1) {
|
||||
if (tdb_lock_bystring_with_timeout(tdb, NOTIFY_PID_LIST_KEY, 10) != 0) {
|
||||
DEBUG(0,("print_notify_register_pid: Failed to lock printer %s\n",
|
||||
printername));
|
||||
if (pdb)
|
||||
@ -1975,7 +1975,7 @@ bool print_notify_deregister_pid(int snum)
|
||||
tdb = pdb->tdb;
|
||||
}
|
||||
|
||||
if (tdb_lock_bystring_with_timeout(tdb, NOTIFY_PID_LIST_KEY, 10) == -1) {
|
||||
if (tdb_lock_bystring_with_timeout(tdb, NOTIFY_PID_LIST_KEY, 10) != 0) {
|
||||
DEBUG(0,("print_notify_register_pid: Failed to lock \
|
||||
printer %s database\n", printername));
|
||||
if (pdb)
|
||||
@ -2134,7 +2134,7 @@ static bool remove_from_jobs_added(const char* sharename, uint32 jobid)
|
||||
|
||||
key = string_tdb_data("INFO/jobs_added");
|
||||
|
||||
if (tdb_chainlock_with_timeout(pdb->tdb, key, 5) == -1)
|
||||
if (tdb_chainlock_with_timeout(pdb->tdb, key, 5) != 0)
|
||||
goto out;
|
||||
|
||||
gotlock = True;
|
||||
@ -2561,7 +2561,7 @@ static WERROR allocate_print_jobid(struct tdb_print_db *pdb, int snum,
|
||||
/* Lock the database - only wait 20 seconds. */
|
||||
ret = tdb_lock_bystring_with_timeout(pdb->tdb,
|
||||
"INFO/nextjob", 20);
|
||||
if (ret == -1) {
|
||||
if (ret != 0) {
|
||||
DEBUG(0, ("allocate_print_jobid: "
|
||||
"Failed to lock printing database %s\n",
|
||||
sharename));
|
||||
@ -2589,7 +2589,7 @@ static WERROR allocate_print_jobid(struct tdb_print_db *pdb, int snum,
|
||||
jobid = NEXT_JOBID(jobid);
|
||||
|
||||
ret = tdb_store_int32(pdb->tdb, "INFO/nextjob", jobid);
|
||||
if (ret == -1) {
|
||||
if (ret != 0) {
|
||||
terr = tdb_error(pdb->tdb);
|
||||
DEBUG(3, ("allocate_print_jobid: "
|
||||
"Failed to store INFO/nextjob.\n"));
|
||||
|
@ -843,7 +843,7 @@ void notify_onelevel(struct notify_context *notify, uint32_t action,
|
||||
if (notify->db_onelevel->fetch(
|
||||
notify->db_onelevel, array,
|
||||
make_tdb_data((uint8_t *)&fid, sizeof(fid)),
|
||||
&dbuf) == -1) {
|
||||
&dbuf) != 0) {
|
||||
TALLOC_FREE(array);
|
||||
return;
|
||||
}
|
||||
|
@ -8348,7 +8348,7 @@ static bool run_local_dbtrans(int dummy)
|
||||
}
|
||||
|
||||
res = db->transaction_start(db);
|
||||
if (res == -1) {
|
||||
if (res != 0) {
|
||||
printf(__location__ "transaction_start failed\n");
|
||||
return false;
|
||||
}
|
||||
@ -8375,7 +8375,7 @@ static bool run_local_dbtrans(int dummy)
|
||||
TALLOC_FREE(rec);
|
||||
|
||||
res = db->transaction_commit(db);
|
||||
if (res == -1) {
|
||||
if (res != 0) {
|
||||
printf(__location__ "transaction_commit failed\n");
|
||||
return false;
|
||||
}
|
||||
@ -8385,7 +8385,7 @@ static bool run_local_dbtrans(int dummy)
|
||||
int i;
|
||||
|
||||
res = db->transaction_start(db);
|
||||
if (res == -1) {
|
||||
if (res != 0) {
|
||||
printf(__location__ "transaction_start failed\n");
|
||||
break;
|
||||
}
|
||||
@ -8415,7 +8415,7 @@ static bool run_local_dbtrans(int dummy)
|
||||
printf("val2=%d\r", val2);
|
||||
|
||||
res = db->transaction_commit(db);
|
||||
if (res == -1) {
|
||||
if (res != 0) {
|
||||
printf(__location__ "transaction_commit failed\n");
|
||||
break;
|
||||
}
|
||||
|
@ -346,7 +346,7 @@ fetch_record(struct check_ctx* ctx, TALLOC_CTX* mem_ctx, TDB_DATA key)
|
||||
{
|
||||
TDB_DATA tmp;
|
||||
|
||||
if (ctx->diff->fetch(ctx->diff, mem_ctx, key, &tmp) == -1) {
|
||||
if (ctx->diff->fetch(ctx->diff, mem_ctx, key, &tmp) != 0) {
|
||||
DEBUG(0, ("Out of memory!\n"));
|
||||
return tdb_null;
|
||||
}
|
||||
@ -357,7 +357,7 @@ fetch_record(struct check_ctx* ctx, TALLOC_CTX* mem_ctx, TDB_DATA key)
|
||||
return ret;
|
||||
}
|
||||
|
||||
if (ctx->db->fetch(ctx->db, mem_ctx, key, &tmp) == -1) {
|
||||
if (ctx->db->fetch(ctx->db, mem_ctx, key, &tmp) != 0) {
|
||||
DEBUG(0, ("Out of memory!\n"));
|
||||
return tdb_null;
|
||||
}
|
||||
|
@ -484,7 +484,7 @@ bool wcache_store_seqnum(const char *domain_name, uint32_t seqnum,
|
||||
ret = tdb_store_bystring(wcache->tdb, key_str,
|
||||
make_tdb_data(buf, sizeof(buf)), TDB_REPLACE);
|
||||
TALLOC_FREE(key_str);
|
||||
if (ret == -1) {
|
||||
if (ret != 0) {
|
||||
DEBUG(10, ("tdb_store_bystring failed: %s\n",
|
||||
tdb_errorstr_compat(wcache->tdb)));
|
||||
TALLOC_FREE(key_str);
|
||||
|
Reference in New Issue
Block a user