From nobody Mon Feb 9 09:10:05 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 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=1562789276; cv=none; d=zoho.com; s=zohoarc; b=nE8rqcG5bobFoLU4Sa4Il1Vdgk+0mxmqhyzrWvVmaJWdMQL+onXP0fwjPHfbym9ZhOoPLOmFm6VFajoMK8IBHUWmPuRXWOCf8+mZ1LOzF8Ljaxpnj8uJC8RTCCRM040hvMUdx3LZ5n+JIDCM7Rd/7q6uUeB5g7lA8WIHupcN99s= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1562789276; 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:ARC-Authentication-Results; bh=d7oFtB5L+cx2V4eAiBypCHorx1tdEzhjNLcwrseDkBU=; b=fBcmDmdq9HNJQFSaw4vGxNJGYZ921dJ+vH2Wmz20LKTV0b94lgwKKz5Itf62/h64t86i41gQnMaMJnlkt2my5Fw5gmOllUhTmSM8jy+JdbKcmJBSsOlLM7IET93LOe9gXBqcT0eV8Azy7SoHg0Pqa7EuP1xwSPHPwATP9L3r6xY= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1562789276537562.9825811368291; Wed, 10 Jul 2019 13:07:56 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id EB99DA3B63; Wed, 10 Jul 2019 20:07:53 +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 BA6DD60C4E; Wed, 10 Jul 2019 20:07:53 +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 73AB9184365F; Wed, 10 Jul 2019 20:07:53 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x6AK7qXi030781 for ; Wed, 10 Jul 2019 16:07:52 -0400 Received: by smtp.corp.redhat.com (Postfix) id B0EF65DC1A; Wed, 10 Jul 2019 20:07:52 +0000 (UTC) Received: from aegolius.redhat.com (ovpn-116-68.phx2.redhat.com [10.3.116.68]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 6C4575D9CD for ; Wed, 10 Jul 2019 20:07:52 +0000 (UTC) From: Jonathon Jongsma To: libvir-list@redhat.com Date: Wed, 10 Jul 2019 15:07:43 -0500 Message-Id: <20190710200747.745-2-jjongsma@redhat.com> In-Reply-To: <20190710200747.745-1-jjongsma@redhat.com> References: <20190710200747.745-1-jjongsma@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 1/5] lib: add API to query info about logged-in users 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: , Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Wed, 10 Jul 2019 20:07:55 +0000 (UTC) Content-Type: text/plain; charset="utf-8" Add API for querying logged-in users from a domain implemented via guest agent. Signed-off-by: Jonathon Jongsma --- include/libvirt/libvirt-domain.h | 18 ++++++++++ src/driver-hypervisor.h | 6 ++++ src/libvirt-domain.c | 62 ++++++++++++++++++++++++++++++++ src/libvirt_public.syms | 5 +++ 4 files changed, 91 insertions(+) diff --git a/include/libvirt/libvirt-domain.h b/include/libvirt/libvirt-dom= ain.h index 2dbd74d4f3..82dbbd3fc5 100644 --- a/include/libvirt/libvirt-domain.h +++ b/include/libvirt/libvirt-domain.h @@ -4896,4 +4896,22 @@ int virDomainGetLaunchSecurityInfo(virDomainPtr doma= in, int *nparams, unsigned int flags); =20 +/** + * virDomainUserInfo: + * + * The data structure containing informationa bout logged-in users within a + * guest + */ +typedef struct _virDomainUserInfo virDomainUserInfo; +typedef virDomainUserInfo *virDomainUserInfoPtr; +struct _virDomainUserInfo { + char *user; /* username */ + char *domain; /* login domain (windows only) */ + unsigned long long loginTime; /* timestamp of login for this user in m= s since epoch */ +}; +int virDomainGetGuestUsers(virDomainPtr domain, + virDomainUserInfoPtr **info, + unsigned int flags); +void virDomainUserInfoFree(virDomainUserInfoPtr info); + #endif /* LIBVIRT_DOMAIN_H */ diff --git a/src/driver-hypervisor.h b/src/driver-hypervisor.h index b15aaa36bc..0ef7257ace 100644 --- a/src/driver-hypervisor.h +++ b/src/driver-hypervisor.h @@ -1327,6 +1327,11 @@ typedef int int *nparams, unsigned int flags); =20 +typedef int +(*virDrvDomainGetGuestUsers)(virDomainPtr domain, + virDomainUserInfoPtr **info, + unsigned int flags); + =20 typedef struct _virHypervisorDriver virHypervisorDriver; typedef virHypervisorDriver *virHypervisorDriverPtr; @@ -1579,4 +1584,5 @@ struct _virHypervisorDriver { virDrvConnectBaselineHypervisorCPU connectBaselineHypervisorCPU; virDrvNodeGetSEVInfo nodeGetSEVInfo; virDrvDomainGetLaunchSecurityInfo domainGetLaunchSecurityInfo; + virDrvDomainGetGuestUsers domainGetGuestUsers; }; diff --git a/src/libvirt-domain.c b/src/libvirt-domain.c index 3d12e7c125..80faa08758 100644 --- a/src/libvirt-domain.c +++ b/src/libvirt-domain.c @@ -12199,6 +12199,68 @@ virDomainSetVcpu(virDomainPtr domain, return -1; } =20 +/** + * virDomainGetGuestUsers: + * @domain: pointer to domain object + * @info: a pointer to a variable to store an array of user info + * @flags: currently unused, callers shall pass 0 + * + * Queries the guest agent for the list of currently active users on the + * guest. The reported data depends on the guest agent implementation. + * + * This API requires the VM to run. The caller is responsible for calling + * virTypedParamsFree to free memory returned in @params. + * + * Returns the number of returned users, or -1 in case of error. + * On success, the array of the information is stored into @info. The call= er is + * responsible for calling virDomainUserInfoFree() on each array element, = then + * calling free() on @info. On error, @info is set to NULL. + */ +int +virDomainGetGuestUsers(virDomainPtr domain, + virDomainUserInfoPtr **info, + unsigned int flags) +{ + virResetLastError(); + + virCheckDomainReturn(domain, -1); + virCheckReadOnlyGoto(domain->conn->flags, error); + + virCheckNonNullArgGoto(info, error); + + if (domain->conn->driver->domainGetGuestUsers) { + int ret; + ret =3D domain->conn->driver->domainGetGuestUsers(domain, info, + flags); + if (ret < 0) + goto error; + return ret; + } + + virReportUnsupportedError(); + + error: + virDispatchError(domain->conn); + return -1; +} + +/** + * virDomainUserInfoFree: + * @info: pointer to a UserInfo object + * + * Frees all the memory occupied by @info. + */ +void +virDomainUserInfoFree(virDomainUserInfoPtr info) +{ + if (!info) + return; + + VIR_FREE(info->user); + VIR_FREE(info->domain); + + VIR_FREE(info); +} =20 /** * virDomainSetBlockThreshold: diff --git a/src/libvirt_public.syms b/src/libvirt_public.syms index 18500ec8b2..7d0e3c7849 100644 --- a/src/libvirt_public.syms +++ b/src/libvirt_public.syms @@ -836,4 +836,9 @@ LIBVIRT_5.5.0 { virNetworkPortSetParameters; } LIBVIRT_5.2.0; =20 +LIBVIRT_5.6.0 { + global: + virDomainGetGuestUsers; + virDomainUserInfoFree; +} LIBVIRT_5.5.0; # .... define new API here using predicted next version number .... --=20 2.20.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list