Add API for querying logged-in users from a domain implemented via guest agent. Signed-off-by: Jonathon Jongsma <jjongsma@xxxxxxxxxx> --- 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-domain.h index 2dbd74d4f3..82dbbd3fc5 100644 --- a/include/libvirt/libvirt-domain.h +++ b/include/libvirt/libvirt-domain.h @@ -4896,4 +4896,22 @@ int virDomainGetLaunchSecurityInfo(virDomainPtr domain, int *nparams, unsigned int flags); +/** + * 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 ms 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); +typedef int +(*virDrvDomainGetGuestUsers)(virDomainPtr domain, + virDomainUserInfoPtr **info, + unsigned int flags); + 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; } +/** + * 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 caller 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 = 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); +} /** * 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; +LIBVIRT_5.6.0 { + global: + virDomainGetGuestUsers; + virDomainUserInfoFree; +} LIBVIRT_5.5.0; # .... define new API here using predicted next version number .... -- 2.20.1 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list