tdb_compat: Higher level API fixes.
authorRusty Russell <rusty@rustcorp.com.au>
Mon, 20 Jun 2011 09:10:33 +0000 (18:40 +0930)
committerRusty Russell <rusty@rustcorp.com.au>
Mon, 20 Jun 2011 09:18:35 +0000 (11:18 +0200)
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>
22 files changed:
lib/util/util_tdb.c
lib/util/util_tdb.h
source3/lib/dbwrap_tdb.c
source3/lib/dbwrap_util.c
source3/lib/eventlog/eventlog.c
source3/lib/server_mutex.c
source3/lib/serverid.c
source3/lib/tdb_validate.c
source3/lib/util.c
source3/lib/util_tdb.c
source3/locking/brlock.c
source3/locking/locking.c
source3/modules/nfs4_acls.c
source3/modules/vfs_acl_tdb.c
source3/modules/vfs_xattr_tdb.c
source3/passdb/login_cache.c
source3/printing/notify.c
source3/printing/printing.c
source3/smbd/notify_internal.c
source3/torture/torture.c
source3/utils/net_idmap_check.c
source3/winbindd/winbindd_cache.c

index 304239f951929077b3ceeaf6d44e5d4efa32e82f..02c7095f66b9fcd8e5c02435e9e97d79c112ef1d 100644 (file)
@@ -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)) {
index edffa058d777bd262f9ef8dd4afbb252718e54b4..2d805d7d20c45961b9577d370ff2e20174dce52c 100644 (file)
@@ -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);
 
index 2b5f58a56d76852689d2f487507703d401ece34e..2efb3dfe39db2e102ccf60d85b4a014b18ae41c0 100644 (file)
@@ -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)
index 44a1b8827b6971ec1e8c3ba23e422ef2f35bc23d..effcf40c6b3737da5e8135f92837dca528fcbd0c 100644 (file)
@@ -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);
        }
 
index c29c6f0ed4ef9ea4cea57dc3370ee3e1714a6eb7..67583b8666c03eae15add015d5b6f29b01836866 100644 (file)
@@ -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;
        }
 
index 6eac3182bee8f5836b80215b13eefbc5cf3006e8..dc658191970f346d21666b9f19ecaf246bf6c9f6 100644 (file)
@@ -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;
index e63818e1b87a7bf584b789daf23c863b526fd0a1..1a1141265a159d19e781252f2c635ed288a7e8f3 100644 (file)
@@ -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;
index 617160ee86b01f95e722fb147cea59a30ba83db1..385f4d0ef810c9113b2827e274dfab639ba0abdf 100644 (file)
@@ -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;
index b25c15c7a3e894f1796d24c8f46927b35cdcfe49..b8fc319a6ff4dacd853b16bc3b5a319205b7e3b5 100644 (file)
@@ -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;
index 2d49b9e2ec3858533693eaf55eaa5f832df7f3af..4756fd84ef7809fdaea69c102383cb4824134d95 100644 (file)
@@ -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)
index ad0f9d5e526e34cf8dc96d38ed6ca316f45b22a1..6eef695f69102c0086deeefc029cb55e00f3dac9 100644 (file)
@@ -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;
index e0a3b93ce785132c46461c9857a4f9f878deba29..81e93a555a129d2d4f44fdb63c4f76e6a2493f44 100644 (file)
@@ -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;
index bbde53236bb7c25aa6de951ad4d40f66d8dbd5be..dbfa36e6c2a869310c286b316a0a0be7b3b795ef 100644 (file)
@@ -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;
index 1e3313120cafdae8082f3e2ef40395a1fe6a90e6..0b03896dd90ae4ec307e04b6af3f589d5e44c950 100644 (file)
@@ -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;
        }
 
index 200450b1310597f8ccfa44997359da497aef78e7..40ccf06dd951e39943872e8a775b8579017b5baa 100644 (file)
@@ -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;
        }
 
index 629f8a7d5e8627b7b654485298b5d221e40b2895..a53fe5b24f7f33dd7f6f0d6dea449fbf8db12322 100644 (file)
@@ -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 */
index 0295ad2f1f12bc5ab38099aba0eeeb5b2698f4fd..b6b7ea045e9ba70f957cec6ec97b3724cf068576 100644 (file)
@@ -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)
index 6503407f82c71ae7e43e5138b3bbf6399f41d288..0c070c766823030c153e67f613560263290224a3 100644 (file)
@@ -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"));
index 3aea1625eb6923f2303b45b03e0f749ada1be572..a0193a446790fd6efac1aa3bedd2887ade597a7b 100644 (file)
@@ -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;
        }
index 0731326cf949f9978e86cadfc02d9fc268ee48f7..faa4326489af6f8f83683eefeac35b648a51ff78 100644 (file)
@@ -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;
                }
index e406a65679eb1cd3352f51d03c66ce62e8f3f6ef..3adc060a7c6620a66d5eacb4d83634171a6be9b8 100644 (file)
@@ -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;
        }
index 50218d0132d5c4c034c72a395e0afec91a995570..58a8e710f6f6b336212bb199109147bf7509f15b 100644 (file)
@@ -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);