s3:dbwrap: change dbwrap_store_uint32() to NTSTATUS return type
authorMichael Adam <obnox@samba.org>
Thu, 6 Oct 2011 19:29:04 +0000 (21:29 +0200)
committerMichael Adam <obnox@samba.org>
Tue, 11 Oct 2011 13:51:00 +0000 (15:51 +0200)
for consistency and better error propagation

Autobuild-User: Michael Adam <obnox@samba.org>
Autobuild-Date: Tue Oct 11 15:51:00 CEST 2011 on sn-devel-104

source3/lib/dbwrap/dbwrap.h
source3/lib/dbwrap/dbwrap_util.c
source3/passdb/account_pol.c
source3/passdb/pdb_tdb.c
source3/winbindd/idmap_tdb.c

index f3e3bfe2d40e41ae46feb083d86e007056eb3112..f0646d3ec1212ee1428a1ae83d5e4308daf554bd 100644 (file)
@@ -76,7 +76,8 @@ 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);
+NTSTATUS 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);
 NTSTATUS dbwrap_trans_change_uint32_atomic(struct db_context *db,
index 31beadb6a2bbce828c89b43d29e864e6b8aab368..48bd9bb13bae294ef7fa8d03c236213379b85e08 100644 (file)
@@ -98,7 +98,8 @@ NTSTATUS dbwrap_fetch_uint32(struct db_context *db, const char *keystr,
        return NT_STATUS_OK;
 }
 
-int dbwrap_store_uint32(struct db_context *db, const char *keystr, uint32_t v)
+NTSTATUS dbwrap_store_uint32(struct db_context *db, const char *keystr,
+                            uint32_t v)
 {
        struct db_record *rec;
        uint32 v_store;
@@ -106,7 +107,7 @@ int dbwrap_store_uint32(struct db_context *db, const char *keystr, uint32_t v)
 
        rec = dbwrap_fetch_locked(db, NULL, string_term_tdb_data(keystr));
        if (rec == NULL) {
-               return -1;
+               return NT_STATUS_INVALID_PARAMETER;
        }
 
        SIVAL(&v_store, 0, v);
@@ -116,7 +117,7 @@ int dbwrap_store_uint32(struct db_context *db, const char *keystr, uint32_t v)
                                                   sizeof(v_store)),
                                     TDB_REPLACE);
        TALLOC_FREE(rec);
-       return NT_STATUS_IS_OK(status) ? 0 : -1;
+       return status;
 }
 
 /**
index bd8cdf725f3a55bdeca39f2bc5bef65187009649..a32d07517d49ebeb637198b9ef7808c158a95cd6 100644 (file)
@@ -265,8 +265,10 @@ bool init_account_policy(void)
        }
 
        if (version != DATABASE_VERSION) {
-               if (dbwrap_store_uint32(db, vstring, DATABASE_VERSION) != 0) {
-                       DEBUG(0, ("dbwrap_store_uint32 failed\n"));
+               status = dbwrap_store_uint32(db, vstring, DATABASE_VERSION);
+               if (!NT_STATUS_IS_OK(status)) {
+                       DEBUG(0, ("dbwrap_store_uint32 failed: %s\n",
+                                 nt_errstr(status)));
                        goto cancel;
                }
 
index f16d99d0f40da2b2e956bb5e5425917a94b9d82b..01c0def57fab97679bc23aadcd715aa3b66fe76f 100644 (file)
@@ -345,7 +345,8 @@ static bool tdbsam_upgrade_next_rid(struct db_context *db)
                rid = BASE_RID;
        }
 
-       if (dbwrap_store_uint32(db, NEXT_RID_STRING, rid) != 0) {
+       status = dbwrap_store_uint32(db, NEXT_RID_STRING, rid);
+       if (!NT_STATUS_IS_OK(status)) {
                return false;
        }
 
index 339655f04455670a248d817eac4564f1a4c9d213..1d1ba64c21e869b7d25c7d82500e4b470f0f31ba 100644 (file)
@@ -251,7 +251,6 @@ static bool idmap_tdb_upgrade(struct idmap_domain *dom, struct db_context *db)
 
 static NTSTATUS idmap_tdb_init_hwm(struct idmap_domain *dom)
 {
-       int ret;
        uint32_t low_uid;
        uint32_t low_gid;
        bool update_uid = false;
@@ -281,21 +280,21 @@ static NTSTATUS idmap_tdb_init_hwm(struct idmap_domain *dom)
        }
 
        if (update_uid) {
-               ret = dbwrap_store_uint32(ctx->db, HWM_USER, dom->low_id);
-               if (ret == -1) {
+               status = dbwrap_store_uint32(ctx->db, HWM_USER, dom->low_id);
+               if (!NT_STATUS_IS_OK(status)) {
                        dbwrap_transaction_cancel(ctx->db);
                        DEBUG(0, ("Unable to initialise user hwm in idmap "
-                                 "database\n"));
+                                 "database: %s\n", nt_errstr(status)));
                        return NT_STATUS_INTERNAL_DB_ERROR;
                }
        }
 
        if (update_gid) {
-               ret = dbwrap_store_uint32(ctx->db, HWM_GROUP, dom->low_id);
-               if (ret == -1) {
+               status = dbwrap_store_uint32(ctx->db, HWM_GROUP, dom->low_id);
+               if (!NT_STATUS_IS_OK(status)) {
                        dbwrap_transaction_cancel(ctx->db);
                        DEBUG(0, ("Unable to initialise group hwm in idmap "
-                                 "database\n"));
+                                 "database: %s\n", nt_errstr(status)));
                        return NT_STATUS_INTERNAL_DB_ERROR;
                }
        }