diff 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
line wrap: on
line diff
--- a/common/util.h	Tue Jul 29 13:15:32 2014 +0200
+++ b/common/util.h	Tue Jul 29 18:12:57 2014 +0200
@@ -21,6 +21,11 @@
 extern "C" {
 #endif
 
+#ifndef WIN32
+/**@def Some value to use as equivalent as MAX_PATH on windows */
+#define MAX_PATH_LINUX 4000
+#endif
+
 /**@brief Check if the current process is running with elevated privileges.
  *
  * Elevates the current process token to check if it is marked as elevated.
@@ -29,6 +34,20 @@
  * @returns true if the current process is elevated.*/
 bool is_elevated();
 
+/**@brief Check if the Software is installed system wide
+ *
+ * On Windows this checks if a registry key under HKLM exists for
+ * trustbridge and that the installation path mentioned there matches
+ * the current module path.
+ *
+ * On linux this looks for the installation configuration in /etc
+ * and checks if the current process is inside the installation prefix.
+ *
+ * The checked path is limited to MAX_PATH on Windows and @MAX_PATH_LINUX on
+ * Linux.
+ */
+bool is_system_install();
+
 /**@brief Check if the user is in the administrators group.
  *
  * The function checks if the account that startet this process
@@ -38,6 +57,18 @@
  */
 bool is_admin();
 
+/**@brief Get the directory in which the current process resides in
+ *
+ * Look up the directory in which the current process is placed.
+ * If the path is longer then MAX_PATH NULL is returned.
+ *
+ * Returns a utf-8 encoded string that has to be freed by the caller
+ * on linux the path is returned as is including the last /.
+ *
+ * @returns The directory of the current process
+ */
+char * get_install_dir();
+
 #ifdef WIN32
 /**@brief Get a copy of the processes owner sid
  *
@@ -52,16 +83,23 @@
  */
 PSID get_process_owner(HANDLE hProcess);
 
-/**@brief Get the directory in which the current process resides in
- *
- * Look up the directory in which the current process is placed.
- * If the path is longer then MAX_PATH NULL is returned.
+/**@brief Read (and expand if necessary) a registry string.
  *
- * Returns a utf-8 encoded string that has to be freed by the caller
+ * Reads a registry string and calls ExpandEnvironmentString
+ * if necessary on it. Returns a newly allocated string array
+ * with the expanded registry value converted to UTF-8
  *
- * @returns The directory of the current process
+ * Caller has to free return value with free.
+ *
+ * @param [in] root the root key (e.g. HKEY_LOCAL_MACHINE)
+ * @param [in] key the key
+ * @param [in] name the name of the value to read.
+ *
+ * @returns the expanded, null terminated utf-8 string of the value.
+ *          or NULL on error.
  */
-char * get_install_dir();
+char * read_registry_string (const HKEY root, const wchar_t *key,
+                             const wchar_t *name);
 #endif
 
 #ifdef __cplusplus

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