[libgda] Correction for bug #651922 - libgda-4.2.8 wants to write on /etc/libgda-4.0/config during compilatio



commit d4c7a44c6a4823379237080692c2e26566ac91b3
Author: Vivien Malerba <malerba gnome-db org>
Date:   Mon Jun 6 20:42:19 2011 +0200

    Correction for bug #651922 - libgda-4.2.8 wants to write on /etc/libgda-4.0/config during compilation with --enable-gtk-doc

 libgda/gda-config.c |   23 +++++++++++++++++++++++
 1 files changed, 23 insertions(+), 0 deletions(-)
---
diff --git a/libgda/gda-config.c b/libgda/gda-config.c
index cc9d74b..c97e962 100644
--- a/libgda/gda-config.c
+++ b/libgda/gda-config.c
@@ -20,6 +20,7 @@
  * Boston, MA 02111-1307, USA.
  */
 
+#include <unistd.h>
 #include <stdio.h>
 #include <gmodule.h>
 #include <libgda/gda-config.h>
@@ -630,12 +631,34 @@ gda_config_constructor (GType type,
 										    LIBGDA_ABI_NAME, "config", NULL);
 		unique_instance->priv->system_config_allowed = FALSE;
 		if (unique_instance->priv->system_file) {
+#ifdef G_OS_WIN32
+
 			FILE *file;
                         file = fopen (unique_instance->priv->system_file, "a");  /* Flawfinder: ignore */
                         if (file) {
                                 unique_instance->priv->system_config_allowed = TRUE;
                                 fclose (file);
                         }
+#else
+			struct stat stbuf;
+			if (stat (unique_instance->priv->system_file, &stbuf) == 0) {
+				/* use effective user and group IDs */
+				uid_t euid;
+				gid_t egid;
+				euid = geteuid ();
+				egid = getegid ();
+				if (euid == stbuf.st_uid) {
+					if ((stbuf.st_mode & S_IWUSR) && (stbuf.st_mode & S_IRUSR))
+						unique_instance->priv->system_config_allowed = TRUE;
+				}
+				else if (egid == stbuf.st_gid) {
+					if ((stbuf.st_mode & S_IWGRP) && (stbuf.st_mode & S_IRGRP))
+						unique_instance->priv->system_config_allowed = TRUE;
+				}
+				else if ((stbuf.st_mode & S_IWOTH) && (stbuf.st_mode & S_IROTH))
+					unique_instance->priv->system_config_allowed = TRUE;
+			}
+#endif
 		}
 
 		/* Setup file monitoring */



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]