comparison common/util.h @ 841:216a65d7fc4b

(issue66) Implement is_system_install and use it This has completly different implementations for linux and Windows. The commit also moves some code into util.c for better reuse.
author Andre Heinecke <andre.heinecke@intevation.de>
date Tue, 29 Jul 2014 18:12:57 +0200
parents 4ad764bfb39c
children 427e2e18b8c8
comparison
equal deleted inserted replaced
840:c9a31544aaab 841:216a65d7fc4b
19 19
20 #ifdef __cplusplus 20 #ifdef __cplusplus
21 extern "C" { 21 extern "C" {
22 #endif 22 #endif
23 23
24 #ifndef WIN32
25 /**@def Some value to use as equivalent as MAX_PATH on windows */
26 #define MAX_PATH_LINUX 4000
27 #endif
28
24 /**@brief Check if the current process is running with elevated privileges. 29 /**@brief Check if the current process is running with elevated privileges.
25 * 30 *
26 * Elevates the current process token to check if it is marked as elevated. 31 * Elevates the current process token to check if it is marked as elevated.
27 * Uses TokenElevation on windows and checks effective UID on Linux. 32 * Uses TokenElevation on windows and checks effective UID on Linux.
28 * 33 *
29 * @returns true if the current process is elevated.*/ 34 * @returns true if the current process is elevated.*/
30 bool is_elevated(); 35 bool is_elevated();
36
37 /**@brief Check if the Software is installed system wide
38 *
39 * On Windows this checks if a registry key under HKLM exists for
40 * trustbridge and that the installation path mentioned there matches
41 * the current module path.
42 *
43 * On linux this looks for the installation configuration in /etc
44 * and checks if the current process is inside the installation prefix.
45 *
46 * The checked path is limited to MAX_PATH on Windows and @MAX_PATH_LINUX on
47 * Linux.
48 */
49 bool is_system_install();
31 50
32 /**@brief Check if the user is in the administrators group. 51 /**@brief Check if the user is in the administrators group.
33 * 52 *
34 * The function checks if the account that startet this process 53 * The function checks if the account that startet this process
35 * belongs to a user that is a member of the Administrators group. 54 * belongs to a user that is a member of the Administrators group.
36 * 55 *
37 * @returns True if the user is in the admin group. False otherwise or on error. 56 * @returns True if the user is in the admin group. False otherwise or on error.
38 */ 57 */
39 bool is_admin(); 58 bool is_admin();
59
60 /**@brief Get the directory in which the current process resides in
61 *
62 * Look up the directory in which the current process is placed.
63 * If the path is longer then MAX_PATH NULL is returned.
64 *
65 * Returns a utf-8 encoded string that has to be freed by the caller
66 * on linux the path is returned as is including the last /.
67 *
68 * @returns The directory of the current process
69 */
70 char * get_install_dir();
40 71
41 #ifdef WIN32 72 #ifdef WIN32
42 /**@brief Get a copy of the processes owner sid 73 /**@brief Get a copy of the processes owner sid
43 * 74 *
44 * Copy the SID of the owner of the process hProcess. 75 * Copy the SID of the owner of the process hProcess.
50 * 81 *
51 * @returns A copy of the process owners sid or NULL on error. 82 * @returns A copy of the process owners sid or NULL on error.
52 */ 83 */
53 PSID get_process_owner(HANDLE hProcess); 84 PSID get_process_owner(HANDLE hProcess);
54 85
55 /**@brief Get the directory in which the current process resides in 86 /**@brief Read (and expand if necessary) a registry string.
56 * 87 *
57 * Look up the directory in which the current process is placed. 88 * Reads a registry string and calls ExpandEnvironmentString
58 * If the path is longer then MAX_PATH NULL is returned. 89 * if necessary on it. Returns a newly allocated string array
90 * with the expanded registry value converted to UTF-8
59 * 91 *
60 * Returns a utf-8 encoded string that has to be freed by the caller 92 * Caller has to free return value with free.
61 * 93 *
62 * @returns The directory of the current process 94 * @param [in] root the root key (e.g. HKEY_LOCAL_MACHINE)
95 * @param [in] key the key
96 * @param [in] name the name of the value to read.
97 *
98 * @returns the expanded, null terminated utf-8 string of the value.
99 * or NULL on error.
63 */ 100 */
64 char * get_install_dir(); 101 char * read_registry_string (const HKEY root, const wchar_t *key,
102 const wchar_t *name);
65 #endif 103 #endif
66 104
67 #ifdef __cplusplus 105 #ifdef __cplusplus
68 } 106 }
69 #endif 107 #endif

http://wald.intevation.org/projects/trustbridge/