static NTSTATUS idmap_tdb_init_hwm(struct idmap_domain *dom) { uint32_t low_uid; uint32_t low_gid; bool update_uid = false; bool update_gid = false; struct idmap_tdb_common_context *ctx; NTSTATUS status; ctx = talloc_get_type(dom->private_data, struct idmap_tdb_common_context); status = dbwrap_fetch_uint32_bystring(ctx->db, HWM_USER, &low_uid); if (!NT_STATUS_IS_OK(status) || low_uid < dom->low_id) { update_uid = true; } status = dbwrap_fetch_uint32_bystring(ctx->db, HWM_GROUP, &low_gid); if (!NT_STATUS_IS_OK(status) || low_gid < dom->low_id) { update_gid = true; } if (!update_uid && !update_gid) { return NT_STATUS_OK; } if (dbwrap_transaction_start(ctx->db) != 0) { DEBUG(0, ("Unable to start upgrade transaction!\n")); return NT_STATUS_INTERNAL_DB_ERROR; } if (update_uid) { status = dbwrap_store_uint32_bystring(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: %s\n", nt_errstr(status))); return NT_STATUS_INTERNAL_DB_ERROR; } } if (update_gid) { status = dbwrap_store_uint32_bystring(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: %s\n", nt_errstr(status))); return NT_STATUS_INTERNAL_DB_ERROR; } } if (dbwrap_transaction_commit(ctx->db) != 0) { DEBUG(0, ("Unable to commit upgrade transaction!\n")); return NT_STATUS_INTERNAL_DB_ERROR; } return NT_STATUS_OK; }
static bool tdbsam_upgrade_next_rid(struct db_context *db) { TDB_CONTEXT *tdb; uint32 rid; bool ok = false; NTSTATUS status; status = dbwrap_fetch_uint32_bystring(db, NEXT_RID_STRING, &rid); if (NT_STATUS_IS_OK(status)) { return true; } tdb = tdb_open_log(state_path("winbindd_idmap.tdb"), 0, TDB_DEFAULT, O_RDONLY, 0644); if (tdb) { ok = tdb_fetch_uint32(tdb, "RID_COUNTER", &rid); if (!ok) { rid = BASE_RID; } tdb_close(tdb); } else { rid = BASE_RID; } status = dbwrap_store_uint32_bystring(db, NEXT_RID_STRING, rid); if (!NT_STATUS_IS_OK(status)) { return false; } return true; }
static int dbwrap_tool_fetch_uint32(struct db_context *db, const char *keyname, const char *data) { uint32_t value; NTSTATUS ret; ret = dbwrap_fetch_uint32_bystring(db, keyname, &value); if (NT_STATUS_IS_OK(ret)) { d_printf("%u\n", value); return 0; } else { d_fprintf(stderr, "ERROR: could not fetch uint32 key '%s': " "%s\n", nt_errstr(ret), keyname); return -1; } }
static NTSTATUS idmap_tdb_common_allocate_id_action(struct db_context *db, void *private_data) { NTSTATUS ret; struct idmap_tdb_common_allocate_id_context *state; uint32_t hwm; state = (struct idmap_tdb_common_allocate_id_context *)private_data; ret = dbwrap_fetch_uint32_bystring(db, state->hwmkey, &hwm); if (!NT_STATUS_IS_OK(ret)) { ret = NT_STATUS_INTERNAL_DB_ERROR; goto done; } /* check it is in the range */ if (hwm > state->high_hwm) { DEBUG(1, ("Fatal Error: %s range full!! (max: %lu)\n", state->hwmtype, (unsigned long)state->high_hwm)); ret = NT_STATUS_UNSUCCESSFUL; goto done; } /* fetch a new id and increment it */ ret = dbwrap_change_uint32_atomic_bystring(db, state->hwmkey, &hwm, 1); if (!NT_STATUS_IS_OK(ret)) { DEBUG(1, ("Fatal error while fetching a new %s value\n!", state->hwmtype)); goto done; } /* recheck it is in the range */ if (hwm > state->high_hwm) { DEBUG(1, ("Fatal Error: %s range full!! (max: %lu)\n", state->hwmtype, (unsigned long)state->high_hwm)); ret = NT_STATUS_UNSUCCESSFUL; goto done; } ret = NT_STATUS_OK; state->hwm = hwm; done: return ret; }
NTSTATUS smb2srv_open_lookup_replay_cache(struct smbXsrv_connection *conn, const struct GUID *create_guid, NTTIME now, /* TODO: needed ? */ struct smbXsrv_open **_open) { NTSTATUS status; char *guid_string; struct GUID_txt_buf buf; uint32_t local_id = 0; struct smbXsrv_open_table *table = conn->client->open_table; struct db_context *db = table->local.replay_cache_db_ctx; if (GUID_all_zero(create_guid)) { return NT_STATUS_NOT_FOUND; } guid_string = GUID_buf_string(create_guid, &buf); if (guid_string == NULL) { return NT_STATUS_INVALID_PARAMETER; } status = dbwrap_fetch_uint32_bystring(db, guid_string, &local_id); if (NT_STATUS_EQUAL(status, NT_STATUS_NOT_FOUND)) { return status; } if (!NT_STATUS_IS_OK(status)) { DBG_ERR("failed to fetch local_id from replay cache: %s\n", nt_errstr(status)); return status; } status = smbXsrv_open_local_lookup(table, local_id, 0, /* global_id */ now, _open); if (!NT_STATUS_IS_OK(status)) { DBG_ERR("smbXsrv_open_local_lookup failed for local_id %u\n", (unsigned)local_id); } return status; }