From nobody Mon Feb 9 13:37:13 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1620826464; cv=none; d=zohomail.com; s=zohoarc; b=Xas0uMUMbCYD6zQRnk1slhFdbXbltkVMiip4Wcm8jxvTSnZjEfZVk4pIqC/STv34+dvpBLNwmxfRUMhG/n/Rej9vXWJRl2b42Qolz2J2tRHnL/XH38Pf2D0KNReUSn4kOVw4stlYeXCouvFjgWZ+gAMeBGiyKFyj+/GZCUhK28A= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1620826464; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=QQB1apvFE5grSJk1OfoWNdtFeH0CZEQcdVExX7cLzhc=; b=X2574g2cpgrrFFzlGb0+5quCr4AW2uOJ0W0gTZWgfxAX+B+5IlSQTP5l3guMDOgnOHjUG1uBgoudbBS9fBGlTEwOsBa6QrJnZjEo4hlTx8MHr7U/WuigN6fbjp/cLx6LmRqTibXIEzCkuHw5BGmCjgICPeCZeWr3b7YG2l3mibE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mx.zohomail.com with SMTPS id 1620826464942979.2649483825564; Wed, 12 May 2021 06:34:24 -0700 (PDT) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-504-6Rq9lCaEOR-UGWKAFngviw-1; Wed, 12 May 2021 09:34:19 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 4C5A9107ACCD; Wed, 12 May 2021 13:34:13 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 2C1EC6268F; Wed, 12 May 2021 13:34:13 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id E5E08180B651; Wed, 12 May 2021 13:34:12 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 14CDYAp4031361 for ; Wed, 12 May 2021 09:34:10 -0400 Received: by smtp.corp.redhat.com (Postfix) id CACD01981F; Wed, 12 May 2021 13:34:10 +0000 (UTC) Received: from foo.redhat.com (ovpn-114-167.ams2.redhat.com [10.36.114.167]) by smtp.corp.redhat.com (Postfix) with ESMTP id C3FFA60657; Wed, 12 May 2021 13:34:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1620826463; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=QQB1apvFE5grSJk1OfoWNdtFeH0CZEQcdVExX7cLzhc=; b=af4/jn3dMnefgWgYaDNFOXFp7L+uthax0j+0SwGp35bjbNZ9cdQtFbQ8k0esCfBpAsQD+8 Ev27qXWL95y9n0ZSbbFuf/4rQQpIIDdZkmA+E0llqlH6z63P/38r3X1k46wifbWXSpiEpv seIg01TTiVGyfa77IlPBmoYqPDYFO2k= X-MC-Unique: 6Rq9lCaEOR-UGWKAFngviw-1 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Subject: [libvirt PATCH v3 07/10] src: add API to determine if current identity is a system identity Date: Wed, 12 May 2021 14:33:53 +0100 Message-Id: <20210512133356.1162418-8-berrange@redhat.com> In-Reply-To: <20210512133356.1162418-1-berrange@redhat.com> References: <20210512133356.1162418-1-berrange@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-loop: libvir-list@redhat.com Cc: Michal Privoznik X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) This is essentially a way to determine if the current identity is that of another libvirt daemon. Reviewed-by: Michal Privoznik Signed-off-by: Daniel P. Berrang=C3=A9 --- src/libvirt_private.syms | 1 + src/util/viridentity.c | 28 ++++++++++++++++++++++++++++ src/util/viridentity.h | 1 + 3 files changed, 30 insertions(+) diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 2ea950c5cd..1df4b8cfe8 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -2411,6 +2411,7 @@ virIdentityGetUNIXGroupID; virIdentityGetUNIXUserID; virIdentityGetUserName; virIdentityGetX509DName; +virIdentityIsCurrentElevated; virIdentityNew; virIdentityNewCopy; virIdentityRestoreHelper; diff --git a/src/util/viridentity.c b/src/util/viridentity.c index 2e3fcc5add..e7e5c31241 100644 --- a/src/util/viridentity.c +++ b/src/util/viridentity.c @@ -366,6 +366,34 @@ virIdentity *virIdentityGetSystem(void) } =20 =20 +/** + * virIdentityIsCurrentElevated: + * + * Determine if the current identity has elevated privileges. + * This indicates that it was invoked on behalf of the + * user by a libvirt daemon. + * + * Returns: true if elevated + */ +int virIdentityIsCurrentElevated(void) +{ + g_autoptr(virIdentity) current =3D virIdentityGetCurrent(); + const char *currentToken =3D NULL; + int rv; + + if (!current) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("No current identity")); + return -1; + } + + rv =3D virIdentityGetSystemToken(current, ¤tToken); + if (rv <=3D 0) + return rv; + + return STREQ_NULLABLE(currentToken, systemToken); +} + /** * virIdentityNew: * diff --git a/src/util/viridentity.h b/src/util/viridentity.h index 848e5b2056..6da6d0c557 100644 --- a/src/util/viridentity.h +++ b/src/util/viridentity.h @@ -35,6 +35,7 @@ virIdentity *virIdentityElevateCurrent(void); =20 void virIdentityRestoreHelper(virIdentity **identptr); =20 +int virIdentityIsCurrentElevated(void); virIdentity *virIdentityGetSystem(void); =20 virIdentity *virIdentityNew(void); --=20 2.31.1