summaryrefslogtreecommitdiff
path: root/src/lib/eina
diff options
context:
space:
mode:
authorCarsten Haitzler (Rasterman) <raster@rasterman.com>2017-02-08 17:35:26 +0900
committerCarsten Haitzler (Rasterman) <raster@rasterman.com>2017-02-08 21:19:39 +0900
commit8094893877c4c176d1d647fee5adf5a25db60244 (patch)
treee1fd0873313011f126ae124bca5f5ea108fba740 /src/lib/eina
parent5b4c032fb5dc73f2fc8fce124c32c59426cdbb25 (diff)
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
Diffstat (limited to 'src/lib/eina')
-rw-r--r--src/lib/eina/eina_util.c34
1 files changed, 29 insertions, 5 deletions
diff --git a/src/lib/eina/eina_util.c b/src/lib/eina/eina_util.c
index 62e1a79b42..1515172694 100644
--- a/src/lib/eina/eina_util.c
+++ b/src/lib/eina/eina_util.c
@@ -24,6 +24,10 @@
24#include <unistd.h> 24#include <unistd.h>
25#ifdef _WIN32 25#ifdef _WIN32
26# include <string.h> 26# include <string.h>
27#else
28# include <sys/types.h>
29# include <pwd.h>
30# include <string.h>
27#endif 31#endif
28 32
29#include "eina_config.h" 33#include "eina_config.h"
@@ -51,9 +55,10 @@ static char home_storage[8];
51EAPI const char * 55EAPI const char *
52eina_environment_home_get(void) 56eina_environment_home_get(void)
53{ 57{
54#ifdef _WIN32 58 static char *home = NULL;
55 char *home;
56 59
60 if (home) return home;
61#ifdef _WIN32
57 home = getenv("USERPROFILE"); 62 home = getenv("USERPROFILE");
58 if (!home) home = getenv("WINDIR"); 63 if (!home) home = getenv("WINDIR");
59 if (!home && 64 if (!home &&
@@ -66,17 +71,36 @@ eina_environment_home_get(void)
66 } 71 }
67 if (!home) home = "C:\\"; 72 if (!home) home = "C:\\";
68 73
69 return home;
70#else 74#else
71 return getenv("HOME"); 75# if defined(HAVE_GETUID) && defined(HAVE_GETEUID)
76 if (getuid() == geteuid()) home = getenv("HOME");
77# endif
78 if (!home)
79 {
80# ifdef HAVE_GETPWENT
81 struct passwd pwent, *pwent2 = NULL;
82 char pwbuf[8129];
83
84 if (!getpwuid_r(getuid(), &pwent, pwbuf, sizeof(pwbuf), &pwent2))
85 {
86 if ((pwent2) && (pwent.pw_dir))
87 home = strdup(pwent.pw_dir);
88 }
89 if (!home) home = strdup("/tmp");
90 return home;
91 }
92# endif
72#endif 93#endif
94 home = strdup(home);
95 return home;
73} 96}
74 97
75EAPI const char * 98EAPI const char *
76eina_environment_tmp_get(void) 99eina_environment_tmp_get(void)
77{ 100{
78 char *tmp = NULL; 101 static char *tmp = NULL;
79 102
103 if (tmp) return tmp;
80#ifdef _WIN32 104#ifdef _WIN32
81 tmp = getenv("TMP"); 105 tmp = getenv("TMP");
82 if (!tmp) tmp = getenv("TEMP"); 106 if (!tmp) tmp = getenv("TEMP");