summaryrefslogtreecommitdiff
path: root/src/lib/eina/eina_vpath.c
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/eina_vpath.c
parent9e7d0d03e4ce54038c3f1659d9206e2614f51866 (diff)
downloadefl-aa416afffbbf064010ccf46b7c67e56227b3cd43.tar.gz
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/eina_vpath.c')
-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)
return EINA_TRUE;
}
+static Eina_Bool
+_fetch_user_homedir(char **str, const char *name, const char *error)
+{
+ *str = NULL;
+#ifdef HAVE_GETPWENT
+ struct passwd *pwent;
+
+ pwent = getpwnam(name);
+ if (!pwent)
+ {
+ ERR("User %s not found\nThe string was: %s", name, error);
+ return EINA_FALSE;
+ }
+ *str = pwent->pw_dir;
+
+ return EINA_TRUE;
+#else
+ ERR("User fetching is disabled on this system\nThe string was: %s", error);
+ return EINA_FALSE;
+#endif
+}
+
+
EAPI char *
eina_vpath_resolve(const char* path)
{
@@ -204,25 +227,17 @@ eina_vpath_resolve(const char* path)
if (path[0] == '~')
{
+ char *home = NULL;
// ~/ <- home directory
if (path[1] == '/')
{
- char buf[PATH_MAX];
- const char *home = eina_hash_find(vpath_data, "home");
-
- if (home)
- {
- snprintf(buf, sizeof(buf), "%s%s", home, path + 1);
- return strdup(buf);
- }
+ home = eina_hash_find(vpath_data, "home");
+ path ++;
}
-#ifdef HAVE_GETPWENT
// ~username/ <- homedir of user "username"
else
{
- const char *p;
- struct passwd pwent, *pwent2 = NULL;
- char *name, buf[PATH_MAX], pwbuf[8129];
+ char *p, *name, buf[PATH_MAX];
for (p = path + 1; *p; p++)
{
@@ -231,16 +246,17 @@ eina_vpath_resolve(const char* path)
name = alloca(p - path);
strncpy(name, path + 1, p - path - 1);
name[p - path - 1] = 0;
- if (!getpwnam_r(name, &pwent, pwbuf, sizeof(pwbuf), &pwent2))
- {
- if ((pwent2) && (pwent.pw_dir))
- {
- return strdup(buf);
- }
- }
+
+ if (!_fetch_user_homedir(&home, name, path))
+ return NULL;
+ path = p;
+ }
+ if (home)
+ {
+ char buf[PATH_MAX];
+ snprintf(buf, sizeof(buf), "%s%s", home, path);
+ return strdup(buf);
}
-#endif /* HAVE_GETPWENT */
- return NULL;
}
// (:xxx:)/* ... <- meta hash table
else if ((path[0] == '(') && (path[1] == ':'))