Hi, I work in an environment, where servers are administered by people with different user names and identical uid (0). The attached patch fixes a bug exposed in such environments: where the logic of retrieving a personal configuration file relies solely on get_home_path(), the different users are forced to share the file of the first user with given uid.
The usage of HOME environment variable (if set) is IMO the right, standard and faster way to get_home_path(). r.
diff --git a/src/port/path.c b/src/port/path.c index 7bf7cbc..33cb790 100644 --- a/src/port/path.c +++ b/src/port/path.c @@ -807,15 +807,24 @@ bool get_home_path(char *ret_path) { #ifndef WIN32 - char pwdbuf[BUFSIZ]; - struct passwd pwdstr; - struct passwd *pwd = NULL; - - (void) pqGetpwuid(geteuid(), &pwdstr, pwdbuf, sizeof(pwdbuf), &pwd); - if (pwd == NULL) - return false; - strlcpy(ret_path, pwd->pw_dir, MAXPGPATH); - return true; + char *envhome = getenv("HOME"); + if (envhome != NULL && strlen(envhome) > 0) + { + strlcpy(ret_path, envhome, MAXPGPATH); + return true; + } + else + { + char pwdbuf[BUFSIZ]; + struct passwd pwdstr; + struct passwd *pwd = NULL; + + (void) pqGetpwuid(geteuid(), &pwdstr, pwdbuf, sizeof(pwdbuf), &pwd); + if (pwd == NULL) + return false; + strlcpy(ret_path, pwd->pw_dir, MAXPGPATH); + return true; + } #else char *tmppath;
-- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers