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