qga: Add 'guest-get-users' command
v2 cover qga: Add 'guest-get-users' command
From: Vinzenz Feenstra <[email protected]>
Changes since v1:
- fixed spelling issues in the commit message and schema
- added login-time field which specifies the time the users logged on
- applied changes suggested for glib hash table usage
- added new link time library dependency for wtsapi32
- setting now _WIN32_WINNT to 0x0600 if not defined globally, which is Windows Vista and/or Windows 2008 Server and higher
Vinzenz Feenstra (1):
qga: Add 'guest-get-users' command
configure | 2 +- include/glib-compat.h | 5 +++ qga/commands-posix.c | 54 +++++++++++++++++++++++++++++++ qga/commands-win32.c | 89 +++++++++++++++++++++++++++++++++++++++++++++++++++ qga/qapi-schema.json | 22 +++++++++++++ 5 files changed, 171 insertions(+), 1 deletion(-)
Signature · 1 line
2.9.3
PATCH v2 1/1 qga: Add 'guest-get-users' command
From: Vinzenz Feenstra <[email protected]>
A command that will list all currently logged in users, and the time since when they are logged in.
Examples:
virsh # qemu-agent-command F25 '{ "execute": "guest-get-users" }' {"return":[{"login-time":1490622289.903835,"user":"root"}]}
virsh # qemu-agent-command Win2k12r2 '{ "execute": "guest-get-users" }' {"return":[{"login-time":1490351044.670552,"domain":"LADIDA", "user":"Administrator"}]}
--- configure | 2 +- include/glib-compat.h | 5 +++ qga/commands-posix.c | 54 +++++++++++++++++++++++++++++++ qga/commands-win32.c | 89 +++++++++++++++++++++++++++++++++++++++++++++++++++ qga/qapi-schema.json | 22 +++++++++++++ 5 files changed, 171 insertions(+), 1 deletion(-)
configure +1 -1
@@ -737,7 +737,7 @@ if test "$mingw32" = "yes" ; then sysconfdir="\${prefix}" local_statedir= confsuffix="" - libs_qga="-lws2_32 -lwinmm -lpowrprof -liphlpapi -lnetapi32 $libs_qga" + libs_qga="-lws2_32 -lwinmm -lpowrprof -lwtsapi32 -liphlpapi -lnetapi32 $libs_qga" fi werror=""
include/glib-compat.h +5 -0
@@ -217,6 +217,11 @@ static inline void g_hash_table_add(GHashTable *hash_table, gpointer key) {g_hash_table_replace (hash_table, key, key); } + +static gboolean g_hash_table_contains (GHashTable *hash_table,gpointer key) +{ +return g_hash_table_lookup_extended (hash_table, key,NULL ,NULL ); +}#endif #ifndef g_assert_true
qga/commands-posix.c +54 -0
63 lines not on this page · raw message
qga/commands-win32.c +89 -0
104 lines not on this page · raw message
qga/qapi-schema.json +22 -0
@@ -1042,3 +1042,25 @@ 'data': { 'path': 'str', '*arg': ['str'], '*env': ['str'], '*input-data': 'str', '*capture-output': 'bool' }, 'returns': 'GuestExec' } + +## +# @GuestUser: +# @user: Username +# @domain: Logon domain (windows only) +# @login-time: Unix timestamp of login +# +# Since: 2.10 +## +{ 'struct': 'GuestUser', + 'data': { 'user': 'str', 'login-time': 'number', '*domain': 'str' } } + +## +# @guest-get-users: +# Retrieves a list of currently active users on the VM. +# +# Returns: A unique list of users. +# +# Since: 2.10 +## +{ 'command': 'guest-get-users', + 'returns': ['GuestUser'] }
Signature · 1 line
2.9.3
Quoted 10 lines · Vinzenz 'evilissimo' Feenstra
From: Vinzenz Feenstra <[email protected]>
A command that will list all currently logged in users, and the time since when they are logged in.
Examples:
virsh # qemu-agent-command F25 '{ "execute": "guest-get-users" }' {"return":[{"login-time":1490622289.903835,"user":"root"}]}
Quoted 6 lines
virsh # qemu-agent-command Win2k12r2 '{ "execute": "guest-get-users" }' {"return":[{"login-time":1490351044.670552,"domain":"LADIDA", "user":"Administrator"}]}
Signed-off-by Vinzenz Feenstra <[email protected]>---
I'll leave the code reviews for others (I'm not comfortable enough with Windows API programming), but focus on the interface here:
qga/qapi-schema.json line 1050
Quoted 11 lines
+++
b/qga/qapi-schema.jsonqga/qapi-schema.json +6
-0@@ -1042,3 +1042,25 @@ 'data': { 'path': 'str', '*arg': ['str'], '*env': ['str'], '*input-data': 'str', '*capture-output': 'bool' }, 'returns': 'GuestExec' } + +## +# @GuestUser: +# @user: Username +# @domain: Logon domain (windows only) +# @login-time: Unix timestamp of login
In what unit? (Fractional) seconds since 1 Jan 1970?
So this is when they connected, and not a duration of how long they have been logged on since then.
Quoted 7 lines
qga/qapi-schema.json +6
-0+# +# Since: 2.10 +## +{ 'struct': 'GuestUser', + 'data': { 'user': 'str', 'login-time': 'number', '*domain': 'str' } } +
qga/qapi-schema.json line 1066
Quoted 10 lines
qga/qapi-schema.json +10
-0+## +# @guest-get-users: +# Retrieves a list of currently active users on the VM. +# +# Returns: A unique list of users. +# +# Since: 2.10 +## +{ 'command': 'guest-get-users', + 'returns': ['GuestUser'] }
The API looks good once you add that additional documentation.
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org