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 /src/bin/initdb | |
| 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 'src/bin/initdb')
| -rw-r--r-- | src/bin/initdb/initdb.c | 37 |
1 files changed, 6 insertions, 31 deletions
diff --git a/src/bin/initdb/initdb.c b/src/bin/initdb/initdb.c index e6bb132bea..964d284bb6 100644 --- a/src/bin/initdb/initdb.c +++ b/src/bin/initdb/initdb.c @@ -770,15 +770,14 @@ exit_nicely(void) /* * find the current user * - * on unix make sure it isn't really root + * on unix make sure it isn't root */ static char * get_id(void) { -#ifndef WIN32 - - struct passwd *pw; + const char *username; +#ifndef WIN32 if (geteuid() == 0) /* 0 is root's uid */ { fprintf(stderr, @@ -789,35 +788,11 @@ get_id(void) progname); exit(1); } - - pw = getpwuid(geteuid()); - if (!pw) - { - fprintf(stderr, - _("%s: could not obtain information about current user: %s\n"), - progname, strerror(errno)); - exit(1); - } -#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; - - pw->pw_uid = 1; - if (!GetUserName(pw->pw_name, &pwname_size)) - { - fprintf(stderr, _("%s: could not get current user name: %s\n"), - progname, strerror(errno)); - exit(1); - } #endif - return pg_strdup(pw->pw_name); + username = get_user_name_or_exit(progname); + + return pg_strdup(username); } static char * |
