s3:idmap_tdb: rename idmap_tdb_alloc_init->idmap_tdb_init_hwm and use db from idmap_t...
authorMichael Adam <obnox@samba.org>
Thu, 17 Jun 2010 05:56:46 +0000 (07:56 +0200)
committerMichael Adam <obnox@samba.org>
Wed, 23 Jun 2010 10:22:12 +0000 (12:22 +0200)
instead of the special idmap_alloc_db

source3/winbindd/idmap_tdb.c

index 0bf6d38649d6c9add09cbfe6667590ac1dd6fc34..d924afc7a103e1653fcfb5e04960eb21a0da95cf 100644 (file)
@@ -330,29 +330,24 @@ static struct db_context *idmap_alloc_db;
  Initialise idmap alloc database. 
 **********************************/
 
-static NTSTATUS idmap_tdb_alloc_init( const char *params )
+static NTSTATUS idmap_tdb_init_hwm(struct idmap_domain *dom)
 {
        int ret;
-       NTSTATUS status;
        uint32_t low_uid;
        uint32_t low_gid;
        bool update_uid = false;
        bool update_gid = false;
+       struct idmap_tdb_context *ctx;
 
-       status = idmap_tdb_open_db(NULL, true, &idmap_alloc_db);
-       if (!NT_STATUS_IS_OK(status)) {
-               DEBUG(0, ("idmap will be unable to map foreign SIDs: %s\n",
-                         nt_errstr(status)));
-               return status;
-       }
+       ctx = talloc_get_type(dom->private_data, struct idmap_tdb_context);
 
-       low_uid = dbwrap_fetch_int32(idmap_alloc_db, HWM_USER);
-       if (low_uid == -1 || low_uid < idmap_tdb_state.low_uid) {
+       low_uid = dbwrap_fetch_int32(ctx->db, HWM_USER);
+       if (low_uid == -1 || low_uid < dom->low_id) {
                update_uid = true;
        }
 
-       low_gid = dbwrap_fetch_int32(idmap_alloc_db, HWM_GROUP);
-       if (low_gid == -1 || low_gid < idmap_tdb_state.low_gid) {
+       low_gid = dbwrap_fetch_int32(ctx->db, HWM_GROUP);
+       if (low_gid == -1 || low_gid < dom->low_id) {
                update_gid = true;
        }
 
@@ -360,18 +355,15 @@ static NTSTATUS idmap_tdb_alloc_init( const char *params )
                return NT_STATUS_OK;
        }
 
-       if (idmap_alloc_db->transaction_start(idmap_alloc_db) != 0) {
-               TALLOC_FREE(idmap_alloc_db);
+       if (ctx->db->transaction_start(ctx->db) != 0) {
                DEBUG(0, ("Unable to start upgrade transaction!\n"));
                return NT_STATUS_INTERNAL_DB_ERROR;
        }
 
        if (update_uid) {
-               ret = dbwrap_store_int32(idmap_alloc_db, HWM_USER,
-                                        idmap_tdb_state.low_uid);
+               ret = dbwrap_store_int32(ctx->db, HWM_USER, dom->low_id);
                if (ret == -1) {
-                       idmap_alloc_db->transaction_cancel(idmap_alloc_db);
-                       TALLOC_FREE(idmap_alloc_db);
+                       ctx->db->transaction_cancel(ctx->db);
                        DEBUG(0, ("Unable to initialise user hwm in idmap "
                                  "database\n"));
                        return NT_STATUS_INTERNAL_DB_ERROR;
@@ -379,19 +371,16 @@ static NTSTATUS idmap_tdb_alloc_init( const char *params )
        }
 
        if (update_gid) {
-               ret = dbwrap_store_int32(idmap_alloc_db, HWM_GROUP,
-                                        idmap_tdb_state.low_gid);
+               ret = dbwrap_store_int32(ctx->db, HWM_GROUP, dom->low_id);
                if (ret == -1) {
-                       idmap_alloc_db->transaction_cancel(idmap_alloc_db);
-                       TALLOC_FREE(idmap_alloc_db);
+                       ctx->db->transaction_cancel(ctx->db);
                        DEBUG(0, ("Unable to initialise group hwm in idmap "
                                  "database\n"));
                        return NT_STATUS_INTERNAL_DB_ERROR;
                }
        }
 
-       if (idmap_alloc_db->transaction_commit(idmap_alloc_db) != 0) {
-               TALLOC_FREE(idmap_alloc_db);
+       if (ctx->db->transaction_commit(ctx->db) != 0) {
                DEBUG(0, ("Unable to commit upgrade transaction!\n"));
                return NT_STATUS_INTERNAL_DB_ERROR;
        }