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



commit 9c1a1809650321c3d752a143f87089d325c49237
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 e1b65c0..e0a51c7 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]