summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Adam <obnox@samba.org>2011-10-06 21:24:07 +0200
committerMichael Adam <obnox@samba.org>2011-10-11 14:17:58 +0200
commitc9bc1e492404077c6b40b5cefe33e859503a4227 (patch)
tree8a38bfafafe0af9f8ee912ac87d53e62c4e2134d
parent658f72128ff6950c6a03994198b4464a273fb300 (diff)
downloadsamba-c9bc1e492404077c6b40b5cefe33e859503a4227.tar.gz
samba-c9bc1e492404077c6b40b5cefe33e859503a4227.tar.bz2
samba-c9bc1e492404077c6b40b5cefe33e859503a4227.zip
s3:dbwrap: change dbwrap_store_int32() to NTSTATUS return type
for consistency and better error propagation
-rw-r--r--source3/lib/dbwrap/dbwrap.h3
-rw-r--r--source3/lib/dbwrap/dbwrap_util.c7
-rw-r--r--source3/lib/sharesec.c24
-rw-r--r--source3/passdb/pdb_tdb.c16
-rw-r--r--source3/utils/net_idmap.c16
-rw-r--r--source3/winbindd/idmap_tdb.c18
6 files changed, 53 insertions, 31 deletions
diff --git a/source3/lib/dbwrap/dbwrap.h b/source3/lib/dbwrap/dbwrap.h
index 423791660c..f3e3bfe2d4 100644
--- a/source3/lib/dbwrap/dbwrap.h
+++ b/source3/lib/dbwrap/dbwrap.h
@@ -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);
diff --git a/source3/lib/dbwrap/dbwrap_util.c b/source3/lib/dbwrap/dbwrap_util.c
index bd29460f49..31beadb6a2 100644
--- a/source3/lib/dbwrap/dbwrap_util.c
+++ b/source3/lib/dbwrap/dbwrap_util.c
@@ -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,
diff --git a/source3/lib/sharesec.c b/source3/lib/sharesec.c
index 9b3d5607fd..2c324cf971 100644
--- a/source3/lib/sharesec.c
+++ b/source3/lib/sharesec.c
@@ -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;
}
diff --git a/source3/passdb/pdb_tdb.c b/source3/passdb/pdb_tdb.c
index 80a4b49f9d..f16d99d0f4 100644
--- a/source3/passdb/pdb_tdb.c
+++ b/source3/passdb/pdb_tdb.c
@@ -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;
}
diff --git a/source3/utils/net_idmap.c b/source3/utils/net_idmap.c
index 08ef920dde..3a3ae21f07 100644
--- a/source3/utils/net_idmap.c
+++ b/source3/utils/net_idmap.c
@@ -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 {
diff --git a/source3/winbindd/idmap_tdb.c b/source3/winbindd/idmap_tdb.c
index c19c9c8163..339655f044 100644
--- a/source3/winbindd/idmap_tdb.c
+++ b/source3/winbindd/idmap_tdb.c
@@ -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;
}