Index: src/backend/libpq/auth.c
===================================================================
RCS file: /var/lib/cvs/pgsql-server/src/backend/libpq/auth.c,v
retrieving revision 1.83
diff -c -r1.83 auth.c
*** src/backend/libpq/auth.c	18 Aug 2002 03:03:25 -0000	1.83
--- src/backend/libpq/auth.c	27 Aug 2002 06:42:19 -0000
***************
*** 809,815 ****
  		return STATUS_EOF;
  	}
  
! 	/* Do not echo failed password to logs, for security. */
  	elog(DEBUG5, "received password packet");
  
  	result = md5_crypt_verify(port, port->user, buf.data);
--- 809,825 ----
  		return STATUS_EOF;
  	}
  
! 	/*
! 	 * We don't actually use the startup packet length the frontend sent
! 	 * us; however, it's a reasonable sanity check to ensure that we
! 	 * read as much data as we expected to.
! 	 *
! 	 * The actual startup packet size is the length of the buffer, plus
! 	 * the size part of the message (4 bytes), plus a terminator.
! 	 */
! 	Assert(len == (buf.len + 4 + 1));
! 
! 	/* Do not echo password to server log, for security. */
  	elog(DEBUG5, "received password packet");
  
  	result = md5_crypt_verify(port, port->user, buf.data);
Index: src/include/libpq/pqcomm.h
===================================================================
RCS file: /var/lib/cvs/pgsql-server/src/include/libpq/pqcomm.h,v
retrieving revision 1.66
diff -c -r1.66 pqcomm.h
*** src/include/libpq/pqcomm.h	18 Aug 2002 03:03:26 -0000	1.66
--- src/include/libpq/pqcomm.h	27 Aug 2002 06:42:19 -0000
***************
*** 106,118 ****
  
  /*
   * Startup message parameters sizes.  These must not be changed without changing
!  * the protcol version.  These are all strings that are '\0' terminated only if
   * there is room.
   */
  
! /* These should all be of near-unlimited length, perhap 10k */
  #define SM_DATABASE		64
- /* SM_USER should be the same size as the others.  bjm 2002-06-02 */
  #define SM_USER			32
  /* We append database name if db_user_namespace true. */
  #define SM_DATABASE_USER (SM_DATABASE+SM_USER+1) /* +1 for @ */
--- 106,124 ----
  
  /*
   * Startup message parameters sizes.  These must not be changed without changing
!  * the protocol version.  These are all strings that are '\0' terminated only if
   * there is room.
   */
  
! /*
!  * FIXME: remove the fixed size limitations on database & user name, use
!  * variable length fields instead. The actual values will still be
!  * limited by NAMEDATALEN, but this will at least allow changing
!  * NAMEDATALEN to increase database & user name limits without changing
!  * the protocol. -neilc, 2002/08/27
!  */
! 
  #define SM_DATABASE		64
  #define SM_USER			32
  /* We append database name if db_user_namespace true. */
  #define SM_DATABASE_USER (SM_DATABASE+SM_USER+1) /* +1 for @ */
***************
*** 120,126 ****
  #define SM_UNUSED		64
  #define SM_TTY			64
  
