From nobody Sun Feb 8 14:12:01 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) client-ip=216.205.24.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 216.205.24.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=1620150307; cv=none; d=zohomail.com; s=zohoarc; b=mMVQuwcRxaRyuVNPn5kWzfeLRPIKnTtkCh/UZMIBJjHMGFdXaDBOGecmtsXo+xMzij6G3FWRV0rzYBZIPqU2Cp9gfRmpmv7dxNOSOm+OYV2azJAXalJU1f1UnU+gCENwjaeo3Skndo0OWiM+yty7H3vJyWFCr1x9iCPKhMKK0IE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1620150307; h=Content-Type:Content-Transfer-Encoding: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=S/vODEhy3eQgO5rI5W7WjdLvXKmwR6srMdbvqWxMyiY=; b=gJXzg5ufz2fx8X5ngz+kf7OZsPblmoLSqDJ6EuGP7ZURwMKM0+RoIv6JIKnn0fe5LbQJ5kueWckfasFBnJsmZ0qg+o/u1BMbfEQHGWsWsDwmyHteCstrKAgH0eagnsMJ7R5icLlArCUs+3S56LbddM4u+sNtZ5NsfLWHoxPyLLo= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.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 [216.205.24.124]) by mx.zohomail.com with SMTPS id 1620150307493879.0724345638571; Tue, 4 May 2021 10:45:07 -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-29-E7ym2FR2PxexAIdLsONxfA-1; Tue, 04 May 2021 13:44:26 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 8C6F36414C; Tue, 4 May 2021 17:44:20 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 71037648A9; Tue, 4 May 2021 17:44:20 +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 3C0DB55356; Tue, 4 May 2021 17:44:20 +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 144Hi33K003937 for ; Tue, 4 May 2021 13:44:03 -0400 Received: by smtp.corp.redhat.com (Postfix) id 99BF850A8B; Tue, 4 May 2021 17:44:03 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-113-37.ams2.redhat.com [10.36.113.37]) by smtp.corp.redhat.com (Postfix) with ESMTP id CFDF31964B; Tue, 4 May 2021 17:44:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1620150306; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to: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=S/vODEhy3eQgO5rI5W7WjdLvXKmwR6srMdbvqWxMyiY=; b=IxPw3NPD7TeV7wpn+RucP134mAcYE2/r6/41Kc+dLMi34SpABI6GmiYInTBX03DHMdtWXp IyJhoPWulGC8GWNeBqi5Hgo90B7YgJ2xMx357uPCmvtI6t1ZROElk2E20e4fvXorOaCmn8 Rc5kPWz3CqLqUJlXGcLHTsVZQ84baQI= X-MC-Unique: E7ym2FR2PxexAIdLsONxfA-1 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Subject: [libvirt PATCH 7/9] src: add API to determine if current identity is a system identity Date: Tue, 4 May 2021 18:43:48 +0100 Message-Id: <20210504174350.488942-8-berrange@redhat.com> In-Reply-To: <20210504174350.488942-1-berrange@redhat.com> References: <20210504174350.488942-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 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.13 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. 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 90ca52c95c..698ba50d6b 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -2409,6 +2409,7 @@ virIdentityGetUNIXGroupID; virIdentityGetUNIXUserID; virIdentityGetUserName; virIdentityGetX509DName; +virIdentityIsCurrentElevated; virIdentityNew; virIdentityNewCopy; virIdentitySetCurrent; diff --git a/src/util/viridentity.c b/src/util/viridentity.c index 9fa6ab0dd0..424de513d9 100644 --- a/src/util/viridentity.c +++ b/src/util/viridentity.c @@ -354,6 +354,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 420cd82854..37a0c1ad4c 100644 --- a/src/util/viridentity.h +++ b/src/util/viridentity.h @@ -31,6 +31,7 @@ virIdentity *virIdentityGetCurrent(void); virIdentity *virIdentityGetCurrentElevated(void); int virIdentitySetCurrent(virIdentity *ident); =20 +int virIdentityIsCurrentElevated(void); virIdentity *virIdentityGetSystem(void); =20 virIdentity *virIdentityNew(void); --=20 2.31.1