-fixes
[oweals/gnunet.git] / src / util / os_installation.c
index c5cf1ccb36394c6a4b437b280715b6acf01cf1f2..e790ce10eec9b46a187431a5d0e1ccab86248ff2 100644 (file)
@@ -56,21 +56,21 @@ get_path_from_proc_maps ()
   char *lgu;
 
   GNUNET_snprintf (fn, sizeof (fn), "/proc/%u/maps", getpid ());
-  f = fopen (fn, "r");
+  f = FOPEN (fn, "r");
   if (f == NULL)
     return NULL;
   while (NULL != fgets (line, sizeof (line), f))
   {
     if ((1 ==
-         sscanf (line, "%*x-%*x %*c%*c%*c%*c %*x %*2u:%*2u %*u%*[ ]%s", dir)) &&
+         SSCANF (line, "%*x-%*x %*c%*c%*c%*c %*x %*2u:%*2u %*u%*[ ]%s", dir)) &&
         (NULL != (lgu = strstr (dir, "libgnunetutil"))))
     {
       lgu[0] = '\0';
-      fclose (f);
+      FCLOSE (f);
       return GNUNET_strdup (dir);
     }
   }
-  fclose (f);
+  FCLOSE (f);
   return NULL;
 }
 
@@ -112,15 +112,19 @@ get_path_from_proc_exe ()
 static char *
 get_path_from_module_filename ()
 {
-  char path[4097];
-  char *idx;
+  wchar_t path[4097];
+  char upath[4097];
+  wchar_t *idx;
 
-  GetModuleFileName (NULL, path, sizeof (path) - 1);
-  idx = path + strlen (path);
-  while ((idx > path) && (*idx != '\\') && (*idx != '/'))
+  GetModuleFileNameW (NULL, path, sizeof (path) - 1);
+  idx = path + wcslen (path);
+  while ((idx > path) && (*idx != L'\\') && (*idx != L'/'))
     idx--;
-  *idx = '\0';
-  return GNUNET_strdup (path);
+  *idx = L'\0';
+  upath[0] = '\0';
+  WideCharToMultiByte (CP_UTF8, 0, path, -1, upath, 4097, NULL, NULL);
+
+  return GNUNET_strdup (upath);
 }
 #endif
 
@@ -467,7 +471,7 @@ GNUNET_OS_check_helper_binary (const char *binary)
     GNUNET_free (p);
     p = pf;
   }
-  free (binaryexe);
+  GNUNET_free (binaryexe);
 #else
   p = get_path_from_PATH (binary);
   if (p != NULL)
@@ -483,6 +487,21 @@ GNUNET_OS_check_helper_binary (const char *binary)
          binary);
     return GNUNET_SYSERR;
   }
+  if (0 != ACCESS (p, X_OK))
+  {
+    LOG (GNUNET_ERROR_TYPE_WARNING, _("access (%s, X_OK) failed: %s\n"), p,
+         STRERROR (errno));
+    GNUNET_free (p);
+    return GNUNET_SYSERR;
+  }
+#ifndef MINGW
+  if (0 == getuid ())
+  {
+    /* as we run as root, we don't insist on SUID */
+    GNUNET_free (p);
+    return GNUNET_OK;
+  }
+#endif
   if (0 != STAT (p, &statbuf))
   {
     LOG (GNUNET_ERROR_TYPE_WARNING, _("stat (%s) failed: %s\n"), p,
@@ -496,13 +515,9 @@ GNUNET_OS_check_helper_binary (const char *binary)
     GNUNET_free (p);
     return GNUNET_YES;
   }
-  if (0 == ACCESS (p, X_OK))
-  {
-    GNUNET_free (p);
-    return GNUNET_NO;
-  }
+  /* binary exists, but not SUID */
   GNUNET_free (p);
-  return GNUNET_SYSERR;
+  return GNUNET_NO;
 #else
   GNUNET_free (p);
   rawsock = socket (AF_INET, SOCK_RAW, IPPROTO_ICMP);