From nobody Tue Feb 10 20:06:00 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; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail(p=none dis=none) header.from=gmail.com 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 1638541245075670.6195915351981; Fri, 3 Dec 2021 06:20:45 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-104-CLe565TKMQySfyhI-gCyRQ-1; Fri, 03 Dec 2021 09:20:42 -0500 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 027B1835E31; Fri, 3 Dec 2021 14:20:34 +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 D81D2ADC5; Fri, 3 Dec 2021 14:20:33 +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 AD2651809CB9; Fri, 3 Dec 2021 14:20:33 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 1B3EKPqH026019 for ; Fri, 3 Dec 2021 09:20:25 -0500 Received: by smtp.corp.redhat.com (Postfix) id C05311402406; Fri, 3 Dec 2021 14:20:24 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast03.extmail.prod.ext.rdu2.redhat.com [10.11.55.19]) by smtp.corp.redhat.com (Postfix) with ESMTPS id BC5C11402408 for ; Fri, 3 Dec 2021 14:20:24 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-2.mimecast.com [205.139.110.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 55FBF811E81 for ; Fri, 3 Dec 2021 14:20:24 +0000 (UTC) Received: from mail-pf1-f181.google.com (mail-pf1-f181.google.com [209.85.210.181]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-284-4L_Rh853PmW7LOSiBKmoRg-1; Fri, 03 Dec 2021 09:20:22 -0500 Received: by mail-pf1-f181.google.com with SMTP id x5so3095746pfr.0 for ; Fri, 03 Dec 2021 06:20:22 -0800 (PST) Received: from localhost ([2400:ddc0:1000::b373:390c]) by smtp.gmail.com with ESMTPSA id o134sm3286374pfg.1.2021.12.03.06.20.20 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Dec 2021 06:20:20 -0800 (PST) X-MC-Unique: CLe565TKMQySfyhI-gCyRQ-1 X-MC-Unique: 4L_Rh853PmW7LOSiBKmoRg-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=+RF8cLULSOhPRpw60Mg/9ZSBDUlgEdCPoPQ2pvp+CLs=; b=3oX5XdgkJtveL0DMtev/NTd0Y/FsxiBU3+CBcMKlu5Jby8FvOMbipptEjyRngLjlnk 6RyAR3miBY7ZqRUIZ2ok8cnoQdeigzuvxCRIvpW3dWfKtuYij+letxj6jKqoELoRZ1Vh Dqpu4NTOnpuaM0qKZdW1z7OSTTpPH+rkuiforGC+EwS9d+0lxCQA4UUbgRf2gVAiL/Qv 2uMujGC6Qt4g1V58ScXklMRhkvSCVL9ZcXrdhHMwaOUqG70QbWhfFoy8VBy1kGMTbicQ NuDk5RsyAGsOnN87g9kBqtzR4EsCHRqj357fpeWFkvbrCYr6pEtid5X5nqGY8jZELnab SXPw== X-Gm-Message-State: AOAM531OHcSXcmNB4p77dmXDlrCoTn5dGyeGIwj9r31S+ykQoYdWjrwE 4QAgl5+AgNS74eLrhW8AHXvhZbXWH/TjxYc/ X-Google-Smtp-Source: ABdhPJy0vQMw4D071JjqsTe7CiWyQKB8WNN4SpqUU1PznlU7dVHw1zWauai1LHRIF2keO1I6nL+d7w== X-Received: by 2002:a63:30c:: with SMTP id 12mr4768437pgd.131.1638541220795; Fri, 03 Dec 2021 06:20:20 -0800 (PST) From: Luke Yue To: libvir-list@redhat.com Subject: [PATCH v2 2/4] virsh: Add '--full-seclabels' option for dominfo Date: Fri, 3 Dec 2021 22:19:55 +0800 Message-Id: <20211203141957.686148-3-lukedyue@gmail.com> In-Reply-To: <20211203141957.686148-1-lukedyue@gmail.com> References: <20211203141957.686148-1-lukedyue@gmail.com> MIME-Version: 1.0 X-Mimecast-Impersonation-Protect: Policy=CLT - Impersonation Protection Definition; Similar Internal Domain=false; Similar Monitored External Domain=false; Custom External Domain=false; Mimecast External Domain=false; Newly Observed Domain=false; Internal User Name=false; Custom Display Name List=false; Reply-to Address Mismatch=false; Targeted Threat Dictionary=false; Mimecast Threat Dictionary=false; Custom Threat Dictionary=false X-Scanned-By: MIMEDefang 2.85 on 10.11.54.7 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.14 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-Transfer-Encoding: quoted-printable X-ZM-MESSAGEID: 1638541247173100001 Content-Type: text/plain; charset="utf-8" There is no virsh command uses virDomainGetSecurityLabelList API, so add an option for dominfo to call it and print full list of security labels. Signed-off-by: Luke Yue --- docs/manpages/virsh.rst | 5 +++-- tools/virsh-domain-monitor.c | 43 +++++++++++++++++++++++++++++++----- 2 files changed, 40 insertions(+), 8 deletions(-) diff --git a/docs/manpages/virsh.rst b/docs/manpages/virsh.rst index 39636a565e..54391b7557 100644 --- a/docs/manpages/virsh.rst +++ b/docs/manpages/virsh.rst @@ -2008,9 +2008,10 @@ dominfo =20 :: =20 - dominfo domain + dominfo domain [--full-seclabels] =20 -Returns basic information about the domain. +Returns basic information about the domain. *--full-seclabels* tells virsh +to print full list of security labels. =20 =20 domjobabort diff --git a/tools/virsh-domain-monitor.c b/tools/virsh-domain-monitor.c index eb3e0ef11a..1bb3bed1cb 100644 --- a/tools/virsh-domain-monitor.c +++ b/tools/virsh-domain-monitor.c @@ -1203,6 +1203,10 @@ static const vshCmdInfo info_dominfo[] =3D { =20 static const vshCmdOptDef opts_dominfo[] =3D { VIRSH_COMMON_OPT_DOMAIN_FULL(0), + {.name =3D "full-seclabels", + .type =3D VSH_OT_BOOL, + .help =3D N_("Show full list of security labels of a domain") + }, {.name =3D NULL} }; =20 @@ -1222,6 +1226,7 @@ cmdDominfo(vshControl *ctl, const vshCmd *cmd) int has_managed_save =3D 0; virshControl *priv =3D ctl->privData; g_auto(GStrv) messages =3D NULL; + bool fullseclabels =3D vshCommandOptBool(cmd, "full-seclabels"); =20 if (!(dom =3D virshCommandOptDomain(ctl, cmd, NULL))) return false; @@ -1303,16 +1308,42 @@ cmdDominfo(vshControl *ctl, const vshCmd *cmd) vshPrint(ctl, "%-15s %s\n", _("Security model:"), secmodel.mod= el); vshPrint(ctl, "%-15s %s\n", _("Security DOI:"), secmodel.doi); =20 - /* Security labels are only valid for active domains */ - seclabel =3D g_new0(virSecurityLabel, 1); + if (fullseclabels) { + int len; + size_t i; =20 - if (virDomainGetSecurityLabel(dom, seclabel) =3D=3D -1) { - VIR_FREE(seclabel); - return false; + if ((len =3D virDomainGetSecurityLabelList(dom, &seclabel)= ) < 0) { + g_clear_pointer(&seclabel, g_free); + return false; + } + + for (i =3D 0; i < len; i++) + if (seclabel[i].label[0] !=3D '\0') + vshPrint(ctl, "%-16s %s (%s)\n", + i =3D=3D 0 ? _("Security labels:") : "", + seclabel[i].label, + seclabel[i].enforcing ? + "enforcing" : + "permissive"); + + g_clear_pointer(&seclabel, g_free); } else { + /* Security labels are only valid for active domains */ + seclabel =3D g_new0(virSecurityLabel, 1); + + if (virDomainGetSecurityLabel(dom, seclabel) < 0) { + g_clear_pointer(&seclabel, g_free); + return false; + } + if (seclabel->label[0] !=3D '\0') vshPrint(ctl, "%-15s %s (%s)\n", _("Security label:"), - seclabel->label, seclabel->enforcing ? "enfor= cing" : "permissive"); + seclabel->label, + seclabel->enforcing ? + "enforcing" : + "permissive"); + + g_clear_pointer(&seclabel, g_free); } =20 VIR_FREE(seclabel); --=20 2.34.1