Exemplo n.º 1
0
static NTSTATUS idmap_tdb_db_init(struct idmap_domain *dom)
{
	NTSTATUS ret;
	struct idmap_tdb_common_context *ctx;

	DEBUG(10, ("idmap_tdb_db_init called for domain '%s'\n", dom->name));

	ctx = talloc_zero(dom, struct idmap_tdb_common_context);
	if ( ! ctx) {
		DEBUG(0, ("Out of memory!\n"));
		return NT_STATUS_NO_MEMORY;
	}

	/* load backend specific configuration here: */
#if 0
	if (strequal(dom->name, "*")) {
	} else {
	}
#endif

	ctx->rw_ops = talloc_zero(ctx, struct idmap_rw_ops);
	if (ctx->rw_ops == NULL) {
		DEBUG(0, ("Out of memory!\n"));
		ret = NT_STATUS_NO_MEMORY;
		goto failed;
	}

	ctx->max_id = dom->high_id;
	ctx->hwmkey_uid = HWM_USER;
	ctx->hwmkey_gid = HWM_GROUP;

	ctx->rw_ops->get_new_id = idmap_tdb_common_get_new_id;
	ctx->rw_ops->set_mapping = idmap_tdb_common_set_mapping;

	dom->private_data = ctx;

	ret = idmap_tdb_open_db(dom);
	if ( ! NT_STATUS_IS_OK(ret)) {
		goto failed;
	}

	return NT_STATUS_OK;

failed:
	talloc_free(ctx);
	return ret;
}
Exemplo n.º 2
0
static NTSTATUS idmap_tdb_alloc_init( const char *params )
{
	int ret;
	NTSTATUS status;
	uint32_t low_uid;
	uint32_t low_gid;
	bool update_uid = false;
	bool update_gid = false;

	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;
	}

	low_uid = dbwrap_fetch_int32(idmap_alloc_db, HWM_USER);
	if (low_uid == -1 || low_uid < idmap_tdb_state.low_uid) {
		update_uid = true;
	}

	low_gid = dbwrap_fetch_int32(idmap_alloc_db, HWM_GROUP);
	if (low_gid == -1 || low_gid < idmap_tdb_state.low_gid) {
		update_gid = true;
	}

	if (!update_uid && !update_gid) {
		return NT_STATUS_OK;
	}

	if (idmap_alloc_db->transaction_start(idmap_alloc_db) != 0) {
		TALLOC_FREE(idmap_alloc_db);
		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);
		if (ret == -1) {
			idmap_alloc_db->transaction_cancel(idmap_alloc_db);
			TALLOC_FREE(idmap_alloc_db);
			DEBUG(0, ("Unable to initialise user hwm in idmap "
				  "database\n"));
			return NT_STATUS_INTERNAL_DB_ERROR;
		}
	}

	if (update_gid) {
		ret = dbwrap_store_int32(idmap_alloc_db, HWM_GROUP,
					 idmap_tdb_state.low_gid);
		if (ret == -1) {
			idmap_alloc_db->transaction_cancel(idmap_alloc_db);
			TALLOC_FREE(idmap_alloc_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);
		DEBUG(0, ("Unable to commit upgrade transaction!\n"));
		return NT_STATUS_INTERNAL_DB_ERROR;
	}

	return NT_STATUS_OK;
}