summaryrefslogtreecommitdiff
path: root/source3
diff options
context:
space:
mode:
authorMichael Adam <obnox@samba.org>2011-10-06 21:07:27 +0200
committerMichael Adam <obnox@samba.org>2011-10-11 14:17:58 +0200
commit658f72128ff6950c6a03994198b4464a273fb300 (patch)
tree121d3cdd05b0cf84ef0eb2361c4aff21d24f5b46 /source3
parent603c3e1bcb7b4106afe4aefdfed43e7832ede956 (diff)
downloadsamba-658f72128ff6950c6a03994198b4464a273fb300.tar.gz
samba-658f72128ff6950c6a03994198b4464a273fb300.tar.bz2
samba-658f72128ff6950c6a03994198b4464a273fb300.zip
s3:dbwrap: change dbwrap_fetch_uint32() to NTSTATUS return type (instead of bool)
for consistency and better error propagation
Diffstat (limited to 'source3')
-rw-r--r--source3/lib/dbwrap/dbwrap.h4
-rw-r--r--source3/lib/dbwrap/dbwrap_util.c14
-rw-r--r--source3/passdb/account_pol.c14
-rw-r--r--source3/passdb/pdb_tdb.c5
-rw-r--r--source3/torture/torture.c12
-rw-r--r--source3/utils/dbwrap_tool.c8
-rw-r--r--source3/utils/net_idmap_check.c12
-rw-r--r--source3/winbindd/idmap_autorid.c19
-rw-r--r--source3/winbindd/idmap_tdb.c11
-rw-r--r--source3/winbindd/idmap_tdb2.c14
10 files changed, 65 insertions, 48 deletions
diff --git a/source3/lib/dbwrap/dbwrap.h b/source3/lib/dbwrap/dbwrap.h
index a549c84d8e..423791660c 100644
--- a/source3/lib/dbwrap/dbwrap.h
+++ b/source3/lib/dbwrap/dbwrap.h
@@ -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);
diff --git a/source3/lib/dbwrap/dbwrap_util.c b/source3/lib/dbwrap/dbwrap_util.c
index 5c3940e97b..bd29460f49 100644
--- a/source3/lib/dbwrap/dbwrap_util.c
+++ b/source3/lib/dbwrap/dbwrap_util.c
@@ -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)
diff --git a/source3/passdb/account_pol.c b/source3/passdb/account_pol.c
index dd495082a2..bd8cdf725f 100644
--- a/source3/passdb/account_pol.c
+++ b/source3/passdb/account_pol.c
@@ -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;
}
diff --git a/source3/passdb/pdb_tdb.c b/source3/passdb/pdb_tdb.c
index 565dd5d309..80a4b49f9d 100644
--- a/source3/passdb/pdb_tdb.c
+++ b/source3/passdb/pdb_tdb.c
@@ -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;
}
diff --git a/source3/torture/torture.c b/source3/torture/torture.c
index 0d81602a04..1e0983a5e1 100644
--- a/source3/torture/torture.c
+++ b/source3/torture/torture.c
@@ -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;
}
diff --git a/source3/utils/dbwrap_tool.c b/source3/utils/dbwrap_tool.c
index 33ef94f6b9..fd599dd504 100644
--- a/source3/utils/dbwrap_tool.c
+++ b/source3/utils/dbwrap_tool.c
@@ -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;
}
}
diff --git a/source3/utils/net_idmap_check.c b/source3/utils/net_idmap_check.c
index eefb700816..960a597073 100644
--- a/source3/utils/net_idmap_check.c
+++ b/source3/utils/net_idmap_check.c
@@ -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) {
diff --git a/source3/winbindd/idmap_autorid.c b/source3/winbindd/idmap_autorid.c
index ed00d3728d..62339f1328 100644
--- a/source3/winbindd/idmap_autorid.c
+++ b/source3/winbindd/idmap_autorid.c
@@ -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;
}
diff --git a/source3/winbindd/idmap_tdb.c b/source3/winbindd/idmap_tdb.c
index b520e09103..c19c9c8163 100644
--- a/source3/winbindd/idmap_tdb.c
+++ b/source3/winbindd/idmap_tdb.c
@@ -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;
}
diff --git a/source3/winbindd/idmap_tdb2.c b/source3/winbindd/idmap_tdb2.c
index 0f50f615a1..ab47fe5389 100644
--- a/source3/winbindd/idmap_tdb2.c
+++ b/source3/winbindd/idmap_tdb2.c
@@ -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;
}