Signed-off-by: Zane Bitter zbitter@redhat.com --- src/lib/host_windows.c | 25 +++++++++----------- src/lib/network_windows.c | 56 ++++++++++++++------------------------------ src/lib/services_windows.c | 6 ++--- 3 files changed, 33 insertions(+), 54 deletions(-)
diff --git a/src/lib/host_windows.c b/src/lib/host_windows.c index 0a599d3..149cc2a 100644 --- a/src/lib/host_windows.c +++ b/src/lib/host_windows.c @@ -44,27 +44,29 @@ host_os_get_cpu_flags(void) }
static void -get_token_priv(HANDLE token, TOKEN_PRIVILEGES tkp) +enable_se_priv(void) { - OpenProcessToken(GetCurrentProcess(), - TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &token); + HANDLE token; + TOKEN_PRIVILEGES tkp; + LookupPrivilegeValue(NULL, SE_SHUTDOWN_NAME, &tkp.Privileges[0].Luid);
tkp.PrivilegeCount = 1; tkp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
- AdjustTokenPrivileges(token, FALSE, &tkp, 0, - (PTOKEN_PRIVILEGES) NULL, 0); + if (OpenProcessToken(GetCurrentProcess(), + TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &token)) { + AdjustTokenPrivileges(token, FALSE, &tkp, 0, + (PTOKEN_PRIVILEGES) NULL, 0); + CloseHandle(token); + } }
void host_os_reboot(void) { - HANDLE token; - TOKEN_PRIVILEGES tkp; - - get_token_priv(token, tkp); + enable_se_priv(); ExitWindowsEx(EWX_REBOOT | EWX_FORCE, SHTDN_REASON_FLAG_PLANNED); } @@ -72,10 +74,7 @@ host_os_reboot(void) void host_os_shutdown(void) { - HANDLE token; - TOKEN_PRIVILEGES tkp; - - get_token_priv(token, tkp); + enable_se_priv(); ExitWindowsEx(EWX_SHUTDOWN | EWX_FORCE, SHTDN_REASON_FLAG_PLANNED); } diff --git a/src/lib/network_windows.c b/src/lib/network_windows.c index 8e017ad..fe300e7 100644 --- a/src/lib/network_windows.c +++ b/src/lib/network_windows.c @@ -25,64 +25,44 @@ #endif
#include "matahari/network.h" +#include "matahari/utilities.h"
#include <config.h>
#include <glib.h> #include <windows.h>
-void -network_os_stop(const char *iface) +static void +network_os_setstate(const char *iface, const char *state) { PROCESS_INFORMATION pi; STARTUPINFO si; char *p; char *exe_path; + wchar_t *wexe_path;
p = getenv("WINDIR"); - exe_path = g_strdup_printf("%s\system32\netsh interface set interface " - "%s disabled", p, iface); + exe_path = g_strdup_printf(""%s\system32\netsh" " + "interface set interface %s %s", + p, iface, state); + wexe_path = char2wide(exe_path); + g_free(exe_path);
- gboolean ok = CreateProcess(NULL, - exe_path, - NULL, - NULL, - TRUE, - 0, - NULL, - NULL, - &si, - &pi); + CreateProcess(NULL, wexe_path, NULL, NULL, TRUE, 0, NULL, NULL, &si, &pi);
CloseHandle(pi.hThread); CloseHandle(pi.hProcess); - g_free(exe_path); + free(wexe_path); }
void -network_os_start(const char *iface) +network_os_stop(const char *iface) { - PROCESS_INFORMATION pi; - STARTUPINFO si; - char *p; - char *exe_path; - - p = getenv("WINDIR"); - exe_path = g_strdup_printf("%s\system32\netsh interface set interface " - "%s enabled", p, iface); - - gboolean ok = CreateProcess(NULL, - exe_path, - NULL, - NULL, - TRUE, - 0, - NULL, - NULL, - &si, - &pi); + network_os_setstate(iface, "disabled"); +}
- CloseHandle(pi.hThread); - CloseHandle(pi.hProcess); - g_free(exe_path); +void +network_os_start(const char *iface) +{ + network_os_setstate(iface, "enabled"); } diff --git a/src/lib/services_windows.c b/src/lib/services_windows.c index 80b9a39..b48805d 100644 --- a/src/lib/services_windows.c +++ b/src/lib/services_windows.c @@ -109,10 +109,9 @@ static int extract_service_status(const char *unmutable, int max) { int lpc = 0, last = 0; - int rc = LSB_STATUS_OTHER_ERROR;
if (unmutable == NULL || max < 10) { - return rc; + return LSB_STATUS_OTHER_ERROR; }
for (; lpc < max; lpc++) { @@ -147,6 +146,7 @@ extract_service_status(const char *unmutable, int max) rc = LSB_STATUS_OK; break; default: + rc = LSB_STATUS_OTHER_ERROR; mh_info("Unknown status: %s", next); } /* free(next); */ @@ -160,7 +160,7 @@ extract_service_status(const char *unmutable, int max) } } mh_info("Couldn't parse service status"); - return rc; + return LSB_STATUS_OTHER_ERROR; }
gboolean
ACK
On 08/24/2011 11:36 AM, Zane Bitter wrote:
Signed-off-by: Zane Bitterzbitter@redhat.com
src/lib/host_windows.c | 25 +++++++++----------- src/lib/network_windows.c | 56 ++++++++++++++------------------------------ src/lib/services_windows.c | 6 ++--- 3 files changed, 33 insertions(+), 54 deletions(-)
diff --git a/src/lib/host_windows.c b/src/lib/host_windows.c index 0a599d3..149cc2a 100644 --- a/src/lib/host_windows.c +++ b/src/lib/host_windows.c @@ -44,27 +44,29 @@ host_os_get_cpu_flags(void) }
static void -get_token_priv(HANDLE token, TOKEN_PRIVILEGES tkp) +enable_se_priv(void) {
- OpenProcessToken(GetCurrentProcess(),
TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY,&token);
HANDLE token;
TOKEN_PRIVILEGES tkp;
LookupPrivilegeValue(NULL, SE_SHUTDOWN_NAME, &tkp.Privileges[0].Luid); tkp.PrivilegeCount = 1; tkp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
- AdjustTokenPrivileges(token, FALSE,&tkp, 0,
(PTOKEN_PRIVILEGES) NULL, 0);
if (OpenProcessToken(GetCurrentProcess(),
TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY,&token)) {
AdjustTokenPrivileges(token, FALSE,&tkp, 0,
(PTOKEN_PRIVILEGES) NULL, 0);
CloseHandle(token);
} }
void host_os_reboot(void) {
- HANDLE token;
- TOKEN_PRIVILEGES tkp;
- get_token_priv(token, tkp);
- enable_se_priv(); ExitWindowsEx(EWX_REBOOT | EWX_FORCE, SHTDN_REASON_FLAG_PLANNED); }
@@ -72,10 +74,7 @@ host_os_reboot(void) void host_os_shutdown(void) {
- HANDLE token;
- TOKEN_PRIVILEGES tkp;
- get_token_priv(token, tkp);
- enable_se_priv(); ExitWindowsEx(EWX_SHUTDOWN | EWX_FORCE, SHTDN_REASON_FLAG_PLANNED); }
diff --git a/src/lib/network_windows.c b/src/lib/network_windows.c index 8e017ad..fe300e7 100644 --- a/src/lib/network_windows.c +++ b/src/lib/network_windows.c @@ -25,64 +25,44 @@ #endif
#include "matahari/network.h" +#include "matahari/utilities.h"
#include<config.h>
#include<glib.h> #include<windows.h>
-void -network_os_stop(const char *iface) +static void +network_os_setstate(const char *iface, const char *state) { PROCESS_INFORMATION pi; STARTUPINFO si; char *p; char *exe_path;
wchar_t *wexe_path;
p = getenv("WINDIR");
- exe_path = g_strdup_printf("%s\system32\netsh interface set interface "
"%s disabled", p, iface);
- exe_path = g_strdup_printf(""%s\system32\netsh" "
"interface set interface %s %s",
p, iface, state);
- wexe_path = char2wide(exe_path);
- g_free(exe_path);
- gboolean ok = CreateProcess(NULL,
exe_path,
NULL,
NULL,
TRUE,
0,
NULL,
NULL,
-&si, -&pi);
CreateProcess(NULL, wexe_path, NULL, NULL, TRUE, 0, NULL, NULL,&si,&pi);
CloseHandle(pi.hThread); CloseHandle(pi.hProcess);
- g_free(exe_path);
free(wexe_path); }
void
-network_os_start(const char *iface) +network_os_stop(const char *iface) {
- PROCESS_INFORMATION pi;
- STARTUPINFO si;
- char *p;
- char *exe_path;
- p = getenv("WINDIR");
- exe_path = g_strdup_printf("%s\system32\netsh interface set interface "
"%s enabled", p, iface);
- gboolean ok = CreateProcess(NULL,
exe_path,
NULL,
NULL,
TRUE,
0,
NULL,
NULL,
-&si, -&pi);
- network_os_setstate(iface, "disabled");
+}
- CloseHandle(pi.hThread);
- CloseHandle(pi.hProcess);
- g_free(exe_path);
+void +network_os_start(const char *iface) +{
- network_os_setstate(iface, "enabled"); }
diff --git a/src/lib/services_windows.c b/src/lib/services_windows.c index 80b9a39..b48805d 100644 --- a/src/lib/services_windows.c +++ b/src/lib/services_windows.c @@ -109,10 +109,9 @@ static int extract_service_status(const char *unmutable, int max) { int lpc = 0, last = 0;
int rc = LSB_STATUS_OTHER_ERROR;
if (unmutable == NULL || max< 10) {
return rc;
return LSB_STATUS_OTHER_ERROR; } for (; lpc< max; lpc++) {
@@ -147,6 +146,7 @@ extract_service_status(const char *unmutable, int max) rc = LSB_STATUS_OK; break; default:
rc = LSB_STATUS_OTHER_ERROR; mh_info("Unknown status: %s", next); } /* free(next); */
@@ -160,7 +160,7 @@ extract_service_status(const char *unmutable, int max) } } mh_info("Couldn't parse service status");
- return rc;
return LSB_STATUS_OTHER_ERROR; }
gboolean
Matahari mailing list Matahari@lists.fedorahosted.org https://fedorahosted.org/mailman/listinfo/matahari
matahari@lists.fedorahosted.org