s3:dbwrap: change dbwrap_store_int32() to NTSTATUS return type
authorMichael Adam <obnox@samba.org>
Thu, 6 Oct 2011 19:24:07 +0000 (21:24 +0200)
committerMichael Adam <obnox@samba.org>
Tue, 11 Oct 2011 12:17:58 +0000 (14:17 +0200)
for consistency and better error propagation

source3/lib/dbwrap/dbwrap.h
source3/lib/dbwrap/dbwrap_util.c
source3/lib/sharesec.c
source3/passdb/pdb_tdb.c
source3/utils/net_idmap.c
source3/winbindd/idmap_tdb.c

index 423791660c1a6e56b66151fff651bc1d0014141c..f3e3bfe2d40e41ae46feb083d86e007056eb3112 100644 (file)
@@ -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);
index bd29460f492f818c68c13d38c5f211f887049ab2..31beadb6a2bbce828c89b43d29e864e6b8aab368 100644 (file)
@@ -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,
index 9b3d5607fdec4635262decf8eabde68f538c7076..2c324cf971c920a6c2f963698f05263ae852b7c8 100644 (file)
@@ -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;
        }
 
index 80a4b49f9dd9e351d20e2fe4e0d54117d1bb0c1c..f16d99d0f40da2b2e956bb5e5425917a94b9d82b 100644 (file)
@@ -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;
        }
 
index 08ef920dde8d47c8b40a644dd8a0d0d140f84eeb..3a3ae21f07323096da901633fd38abaa16b35804 100644 (file)
@@ -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 {
index c19c9c81632c25cfb57a2f63cf34194018c1f5ad..339655f04455670a248d817eac4564f1a4c9d213 100644 (file)
@@ -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;
        }