mirror of https://github.com/xemu-project/xemu.git
qga-pull-2023-07-10
-----BEGIN PGP SIGNATURE----- iQIzBAABCgAdFiEEwsLBCepDxjwUI+uE711egWG6hOcFAmSsBN8ACgkQ711egWG6 hOfGzw/9HJl1sQQQWO/Nv3HOtiC7Nnk3d06Wx8nC3d3L4fyDDsyCm1gBQK2YX6x5 jlDCwgf28DoSDgvznyRvoUrDaQ4QBwcd2Xc5ukQRxZ4K2zEfWjp/NI7AWzUxQ2ID G1dAWrnY94qm8vkkjAV6ABpDZNMWQlahwcABG8S5rFWaIqv+TSsFD9qRbrcA/LsJ hKbcGSuWEzQSYcFD4ctGbQP4JgQQOO5Yk/3S7PO0+j/04vaYoers/9ZhRc8WhxGs WAqxMdmUMcuYU0VkDLRVaGfJ5TrlHqm/iHz9UnTNbWekGjeNiEMyGN3shWCKN2AE mMXU2zd74dBdMhwIzSlz7MW0XuX3TLrI3DZ9W7lY+8FfafQi8Dd2FPfPdKNDhEp0 NQ8N/W6LAXPkVWci3uSvw50K+Q0svWee6mZV3qI6DbD1a8dRKvlFvvL7FCvHt8eF 7YIHanJEzHbday31dhaRBBDn0EehBsFiJVImyfKBrMxGPfhTva+rH4KWKIW2pGfU 3Sqk3KJ+c0Byh1Rkv6LTeYQSUV4x/fwve/EnvBhau1CyuoFSR0/Eoyqzi3aX3koL Ord9BUGgmEc3TzDj0LhonEWnlWmNcUm/ck9dZTkYcDWyLLaArJ5pW9iUU9eh9Vx/ 56r3/Jyz4QM6CjFmWWGEsEFMrM0wMGxl9JQKRcc39Eo2GpgWtuI= =zeI3 -----END PGP SIGNATURE----- Merge tag 'qga-pull-2023-07-10' of https://github.com/kostyanf14/qemu into staging qga-pull-2023-07-10 # -----BEGIN PGP SIGNATURE----- # # iQIzBAABCgAdFiEEwsLBCepDxjwUI+uE711egWG6hOcFAmSsBN8ACgkQ711egWG6 # hOfGzw/9HJl1sQQQWO/Nv3HOtiC7Nnk3d06Wx8nC3d3L4fyDDsyCm1gBQK2YX6x5 # jlDCwgf28DoSDgvznyRvoUrDaQ4QBwcd2Xc5ukQRxZ4K2zEfWjp/NI7AWzUxQ2ID # G1dAWrnY94qm8vkkjAV6ABpDZNMWQlahwcABG8S5rFWaIqv+TSsFD9qRbrcA/LsJ # hKbcGSuWEzQSYcFD4ctGbQP4JgQQOO5Yk/3S7PO0+j/04vaYoers/9ZhRc8WhxGs # WAqxMdmUMcuYU0VkDLRVaGfJ5TrlHqm/iHz9UnTNbWekGjeNiEMyGN3shWCKN2AE # mMXU2zd74dBdMhwIzSlz7MW0XuX3TLrI3DZ9W7lY+8FfafQi8Dd2FPfPdKNDhEp0 # NQ8N/W6LAXPkVWci3uSvw50K+Q0svWee6mZV3qI6DbD1a8dRKvlFvvL7FCvHt8eF # 7YIHanJEzHbday31dhaRBBDn0EehBsFiJVImyfKBrMxGPfhTva+rH4KWKIW2pGfU # 3Sqk3KJ+c0Byh1Rkv6LTeYQSUV4x/fwve/EnvBhau1CyuoFSR0/Eoyqzi3aX3koL # Ord9BUGgmEc3TzDj0LhonEWnlWmNcUm/ck9dZTkYcDWyLLaArJ5pW9iUU9eh9Vx/ # 56r3/Jyz4QM6CjFmWWGEsEFMrM0wMGxl9JQKRcc39Eo2GpgWtuI= # =zeI3 # -----END PGP SIGNATURE----- # gpg: Signature made Mon 10 Jul 2023 02:17:19 PM BST # gpg: using RSA key C2C2C109EA43C63C1423EB84EF5D5E8161BA84E7 # gpg: Good signature from "Kostiantyn Kostiuk (Upstream PR sign) <kkostiuk@redhat.com>" [unknown] # gpg: WARNING: This key is not certified with a trusted signature! # gpg: There is no indication that the signature belongs to the owner. # Primary key fingerprint: C2C2 C109 EA43 C63C 1423 EB84 EF5D 5E81 61BA 84E7 * tag 'qga-pull-2023-07-10' of https://github.com/kostyanf14/qemu: QGA VSS: Add log in functions begin/end QGA VSS: Print error in err_set QGA VSS: Replace 'fprintf(stderr' with qga_debug QGA VSS: Add wrapper to send log to debugger and stderr qga: Add tests for --allow-rpcs option qga: Add new option --allow-rpcs qga: Rename ga_disable_not_allowed -> ga_disable_not_allowed_freeze Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
This commit is contained in:
commit
adc97c4b80
|
@ -84,6 +84,11 @@ Options
|
||||||
Comma-separated list of RPCs to disable (no spaces, use ``help`` to
|
Comma-separated list of RPCs to disable (no spaces, use ``help`` to
|
||||||
list available RPCs).
|
list available RPCs).
|
||||||
|
|
||||||
|
.. option:: -a, --allow-rpcs=LIST
|
||||||
|
|
||||||
|
Comma-separated list of RPCs to enable (no spaces, use ``help`` to
|
||||||
|
list available RPCs).
|
||||||
|
|
||||||
.. option:: -D, --dump-conf
|
.. option:: -D, --dump-conf
|
||||||
|
|
||||||
Dump the configuration in a format compatible with ``qemu-ga.conf``
|
Dump the configuration in a format compatible with ``qemu-ga.conf``
|
||||||
|
|
91
qga/main.c
91
qga/main.c
|
@ -87,6 +87,7 @@ struct GAState {
|
||||||
bool delimit_response;
|
bool delimit_response;
|
||||||
bool frozen;
|
bool frozen;
|
||||||
GList *blockedrpcs;
|
GList *blockedrpcs;
|
||||||
|
GList *allowedrpcs;
|
||||||
char *state_filepath_isfrozen;
|
char *state_filepath_isfrozen;
|
||||||
struct {
|
struct {
|
||||||
const char *log_filepath;
|
const char *log_filepath;
|
||||||
|
@ -261,6 +262,8 @@ QEMU_COPYRIGHT "\n"
|
||||||
#endif
|
#endif
|
||||||
" -b, --block-rpcs comma-separated list of RPCs to disable (no spaces,\n"
|
" -b, --block-rpcs comma-separated list of RPCs to disable (no spaces,\n"
|
||||||
" use \"help\" to list available RPCs)\n"
|
" use \"help\" to list available RPCs)\n"
|
||||||
|
" -a, --allow-rpcs comma-separated list of RPCs to enable (no spaces,\n"
|
||||||
|
" use \"help\" to list available RPCs)\n"
|
||||||
" -D, --dump-conf dump a qemu-ga config file based on current config\n"
|
" -D, --dump-conf dump a qemu-ga config file based on current config\n"
|
||||||
" options / command-line parameters to stdout\n"
|
" options / command-line parameters to stdout\n"
|
||||||
" -r, --retry-path attempt re-opening path if it's unavailable or closed\n"
|
" -r, --retry-path attempt re-opening path if it's unavailable or closed\n"
|
||||||
|
@ -395,7 +398,7 @@ static gint ga_strcmp(gconstpointer str1, gconstpointer str2)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* disable commands that aren't safe for fsfreeze */
|
/* disable commands that aren't safe for fsfreeze */
|
||||||
static void ga_disable_not_allowed(const QmpCommand *cmd, void *opaque)
|
static void ga_disable_not_allowed_freeze(const QmpCommand *cmd, void *opaque)
|
||||||
{
|
{
|
||||||
bool allowed = false;
|
bool allowed = false;
|
||||||
int i = 0;
|
int i = 0;
|
||||||
|
@ -416,16 +419,38 @@ static void ga_disable_not_allowed(const QmpCommand *cmd, void *opaque)
|
||||||
/* [re-]enable all commands, except those explicitly blocked by user */
|
/* [re-]enable all commands, except those explicitly blocked by user */
|
||||||
static void ga_enable_non_blocked(const QmpCommand *cmd, void *opaque)
|
static void ga_enable_non_blocked(const QmpCommand *cmd, void *opaque)
|
||||||
{
|
{
|
||||||
GList *blockedrpcs = opaque;
|
GAState *s = opaque;
|
||||||
|
GList *blockedrpcs = s->blockedrpcs;
|
||||||
|
GList *allowedrpcs = s->allowedrpcs;
|
||||||
const char *name = qmp_command_name(cmd);
|
const char *name = qmp_command_name(cmd);
|
||||||
|
|
||||||
if (g_list_find_custom(blockedrpcs, name, ga_strcmp) == NULL &&
|
if (g_list_find_custom(blockedrpcs, name, ga_strcmp) == NULL) {
|
||||||
!qmp_command_is_enabled(cmd)) {
|
if (qmp_command_is_enabled(cmd)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (allowedrpcs &&
|
||||||
|
g_list_find_custom(allowedrpcs, name, ga_strcmp) == NULL) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
g_debug("enabling command: %s", name);
|
g_debug("enabling command: %s", name);
|
||||||
qmp_enable_command(&ga_commands, name);
|
qmp_enable_command(&ga_commands, name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* disable commands that aren't allowed */
|
||||||
|
static void ga_disable_not_allowed(const QmpCommand *cmd, void *opaque)
|
||||||
|
{
|
||||||
|
GList *allowedrpcs = opaque;
|
||||||
|
const char *name = qmp_command_name(cmd);
|
||||||
|
|
||||||
|
if (g_list_find_custom(allowedrpcs, name, ga_strcmp) == NULL) {
|
||||||
|
g_debug("disabling command: %s", name);
|
||||||
|
qmp_disable_command(&ga_commands, name, "the command is not allowed");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static bool ga_create_file(const char *path)
|
static bool ga_create_file(const char *path)
|
||||||
{
|
{
|
||||||
int fd = open(path, O_CREAT | O_WRONLY, S_IWUSR | S_IRUSR);
|
int fd = open(path, O_CREAT | O_WRONLY, S_IWUSR | S_IRUSR);
|
||||||
|
@ -459,7 +484,7 @@ void ga_set_frozen(GAState *s)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
/* disable all forbidden (for frozen state) commands */
|
/* disable all forbidden (for frozen state) commands */
|
||||||
qmp_for_each_command(&ga_commands, ga_disable_not_allowed, NULL);
|
qmp_for_each_command(&ga_commands, ga_disable_not_allowed_freeze, NULL);
|
||||||
g_warning("disabling logging due to filesystem freeze");
|
g_warning("disabling logging due to filesystem freeze");
|
||||||
ga_disable_logging(s);
|
ga_disable_logging(s);
|
||||||
s->frozen = true;
|
s->frozen = true;
|
||||||
|
@ -497,8 +522,8 @@ void ga_unset_frozen(GAState *s)
|
||||||
s->deferred_options.pid_filepath = NULL;
|
s->deferred_options.pid_filepath = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* enable all disabled, non-blocked commands */
|
/* enable all disabled, non-blocked and allowed commands */
|
||||||
qmp_for_each_command(&ga_commands, ga_enable_non_blocked, s->blockedrpcs);
|
qmp_for_each_command(&ga_commands, ga_enable_non_blocked, s);
|
||||||
s->frozen = false;
|
s->frozen = false;
|
||||||
if (!ga_delete_file(s->state_filepath_isfrozen)) {
|
if (!ga_delete_file(s->state_filepath_isfrozen)) {
|
||||||
g_warning("unable to delete %s, fsfreeze may not function properly",
|
g_warning("unable to delete %s, fsfreeze may not function properly",
|
||||||
|
@ -984,7 +1009,9 @@ struct GAConfig {
|
||||||
const char *service;
|
const char *service;
|
||||||
#endif
|
#endif
|
||||||
gchar *bliststr; /* blockedrpcs may point to this string */
|
gchar *bliststr; /* blockedrpcs may point to this string */
|
||||||
|
gchar *aliststr; /* allowedrpcs may point to this string */
|
||||||
GList *blockedrpcs;
|
GList *blockedrpcs;
|
||||||
|
GList *allowedrpcs;
|
||||||
int daemonize;
|
int daemonize;
|
||||||
GLogLevelFlags log_level;
|
GLogLevelFlags log_level;
|
||||||
int dumpconf;
|
int dumpconf;
|
||||||
|
@ -1055,6 +1082,19 @@ static void config_load(GAConfig *config)
|
||||||
config->blockedrpcs = g_list_concat(config->blockedrpcs,
|
config->blockedrpcs = g_list_concat(config->blockedrpcs,
|
||||||
split_list(config->bliststr, ","));
|
split_list(config->bliststr, ","));
|
||||||
}
|
}
|
||||||
|
if (g_key_file_has_key(keyfile, "general", "allow-rpcs", NULL)) {
|
||||||
|
config->aliststr =
|
||||||
|
g_key_file_get_string(keyfile, "general", "allow-rpcs", &gerr);
|
||||||
|
config->allowedrpcs = g_list_concat(config->allowedrpcs,
|
||||||
|
split_list(config->aliststr, ","));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (g_key_file_has_key(keyfile, "general", blockrpcs_key, NULL) &&
|
||||||
|
g_key_file_has_key(keyfile, "general", "allow-rpcs", NULL)) {
|
||||||
|
g_critical("wrong config, using 'block-rpcs' and 'allow-rpcs' keys at"
|
||||||
|
" the same time is not allowed");
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
|
||||||
end:
|
end:
|
||||||
g_key_file_free(keyfile);
|
g_key_file_free(keyfile);
|
||||||
|
@ -1115,6 +1155,9 @@ static void config_dump(GAConfig *config)
|
||||||
tmp = list_join(config->blockedrpcs, ',');
|
tmp = list_join(config->blockedrpcs, ',');
|
||||||
g_key_file_set_string(keyfile, "general", "block-rpcs", tmp);
|
g_key_file_set_string(keyfile, "general", "block-rpcs", tmp);
|
||||||
g_free(tmp);
|
g_free(tmp);
|
||||||
|
tmp = list_join(config->allowedrpcs, ',');
|
||||||
|
g_key_file_set_string(keyfile, "general", "allow-rpcs", tmp);
|
||||||
|
g_free(tmp);
|
||||||
|
|
||||||
tmp = g_key_file_to_data(keyfile, NULL, &error);
|
tmp = g_key_file_to_data(keyfile, NULL, &error);
|
||||||
if (error) {
|
if (error) {
|
||||||
|
@ -1130,8 +1173,9 @@ static void config_dump(GAConfig *config)
|
||||||
|
|
||||||
static void config_parse(GAConfig *config, int argc, char **argv)
|
static void config_parse(GAConfig *config, int argc, char **argv)
|
||||||
{
|
{
|
||||||
const char *sopt = "hVvdm:p:l:f:F::b:s:t:Dr";
|
const char *sopt = "hVvdm:p:l:f:F::b:a:s:t:Dr";
|
||||||
int opt_ind = 0, ch;
|
int opt_ind = 0, ch;
|
||||||
|
bool block_rpcs = false, allow_rpcs = false;
|
||||||
const struct option lopt[] = {
|
const struct option lopt[] = {
|
||||||
{ "help", 0, NULL, 'h' },
|
{ "help", 0, NULL, 'h' },
|
||||||
{ "version", 0, NULL, 'V' },
|
{ "version", 0, NULL, 'V' },
|
||||||
|
@ -1147,6 +1191,7 @@ static void config_parse(GAConfig *config, int argc, char **argv)
|
||||||
{ "daemonize", 0, NULL, 'd' },
|
{ "daemonize", 0, NULL, 'd' },
|
||||||
{ "block-rpcs", 1, NULL, 'b' },
|
{ "block-rpcs", 1, NULL, 'b' },
|
||||||
{ "blacklist", 1, NULL, 'b' }, /* deprecated alias for 'block-rpcs' */
|
{ "blacklist", 1, NULL, 'b' }, /* deprecated alias for 'block-rpcs' */
|
||||||
|
{ "allow-rpcs", 1, NULL, 'a' },
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
{ "service", 1, NULL, 's' },
|
{ "service", 1, NULL, 's' },
|
||||||
#endif
|
#endif
|
||||||
|
@ -1206,6 +1251,17 @@ static void config_parse(GAConfig *config, int argc, char **argv)
|
||||||
}
|
}
|
||||||
config->blockedrpcs = g_list_concat(config->blockedrpcs,
|
config->blockedrpcs = g_list_concat(config->blockedrpcs,
|
||||||
split_list(optarg, ","));
|
split_list(optarg, ","));
|
||||||
|
block_rpcs = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case 'a': {
|
||||||
|
if (is_help_option(optarg)) {
|
||||||
|
qmp_for_each_command(&ga_commands, ga_print_cmd, NULL);
|
||||||
|
exit(EXIT_SUCCESS);
|
||||||
|
}
|
||||||
|
config->allowedrpcs = g_list_concat(config->allowedrpcs,
|
||||||
|
split_list(optarg, ","));
|
||||||
|
allow_rpcs = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
|
@ -1246,6 +1302,12 @@ static void config_parse(GAConfig *config, int argc, char **argv)
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (block_rpcs && allow_rpcs) {
|
||||||
|
g_critical("wrong commandline, using --block-rpcs and --allow-rpcs at the"
|
||||||
|
" same time is not allowed");
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void config_free(GAConfig *config)
|
static void config_free(GAConfig *config)
|
||||||
|
@ -1256,10 +1318,12 @@ static void config_free(GAConfig *config)
|
||||||
g_free(config->state_dir);
|
g_free(config->state_dir);
|
||||||
g_free(config->channel_path);
|
g_free(config->channel_path);
|
||||||
g_free(config->bliststr);
|
g_free(config->bliststr);
|
||||||
|
g_free(config->aliststr);
|
||||||
#ifdef CONFIG_FSFREEZE
|
#ifdef CONFIG_FSFREEZE
|
||||||
g_free(config->fsfreeze_hook);
|
g_free(config->fsfreeze_hook);
|
||||||
#endif
|
#endif
|
||||||
g_list_free_full(config->blockedrpcs, g_free);
|
g_list_free_full(config->blockedrpcs, g_free);
|
||||||
|
g_list_free_full(config->allowedrpcs, g_free);
|
||||||
g_free(config);
|
g_free(config);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1350,7 +1414,7 @@ static GAState *initialize_agent(GAConfig *config, int socket_activation)
|
||||||
s->deferred_options.log_filepath = config->log_filepath;
|
s->deferred_options.log_filepath = config->log_filepath;
|
||||||
}
|
}
|
||||||
ga_disable_logging(s);
|
ga_disable_logging(s);
|
||||||
qmp_for_each_command(&ga_commands, ga_disable_not_allowed, NULL);
|
qmp_for_each_command(&ga_commands, ga_disable_not_allowed_freeze, NULL);
|
||||||
} else {
|
} else {
|
||||||
if (config->daemonize) {
|
if (config->daemonize) {
|
||||||
become_daemon(config->pid_filepath);
|
become_daemon(config->pid_filepath);
|
||||||
|
@ -1374,6 +1438,15 @@ static GAState *initialize_agent(GAConfig *config, int socket_activation)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (config->allowedrpcs) {
|
||||||
|
qmp_for_each_command(&ga_commands, ga_disable_not_allowed, config->allowedrpcs);
|
||||||
|
s->allowedrpcs = config->allowedrpcs;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Some commands can be blocked due to system limitation.
|
||||||
|
* Initialize blockedrpcs list even if allowedrpcs specified.
|
||||||
|
*/
|
||||||
config->blockedrpcs = ga_command_init_blockedrpcs(config->blockedrpcs);
|
config->blockedrpcs = ga_command_init_blockedrpcs(config->blockedrpcs);
|
||||||
if (config->blockedrpcs) {
|
if (config->blockedrpcs) {
|
||||||
GList *l = config->blockedrpcs;
|
GList *l = config->blockedrpcs;
|
||||||
|
|
|
@ -13,6 +13,7 @@
|
||||||
#include "qemu/osdep.h"
|
#include "qemu/osdep.h"
|
||||||
|
|
||||||
#include "vss-common.h"
|
#include "vss-common.h"
|
||||||
|
#include "vss-debug.h"
|
||||||
#ifdef HAVE_VSS_SDK
|
#ifdef HAVE_VSS_SDK
|
||||||
#include <vscoordint.h>
|
#include <vscoordint.h>
|
||||||
#else
|
#else
|
||||||
|
@ -54,7 +55,7 @@ void errmsg(DWORD err, const char *text)
|
||||||
FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
|
FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
|
||||||
NULL, err, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
|
NULL, err, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
|
||||||
(char *)&msg, 0, NULL);
|
(char *)&msg, 0, NULL);
|
||||||
fprintf(stderr, "%.*s. (Error: %lx) %s\n", len, text, err, msg);
|
qga_debug("%.*s. (Error: %lx) %s", len, text, err, msg);
|
||||||
LocalFree(msg);
|
LocalFree(msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -99,6 +100,8 @@ HRESULT put_Value(ICatalogObject *pObj, LPCWSTR name, T val)
|
||||||
/* Lookup Administrators group name from winmgmt */
|
/* Lookup Administrators group name from winmgmt */
|
||||||
static HRESULT GetAdminName(_bstr_t *name)
|
static HRESULT GetAdminName(_bstr_t *name)
|
||||||
{
|
{
|
||||||
|
qga_debug_begin;
|
||||||
|
|
||||||
HRESULT hr;
|
HRESULT hr;
|
||||||
COMPointer<IWbemLocator> pLoc;
|
COMPointer<IWbemLocator> pLoc;
|
||||||
COMPointer<IWbemServices> pSvc;
|
COMPointer<IWbemServices> pSvc;
|
||||||
|
@ -141,6 +144,7 @@ static HRESULT GetAdminName(_bstr_t *name)
|
||||||
}
|
}
|
||||||
|
|
||||||
out:
|
out:
|
||||||
|
qga_debug_end;
|
||||||
return hr;
|
return hr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -148,6 +152,8 @@ out:
|
||||||
static HRESULT getNameByStringSID(
|
static HRESULT getNameByStringSID(
|
||||||
const wchar_t *sid, LPWSTR buffer, LPDWORD bufferLen)
|
const wchar_t *sid, LPWSTR buffer, LPDWORD bufferLen)
|
||||||
{
|
{
|
||||||
|
qga_debug_begin;
|
||||||
|
|
||||||
HRESULT hr = S_OK;
|
HRESULT hr = S_OK;
|
||||||
PSID psid = NULL;
|
PSID psid = NULL;
|
||||||
SID_NAME_USE groupType;
|
SID_NAME_USE groupType;
|
||||||
|
@ -167,6 +173,7 @@ static HRESULT getNameByStringSID(
|
||||||
LocalFree(psid);
|
LocalFree(psid);
|
||||||
|
|
||||||
out:
|
out:
|
||||||
|
qga_debug_end;
|
||||||
return hr;
|
return hr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -174,6 +181,8 @@ out:
|
||||||
static HRESULT QGAProviderFind(
|
static HRESULT QGAProviderFind(
|
||||||
HRESULT (*found)(ICatalogCollection *, int, void *), void *arg)
|
HRESULT (*found)(ICatalogCollection *, int, void *), void *arg)
|
||||||
{
|
{
|
||||||
|
qga_debug_begin;
|
||||||
|
|
||||||
HRESULT hr;
|
HRESULT hr;
|
||||||
COMInitializer initializer;
|
COMInitializer initializer;
|
||||||
COMPointer<IUnknown> pUnknown;
|
COMPointer<IUnknown> pUnknown;
|
||||||
|
@ -204,41 +213,53 @@ static HRESULT QGAProviderFind(
|
||||||
chk(pColl->SaveChanges(&n));
|
chk(pColl->SaveChanges(&n));
|
||||||
|
|
||||||
out:
|
out:
|
||||||
|
qga_debug_end;
|
||||||
return hr;
|
return hr;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Count QGA VSS provider in COM+ Application Catalog */
|
/* Count QGA VSS provider in COM+ Application Catalog */
|
||||||
static HRESULT QGAProviderCount(ICatalogCollection *coll, int i, void *arg)
|
static HRESULT QGAProviderCount(ICatalogCollection *coll, int i, void *arg)
|
||||||
{
|
{
|
||||||
|
qga_debug_begin;
|
||||||
|
|
||||||
(*(int *)arg)++;
|
(*(int *)arg)++;
|
||||||
|
|
||||||
|
qga_debug_end;
|
||||||
return S_OK;
|
return S_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Remove QGA VSS provider from COM+ Application Catalog Collection */
|
/* Remove QGA VSS provider from COM+ Application Catalog Collection */
|
||||||
static HRESULT QGAProviderRemove(ICatalogCollection *coll, int i, void *arg)
|
static HRESULT QGAProviderRemove(ICatalogCollection *coll, int i, void *arg)
|
||||||
{
|
{
|
||||||
|
qga_debug_begin;
|
||||||
HRESULT hr;
|
HRESULT hr;
|
||||||
|
|
||||||
fprintf(stderr, "Removing COM+ Application: %s\n", QGA_PROVIDER_NAME);
|
qga_debug("Removing COM+ Application: %s", QGA_PROVIDER_NAME);
|
||||||
chk(coll->Remove(i));
|
chk(coll->Remove(i));
|
||||||
out:
|
out:
|
||||||
|
qga_debug_end;
|
||||||
return hr;
|
return hr;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Unregister this module from COM+ Applications Catalog */
|
/* Unregister this module from COM+ Applications Catalog */
|
||||||
STDAPI COMUnregister(void)
|
STDAPI COMUnregister(void)
|
||||||
{
|
{
|
||||||
|
qga_debug_begin;
|
||||||
|
|
||||||
HRESULT hr;
|
HRESULT hr;
|
||||||
|
|
||||||
DllUnregisterServer();
|
DllUnregisterServer();
|
||||||
chk(QGAProviderFind(QGAProviderRemove, NULL));
|
chk(QGAProviderFind(QGAProviderRemove, NULL));
|
||||||
out:
|
out:
|
||||||
|
qga_debug_end;
|
||||||
return hr;
|
return hr;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Register this module to COM+ Applications Catalog */
|
/* Register this module to COM+ Applications Catalog */
|
||||||
STDAPI COMRegister(void)
|
STDAPI COMRegister(void)
|
||||||
{
|
{
|
||||||
|
qga_debug_begin;
|
||||||
|
|
||||||
HRESULT hr;
|
HRESULT hr;
|
||||||
COMInitializer initializer;
|
COMInitializer initializer;
|
||||||
COMPointer<IUnknown> pUnknown;
|
COMPointer<IUnknown> pUnknown;
|
||||||
|
@ -258,12 +279,14 @@ STDAPI COMRegister(void)
|
||||||
|
|
||||||
if (!g_hinstDll) {
|
if (!g_hinstDll) {
|
||||||
errmsg(E_FAIL, "Failed to initialize DLL");
|
errmsg(E_FAIL, "Failed to initialize DLL");
|
||||||
|
qga_debug_end;
|
||||||
return E_FAIL;
|
return E_FAIL;
|
||||||
}
|
}
|
||||||
|
|
||||||
chk(QGAProviderFind(QGAProviderCount, (void *)&count));
|
chk(QGAProviderFind(QGAProviderCount, (void *)&count));
|
||||||
if (count) {
|
if (count) {
|
||||||
errmsg(E_ABORT, "QGA VSS Provider is already installed");
|
errmsg(E_ABORT, "QGA VSS Provider is already installed");
|
||||||
|
qga_debug_end;
|
||||||
return E_ABORT;
|
return E_ABORT;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -304,9 +327,8 @@ STDAPI COMRegister(void)
|
||||||
}
|
}
|
||||||
strcpy(tlbPath, dllPath);
|
strcpy(tlbPath, dllPath);
|
||||||
strcpy(tlbPath+n-3, "tlb");
|
strcpy(tlbPath+n-3, "tlb");
|
||||||
fprintf(stderr, "Registering " QGA_PROVIDER_NAME ":\n");
|
qga_debug("Registering " QGA_PROVIDER_NAME ": %s %s",
|
||||||
fprintf(stderr, " %s\n", dllPath);
|
dllPath, tlbPath);
|
||||||
fprintf(stderr, " %s\n", tlbPath);
|
|
||||||
if (!PathFileExists(tlbPath)) {
|
if (!PathFileExists(tlbPath)) {
|
||||||
hr = HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND);
|
hr = HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND);
|
||||||
errmsg(hr, "Failed to lookup tlb");
|
errmsg(hr, "Failed to lookup tlb");
|
||||||
|
@ -354,6 +376,7 @@ out:
|
||||||
COMUnregister();
|
COMUnregister();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
qga_debug_end;
|
||||||
return hr;
|
return hr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -369,6 +392,8 @@ STDAPI_(void) CALLBACK DLLCOMUnregister(HWND, HINSTANCE, LPSTR, int)
|
||||||
|
|
||||||
static BOOL CreateRegistryKey(LPCTSTR key, LPCTSTR value, LPCTSTR data)
|
static BOOL CreateRegistryKey(LPCTSTR key, LPCTSTR value, LPCTSTR data)
|
||||||
{
|
{
|
||||||
|
qga_debug_begin;
|
||||||
|
|
||||||
HKEY hKey;
|
HKEY hKey;
|
||||||
LONG ret;
|
LONG ret;
|
||||||
DWORD size;
|
DWORD size;
|
||||||
|
@ -389,6 +414,7 @@ static BOOL CreateRegistryKey(LPCTSTR key, LPCTSTR value, LPCTSTR data)
|
||||||
RegCloseKey(hKey);
|
RegCloseKey(hKey);
|
||||||
|
|
||||||
out:
|
out:
|
||||||
|
qga_debug_end;
|
||||||
if (ret != ERROR_SUCCESS) {
|
if (ret != ERROR_SUCCESS) {
|
||||||
/* As we cannot printf within DllRegisterServer(), show a dialog. */
|
/* As we cannot printf within DllRegisterServer(), show a dialog. */
|
||||||
errmsg_dialog(ret, "Cannot add registry", key);
|
errmsg_dialog(ret, "Cannot add registry", key);
|
||||||
|
@ -400,6 +426,8 @@ out:
|
||||||
/* Register this dll as a VSS provider */
|
/* Register this dll as a VSS provider */
|
||||||
STDAPI DllRegisterServer(void)
|
STDAPI DllRegisterServer(void)
|
||||||
{
|
{
|
||||||
|
qga_debug_begin;
|
||||||
|
|
||||||
COMInitializer initializer;
|
COMInitializer initializer;
|
||||||
COMPointer<IVssAdmin> pVssAdmin;
|
COMPointer<IVssAdmin> pVssAdmin;
|
||||||
HRESULT hr = E_FAIL;
|
HRESULT hr = E_FAIL;
|
||||||
|
@ -478,12 +506,15 @@ out:
|
||||||
DllUnregisterServer();
|
DllUnregisterServer();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
qga_debug_end;
|
||||||
return hr;
|
return hr;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Unregister this VSS hardware provider from the system */
|
/* Unregister this VSS hardware provider from the system */
|
||||||
STDAPI DllUnregisterServer(void)
|
STDAPI DllUnregisterServer(void)
|
||||||
{
|
{
|
||||||
|
qga_debug_begin;
|
||||||
|
|
||||||
TCHAR key[256];
|
TCHAR key[256];
|
||||||
COMInitializer initializer;
|
COMInitializer initializer;
|
||||||
COMPointer<IVssAdmin> pVssAdmin;
|
COMPointer<IVssAdmin> pVssAdmin;
|
||||||
|
@ -501,6 +532,7 @@ STDAPI DllUnregisterServer(void)
|
||||||
SHDeleteKey(HKEY_CLASSES_ROOT, key);
|
SHDeleteKey(HKEY_CLASSES_ROOT, key);
|
||||||
SHDeleteKey(HKEY_CLASSES_ROOT, g_szProgid);
|
SHDeleteKey(HKEY_CLASSES_ROOT, g_szProgid);
|
||||||
|
|
||||||
|
qga_debug_end;
|
||||||
return S_OK; /* Uninstall should never fail */
|
return S_OK; /* Uninstall should never fail */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -517,7 +549,7 @@ namespace _com_util
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mbstowcs(bstr, ascii, len) == (size_t)-1) {
|
if (mbstowcs(bstr, ascii, len) == (size_t)-1) {
|
||||||
fprintf(stderr, "Failed to convert string '%s' into BSTR", ascii);
|
qga_debug("Failed to convert string '%s' into BSTR", ascii);
|
||||||
bstr[0] = 0;
|
bstr[0] = 0;
|
||||||
}
|
}
|
||||||
return bstr;
|
return bstr;
|
||||||
|
@ -527,6 +559,8 @@ namespace _com_util
|
||||||
/* Stop QGA VSS provider service using Winsvc API */
|
/* Stop QGA VSS provider service using Winsvc API */
|
||||||
STDAPI StopService(void)
|
STDAPI StopService(void)
|
||||||
{
|
{
|
||||||
|
qga_debug_begin;
|
||||||
|
|
||||||
HRESULT hr = S_OK;
|
HRESULT hr = S_OK;
|
||||||
SC_HANDLE manager = OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS);
|
SC_HANDLE manager = OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS);
|
||||||
SC_HANDLE service = NULL;
|
SC_HANDLE service = NULL;
|
||||||
|
@ -551,5 +585,6 @@ STDAPI StopService(void)
|
||||||
out:
|
out:
|
||||||
CloseServiceHandle(service);
|
CloseServiceHandle(service);
|
||||||
CloseServiceHandle(manager);
|
CloseServiceHandle(manager);
|
||||||
|
qga_debug_end;
|
||||||
return hr;
|
return hr;
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,7 +7,7 @@ link_args = cc.get_supported_link_arguments([
|
||||||
|
|
||||||
qga_vss = shared_module(
|
qga_vss = shared_module(
|
||||||
'qga-vss',
|
'qga-vss',
|
||||||
['requester.cpp', 'provider.cpp', 'install.cpp', genh],
|
['requester.cpp', 'provider.cpp', 'install.cpp', 'vss-debug.cpp', genh],
|
||||||
name_prefix: '',
|
name_prefix: '',
|
||||||
cpp_args: ['-Wno-unknown-pragmas', '-Wno-delete-non-virtual-dtor', '-Wno-non-virtual-dtor'],
|
cpp_args: ['-Wno-unknown-pragmas', '-Wno-delete-non-virtual-dtor', '-Wno-non-virtual-dtor'],
|
||||||
link_args: link_args,
|
link_args: link_args,
|
||||||
|
|
|
@ -12,6 +12,7 @@
|
||||||
|
|
||||||
#include "qemu/osdep.h"
|
#include "qemu/osdep.h"
|
||||||
#include "vss-common.h"
|
#include "vss-common.h"
|
||||||
|
#include "vss-debug.h"
|
||||||
#ifdef HAVE_VSS_SDK
|
#ifdef HAVE_VSS_SDK
|
||||||
#include <vscoordint.h>
|
#include <vscoordint.h>
|
||||||
#else
|
#else
|
||||||
|
@ -529,9 +530,11 @@ STDAPI DllCanUnloadNow()
|
||||||
EXTERN_C
|
EXTERN_C
|
||||||
BOOL WINAPI DllMain(HINSTANCE hinstDll, DWORD dwReason, LPVOID lpReserved)
|
BOOL WINAPI DllMain(HINSTANCE hinstDll, DWORD dwReason, LPVOID lpReserved)
|
||||||
{
|
{
|
||||||
|
qga_debug("begin, reason = %lu", dwReason);
|
||||||
if (dwReason == DLL_PROCESS_ATTACH) {
|
if (dwReason == DLL_PROCESS_ATTACH) {
|
||||||
g_hinstDll = hinstDll;
|
g_hinstDll = hinstDll;
|
||||||
DisableThreadLibraryCalls(hinstDll);
|
DisableThreadLibraryCalls(hinstDll);
|
||||||
}
|
}
|
||||||
|
qga_debug_end;
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,6 +12,7 @@
|
||||||
|
|
||||||
#include "qemu/osdep.h"
|
#include "qemu/osdep.h"
|
||||||
#include "vss-common.h"
|
#include "vss-common.h"
|
||||||
|
#include "vss-debug.h"
|
||||||
#include "requester.h"
|
#include "requester.h"
|
||||||
#include "install.h"
|
#include "install.h"
|
||||||
#include <vswriter.h>
|
#include <vswriter.h>
|
||||||
|
@ -25,9 +26,11 @@
|
||||||
|
|
||||||
#define DEFAULT_VSS_BACKUP_TYPE VSS_BT_FULL
|
#define DEFAULT_VSS_BACKUP_TYPE VSS_BT_FULL
|
||||||
|
|
||||||
#define err_set(e, err, fmt, ...) \
|
#define err_set(e, err, fmt, ...) { \
|
||||||
((e)->error_setg_win32_wrapper((e)->errp, __FILE__, __LINE__, __func__, \
|
(e)->error_setg_win32_wrapper((e)->errp, __FILE__, __LINE__, __func__, \
|
||||||
err, fmt, ## __VA_ARGS__))
|
err, fmt, ## __VA_ARGS__); \
|
||||||
|
qga_debug(fmt, ## __VA_ARGS__); \
|
||||||
|
}
|
||||||
/* Bad idea, works only when (e)->errp != NULL: */
|
/* Bad idea, works only when (e)->errp != NULL: */
|
||||||
#define err_is_set(e) ((e)->errp && *(e)->errp)
|
#define err_is_set(e) ((e)->errp && *(e)->errp)
|
||||||
/* To lift this restriction, error_propagate(), like we do in QEMU code */
|
/* To lift this restriction, error_propagate(), like we do in QEMU code */
|
||||||
|
@ -54,18 +57,20 @@ static struct QGAVSSContext {
|
||||||
|
|
||||||
STDAPI requester_init(void)
|
STDAPI requester_init(void)
|
||||||
{
|
{
|
||||||
|
qga_debug_begin;
|
||||||
|
|
||||||
COMInitializer initializer; /* to call CoInitializeSecurity */
|
COMInitializer initializer; /* to call CoInitializeSecurity */
|
||||||
HRESULT hr = CoInitializeSecurity(
|
HRESULT hr = CoInitializeSecurity(
|
||||||
NULL, -1, NULL, NULL, RPC_C_AUTHN_LEVEL_PKT_PRIVACY,
|
NULL, -1, NULL, NULL, RPC_C_AUTHN_LEVEL_PKT_PRIVACY,
|
||||||
RPC_C_IMP_LEVEL_IDENTIFY, NULL, EOAC_NONE, NULL);
|
RPC_C_IMP_LEVEL_IDENTIFY, NULL, EOAC_NONE, NULL);
|
||||||
if (FAILED(hr)) {
|
if (FAILED(hr)) {
|
||||||
fprintf(stderr, "failed to CoInitializeSecurity (error %lx)\n", hr);
|
qga_debug("failed to CoInitializeSecurity (error %lx)", hr);
|
||||||
return hr;
|
return hr;
|
||||||
}
|
}
|
||||||
|
|
||||||
hLib = LoadLibraryA("VSSAPI.DLL");
|
hLib = LoadLibraryA("VSSAPI.DLL");
|
||||||
if (!hLib) {
|
if (!hLib) {
|
||||||
fprintf(stderr, "failed to load VSSAPI.DLL\n");
|
qga_debug("failed to load VSSAPI.DLL");
|
||||||
return HRESULT_FROM_WIN32(GetLastError());
|
return HRESULT_FROM_WIN32(GetLastError());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -78,22 +83,25 @@ STDAPI requester_init(void)
|
||||||
#endif
|
#endif
|
||||||
);
|
);
|
||||||
if (!pCreateVssBackupComponents) {
|
if (!pCreateVssBackupComponents) {
|
||||||
fprintf(stderr, "failed to get proc address from VSSAPI.DLL\n");
|
qga_debug("failed to get proc address from VSSAPI.DLL");
|
||||||
return HRESULT_FROM_WIN32(GetLastError());
|
return HRESULT_FROM_WIN32(GetLastError());
|
||||||
}
|
}
|
||||||
|
|
||||||
pVssFreeSnapshotProperties = (t_VssFreeSnapshotProperties)
|
pVssFreeSnapshotProperties = (t_VssFreeSnapshotProperties)
|
||||||
GetProcAddress(hLib, "VssFreeSnapshotProperties");
|
GetProcAddress(hLib, "VssFreeSnapshotProperties");
|
||||||
if (!pVssFreeSnapshotProperties) {
|
if (!pVssFreeSnapshotProperties) {
|
||||||
fprintf(stderr, "failed to get proc address from VSSAPI.DLL\n");
|
qga_debug("failed to get proc address from VSSAPI.DLL");
|
||||||
return HRESULT_FROM_WIN32(GetLastError());
|
return HRESULT_FROM_WIN32(GetLastError());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
qga_debug_end;
|
||||||
return S_OK;
|
return S_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void requester_cleanup(void)
|
static void requester_cleanup(void)
|
||||||
{
|
{
|
||||||
|
qga_debug_begin;
|
||||||
|
|
||||||
if (vss_ctx.hEventFrozen) {
|
if (vss_ctx.hEventFrozen) {
|
||||||
CloseHandle(vss_ctx.hEventFrozen);
|
CloseHandle(vss_ctx.hEventFrozen);
|
||||||
vss_ctx.hEventFrozen = NULL;
|
vss_ctx.hEventFrozen = NULL;
|
||||||
|
@ -115,10 +123,13 @@ static void requester_cleanup(void)
|
||||||
vss_ctx.pVssbc = NULL;
|
vss_ctx.pVssbc = NULL;
|
||||||
}
|
}
|
||||||
vss_ctx.cFrozenVols = 0;
|
vss_ctx.cFrozenVols = 0;
|
||||||
|
qga_debug_end;
|
||||||
}
|
}
|
||||||
|
|
||||||
STDAPI requester_deinit(void)
|
STDAPI requester_deinit(void)
|
||||||
{
|
{
|
||||||
|
qga_debug_begin;
|
||||||
|
|
||||||
requester_cleanup();
|
requester_cleanup();
|
||||||
|
|
||||||
pCreateVssBackupComponents = NULL;
|
pCreateVssBackupComponents = NULL;
|
||||||
|
@ -128,11 +139,14 @@ STDAPI requester_deinit(void)
|
||||||
hLib = NULL;
|
hLib = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
qga_debug_end;
|
||||||
return S_OK;
|
return S_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
static HRESULT WaitForAsync(IVssAsync *pAsync)
|
static HRESULT WaitForAsync(IVssAsync *pAsync)
|
||||||
{
|
{
|
||||||
|
qga_debug_begin;
|
||||||
|
|
||||||
HRESULT ret, hr;
|
HRESULT ret, hr;
|
||||||
|
|
||||||
do {
|
do {
|
||||||
|
@ -148,11 +162,14 @@ static HRESULT WaitForAsync(IVssAsync *pAsync)
|
||||||
}
|
}
|
||||||
} while (ret == VSS_S_ASYNC_PENDING);
|
} while (ret == VSS_S_ASYNC_PENDING);
|
||||||
|
|
||||||
|
qga_debug_end;
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void AddComponents(ErrorSet *errset)
|
static void AddComponents(ErrorSet *errset)
|
||||||
{
|
{
|
||||||
|
qga_debug_begin;
|
||||||
|
|
||||||
unsigned int cWriters, i;
|
unsigned int cWriters, i;
|
||||||
VSS_ID id, idInstance, idWriter;
|
VSS_ID id, idInstance, idWriter;
|
||||||
BSTR bstrWriterName = NULL;
|
BSTR bstrWriterName = NULL;
|
||||||
|
@ -234,17 +251,21 @@ out:
|
||||||
if (pComponent && info) {
|
if (pComponent && info) {
|
||||||
pComponent->FreeComponentInfo(info);
|
pComponent->FreeComponentInfo(info);
|
||||||
}
|
}
|
||||||
|
qga_debug_end;
|
||||||
}
|
}
|
||||||
|
|
||||||
DWORD get_reg_dword_value(HKEY baseKey, LPCSTR subKey, LPCSTR valueName,
|
DWORD get_reg_dword_value(HKEY baseKey, LPCSTR subKey, LPCSTR valueName,
|
||||||
DWORD defaultData)
|
DWORD defaultData)
|
||||||
{
|
{
|
||||||
|
qga_debug_begin;
|
||||||
|
|
||||||
DWORD regGetValueError;
|
DWORD regGetValueError;
|
||||||
DWORD dwordData;
|
DWORD dwordData;
|
||||||
DWORD dataSize = sizeof(DWORD);
|
DWORD dataSize = sizeof(DWORD);
|
||||||
|
|
||||||
regGetValueError = RegGetValue(baseKey, subKey, valueName, RRF_RT_DWORD,
|
regGetValueError = RegGetValue(baseKey, subKey, valueName, RRF_RT_DWORD,
|
||||||
NULL, &dwordData, &dataSize);
|
NULL, &dwordData, &dataSize);
|
||||||
|
qga_debug_end;
|
||||||
if (regGetValueError != ERROR_SUCCESS) {
|
if (regGetValueError != ERROR_SUCCESS) {
|
||||||
return defaultData;
|
return defaultData;
|
||||||
}
|
}
|
||||||
|
@ -259,6 +280,8 @@ bool is_valid_vss_backup_type(VSS_BACKUP_TYPE vssBT)
|
||||||
VSS_BACKUP_TYPE get_vss_backup_type(
|
VSS_BACKUP_TYPE get_vss_backup_type(
|
||||||
VSS_BACKUP_TYPE defaultVssBT = DEFAULT_VSS_BACKUP_TYPE)
|
VSS_BACKUP_TYPE defaultVssBT = DEFAULT_VSS_BACKUP_TYPE)
|
||||||
{
|
{
|
||||||
|
qga_debug_begin;
|
||||||
|
|
||||||
VSS_BACKUP_TYPE vssBackupType;
|
VSS_BACKUP_TYPE vssBackupType;
|
||||||
|
|
||||||
vssBackupType = static_cast<VSS_BACKUP_TYPE>(
|
vssBackupType = static_cast<VSS_BACKUP_TYPE>(
|
||||||
|
@ -266,6 +289,7 @@ VSS_BACKUP_TYPE get_vss_backup_type(
|
||||||
QGA_PROVIDER_REGISTRY_ADDRESS,
|
QGA_PROVIDER_REGISTRY_ADDRESS,
|
||||||
"VssOption",
|
"VssOption",
|
||||||
defaultVssBT));
|
defaultVssBT));
|
||||||
|
qga_debug_end;
|
||||||
if (!is_valid_vss_backup_type(vssBackupType)) {
|
if (!is_valid_vss_backup_type(vssBackupType)) {
|
||||||
return defaultVssBT;
|
return defaultVssBT;
|
||||||
}
|
}
|
||||||
|
@ -274,6 +298,8 @@ VSS_BACKUP_TYPE get_vss_backup_type(
|
||||||
|
|
||||||
void requester_freeze(int *num_vols, void *mountpoints, ErrorSet *errset)
|
void requester_freeze(int *num_vols, void *mountpoints, ErrorSet *errset)
|
||||||
{
|
{
|
||||||
|
qga_debug_begin;
|
||||||
|
|
||||||
COMPointer<IVssAsync> pAsync;
|
COMPointer<IVssAsync> pAsync;
|
||||||
HANDLE volume;
|
HANDLE volume;
|
||||||
HRESULT hr;
|
HRESULT hr;
|
||||||
|
@ -289,6 +315,7 @@ void requester_freeze(int *num_vols, void *mountpoints, ErrorSet *errset)
|
||||||
|
|
||||||
if (vss_ctx.pVssbc) { /* already frozen */
|
if (vss_ctx.pVssbc) { /* already frozen */
|
||||||
*num_vols = 0;
|
*num_vols = 0;
|
||||||
|
qga_debug("finished, already frozen");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -446,6 +473,7 @@ void requester_freeze(int *num_vols, void *mountpoints, ErrorSet *errset)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
qga_debug("preparing for backup");
|
||||||
hr = vss_ctx.pVssbc->PrepareForBackup(pAsync.replace());
|
hr = vss_ctx.pVssbc->PrepareForBackup(pAsync.replace());
|
||||||
if (SUCCEEDED(hr)) {
|
if (SUCCEEDED(hr)) {
|
||||||
hr = WaitForAsync(pAsync);
|
hr = WaitForAsync(pAsync);
|
||||||
|
@ -469,6 +497,7 @@ void requester_freeze(int *num_vols, void *mountpoints, ErrorSet *errset)
|
||||||
* CQGAVssProvider::CommitSnapshots will kick vss_ctx.hEventFrozen
|
* CQGAVssProvider::CommitSnapshots will kick vss_ctx.hEventFrozen
|
||||||
* after the applications and filesystems are frozen.
|
* after the applications and filesystems are frozen.
|
||||||
*/
|
*/
|
||||||
|
qga_debug("do snapshot set");
|
||||||
hr = vss_ctx.pVssbc->DoSnapshotSet(&vss_ctx.pAsyncSnapshot);
|
hr = vss_ctx.pVssbc->DoSnapshotSet(&vss_ctx.pAsyncSnapshot);
|
||||||
if (FAILED(hr)) {
|
if (FAILED(hr)) {
|
||||||
err_set(errset, hr, "failed to do snapshot set");
|
err_set(errset, hr, "failed to do snapshot set");
|
||||||
|
@ -515,6 +544,7 @@ void requester_freeze(int *num_vols, void *mountpoints, ErrorSet *errset)
|
||||||
*num_vols = vss_ctx.cFrozenVols = num_fixed_drives;
|
*num_vols = vss_ctx.cFrozenVols = num_fixed_drives;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
qga_debug("end successful");
|
||||||
return;
|
return;
|
||||||
|
|
||||||
out:
|
out:
|
||||||
|
@ -525,11 +555,14 @@ out:
|
||||||
out1:
|
out1:
|
||||||
requester_cleanup();
|
requester_cleanup();
|
||||||
CoUninitialize();
|
CoUninitialize();
|
||||||
|
|
||||||
|
qga_debug_end;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void requester_thaw(int *num_vols, void *mountpints, ErrorSet *errset)
|
void requester_thaw(int *num_vols, void *mountpints, ErrorSet *errset)
|
||||||
{
|
{
|
||||||
|
qga_debug_begin;
|
||||||
COMPointer<IVssAsync> pAsync;
|
COMPointer<IVssAsync> pAsync;
|
||||||
|
|
||||||
if (!vss_ctx.hEventThaw) {
|
if (!vss_ctx.hEventThaw) {
|
||||||
|
@ -538,6 +571,8 @@ void requester_thaw(int *num_vols, void *mountpints, ErrorSet *errset)
|
||||||
* and no volumes must be frozen. We return without an error.
|
* and no volumes must be frozen. We return without an error.
|
||||||
*/
|
*/
|
||||||
*num_vols = 0;
|
*num_vols = 0;
|
||||||
|
qga_debug("finished, no volumes were frozen");
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -594,4 +629,6 @@ void requester_thaw(int *num_vols, void *mountpints, ErrorSet *errset)
|
||||||
|
|
||||||
CoUninitialize();
|
CoUninitialize();
|
||||||
StopService();
|
StopService();
|
||||||
|
|
||||||
|
qga_debug_end;
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,39 @@
|
||||||
|
/*
|
||||||
|
* QEMU Guest Agent VSS debug declarations
|
||||||
|
*
|
||||||
|
* Copyright (C) 2023 Red Hat Inc
|
||||||
|
*
|
||||||
|
* Authors:
|
||||||
|
* Konstantin Kostiuk <kkostiuk@redhat.com>
|
||||||
|
*
|
||||||
|
* This work is licensed under the terms of the GNU GPL, version 2 or later.
|
||||||
|
* See the COPYING file in the top-level directory.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "qemu/osdep.h"
|
||||||
|
#include "vss-debug.h"
|
||||||
|
#include "vss-common.h"
|
||||||
|
|
||||||
|
void qga_debug_internal(const char *funcname, const char *fmt, ...)
|
||||||
|
{
|
||||||
|
char user_string[512] = {0};
|
||||||
|
char full_string[640] = {0};
|
||||||
|
|
||||||
|
va_list args;
|
||||||
|
va_start(args, fmt);
|
||||||
|
if (vsnprintf(user_string, _countof(user_string), fmt, args) <= 0) {
|
||||||
|
va_end(args);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
va_end(args);
|
||||||
|
|
||||||
|
if (snprintf(full_string, _countof(full_string),
|
||||||
|
QGA_PROVIDER_NAME "[%lu]: %s %s\n",
|
||||||
|
GetCurrentThreadId(), funcname, user_string) <= 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
OutputDebugString(full_string);
|
||||||
|
fputs(full_string, stderr);
|
||||||
|
}
|
|
@ -0,0 +1,25 @@
|
||||||
|
/*
|
||||||
|
* QEMU Guest Agent VSS debug declarations
|
||||||
|
*
|
||||||
|
* Copyright (C) 2023 Red Hat Inc
|
||||||
|
*
|
||||||
|
* Authors:
|
||||||
|
* Konstantin Kostiuk <kkostiuk@redhat.com>
|
||||||
|
*
|
||||||
|
* This work is licensed under the terms of the GNU GPL, version 2 or later.
|
||||||
|
* See the COPYING file in the top-level directory.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "qemu/osdep.h"
|
||||||
|
#include <vss-handles.h>
|
||||||
|
|
||||||
|
#ifndef VSS_DEBUG_H
|
||||||
|
#define VSS_DEBUG_H
|
||||||
|
|
||||||
|
void qga_debug_internal(const char *funcname, const char *fmt, ...) G_GNUC_PRINTF(2, 3);
|
||||||
|
|
||||||
|
#define qga_debug(fmt, ...) qga_debug_internal(__func__, fmt, ## __VA_ARGS__)
|
||||||
|
#define qga_debug_begin qga_debug("begin")
|
||||||
|
#define qga_debug_end qga_debug("end")
|
||||||
|
|
||||||
|
#endif
|
|
@ -665,6 +665,36 @@ static void test_qga_blockedrpcs(gconstpointer data)
|
||||||
fixture_tear_down(&fix, NULL);
|
fixture_tear_down(&fix, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void test_qga_allowedrpcs(gconstpointer data)
|
||||||
|
{
|
||||||
|
TestFixture fix;
|
||||||
|
QDict *ret, *error;
|
||||||
|
const gchar *class, *desc;
|
||||||
|
|
||||||
|
fixture_setup(&fix, "-a guest-ping,guest-get-time", NULL);
|
||||||
|
|
||||||
|
/* check allowed RPCs */
|
||||||
|
ret = qmp_fd(fix.fd, "{'execute': 'guest-ping'}");
|
||||||
|
qmp_assert_no_error(ret);
|
||||||
|
qobject_unref(ret);
|
||||||
|
|
||||||
|
ret = qmp_fd(fix.fd, "{'execute': 'guest-get-time'}");
|
||||||
|
qmp_assert_no_error(ret);
|
||||||
|
qobject_unref(ret);
|
||||||
|
|
||||||
|
/* check something else */
|
||||||
|
ret = qmp_fd(fix.fd, "{'execute': 'guest-get-fsinfo'}");
|
||||||
|
g_assert_nonnull(ret);
|
||||||
|
error = qdict_get_qdict(ret, "error");
|
||||||
|
class = qdict_get_try_str(error, "class");
|
||||||
|
desc = qdict_get_try_str(error, "desc");
|
||||||
|
g_assert_cmpstr(class, ==, "CommandNotFound");
|
||||||
|
g_assert_nonnull(g_strstr_len(desc, -1, "has been disabled"));
|
||||||
|
qobject_unref(ret);
|
||||||
|
|
||||||
|
fixture_tear_down(&fix, NULL);
|
||||||
|
}
|
||||||
|
|
||||||
static void test_qga_config(gconstpointer data)
|
static void test_qga_config(gconstpointer data)
|
||||||
{
|
{
|
||||||
GError *error = NULL;
|
GError *error = NULL;
|
||||||
|
@ -1090,6 +1120,7 @@ int main(int argc, char **argv)
|
||||||
test_qga_fsfreeze_status);
|
test_qga_fsfreeze_status);
|
||||||
|
|
||||||
g_test_add_data_func("/qga/blockedrpcs", NULL, test_qga_blockedrpcs);
|
g_test_add_data_func("/qga/blockedrpcs", NULL, test_qga_blockedrpcs);
|
||||||
|
g_test_add_data_func("/qga/allowedrpcs", NULL, test_qga_allowedrpcs);
|
||||||
g_test_add_data_func("/qga/config", NULL, test_qga_config);
|
g_test_add_data_func("/qga/config", NULL, test_qga_config);
|
||||||
g_test_add_data_func("/qga/guest-exec", &fix, test_qga_guest_exec);
|
g_test_add_data_func("/qga/guest-exec", &fix, test_qga_guest_exec);
|
||||||
g_test_add_data_func("/qga/guest-exec-separated", &fix,
|
g_test_add_data_func("/qga/guest-exec-separated", &fix,
|
||||||
|
|
Loading…
Reference in New Issue