Index: doc/src/sgml/libpq.sgml
===================================================================
RCS file: /var/lib/cvs/pgsql-server/doc/src/sgml/libpq.sgml,v
retrieving revision 1.106
diff -c -r1.106 libpq.sgml
*** doc/src/sgml/libpq.sgml	19 Jan 2003 00:13:28 -0000	1.106
--- doc/src/sgml/libpq.sgml	28 Jan 2003 19:37:25 -0000
***************
*** 2010,2019 ****
  
  <para>
  The following environment variables can be used to select default
! connection parameter values, which will be used by <function>PQconnectdb</function> or
! <function>PQsetdbLogin</function> if no value is directly specified by the calling code.
! These are useful to avoid hard-coding database names into simple
! application programs.
  
  <itemizedlist>
  <listitem>
--- 2010,2020 ----
  
  <para>
  The following environment variables can be used to select default
! connection parameter values, which will be used by
! <function>PQconnectdb</>, <function>PQsetdbLogin</> and
! <function>PQsetdb</> if no value is directly specified by the calling
! code.  These are useful to avoid hard-coding database connection
! information into simple client applications.
  
  <itemizedlist>
  <listitem>
***************
*** 2091,2096 ****
--- 2092,2115 ----
  messages from the backend server are displayed.
  </para>
  </listitem>
+ <listitem>
+ <para>
+ <envar>PGREQUIRESSL</envar> sets whether or not the connection must be
+ made over <acronym>SSL</acronym>. If enabled (set to
+ <quote>1</quote>), non-<acronym>SSL</acronym> connections will not be
+ attempted if the server does not allow <acronym>SSL</acronym>
+ connections. This option is only available if
+ <productname>PostgreSQL</> is compiled with SSL support.
+ </para>
+ </listitem>
+ <listitem>
+ <para>
+ <envar>PGCONNECT_TIMEOUT</envar> sets the maximum number of seconds
+ that <application>libpq</application> will wait when attempting to
+ connect to the <productname>PostgreSQL</productname> server. This
+ option should be set to at least 2 seconds.
+ </para>
+ </listitem>
  </itemizedlist>
  </para>
  
***************
*** 2161,2170 ****
  <synopsis>
  <replaceable>hostname</replaceable>:<replaceable>port</replaceable>:<replaceable>database</replaceable>:<replaceable>username</replaceable>:<replaceable>password</replaceable>
  </synopsis>
! Any of these may be a literal name, or <literal>*</literal>, which matches
! anything.  The first match will be used so put more specific entries first.
! Entries with <literal>:</literal> or <literal>\</literal> should be escaped
! with <literal>\</literal>.
  </para>
  <para>
  The permissions on <filename>.pgpass</filename> must disallow any
--- 2180,2189 ----
  <synopsis>
  <replaceable>hostname</replaceable>:<replaceable>port</replaceable>:<replaceable>database</replaceable>:<replaceable>username</replaceable>:<replaceable>password</replaceable>
  </synopsis>
! Any of these may be a literal name, or <literal>*</literal>, which
! matches anything.  The first matching entry will be used, so put more
! specific entries first.  Entries with <literal>:</literal> or
! <literal>\</literal> should be escaped with <literal>\</literal>.
  </para>
  <para>
  The permissions on <filename>.pgpass</filename> must disallow any
Index: src/interfaces/libpq/fe-connect.c
===================================================================
RCS file: /var/lib/cvs/pgsql-server/src/interfaces/libpq/fe-connect.c,v
retrieving revision 1.221
diff -c -r1.221 fe-connect.c
*** src/interfaces/libpq/fe-connect.c	8 Jan 2003 21:33:27 -0000	1.221
--- src/interfaces/libpq/fe-connect.c	28 Jan 2003 19:35:21 -0000
***************
*** 123,129 ****
  	"Database-Password", "*", 20},
  
  	{"connect_timeout", "PGCONNECT_TIMEOUT", NULL, NULL,
! 	"Connect-timeout", "", 10}, /* strlen( INT32_MAX) == 10 */
  
  	{"dbname", "PGDATABASE", NULL, NULL,
  	"Database-Name", "", 20},
