s3:dbwrap: change dbwrap_fetch_uint32() to NTSTATUS return type (instead of bool)
authorMichael Adam <obnox@samba.org>
Thu, 6 Oct 2011 19:07:27 +0000 (21:07 +0200)
committerMichael Adam <obnox@samba.org>
Tue, 11 Oct 2011 12:17:58 +0000 (14:17 +0200)
for consistency and better error propagation

source3/lib/dbwrap/dbwrap.h
source3/lib/dbwrap/dbwrap_util.c
source3/passdb/account_pol.c
source3/passdb/pdb_tdb.c
source3/torture/torture.c
source3/utils/dbwrap_tool.c
source3/utils/net_idmap_check.c
source3/winbindd/idmap_autorid.c
source3/winbindd/idmap_tdb.c
source3/winbindd/idmap_tdb2.c

index a549c84d8e1f8e93e0b67f36d84c4d7d0f5f432f..423791660c1a6e56b66151fff651bc1d0014141c 100644 (file)
@@ -73,8 +73,8 @@ NTSTATUS dbwrap_fetch_bystring(struct db_context *db, TALLOC_CTX *mem_ctx,
 NTSTATUS dbwrap_fetch_int32(struct db_context *db, const char *keystr,
                            int32_t *result);
 int dbwrap_store_int32(struct db_context *db, const char *keystr, int32_t v);
-bool dbwrap_fetch_uint32(struct db_context *db, const char *keystr,
-                        uint32_t *val);
+NTSTATUS dbwrap_fetch_uint32(struct db_context *db, const char *keystr,
+                            uint32_t *val);
 int dbwrap_store_uint32(struct db_context *db, const char *keystr, uint32_t v);
 NTSTATUS dbwrap_change_uint32_atomic(struct db_context *db, const char *keystr,
                                     uint32_t *oldval, uint32_t change_val);
index 5c3940e97b8142008ce7a5c9e9319ef97872f265..bd29460f492f818c68c13d38c5f211f887049ab2 100644 (file)
@@ -72,25 +72,29 @@ int dbwrap_store_int32(struct db_context *db, const char *keystr, int32_t v)
        return NT_STATUS_IS_OK(status) ? 0 : -1;
 }
 
-bool dbwrap_fetch_uint32(struct db_context *db, const char *keystr,
-                        uint32_t *val)
+NTSTATUS dbwrap_fetch_uint32(struct db_context *db, const char *keystr,
+                            uint32_t *val)
 {
        TDB_DATA dbuf;
        NTSTATUS status;
 
+       if (val == NULL) {
+               return NT_STATUS_INVALID_PARAMETER;
+       }
+
        status = dbwrap_fetch_bystring(db, NULL, keystr, &dbuf);
        if (!NT_STATUS_IS_OK(status)) {
-               return false;
+               return status;
        }
 
        if ((dbuf.dptr == NULL) || (dbuf.dsize != sizeof(uint32_t))) {
                TALLOC_FREE(dbuf.dptr);
-               return false;
+               return NT_STATUS_NOT_FOUND;
        }
 
        *val = IVAL(dbuf.dptr, 0);
        TALLOC_FREE(dbuf.dptr);
-       return true;
+       return NT_STATUS_OK;
 }
 
 int dbwrap_store_uint32(struct db_context *db, const char *keystr, uint32_t v)
index dd495082a282ff932c75d4b633a991c8c992510e..bd8cdf725f3a55bdeca39f2bc5bef65187009649 100644 (file)
@@ -213,7 +213,7 @@ bool init_account_policy(void)
        const char *vstring = "INFO/version";
        uint32_t version = 0;
        int i;
-       bool ret;
+       NTSTATUS status;
 
        if (db != NULL) {
                return True;
@@ -232,8 +232,8 @@ bool init_account_policy(void)
                }
        }
 
-       ret = dbwrap_fetch_uint32(db, vstring, &version);
-       if (!ret) {
+       status = dbwrap_fetch_uint32(db, vstring, &version);
+       if (!NT_STATUS_IS_OK(status)) {
                version = 0;
        }
 
@@ -249,8 +249,8 @@ bool init_account_policy(void)
                return false;
        }
 
