Link libgnunetblockgroup to libgnunetblock
[oweals/gnunet.git] / src / util / os_installation.c
index 38cf7b539e3087434b521369aabc80b9ca8382ef..1226c59662272be443a1a0bf17a21717ec43d4ab 100644 (file)
@@ -44,9 +44,9 @@
 #endif
 
 
-#define LOG(kind,...) GNUNET_log_from (kind, "util", __VA_ARGS__)
+#define LOG(kind,...) GNUNET_log_from (kind, "util-os-installation", __VA_ARGS__)
 
-#define LOG_STRERROR_FILE(kind,syscall,filename) GNUNET_log_from_strerror_file (kind, "util", syscall, filename)
+#define LOG_STRERROR_FILE(kind,syscall,filename) GNUNET_log_from_strerror_file (kind, "util-os-installation", syscall, filename)
 
 
 /**
@@ -58,6 +58,11 @@ static const struct GNUNET_OS_ProjectData default_pd = {
   .project_dirname = "gnunet",
   .binary_name = "gnunet-arm",
   .env_varname = "GNUNET_PREFIX",
+  .base_config_varname = "GNUNET_BASE_CONFIG",
+  .bug_email = "gnunet-developers@gnu.org",
+  .homepage = "http://www.gnu.org/s/gnunet/",
+  .config_file = "gnunet.conf",
+  .user_config_file = "~/.config/gnunet.conf",
 };
 
 /**
@@ -76,6 +81,16 @@ GNUNET_OS_project_data_default (void)
 }
 
 
+/**
+ * @return current project data.
+ */
+const struct GNUNET_OS_ProjectData *
+GNUNET_OS_project_data_get ()
+{
+  return current_pd;
+}
+
+
 /**
  * Setup OS subsystem with project data.
  *
@@ -89,7 +104,6 @@ GNUNET_OS_init (const struct GNUNET_OS_ProjectData *pd)
 }
 
 
-
 #if LINUX
 /**
  * Try to determine path by reading /proc/PID/exe
@@ -275,7 +289,7 @@ get_path_from_module_filename ()
     GNUNET_assert (0);
 
   upath = GNUNET_malloc (u8_string_length + 1);
-  memcpy (upath, u8_string, u8_string_length);
+  GNUNET_memcpy (upath, u8_string, u8_string_length);
   upath[u8_string_length] = '\0';
 
   free (u8_string);
@@ -740,6 +754,7 @@ GNUNET_OS_installation_get_path (enum GNUNET_OS_InstallationPathKind dirkind)
                    "%s%s",
                    execpath,
                    dirname);
+  GNUNET_free (dirname);
   GNUNET_free (execpath);
   return tmp;
 }
@@ -808,9 +823,13 @@ GNUNET_OS_check_helper_binary (const char *binary,
 #ifdef MINGW
   char *binaryexe;
 
-  GNUNET_asprintf (&binaryexe, "%s.exe", binary);
-  if ( (GNUNET_YES == GNUNET_STRINGS_path_is_absolute (binaryexe, GNUNET_NO,
-                                                      NULL, NULL)) ||
+  GNUNET_asprintf (&binaryexe,
+                   "%s.exe",
+                   binary);
+  if ( (GNUNET_YES ==
+        GNUNET_STRINGS_path_is_absolute (binaryexe,
+                                         GNUNET_NO,
+                                         NULL, NULL)) ||
        (0 == strncmp (binary, "./", 2)) )
     p = GNUNET_strdup (binaryexe);
   else
@@ -825,16 +844,24 @@ GNUNET_OS_check_helper_binary (const char *binary,
   }
   GNUNET_free (binaryexe);
 #else
-  if ( (GNUNET_YES == GNUNET_STRINGS_path_is_absolute (binary, GNUNET_NO,
-                                                      NULL, NULL)) ||
+  if ( (GNUNET_YES ==
+        GNUNET_STRINGS_path_is_absolute (binary,
+                                         GNUNET_NO,
+                                         NULL,
+                                         NULL)) ||
        (0 == strncmp (binary, "./", 2)) )
+  {
     p = GNUNET_strdup (binary);
+  }
   else
   {
     p = get_path_from_PATH (binary);
     if (NULL != p)
     {
-      GNUNET_asprintf (&pf, "%s/%s", p, binary);
+      GNUNET_asprintf (&pf,
+                       "%s/%s",
+                       p,
+                       binary);
       GNUNET_free (p);
       p = pf;
     }
@@ -847,9 +874,12 @@ GNUNET_OS_check_helper_binary (const char *binary,
          binary);
     return GNUNET_SYSERR;
   }
-  if (0 != ACCESS (p, X_OK))
+  if (0 != ACCESS (p,
+                   X_OK))
   {
-    LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "access", p);
+    LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING,
+                       "access",
+                       p);
     GNUNET_free (p);
     return GNUNET_SYSERR;
   }
@@ -858,22 +888,30 @@ GNUNET_OS_check_helper_binary (const char *binary,
   {
     /* as we run as root, we don't insist on SUID */
     GNUNET_free (p);
-    return GNUNET_OK;
+    return GNUNET_YES;
   }
 #endif
-  if (0 != STAT (p, &statbuf))
+  if (0 != STAT (p,
+                 &statbuf))
   {
-    LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "stat", p);
+    LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING,
+                       "stat",
+                       p);
     GNUNET_free (p);
     return GNUNET_SYSERR;
   }
-  if (check_suid){
+  if (check_suid)
+  {
 #ifndef MINGW
-    if ((0 != (statbuf.st_mode & S_ISUID)) && (0 == statbuf.st_uid))
+    if ( (0 != (statbuf.st_mode & S_ISUID)) &&
+         (0 == statbuf.st_uid) )
     {
       GNUNET_free (p);
       return GNUNET_YES;
     }
+    GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+                _("Binary `%s' exists, but is not SUID\n"),
+                p);
     /* binary exists, but not SUID */
 #else
     STARTUPINFO start;