mirror of
https://github.com/samba-team/samba.git
synced 2025-02-02 09:47:23 +03:00
s3:dbwrap: change dbwrap_store_int32() to NTSTATUS return type
for consistency and better error propagation
This commit is contained in:
parent
658f72128f
commit
c9bc1e4924
@ -72,7 +72,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);
|
||||
NTSTATUS dbwrap_store_int32(struct db_context *db, const char *keystr,
|
||||
int32_t v);
|
||||
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);
|
||||
|
@ -51,7 +51,8 @@ NTSTATUS dbwrap_fetch_int32(struct db_context *db, const char *keystr,
|
||||
return NT_STATUS_OK;
|
||||
}
|
||||
|
||||
int dbwrap_store_int32(struct db_context *db, const char *keystr, int32_t v)
|
||||
NTSTATUS dbwrap_store_int32(struct db_context *db, const char *keystr,
|
||||
int32_t v)
|
||||
{
|
||||
struct db_record *rec;
|
||||
int32 v_store;
|
||||
@ -59,7 +60,7 @@ int dbwrap_store_int32(struct db_context *db, const char *keystr, int32_t v)
|
||||
|
||||
rec = dbwrap_fetch_locked(db, NULL, string_term_tdb_data(keystr));
|
||||
if (rec == NULL) {
|
||||
return -1;
|
||||
return NT_STATUS_UNSUCCESSFUL;
|
||||
}
|
||||
|
||||
SIVAL(&v_store, 0, v);
|
||||
@ -69,7 +70,7 @@ int dbwrap_store_int32(struct db_context *db, const char *keystr, int32_t v)
|
||||
sizeof(v_store)),
|
||||
TDB_REPLACE);
|
||||
TALLOC_FREE(rec);
|
||||
return NT_STATUS_IS_OK(status) ? 0 : -1;
|
||||
return status;
|
||||
}
|
||||
|
||||
NTSTATUS dbwrap_fetch_uint32(struct db_context *db, const char *keystr,
|
||||
|
@ -191,9 +191,11 @@ bool share_info_db_init(void)
|
||||
if ((vers_id == SHARE_DATABASE_VERSION_V1) || (IREV(vers_id) == SHARE_DATABASE_VERSION_V1)) {
|
||||
/* Written on a bigendian machine with old fetch_int code. Save as le. */
|
||||
|
||||
if (dbwrap_store_int32(share_db, vstring,
|
||||
SHARE_DATABASE_VERSION_V2) != 0) {
|
||||
DEBUG(0, ("dbwrap_store_int32 failed\n"));
|
||||
status = dbwrap_store_int32(share_db, vstring,
|
||||
SHARE_DATABASE_VERSION_V2);
|
||||
if (!NT_STATUS_IS_OK(status)) {
|
||||
DEBUG(0, ("dbwrap_store_int32 failed: %s\n",
|
||||
nt_errstr(status)));
|
||||
goto cancel;
|
||||
}
|
||||
vers_id = SHARE_DATABASE_VERSION_V2;
|
||||
@ -205,9 +207,11 @@ bool share_info_db_init(void)
|
||||
DEBUG(0, ("traverse failed\n"));
|
||||
goto cancel;
|
||||
}
|
||||
if (dbwrap_store_int32(share_db, vstring,
|
||||
SHARE_DATABASE_VERSION_V2) != 0) {
|
||||
DEBUG(0, ("dbwrap_store_int32 failed\n"));
|
||||
status = dbwrap_store_int32(share_db, vstring,
|
||||
SHARE_DATABASE_VERSION_V2);
|
||||
if (!NT_STATUS_IS_OK(status)) {
|
||||
DEBUG(0, ("dbwrap_store_int32 failed: %s\n",
|
||||
nt_errstr(status)));
|
||||
goto cancel;
|
||||
}
|
||||
}
|
||||
@ -219,9 +223,11 @@ bool share_info_db_init(void)
|
||||
DEBUG(0, ("traverse failed\n"));
|
||||
goto cancel;
|
||||
}
|
||||
if (dbwrap_store_int32(share_db, vstring,
|
||||
SHARE_DATABASE_VERSION_V3) != 0) {
|
||||
DEBUG(0, ("dbwrap_store_int32 failed\n"));
|
||||
status = dbwrap_store_int32(share_db, vstring,
|
||||
SHARE_DATABASE_VERSION_V3);
|
||||
if (!NT_STATUS_IS_OK(status)) {
|
||||
DEBUG(0, ("dbwrap_store_int32 failed: %s\n",
|
||||
nt_errstr(status)));
|
||||
goto cancel;
|
||||
}
|
||||
|
||||
|
@ -389,15 +389,19 @@ static bool tdbsam_convert(struct db_context **pp_db, const char *name, int32 fr
|
||||
goto cancel;
|
||||
}
|
||||
|
||||
if (dbwrap_store_int32(db, TDBSAM_VERSION_STRING,
|
||||
TDBSAM_VERSION) != 0) {
|
||||
DEBUG(0, ("tdbsam_convert: Could not store tdbsam version\n"));
|
||||
status = dbwrap_store_int32(db, TDBSAM_VERSION_STRING,
|
||||
TDBSAM_VERSION);
|
||||
if (!NT_STATUS_IS_OK(status)) {
|
||||
DEBUG(0, ("tdbsam_convert: Could not store tdbsam version: "
|
||||
"%s\n", nt_errstr(status)));
|
||||
goto cancel;
|
||||
}
|
||||
|
||||
if (dbwrap_store_int32(db, TDBSAM_MINOR_VERSION_STRING,
|
||||
TDBSAM_MINOR_VERSION) != 0) {
|
||||
DEBUG(0, ("tdbsam_convert: Could not store tdbsam minor version\n"));
|
||||
status = dbwrap_store_int32(db, TDBSAM_MINOR_VERSION_STRING,
|
||||
TDBSAM_MINOR_VERSION);
|
||||
if (!NT_STATUS_IS_OK(status)) {
|
||||
DEBUG(0, ("tdbsam_convert: Could not store tdbsam minor "
|
||||
"version: %s\n", nt_errstr(status)));
|
||||
goto cancel;
|
||||
}
|
||||
|
||||
|
@ -258,6 +258,7 @@ static int net_idmap_restore(struct net_context *c, int argc, const char **argv)
|
||||
char line[128], sid_string[128];
|
||||
int len;
|
||||
unsigned long idval;
|
||||
NTSTATUS status;
|
||||
|
||||
if (fgets(line, 127, input) == NULL)
|
||||
break;
|
||||
@ -282,16 +283,19 @@ static int net_idmap_restore(struct net_context *c, int argc, const char **argv)
|
||||
break;
|
||||
}
|
||||
} else if (sscanf(line, "USER HWM %lu", &idval) == 1) {
|
||||
ret = dbwrap_store_int32(db, "USER HWM", idval);
|
||||
if (ret != 0) {
|
||||
d_fprintf(stderr, _("Could not store USER HWM.\n"));
|
||||
status = dbwrap_store_int32(db, "USER HWM", idval);
|
||||
if (!NT_STATUS_IS_OK(status)) {
|
||||
d_fprintf(stderr,
|
||||
_("Could not store USER HWM: %s\n"),
|
||||
nt_errstr(status));
|
||||
break;
|
||||
}
|
||||
} else if (sscanf(line, "GROUP HWM %lu", &idval) == 1) {
|
||||
ret = dbwrap_store_int32(db, "GROUP HWM", idval);
|
||||
if (ret != 0) {
|
||||
status = dbwrap_store_int32(db, "GROUP HWM", idval);
|
||||
if (!NT_STATUS_IS_OK(status)) {
|
||||
d_fprintf(stderr,
|
||||
_("Could not store GROUP HWM.\n"));
|
||||
_("Could not store GROUP HWM: %s\n"),
|
||||
nt_errstr(status));
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
|
@ -197,8 +197,10 @@ static bool idmap_tdb_upgrade(struct idmap_domain *dom, struct db_context *db)
|
||||
wm = dom->low_id;
|
||||
}
|
||||
|
||||
if (dbwrap_store_int32(db, HWM_USER, wm) == -1) {
|
||||
DEBUG(0, ("Unable to byteswap user hwm in idmap database\n"));
|
||||
status = dbwrap_store_int32(db, HWM_USER, wm);
|
||||
if (!NT_STATUS_IS_OK(status)) {
|
||||
DEBUG(0, ("Unable to byteswap user hwm in idmap "
|
||||
"database: %s\n", nt_errstr(status)));
|
||||
return False;
|
||||
}
|
||||
|
||||
@ -213,8 +215,10 @@ static bool idmap_tdb_upgrade(struct idmap_domain *dom, struct db_context *db)
|
||||
wm = dom->low_id;
|
||||
}
|
||||
|
||||
if (dbwrap_store_int32(db, HWM_GROUP, wm) == -1) {
|
||||
DEBUG(0, ("Unable to byteswap group hwm in idmap database\n"));
|
||||
status = dbwrap_store_int32(db, HWM_GROUP, wm);
|
||||
if (!NT_STATUS_IS_OK(status)) {
|
||||
DEBUG(0, ("Unable to byteswap group hwm in idmap "
|
||||
"database: %s\n", nt_errstr(status)));
|
||||
return False;
|
||||
}
|
||||
}
|
||||
@ -235,8 +239,10 @@ static bool idmap_tdb_upgrade(struct idmap_domain *dom, struct db_context *db)
|
||||
return False;
|
||||
}
|
||||
|
||||
if (dbwrap_store_int32(db, "IDMAP_VERSION", IDMAP_VERSION) == -1) {
|
||||
DEBUG(0, ("Unable to store idmap version in database\n"));
|
||||
status = dbwrap_store_int32(db, "IDMAP_VERSION", IDMAP_VERSION);
|
||||
if (!NT_STATUS_IS_OK(status)) {
|
||||
DEBUG(0, ("Unable to store idmap version in database: %s\n",
|
||||
nt_errstr(status)));
|
||||
return False;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user