root / qga / commands-win32.c @ 546b60d0
History | View | Annotate | Download (3.3 kB)
1 |
/*
|
---|---|
2 |
* QEMU Guest Agent win32-specific command implementations
|
3 |
*
|
4 |
* Copyright IBM Corp. 2012
|
5 |
*
|
6 |
* Authors:
|
7 |
* Michael Roth <mdroth@linux.vnet.ibm.com>
|
8 |
*
|
9 |
* This work is licensed under the terms of the GNU GPL, version 2 or later.
|
10 |
* See the COPYING file in the top-level directory.
|
11 |
*/
|
12 |
|
13 |
#include <glib.h> |
14 |
#include "qga/guest-agent-core.h" |
15 |
#include "qga-qmp-commands.h" |
16 |
#include "qerror.h" |
17 |
|
18 |
#ifndef SHTDN_REASON_FLAG_PLANNED
|
19 |
#define SHTDN_REASON_FLAG_PLANNED 0x80000000 |
20 |
#endif
|
21 |
|
22 |
void qmp_guest_shutdown(bool has_mode, const char *mode, Error **err) |
23 |
{ |
24 |
HANDLE token; |
25 |
TOKEN_PRIVILEGES priv; |
26 |
UINT shutdown_flag = EWX_FORCE; |
27 |
|
28 |
slog("guest-shutdown called, mode: %s", mode);
|
29 |
|
30 |
if (!has_mode || strcmp(mode, "powerdown") == 0) { |
31 |
shutdown_flag |= EWX_POWEROFF; |
32 |
} else if (strcmp(mode, "halt") == 0) { |
33 |
shutdown_flag |= EWX_SHUTDOWN; |
34 |
} else if (strcmp(mode, "reboot") == 0) { |
35 |
shutdown_flag |= EWX_REBOOT; |
36 |
} else {
|
37 |
error_set(err, QERR_INVALID_PARAMETER_VALUE, "mode",
|
38 |
"halt|powerdown|reboot");
|
39 |
return;
|
40 |
} |
41 |
|
42 |
/* Request a shutdown privilege, but try to shut down the system
|
43 |
anyway. */
|
44 |
if (OpenProcessToken(GetCurrentProcess(),
|
45 |
TOKEN_ADJUST_PRIVILEGES|TOKEN_QUERY, &token)) |
46 |
{ |
47 |
LookupPrivilegeValue(NULL, SE_SHUTDOWN_NAME,
|
48 |
&priv.Privileges[0].Luid);
|
49 |
|
50 |
priv.PrivilegeCount = 1;
|
51 |
priv.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
|
52 |
|
53 |
AdjustTokenPrivileges(token, FALSE, &priv, 0, NULL, 0); |
54 |
} |
55 |
|
56 |
if (!ExitWindowsEx(shutdown_flag, SHTDN_REASON_FLAG_PLANNED)) {
|
57 |
slog("guest-shutdown failed: %d", GetLastError());
|
58 |
error_set(err, QERR_UNDEFINED_ERROR); |
59 |
} |
60 |
} |
61 |
|
62 |
int64_t qmp_guest_file_open(const char *path, bool has_mode, const char *mode, Error **err) |
63 |
{ |
64 |
error_set(err, QERR_UNSUPPORTED); |
65 |
return 0; |
66 |
} |
67 |
|
68 |
void qmp_guest_file_close(int64_t handle, Error **err)
|
69 |
{ |
70 |
error_set(err, QERR_UNSUPPORTED); |
71 |
} |
72 |
|
73 |
GuestFileRead *qmp_guest_file_read(int64_t handle, bool has_count,
|
74 |
int64_t count, Error **err) |
75 |
{ |
76 |
error_set(err, QERR_UNSUPPORTED); |
77 |
return 0; |
78 |
} |
79 |
|
80 |
GuestFileWrite *qmp_guest_file_write(int64_t handle, const char *buf_b64, |
81 |
bool has_count, int64_t count, Error **err)
|
82 |
{ |
83 |
error_set(err, QERR_UNSUPPORTED); |
84 |
return 0; |
85 |
} |
86 |
|
87 |
GuestFileSeek *qmp_guest_file_seek(int64_t handle, int64_t offset, |
88 |
int64_t whence, Error **err) |
89 |
{ |
90 |
error_set(err, QERR_UNSUPPORTED); |
91 |
return 0; |
92 |
} |
93 |
|
94 |
void qmp_guest_file_flush(int64_t handle, Error **err)
|
95 |
{ |
96 |
error_set(err, QERR_UNSUPPORTED); |
97 |
} |
98 |
|
99 |
/*
|
100 |
* Return status of freeze/thaw
|
101 |
*/
|
102 |
GuestFsfreezeStatus qmp_guest_fsfreeze_status(Error **err) |
103 |
{ |
104 |
error_set(err, QERR_UNSUPPORTED); |
105 |
return 0; |
106 |
} |
107 |
|
108 |
/*
|
109 |
* Walk list of mounted file systems in the guest, and freeze the ones which
|
110 |
* are real local file systems.
|
111 |
*/
|
112 |
int64_t qmp_guest_fsfreeze_freeze(Error **err) |
113 |
{ |
114 |
error_set(err, QERR_UNSUPPORTED); |
115 |
return 0; |
116 |
} |
117 |
|
118 |
/*
|
119 |
* Walk list of frozen file systems in the guest, and thaw them.
|
120 |
*/
|
121 |
int64_t qmp_guest_fsfreeze_thaw(Error **err) |
122 |
{ |
123 |
error_set(err, QERR_UNSUPPORTED); |
124 |
return 0; |
125 |
} |
126 |
|
127 |
/* register init/cleanup routines for stateful command groups */
|
128 |
void ga_command_state_init(GAState *s, GACommandState *cs)
|
129 |
{ |
130 |
} |