diff options
author | Bruce Momjian | 2013-12-18 17:16:16 +0000 |
---|---|---|
committer | Bruce Momjian | 2013-12-18 17:16:21 +0000 |
commit | 613c6d26bd42dd8c2dd0664315be9551475b8864 (patch) | |
tree | e0eb178bf76220fc9b082d9e849bee67c03f9e13 /contrib/pg_upgrade/util.c | |
parent | 11ac4c73cb89551d7e0d0180b58d82186f072f8d (diff) |
Fix incorrect error message reported for non-existent users
Previously, lookups of non-existent user names could return "Success";
it will now return "User does not exist" by resetting errno. This also
centralizes the user name lookup code in libpgport.
Report and analysis by Nicolas Marchildon; patch by me
Diffstat (limited to 'contrib/pg_upgrade/util.c')
-rw-r--r-- | contrib/pg_upgrade/util.c | 23 |
1 files changed, 8 insertions, 15 deletions
diff --git a/contrib/pg_upgrade/util.c b/contrib/pg_upgrade/util.c index a67bd64043f..c3d45237fde 100644 --- a/contrib/pg_upgrade/util.c +++ b/contrib/pg_upgrade/util.c @@ -203,32 +203,25 @@ quote_identifier(const char *s) /* * get_user_info() - * (copied from initdb.c) find the current user */ int get_user_info(char **user_name) { int user_id; + char *errstr; #ifndef WIN32 - struct passwd *pw = getpwuid(geteuid()); - user_id = geteuid(); -#else /* the windows code */ - struct passwd_win32 - { - int pw_uid; - char pw_name[128]; - } pass_win32; - struct passwd_win32 *pw = &pass_win32; - DWORD pwname_size = sizeof(pass_win32.pw_name) - 1; - - GetUserName(pw->pw_name, &pwname_size); - +#else user_id = 1; #endif - *user_name = pg_strdup(pw->pw_name); + *user_name = get_user_name(&errstr); + if (!*user_name) + pg_fatal("%s\n", errstr); + + /* make a copy */ + *user_name = pg_strdup(*user_name); return user_id; } |