--- 123,129 ----
  	"Database-Password", "*", 20},
  
  	{"connect_timeout", "PGCONNECT_TIMEOUT", NULL, NULL,
! 	"Connect-timeout", "", 10}, /* strlen(INT32_MAX) == 10 */
  
  	{"dbname", "PGDATABASE", NULL, NULL,
  	"Database-Name", "", 20},
***************
*** 506,519 ****
  	else
  		conn->dbName = strdup(dbName);
  
- 	/*
- 	 * getPasswordFromFile mallocs its result, so we don't need strdup
- 	 * here
- 	 */
  	if (pwd)
  		conn->pgpass = strdup(pwd);
  	else if ((tmp = getenv("PGPASSWORD")) != NULL)
  		conn->pgpass = strdup(tmp);
  	else
  		conn->pgpass = strdup(DefaultPassword);
  
--- 506,518 ----
  	else
  		conn->dbName = strdup(dbName);
  
  	if (pwd)
  		conn->pgpass = strdup(pwd);
  	else if ((tmp = getenv("PGPASSWORD")) != NULL)
  		conn->pgpass = strdup(tmp);
+ 	else if ((tmp = PasswordFromFile(conn->pghost, conn->pgport,
+ 									 conn->dbName, conn->pguser)) != NULL)
+ 		conn->pgpass = tmp;
  	else
  		conn->pgpass = strdup(DefaultPassword);
  
***************
*** 2946,2952 ****
  	return NULL;
  }
  
! /* get a password from the password file. */
  char *
  PasswordFromFile(char *hostname, char *port, char *dbname, char *username)
  {
--- 2945,2951 ----
  	return NULL;
  }
  
! /* Get a password from the password file. Return value is malloc'd. */
  char *
  PasswordFromFile(char *hostname, char *port, char *dbname, char *username)
  {
***************
*** 2972,2988 ****
  
  	/* Look for it in the home dir */
  	home = getenv("HOME");
! 	if (home)
  	{
! 		pgpassfile = malloc(strlen(home) + 1 + strlen(PGPASSFILE) + 1);
! 		if (!pgpassfile)
! 		{
! 			fprintf(stderr, libpq_gettext("out of memory\n"));
! 			return NULL;
! 		}
! 	}
! 	else
  		return NULL;
  
  	sprintf(pgpassfile, "%s/%s", home, PGPASSFILE);
  
--- 2971,2985 ----
  
  	/* Look for it in the home dir */
  	home = getenv("HOME");
! 	if (!home)
! 		return NULL;
! 
! 	pgpassfile = malloc(strlen(home) + 1 + strlen(PGPASSFILE) + 1);
! 	if (!pgpassfile)
  	{
! 		fprintf(stderr, libpq_gettext("out of memory\n"));
  		return NULL;
+ 	}
  
  	sprintf(pgpassfile, "%s/%s", home, PGPASSFILE);
  
***************
*** 3014,3025 ****
  	{
  		char	   *t = buf,
  				   *ret;
  
  		fgets(buf, LINELEN - 1, fp);
! 		if (strlen(buf) == 0)
  			continue;
  
! 		buf[strlen(buf) - 1] = 0;
  		if ((t = pwdfMatchesString(t, hostname)) == NULL ||
  			(t = pwdfMatchesString(t, port)) == NULL ||
  			(t = pwdfMatchesString(t, dbname)) == NULL ||
--- 3011,3028 ----
  	{
  		char	   *t = buf,
  				   *ret;
+ 		int			len;
  
  		fgets(buf, LINELEN - 1, fp);
! 
! 		len = strlen(buf);
! 		if (len == 0)
  			continue;
  
! 		/* Remove trailing newline */
! 		if (buf[len - 1] == '\n')
! 			buf[len - 1] = 0;
! 
  		if ((t = pwdfMatchesString(t, hostname)) == NULL ||
  			(t = pwdfMatchesString(t, port)) == NULL ||
  			(t = pwdfMatchesString(t, dbname)) == NULL ||
