baseten / Patches / libpq.patch

--- src/interfaces/libpq/fe-connect.c	2008-01-29 04:06:30.000000000 +0200
+++ src/interfaces/libpq/fe-connect.c	2008-07-29 22:29:06.000000000 +0300
@@ -1029,6 +1029,7 @@
 
 			/* Special cases: proceed without waiting. */
 		case CONNECTION_SSL_STARTUP:
+		case CONNECTION_SSL_CONTINUE:
 		case CONNECTION_NEEDED:
 			break;
 
@@ -1336,13 +1337,17 @@
 		case CONNECTION_SSL_STARTUP:
 			{
 #ifdef USE_SSL
-				PostgresPollingStatusType pollres;
-
 				/*
 				 * On first time through, get the postmaster's response to our
 				 * SSL negotiation packet.
 				 */
-				if (conn->ssl == NULL)
+				if (conn->ssl != NULL)
+				{
+					/* We shouldn't end up here */
+					conn->status = CONNECTION_SSL_CONTINUE;
+					return PGRES_POLLING_WRITING;
+				}
+				else
 				{
 					/*
 					 * We use pqReadData here since it has the logic to
@@ -1375,6 +1380,9 @@
 						/* Do one-time setup; this creates conn->ssl */
 						if (pqsecure_initialize(conn) == -1)
 							goto error_return;
+
+						conn->status = CONNECTION_SSL_CONTINUE;
+						return pqsecure_prepare_client (conn);
 					}
 					else if (SSLok == 'N')
 					{
@@ -1420,11 +1428,18 @@
 						goto error_return;
 					}
 				}
-
+#else /* !USE_SSL */
+				/* can't get here */
+				goto error_return;
+#endif   /* USE_SSL */
+            }
+        case CONNECTION_SSL_CONTINUE:
+            {
+#ifdef USE_SSL
 				/*
 				 * Begin or continue the SSL negotiation process.
 				 */
-				pollres = pqsecure_open_client(conn);
+				PostgresPollingStatusType pollres = pqsecure_open_client(conn);
 				if (pollres == PGRES_POLLING_OK)
 				{
 					/* SSL handshake done, ready to send startup packet */
--- src/interfaces/libpq/fe-secure.c	2008-01-29 04:03:39.000000000 +0200
+++ src/interfaces/libpq/fe-secure.c	2008-07-29 23:10:33.000000000 +0300
@@ -250,10 +250,10 @@
 }
 
 /*
- *	Attempt to negotiate secure session.
+ *	Set conn->ssl.
  */
 PostgresPollingStatusType
-pqsecure_open_client(PGconn *conn)
+pqsecure_prepare_client(PGconn *conn)
 {
 #ifdef USE_SSL
 	/* First time through? */
@@ -279,6 +279,20 @@
 		 */
 		resetPQExpBuffer(&conn->errorMessage);
 	}
+	return PGRES_POLLING_WRITING;
+#else
+	/* shouldn't get here */
+	return PGRES_POLLING_FAILED;
+#endif
+}
+
+/*
+ *	Attempt to negotiate secure session.
+ */
+PostgresPollingStatusType
+pqsecure_open_client(PGconn *conn)
+{
+#ifdef USE_SSL
 	/* Begin or continue the actual handshake */
 	return open_client_SSL(conn);
 #else
--- src/interfaces/libpq/libpq-fe.h	2008-01-01 21:46:00.000000000 +0200
+++ src/interfaces/libpq/libpq-fe.h	2008-07-29 22:18:41.000000000 +0300
@@ -53,7 +53,8 @@
 								 * backend startup. */
 	CONNECTION_SETENV,			/* Negotiating environment. */
 	CONNECTION_SSL_STARTUP,		/* Negotiating SSL. */
-	CONNECTION_NEEDED			/* Internal state: connect() needed */
+	CONNECTION_NEEDED,			/* Internal state: connect() needed */
+	CONNECTION_SSL_CONTINUE,
 } ConnStatusType;
 
 typedef enum
--- src/interfaces/libpq/libpq-int.h	2008-01-01 21:46:00.000000000 +0200
+++ src/interfaces/libpq/libpq-int.h	2008-07-29 22:17:33.000000000 +0300
@@ -528,6 +528,7 @@
 
 extern int	pqsecure_initialize(PGconn *);
 extern void pqsecure_destroy(void);
+extern PostgresPollingStatusType pqsecure_prepare_client(PGconn *);
 extern PostgresPollingStatusType pqsecure_open_client(PGconn *);
 extern void pqsecure_close(PGconn *);
 extern ssize_t pqsecure_read(PGconn *, void *ptr, size_t len);
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.