aboutsummaryrefslogtreecommitdiff
path: root/src/interfaces/libpq/fe-auth.c
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2005-01-04 23:18:25 +0000
committerTom Lane <tgl@sss.pgh.pa.us>2005-01-04 23:18:25 +0000
commitedf3832b5c5b3b12528a2208d4e077e2f0d48903 (patch)
treeafc59b310cb6aad495b57e131d5533d9e82d0bd1 /src/interfaces/libpq/fe-auth.c
parentd877de9e6bd1fb6f9b1590ca0e6ce35b61077d6e (diff)
downloadpostgresql-edf3832b5c5b3b12528a2208d4e077e2f0d48903.tar.gz
postgresql-edf3832b5c5b3b12528a2208d4e077e2f0d48903.zip
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.
Diffstat (limited to 'src/interfaces/libpq/fe-auth.c')
-rw-r--r--src/interfaces/libpq/fe-auth.c28
1 files changed, 15 insertions, 13 deletions
diff --git a/src/interfaces/libpq/fe-auth.c b/src/interfaces/libpq/fe-auth.c
index 35f70205807..f326335bf91 100644
--- a/src/interfaces/libpq/fe-auth.c
+++ b/src/interfaces/libpq/fe-auth.c
@@ -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;
}