# HG changeset patch # User Andre Heinecke # Date 1396868327 0 # Node ID 824ef90a672176889e4c5ff2be4a6fd948890668 # Parent 1628615d904e37d455b5cbaeef4358563de4c90a Move is_elevated into common/util.c file for better reuse diff -r 1628615d904e -r 824ef90a6721 cinst/nssstore_linux.c --- 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 #include #include diff -r 1628615d904e -r 824ef90a6721 cinst/windowsstore.c --- 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) { diff -r 1628615d904e -r 824ef90a6721 common/CMakeLists.txt --- 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}) diff -r 1628615d904e -r 824ef90a6721 common/util.c --- /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 +#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 diff -r 1628615d904e -r 824ef90a6721 common/util.h --- /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 + +#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