! typedef uint32 ProtocolVersion; /* Fe/Be protocol version nr. */
  
  typedef struct StartupPacket
  {
--- 126,132 ----
  #define SM_UNUSED		64
  #define SM_TTY			64
  
! typedef uint32 ProtocolVersion; /* Fe/Be protocol version number */
  
  typedef struct StartupPacket
  {
Index: src/interfaces/libpq/fe-connect.c
===================================================================
RCS file: /var/lib/cvs/pgsql-server/src/interfaces/libpq/fe-connect.c,v
retrieving revision 1.194
diff -c -r1.194 fe-connect.c
*** src/interfaces/libpq/fe-connect.c	18 Aug 2002 01:35:39 -0000	1.194
--- src/interfaces/libpq/fe-connect.c	27 Aug 2002 06:42:19 -0000
***************
*** 1063,1094 ****
  	if (conn == NULL || conn->status == CONNECTION_BAD)
  		return 0;
  
!       /*
!        * Prepare to time calculations, if connect_timeout isn't zero.
!        */
!       if (conn->connect_timeout != NULL)
  	{
!               remains.tv_sec = atoi(conn->connect_timeout);
!               if (!remains.tv_sec)
!               {
!                       conn->status = CONNECTION_BAD;
!                       return 0;
!               }
!               remains.tv_usec = 0;
!               rp = &remains;
!       }
  
  
!       while (rp == NULL || remains.tv_sec > 0 || (remains.tv_sec == 0 && remains.tv_usec > 0))
!       {
  		/*
!                * If connecting timeout is set, get current time.
!                */
!               if (rp != NULL && gettimeofday(&start_time, NULL) == -1)
!               {
!                       conn->status = CONNECTION_BAD;
!                       return 0;
!               }
  
          /*
  		 * Wait, if necessary.	Note that the initial state (just after
--- 1063,1094 ----
  	if (conn == NULL || conn->status == CONNECTION_BAD)
  		return 0;
  
! 	/*
! 	 * Prepare to time calculations, if connect_timeout isn't zero.
! 	 */
! 	if (conn->connect_timeout != NULL)
  	{
! 		remains.tv_sec = atoi(conn->connect_timeout);
! 		if (!remains.tv_sec)
! 		{
! 			conn->status = CONNECTION_BAD;
! 			return 0;
! 		}
! 		remains.tv_usec = 0;
! 		rp = &remains;
! 	}
  
  
! 	while (rp == NULL || remains.tv_sec > 0 || remains.tv_usec > 0)
! 	{
  		/*
! 		 * If connecting timeout is set, get current time.
! 		 */
! 		if (rp != NULL && gettimeofday(&start_time, NULL) == -1)
! 		{
! 			conn->status = CONNECTION_BAD;
! 			return 0;
! 		}
  
          /*
  		 * Wait, if necessary.	Note that the initial state (just after
***************
*** 1104,1110 ****
  				return 1;		/* success! */
  
  			case PGRES_POLLING_READING:
!                               if (pqWaitTimed(1, 0, conn, rp))
  				{
  					conn->status = CONNECTION_BAD;
  					return 0;
--- 1104,1110 ----
  				return 1;		/* success! */
  
  			case PGRES_POLLING_READING:
! 				if (pqWaitTimed(1, 0, conn, rp))
  				{
  					conn->status = CONNECTION_BAD;
  					return 0;
***************
*** 1112,1118 ****
  				break;
  
  			case PGRES_POLLING_WRITING:
!                               if (pqWaitTimed(0, 1, conn, rp))
  				{
  					conn->status = CONNECTION_BAD;
  					return 0;
--- 1112,1118 ----
  				break;
  
  			case PGRES_POLLING_WRITING:
! 				if (pqWaitTimed(0, 1, conn, rp))
  				{
  					conn->status = CONNECTION_BAD;
  					return 0;
***************
*** 1130,1159 ****
  		 */
  		flag = PQconnectPoll(conn);
  
!               /*
!                * If connecting timeout is set, calculate remain time.
!                */
!               if (NULL != rp) {
!                       if (-1 == gettimeofday(&finish_time, NULL))
!                       {
!                               conn->status = CONNECTION_BAD;
!                               return 0;
!                       }
!                       if (0 > (finish_time.tv_usec -= start_time.tv_usec))
!                       {
!                               remains.tv_sec++;
!                               finish_time.tv_usec += 1000000;
!                       }
!                       if (0 > (remains.tv_usec -= finish_time.tv_usec))
!                       {
!                               remains.tv_sec--;
!                               remains.tv_usec += 1000000;
!                       }
!                       remains.tv_sec -= finish_time.tv_sec - start_time.tv_sec;
!               }
  	}
!       conn->status = CONNECTION_BAD;
!       return 0;
  }
  
  /* ----------------
--- 1130,1160 ----
  		 */
  		flag = PQconnectPoll(conn);
  
! 		/*
! 		 * If connecting timeout is set, calculate remaining time.
! 		 */
! 		if (rp != NULL)
! 		{
! 			if (gettimeofday(&finish_time, NULL) == -1)
! 			{
! 				conn->status = CONNECTION_BAD;
! 				return 0;
! 			}
! 			if (0 > (finish_time.tv_usec -= start_time.tv_usec))
! 			{
! 				remains.tv_sec++;
! 				finish_time.tv_usec += 1000000;
! 			}
! 			if (0 > (remains.tv_usec -= finish_time.tv_usec))
! 			{
! 				remains.tv_sec--;
! 				remains.tv_usec += 1000000;
! 			}
! 			remains.tv_sec -= finish_time.tv_sec - start_time.tv_sec;
! 		}
  	}
! 	conn->status = CONNECTION_BAD;
! 	return 0;
  }
  
  /* ----------------
***************
*** 1356,1362 ****
  				{
  					if (pqGets(&conn->errorMessage, conn))
  					{
! 						/* We'll come back when there are more data */
  						return PGRES_POLLING_READING;
  					}
  					/* OK, we read the message; mark data consumed */
--- 1357,1363 ----
  				{
  					if (pqGets(&conn->errorMessage, conn))
  					{
! 						/* We'll come back when there is more data */
  						return PGRES_POLLING_READING;
  					}
  					/* OK, we read the message; mark data consumed */
