Re: [HACKERS] Re: [COMMITTERS] pgsql: libpq: change PQconndefaults() to ignore invalid service files

2014-03-20 Thread Bruce Momjian
On Sat, Mar  8, 2014 at 08:44:34PM -0500, Bruce Momjian wrote:
 [Just getting back to this.]
 
 Agreed.  I have developed the attached patch which passes the strdup()
 failure up from pg_fe_getauthname() and maps the failure to
 PQconndefaults(), which is now documented as being memory allocation
 failure.
 
 FYI, there was odd coding in PQconndefaults() where we set local
 variable 'name' to NULL, then we tested to see if it was NULL --- I
 removed that test.
 
  idea that we're ignoring failure returns from pqGetpwuid/GetUserName?
 
 If we want pqGetpwuid/GetUserName to be a special return value, we would
 need to modify PQconndefaults()'s API, which doesn't seem worth it.

Applied.  I added a C comment about why we ignore pqGetpwuid/GetUserName
failures.

-- 
  Bruce Momjian  br...@momjian.ushttp://momjian.us
  EnterpriseDB http://enterprisedb.com

  + Everyone has their own god. +


-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers


[HACKERS] Re: [COMMITTERS] pgsql: libpq: change PQconndefaults() to ignore invalid service files

2014-03-08 Thread Bruce Momjian
On Tue, Dec  3, 2013 at 11:42:08AM -0500, Tom Lane wrote:
 Bruce Momjian br...@momjian.us writes:
  On Tue, Dec  3, 2013 at 11:30:15AM -0500, Tom Lane wrote:
  Why does this patch remove the errorMessage argument from
  pg_fe_getauthname?  I gauge the amount of thought that went into
  that choice by the fact that the comment wasn't updated.
 
  Oh, the argument was not used, so I remove it.  C comment updated. 
  Thanks.
 
 My point was that I didn't think you'd thought about error handling.
 
 In particular, it appears to me that if the strdup in pg_fe_getauthname
 fails, we'll just let that pass without comment, which is inconsistent
 with all the other out-of-memory cases in conninfo_add_defaults.
 (I wonder whether any code downstream of this supposes that we always
 have a value for the user option.  It's a pretty safe bet that the
 case is hardly ever tested.)
 
 More generally, why is it that we'd want to eliminate any prospect
 of reporting other errors in pg_fe_getauthname?  Is it such a great

[Just getting back to this.]

Agreed.  I have developed the attached patch which passes the strdup()
failure up from pg_fe_getauthname() and maps the failure to
PQconndefaults(), which is now documented as being memory allocation
failure.

FYI, there was odd coding in PQconndefaults() where we set local
variable 'name' to NULL, then we tested to see if it was NULL --- I
removed that test.

 idea that we're ignoring failure returns from pqGetpwuid/GetUserName?

If we want pqGetpwuid/GetUserName to be a special return value, we would
need to modify PQconndefaults()'s API, which doesn't seem worth it.

-- 
  Bruce Momjian  br...@momjian.ushttp://momjian.us
  EnterpriseDB http://enterprisedb.com

  + Everyone has their own god. +
diff --git a/src/interfaces/libpq/fe-auth.c b/src/interfaces/libpq/fe-auth.c
new file mode 100644
index e10c970..3312678
*** a/src/interfaces/libpq/fe-auth.c
--- b/src/interfaces/libpq/fe-auth.c
*** pg_fe_getauthname(void)
*** 741,756 
  	 */
  	pglock_thread();
  
- 	if (!name)
- 	{
  #ifdef WIN32
! 		if (GetUserName(username, namesize))
! 			name = username;
  #else
! 		if (pqGetpwuid(geteuid(), pwdstr, pwdbuf, sizeof(pwdbuf), pw) == 0)
! 			name = pw-pw_name;
  #endif
- 	}
  
  	authn = name ? strdup(name) : NULL;
  
--- 741,753 
  	 */
  	pglock_thread();
  
  #ifdef WIN32
! 	if (GetUserName(username, namesize))
! 		name = username;
  #else
! 	if (pqGetpwuid(geteuid(), pwdstr, pwdbuf, sizeof(pwdbuf), pw) == 0)
! 		name = pw-pw_name;
  #endif
  
  	authn = name ? strdup(name) : NULL;
  
diff --git a/src/interfaces/libpq/fe-connect.c b/src/interfaces/libpq/fe-connect.c
new file mode 100644
index 1f0eeaf..669bcf5
*** a/src/interfaces/libpq/fe-connect.c
--- b/src/interfaces/libpq/fe-connect.c
*** conninfo_add_defaults(PQconninfoOption *
*** 4483,4488 
--- 4483,4495 
  		if (strcmp(option-keyword, user) == 0)
  		{
  			option-val = pg_fe_getauthname();
+ 			if (!option-val)
+ 			{
+ if (errorMessage)
+ 	printfPQExpBuffer(errorMessage,
+ 	  libpq_gettext(out of memory\n));
+ return false;
+ 			}
  			continue;
  		}
  	}

-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers