summaryrefslogtreecommitdiff
path: root/src/lib/eina
diff options
context:
space:
mode:
authorMarcel Hollerbach <mail@marcel-hollerbach.de>2018-08-20 12:56:30 -0400
committerMike Blumenkrantz <zmike@samsung.com>2018-08-20 12:56:30 -0400
commitaa416afffbbf064010ccf46b7c67e56227b3cd43 (patch)
tree4558b89b5bc644d8d602653c453e186c1a45c0a3 /src/lib/eina
parent9e7d0d03e4ce54038c3f1659d9206e2614f51866 (diff)
eina_vpath: fix homedirectory fetching
Summary: the fetching of the homedirectorty did not work. pw_dir was never prepended. Additionally you would get a silent NULL string back if the system does not support HAVE_GETPWENT. ref T7107 Depends on D6737 Reviewers: zmike Reviewed By: zmike Subscribers: #reviewers, raster, vtorri, cedric, #committers, zmike Tags: #efl Maniphest Tasks: T7107 Differential Revision: https://phab.enlightenment.org/D6742
Diffstat (limited to 'src/lib/eina')
-rw-r--r--src/lib/eina/eina_vpath.c58
1 files changed, 37 insertions, 21 deletions
diff --git a/src/lib/eina/eina_vpath.c b/src/lib/eina/eina_vpath.c
index f49a9e1f13..c958bbe4f9 100644
--- a/src/lib/eina/eina_vpath.c
+++ b/src/lib/eina/eina_vpath.c
@@ -188,6 +188,29 @@ eina_vpath_shutdown(void)
188 return EINA_TRUE; 188 return EINA_TRUE;
189} 189}
190 190
191static Eina_Bool
192_fetch_user_homedir(char **str, const char *name, const char *error)
193{
194 *str = NULL;
195#ifdef HAVE_GETPWENT
196 struct passwd *pwent;
197
198 pwent = getpwnam(name);
199 if (!pwent)
200 {
201 ERR("User %s not found\nThe string was: %s", name, error);
202 return EINA_FALSE;
203 }
204 *str = pwent->pw_dir;
205
206 return EINA_TRUE;
207#else
208 ERR("User fetching is disabled on this system\nThe string was: %s", error);
209 return EINA_FALSE;
210#endif
211}
212
213
191EAPI char * 214EAPI char *
192eina_vpath_resolve(const char* path) 215eina_vpath_resolve(const char* path)
193{ 216{
@@ -204,25 +227,17 @@ eina_vpath_resolve(const char* path)
204 227
205 if (path[0] == '~') 228 if (path[0] == '~')
206 { 229 {
230 char *home = NULL;
207 // ~/ <- home directory 231 // ~/ <- home directory
208 if (path[1] == '/') 232 if (path[1] == '/')
209 { 233 {
210 char buf[PATH_MAX]; 234 home = eina_hash_find(vpath_data, "home");
211 const char *home = eina_hash_find(vpath_data, "home"); 235 path ++;
212
213 if (home)
214 {
215 snprintf(buf, sizeof(buf), "%s%s", home, path + 1);
216 return strdup(buf);
217 }
218 } 236 }
219#ifdef HAVE_GETPWENT
220 // ~username/ <- homedir of user "username" 237 // ~username/ <- homedir of user "username"
221 else 238 else
222 { 239 {
223 const char *p; 240 char *p, *name, buf[PATH_MAX];
224 struct passwd pwent, *pwent2 = NULL;
225 char *name, buf[PATH_MAX], pwbuf[8129];
226 241
227 for (p = path + 1; *p; p++) 242 for (p = path + 1; *p; p++)
228 { 243 {
@@ -231,16 +246,17 @@ eina_vpath_resolve(const char* path)
231 name = alloca(p - path); 246 name = alloca(p - path);
232 strncpy(name, path + 1, p - path - 1); 247 strncpy(name, path + 1, p - path - 1);
233 name[p - path - 1] = 0; 248 name[p - path - 1] = 0;
234 if (!getpwnam_r(name, &pwent, pwbuf, sizeof(pwbuf), &pwent2)) 249
235 { 250 if (!_fetch_user_homedir(&home, name, path))
236 if ((pwent2) && (pwent.pw_dir)) 251 return NULL;
237 { 252 path = p;
238 return strdup(buf); 253 }
239 } 254 if (home)
240 } 255 {
256 char buf[PATH_MAX];
257 snprintf(buf, sizeof(buf), "%s%s", home, path);
258 return strdup(buf);
241 } 259 }
242#endif /* HAVE_GETPWENT */
243 return NULL;
244 } 260 }
245 // (:xxx:)/* ... <- meta hash table 261 // (:xxx:)/* ... <- meta hash table
246 else if ((path[0] == '(') && (path[1] == ':')) 262 else if ((path[0] == '(') && (path[1] == ':'))