aheinecke@404: /* Copyright (C) 2014 by Bundesamt für Sicherheit in der Informationstechnik aheinecke@404: * Software engineering by Intevation GmbH aheinecke@404: * aheinecke@404: * This file is Free Software under the GNU GPL (v>=2) aheinecke@404: * and comes with ABSOLUTELY NO WARRANTY! aheinecke@404: * See LICENSE.txt for details. aheinecke@404: */ aheinecke@321: #ifndef COMMON_UTIL_H aheinecke@321: #define COMMON_UTIL_H aheinecke@321: /* @file util.h aheinecke@321: * @brief The usual useful stuff that fit nowhere else aheinecke@321: */ aheinecke@321: #include aheinecke@321: andre@670: #ifdef WIN32 andre@670: #include andre@670: #include andre@670: #endif andre@670: aheinecke@505: #ifdef __cplusplus aheinecke@505: extern "C" { aheinecke@505: #endif aheinecke@505: aheinecke@321: /**@brief Check if the current process is running with elevated privileges. aheinecke@321: * aheinecke@321: * Elevates the current process token to check if it is marked as elevated. wilde@323: * Uses TokenElevation on windows and checks effective UID on Linux. aheinecke@321: * aheinecke@321: * @returns true if the current process is elevated.*/ aheinecke@321: bool is_elevated(); wilde@323: aheinecke@505: /**@brief Check if the user is in the administrators group. aheinecke@505: * aheinecke@505: * The function checks if the account that startet this process aheinecke@505: * belongs to a user that is a member of the Administrators group. aheinecke@505: * aheinecke@505: * @returns True if the user is in the admin group. False otherwise or on error. aheinecke@505: */ aheinecke@505: bool is_admin(); aheinecke@505: andre@670: #ifdef WIN32 andre@670: /**@brief Get a copy of the processes owner sid andre@670: * andre@670: * Copy the SID of the owner of the process hProcess. andre@670: * andre@670: * The returned sid structure has to be freed with free by the caller andre@670: * andre@670: * @param[in] hProcess A handle to the process whose user should be obtained. andre@670: * The process must have the PROCESS_QUERY_INFORMATION access permission. andre@670: * andre@670: * @returns A copy of the process owners sid or NULL on error. andre@670: */ andre@670: PSID get_process_owner(HANDLE hProcess); andre@675: andre@675: /**@brief Get the directory in which the current process resides in andre@675: * andre@675: * Look up the directory in which the current process is placed. andre@675: * If the path is longer then MAX_PATH NULL is returned. andre@675: * andre@675: * Returns a utf-8 encoded string that has to be freed by the caller andre@675: * andre@675: * @returns The directory of the current process andre@675: */ andre@675: char * get_install_dir(); andre@670: #endif andre@670: aheinecke@505: #ifdef __cplusplus aheinecke@505: } aheinecke@505: #endif aheinecke@505: aheinecke@321: #endif // COMMON_UTIL_H