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);
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)
const char *vstring = "INFO/version";
uint32_t version = 0;
int i;
- bool ret;
+ NTSTATUS status;
if (db != NULL) {
return True;
}
}
- ret = dbwrap_fetch_uint32(db, vstring, &version);
- if (!ret) {
+ status = dbwrap_fetch_uint32(db, vstring, &version);
+ if (!NT_STATUS_IS_OK(status)) {
version = 0;
}
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;
}
{
const char *name;
uint32 regval;
+ NTSTATUS status;
if (!init_account_policy()) {
return False;
return False;
}
- if (!dbwrap_fetch_uint32(db, name, ®val)) {
+ status = dbwrap_fetch_uint32(db, name, ®val);
+ 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;
}
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;
}
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;
}
}
}
- 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;
}
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;
}
}
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) {
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) {
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;
}
/* 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;
}
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;
}
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;
}
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;
}
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)) {
}
}
- 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)) {
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;
}