1
0
mirror of https://github.com/postgres/postgres.git synced 2025-07-02 09:02:37 +03:00

Clean up code in libpq that obtains user's home directory: make a single

subroutine that can hide platform dependencies.  The WIN32 path is still
a stub, but I await a fix from one of the win32 hackers.
Also clean up unnecessary #ifdef WIN32 ugliness in a couple of places.
This commit is contained in:
Tom Lane
2005-01-04 23:18:25 +00:00
parent d877de9e6b
commit edf3832b5c
3 changed files with 68 additions and 62 deletions

View File

@ -10,7 +10,7 @@
* exceed INITIAL_EXPBUFFER_SIZE (currently 256 bytes).
*
* IDENTIFICATION
* $PostgreSQL: pgsql/src/interfaces/libpq/fe-auth.c,v 1.97 2004/12/31 22:03:50 pgsql Exp $
* $PostgreSQL: pgsql/src/interfaces/libpq/fe-auth.c,v 1.98 2005/01/04 23:18:25 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@ -718,8 +718,16 @@ char *
fe_getauthname(char *PQerrormsg)
{
const char *name = NULL;
char *authn = NULL;
char *authn;
MsgType authsvc;
#ifdef WIN32
char username[128];
DWORD namesize = sizeof(username) - 1;
#else
char pwdbuf[BUFSIZ];
struct passwd pwdstr;
struct passwd *pw = NULL;
#endif
authsvc = fe_getauthsvc(PQerrormsg);
@ -728,6 +736,7 @@ fe_getauthname(char *PQerrormsg)
return NULL; /* leave original error message in place */
pglock_thread();
#ifdef KRB4
if (authsvc == STARTUP_KRB4_MSG)
name = pg_krb4_authname(PQerrormsg);
@ -742,18 +751,10 @@ fe_getauthname(char *PQerrormsg)
|| (authsvc == STARTUP_KRB5_MSG && !name))
{
#ifdef WIN32
char username[128];
DWORD namesize = sizeof(username) - 1;
if (GetUserName(username, &namesize))
name = username;
#else
char pwdbuf[BUFSIZ];
struct passwd pwdstr;
struct passwd *pw = NULL;
if (pqGetpwuid(geteuid(), &pwdstr,
pwdbuf, sizeof(pwdbuf), &pw) == 0)
if (pqGetpwuid(geteuid(), &pwdstr, pwdbuf, sizeof(pwdbuf), &pw) == 0)
name = pw->pw_name;
#endif
}
@ -763,8 +764,9 @@ fe_getauthname(char *PQerrormsg)
libpq_gettext("fe_getauthname: invalid authentication system: %d\n"),
authsvc);
if (name && (authn = (char *) malloc(strlen(name) + 1)))
strcpy(authn, name);
authn = name ? strdup(name) : NULL;
pgunlock_thread();
return authn;
}