raster pushed a commit to branch master.

http://git.enlightenment.org/core/efl.git/commit/?id=8094893877c4c176d1d647fee5adf5a25db60244

commit 8094893877c4c176d1d647fee5adf5a25db60244
Author: Carsten Haitzler (Rasterman) <[email protected]>
Date:   Wed Feb 8 17:35:26 2017 +0900

    eina utils - home and tmp environ - store statitcally and handle setuid
    
    if setuod we dont want to trust HOME environ at all and get it from
    passwd file... also we dont want to keep re-getting too... so store
    statically as well as tmp.
    
    this also kind of helps CID 1366469
---
 src/lib/eina/eina_util.c | 34 +++++++++++++++++++++++++++++-----
 1 file changed, 29 insertions(+), 5 deletions(-)

diff --git a/src/lib/eina/eina_util.c b/src/lib/eina/eina_util.c
index 62e1a79..1515172 100644
--- a/src/lib/eina/eina_util.c
+++ b/src/lib/eina/eina_util.c
@@ -24,6 +24,10 @@
 #include <unistd.h>
 #ifdef _WIN32
 # include <string.h>
+#else
+# include <sys/types.h>
+# include <pwd.h>
+# include <string.h>
 #endif
 
 #include "eina_config.h"
@@ -51,9 +55,10 @@ static char home_storage[8];
 EAPI const char *
 eina_environment_home_get(void)
 {
-#ifdef _WIN32
-   char *home;
+   static char *home = NULL;
 
+   if (home) return home;
+#ifdef _WIN32
    home = getenv("USERPROFILE");
    if (!home) home = getenv("WINDIR");
    if (!home &&
@@ -66,17 +71,36 @@ eina_environment_home_get(void)
      }
    if (!home) home = "C:\\";
 
-   return home;
 #else
-   return getenv("HOME");
+# if defined(HAVE_GETUID) && defined(HAVE_GETEUID)
+   if (getuid() == geteuid()) home = getenv("HOME");
+# endif
+   if (!home)
+     {
+# ifdef HAVE_GETPWENT
+        struct passwd pwent, *pwent2 = NULL;
+        char pwbuf[8129];
+
+        if (!getpwuid_r(getuid(), &pwent, pwbuf, sizeof(pwbuf), &pwent2))
+          {
+             if ((pwent2) && (pwent.pw_dir))
+               home = strdup(pwent.pw_dir);
+          }
+        if (!home) home = strdup("/tmp");
+        return home;
+     }
+# endif
 #endif
+   home = strdup(home);
+   return home;
 }
 
 EAPI const char *
 eina_environment_tmp_get(void)
 {
-   char *tmp = NULL;
+   static char *tmp = NULL;
 
+   if (tmp) return tmp;
 #ifdef _WIN32
    tmp = getenv("TMP");
    if (!tmp) tmp = getenv("TEMP");

-- 


Reply via email to