-       ret = dbwrap_fetch_uint32(db, vstring, &version);
-       if (!ret) {
+       status = dbwrap_fetch_uint32(db, vstring, &version);
+       if (!NT_STATUS_IS_OK(status)) {
                version = 0;
        }
 
@@ -321,6 +321,7 @@ bool account_policy_get(enum pdb_policy_type type, uint32_t *value)
 {
        const char *name;
        uint32 regval;
+       NTSTATUS status;
 
        if (!init_account_policy()) {
                return False;
@@ -336,7 +337,8 @@ bool account_policy_get(enum pdb_policy_type type, uint32_t *value)
                return False;
        }
 
-       if (!dbwrap_fetch_uint32(db, name, &regval)) {
+       status = dbwrap_fetch_uint32(db, name, &regval);
+       if (!NT_STATUS_IS_OK(status)) {
                DEBUG(1, ("account_policy_get: tdb_fetch_uint32 failed for type %d (%s), returning 0\n", type, name));
                return False;
        }
index 565dd5d309826cdafa121a4ffac62ed7036a63a4..80a4b49f9dd9e351d20e2fe4e0d54117d1bb0c1c 100644 (file)
@@ -325,9 +325,10 @@ static bool tdbsam_upgrade_next_rid(struct db_context *db)
        TDB_CONTEXT *tdb;
        uint32 rid;
        bool ok = false;
+       NTSTATUS status;
 
-       ok = dbwrap_fetch_uint32(db, NEXT_RID_STRING, &rid);
-       if (ok) {
+       status = dbwrap_fetch_uint32(db, NEXT_RID_STRING, &rid);
+       if (NT_STATUS_IS_OK(status)) {
                return true;
        }
 
index 0d81602a0475665c7b26012b729e8dea6c238b0a..1e0983a5e10d143ed38ca777280dbd98e03ee617 100644 (file)
@@ -8595,8 +8595,10 @@ static bool run_local_dbtrans(int dummy)
                        break;
                }
 
-               if (!dbwrap_fetch_uint32(db, "transtest", &val)) {
-                       printf(__location__ "dbwrap_fetch_uint32 failed\n");
+               status = dbwrap_fetch_uint32(db, "transtest", &val);
+               if (!NT_STATUS_IS_OK(status)) {
+                       printf(__location__ "dbwrap_fetch_uint32 failed: %s\n",
+                              nt_errstr(status));
                        break;
                }
 
@@ -8606,8 +8608,10 @@ static bool run_local_dbtrans(int dummy)
                        }
                }
 
-               if (!dbwrap_fetch_uint32(db, "transtest", &val2)) {
-                       printf(__location__ "dbwrap_fetch_uint32 failed\n");
+               status = dbwrap_fetch_uint32(db, "transtest", &val2);
+               if (!NT_STATUS_IS_OK(status)) {
+                       printf(__location__ "dbwrap_fetch_uint32 failed: %s\n",
+                              nt_errstr(status));
                        break;
                }
 
index 33ef94f6b95e7edefc3b208304645060dbdfa6dd..fd599dd504240ea7d8679de63db3b63dd5c0a857 100644 (file)
@@ -53,15 +53,15 @@ static int dbwrap_tool_fetch_uint32(struct db_context *db,
                                    void *data)
 {
        uint32_t value;
-       bool ret;
+       NTSTATUS ret;
 
        ret = dbwrap_fetch_uint32(db, keyname, &value);
-       if (ret) {
+       if (NT_STATUS_IS_OK(ret)) {
                d_printf("%u\n", value);
                return 0;
        } else {
-               d_fprintf(stderr, "ERROR: could not fetch uint32 key '%s'\n",
-                         keyname);
+               d_fprintf(stderr, "ERROR: could not fetch uint32 key '%s': "
+                         "%s\n", nt_errstr(ret), keyname);
                return -1;
        }
 }
index eefb7008169c9269fb4561b4ebea1e79ff49b304..960a59707387607a7c533e68b3ee31d03ee5f1ac 100644 (file)
@@ -400,10 +400,12 @@ static void edit_record(struct record* r) {
 static bool check_version(struct check_ctx* ctx) {
        static const char* key = "IDMAP_VERSION";
        uint32_t version;
-       bool no_version = !dbwrap_fetch_uint32(ctx->db, key, &version);
+       NTSTATUS status;
        char action = 's';
        struct check_actions* act = &ctx->action;
-       if (no_version) {
+
+       status = dbwrap_fetch_uint32(ctx->db, key, &version);
+       if (!NT_STATUS_IS_OK(status)) {
                d_printf("No version number, assume 2\n");
                action = get_action(&act->no_version, NULL, NULL);
        } else if (version != 2) {
@@ -429,9 +431,11 @@ static bool check_version(struct check_ctx* ctx) {
 static void check_hwm(struct check_ctx* ctx, const char* key, uint32_t target) {
        uint32_t hwm;
        char action = 's';
-       bool found = dbwrap_fetch_uint32(ctx->db, key, &hwm);
+       NTSTATUS status;
        struct check_actions* act = &ctx->action;
-       if (!found) {
+
+       status = dbwrap_fetch_uint32(ctx->db, key, &hwm);
+       if (!NT_STATUS_IS_OK(status)) {
                d_printf("No %s should be %d\n", key, target);
                action = get_action(&act->invalid_hwm, NULL, NULL);
        } else if (target < hwm) {
index ed00d3728d943b0b4c5692718a0d47a643150822..62339f132853c4ed8576ddcf95a70a69f9a540eb 100644 (file)
@@ -66,13 +66,15 @@ static NTSTATUS idmap_autorid_get_domainrange(struct db_context *db,
        cfg = (struct autorid_domain_config *)private_data;
        dom_sid_string_buf(&(cfg->sid), sidstr, sizeof(sidstr));
 
-       if (!dbwrap_fetch_uint32(db, sidstr, &domainnum)) {
+       ret = dbwrap_fetch_uint32(db, sidstr, &domainnum);
+       if (!NT_STATUS_IS_OK(ret)) {
                DEBUG(10, ("Acquiring new range for domain %s\n", sidstr));
 
                /* fetch the current HWM */
-               if (!dbwrap_fetch_uint32(db, HWM, &hwm)) {
+               ret = dbwrap_fetch_uint32(db, HWM, &hwm);
+               if (!NT_STATUS_IS_OK(ret)) {
                        DEBUG(1, ("Fatal error while fetching current "
-                                 "HWM value!\n"));
+                                 "HWM value: %s\n", nt_errstr(ret)));
                        ret = NT_STATUS_INTERNAL_ERROR;
                        goto error;
                }
@@ -519,9 +521,10 @@ static NTSTATUS idmap_autorid_initialize(struct idmap_domain *dom)
        /* read previously stored config and current HWM */
        storedconfig = idmap_autorid_loadconfig(talloc_tos());
 
-       if (!dbwrap_fetch_uint32(autorid_db, HWM, &hwm)) {
+       status = dbwrap_fetch_uint32(autorid_db, HWM, &hwm);
+       if (!NT_STATUS_IS_OK(status)) {
                DEBUG(1, ("Fatal error while fetching current "
-                         "HWM value!\n"));
+                         "HWM value: %s\n", nt_errstr(status)));
                status = NT_STATUS_INTERNAL_ERROR;
                goto error;
        }
@@ -590,8 +593,10 @@ static NTSTATUS idmap_autorid_allocate_id(struct idmap_domain *dom,
        globalcfg = talloc_get_type(dom->private_data,
                                    struct autorid_global_config);
 
-       if (!dbwrap_fetch_uint32(autorid_db, ALLOC_HWM, &hwm)) {
-               DEBUG(1, ("Failed to fetch current allocation HWM value!\n"));
+       ret = dbwrap_fetch_uint32(autorid_db, ALLOC_HWM, &hwm);
+       if (!NT_STATUS_IS_OK(ret)) {
+               DEBUG(1, ("Failed to fetch current allocation HWM value: %s\n",
+                         nt_errstr(ret)));
                return NT_STATUS_INTERNAL_ERROR;
        }
 
index b520e091031b73841918a741839544d1463343e9..c19c9c81632c25cfb57a2f63cf34194018c1f5ad 100644 (file)
@@ -251,17 +251,17 @@ static NTSTATUS idmap_tdb_init_hwm(struct idmap_domain *dom)
        bool update_uid = false;
        bool update_gid = false;
        struct idmap_tdb_context *ctx;
-       bool status;
+       NTSTATUS status;
 
        ctx = talloc_get_type(dom->private_data, struct idmap_tdb_context);
 
        status = dbwrap_fetch_uint32(ctx->db, HWM_USER, &low_uid);
-       if (!status || low_uid < dom->low_id) {
+       if (!NT_STATUS_IS_OK(status) || low_uid < dom->low_id) {
                update_uid = true;
        }
 
        status = dbwrap_fetch_uint32(ctx->db, HWM_GROUP, &low_gid);
-       if (!status || low_gid < dom->low_id) {
+       if (!NT_STATUS_IS_OK(status) || low_gid < dom->low_id) {
                update_gid = true;
        }
 
@@ -404,12 +404,11 @@ static NTSTATUS idmap_tdb_allocate_id_action(struct db_context *db,
        NTSTATUS ret;
        struct idmap_tdb_allocate_id_context *state;
        uint32_t hwm;
-       bool ret2;
 
        state = (struct idmap_tdb_allocate_id_context *)private_data;
 
-       ret2 = dbwrap_fetch_uint32(db, state->hwmkey, &hwm);
-       if (!ret2) {
+       ret = dbwrap_fetch_uint32(db, state->hwmkey, &hwm);
+       if (!NT_STATUS_IS_OK(ret)) {
                ret = NT_STATUS_INTERNAL_DB_ERROR;
                goto done;
        }
index 0f50f615a13b31df676df1b9d5810cd09fa64075..ab47fe5389d2b2f8ab32a0d5854c7f131412f2b9 100644 (file)
@@ -63,14 +63,13 @@ static NTSTATUS idmap_tdb2_init_hwm(struct idmap_domain *dom)
        NTSTATUS status;
        uint32 low_id;
        struct idmap_tdb2_context *ctx;
-       bool ret;
 
        ctx = talloc_get_type(dom->private_data, struct idmap_tdb2_context);
 
        /* Create high water marks for group and user id */
 
-       ret = dbwrap_fetch_uint32(ctx->db, HWM_USER, &low_id);
-       if (!ret || (low_id < dom->low_id)) {
+       status = dbwrap_fetch_uint32(ctx->db, HWM_USER, &low_id);
+       if (!NT_STATUS_IS_OK(status) || (low_id < dom->low_id)) {
                status = dbwrap_trans_store_uint32(ctx->db, HWM_USER,
                                                   dom->low_id);
                if (!NT_STATUS_IS_OK(status)) {
@@ -80,8 +79,8 @@ static NTSTATUS idmap_tdb2_init_hwm(struct idmap_domain *dom)
                }
        }
 
-       ret = dbwrap_fetch_uint32(ctx->db, HWM_GROUP, &low_id);
-       if (!ret || (low_id < dom->low_id)) {
+       status = dbwrap_fetch_uint32(ctx->db, HWM_GROUP, &low_id);
+       if (!NT_STATUS_IS_OK(status) || (low_id < dom->low_id)) {
                status = dbwrap_trans_store_uint32(ctx->db, HWM_GROUP,
                                                   dom->low_id);
                if (!NT_STATUS_IS_OK(status)) {
@@ -144,12 +143,11 @@ static NTSTATUS idmap_tdb2_allocate_id_action(struct db_context *db,
        NTSTATUS ret;
        struct idmap_tdb2_allocate_id_context *state;
        uint32_t hwm;
-       bool ret2;
 
        state = (struct idmap_tdb2_allocate_id_context *)private_data;
 
-       ret2 = dbwrap_fetch_uint32(db, state->hwmkey, &hwm);
-       if (!ret2) {
+       ret = dbwrap_fetch_uint32(db, state->hwmkey, &hwm);
+       if (!NT_STATUS_IS_OK(ret)) {
                ret = NT_STATUS_INTERNAL_DB_ERROR;
                goto done;
        }