Mercurial > trustbridge
changeset 321:824ef90a6721
Move is_elevated into common/util.c file for better reuse
author | Andre Heinecke <aheinecke@intevation.de> |
---|---|
date | Mon, 07 Apr 2014 10:58:47 +0000 |
parents | 1628615d904e |
children | e30c9fee111a |
files | cinst/nssstore_linux.c cinst/windowsstore.c common/CMakeLists.txt common/util.c common/util.h |
diffstat | 5 files changed, 49 insertions(+), 19 deletions(-) [+] |
line wrap: on
line diff
--- a/cinst/nssstore_linux.c Fri Apr 04 18:00:40 2014 +0200 +++ b/cinst/nssstore_linux.c Mon Apr 07 10:58:47 2014 +0000 @@ -1,5 +1,9 @@ #ifndef WIN32 +/* @file + @brief Linux implementation of nssstore process control. +*/ + #include <stdbool.h> #include <stdio.h> #include <unistd.h>
--- a/cinst/windowsstore.c Fri Apr 04 18:00:40 2014 +0200 +++ b/cinst/windowsstore.c Mon Apr 07 10:58:47 2014 +0000 @@ -7,6 +7,7 @@ #include "listutil.h" #include "strhelp.h" #include "logging.h" +#include "util.h" static PCCERT_CONTEXT b64_to_cert_context(char *b64_data, size_t b64_size) @@ -160,25 +161,6 @@ return; } -static bool is_elevated() { - HANDLE hToken = NULL; - bool ret = false; - if (OpenProcessToken (GetCurrentProcess(), TOKEN_QUERY, &hToken)) - { - DWORD elevation; - DWORD cbSize = sizeof (DWORD); - if (GetTokenInformation (hToken, TokenElevation, &elevation, - sizeof (TokenElevation), &cbSize)) - { - ret = elevation; - } - } - if (hToken) - CloseHandle (hToken); - - return ret; -} - int write_stores_win (char **to_install, char **to_remove) {
--- a/common/CMakeLists.txt Fri Apr 04 18:00:40 2014 +0200 +++ b/common/CMakeLists.txt Mon Apr 07 10:58:47 2014 +0000 @@ -4,6 +4,7 @@ logging.c portpath.c strhelp.c + util.c ) add_library(m13_common STATIC ${m13_common_src})
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/common/util.c Mon Apr 07 10:58:47 2014 +0000 @@ -0,0 +1,26 @@ +#include "util.h" +#ifdef WIN32 +#include <windows.h> +#endif + +#ifdef WIN32 +bool +is_elevated() { + HANDLE hToken = NULL; + bool ret = false; + if (OpenProcessToken (GetCurrentProcess(), TOKEN_QUERY, &hToken)) + { + DWORD elevation; + DWORD cbSize = sizeof (DWORD); + if (GetTokenInformation (hToken, TokenElevation, &elevation, + sizeof (TokenElevation), &cbSize)) + { + ret = elevation; + } + } + if (hToken) + CloseHandle (hToken); + + return ret; +} +#endif
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/common/util.h Mon Apr 07 10:58:47 2014 +0000 @@ -0,0 +1,17 @@ +#ifndef COMMON_UTIL_H +#define COMMON_UTIL_H +/* @file util.h + * @brief The usual useful stuff that fit nowhere else + */ +#include <stdbool.h> + +#ifdef WIN32 +/**@brief Check if the current process is running with elevated privileges. + * + * Elevates the current process token to check if it is marked as elevated. + * Uses TokenElevation. + * + * @returns true if the current process is elevated.*/ +bool is_elevated(); +#endif +#endif // COMMON_UTIL_H