--- a/postgresql-9.5.2/src/interfaces/libpq/fe-secure-openssl.c 2016-03-28 16:07:39.000000000 -0400 +++ b/postgresql-9.5.2/src/interfaces/libpq/fe-secure-openssl.c 2016-04-15 23:12:17.493355856 -0400 @@ -35,6 +35,7 @@ #else #include #include +#include #include #include #ifdef HAVE_NETINET_TCP_H @@ -936,7 +937,14 @@ bool have_homedir; bool have_cert; EVP_PKEY *pkey = NULL; - + char *custom_homedir; + bool have_custom_homedir; + + custom_homedir = getenv("PGSQL_SSL_PATH"); + + if(custom_homedir == NULL) { have_custom_homedir = false; } + else { have_custom_homedir = true; } + /* * We'll need the home directory if any of the relevant parameters are * defaulted. If pqGetHomeDirectory fails, act as though none of the @@ -953,6 +961,9 @@ /* Read the client certificate file */ if (conn->sslcert && strlen(conn->sslcert) > 0) strlcpy(fnbuf, conn->sslcert, sizeof(fnbuf)); + /* ENV variable specified, load that certificate file */ + else if (have_custom_homedir) + snprintf(fnbuf, sizeof(fnbuf), "%s/%s", custom_homedir, USER_CERT_FILE); else if (have_homedir) snprintf(fnbuf, sizeof(fnbuf), "%s/%s", homedir, USER_CERT_FILE); else @@ -1146,6 +1157,11 @@ strlcpy(fnbuf, conn->sslkey, sizeof(fnbuf)); } } + else if (have_custom_homedir) + { + /* ENV variable specified, load that file */ + snprintf(fnbuf, sizeof(fnbuf), "%s/%s", custom_homedir, USER_KEY_FILE); + } else if (have_homedir) { /* No PGSSLKEY specified, load default file */ @@ -1207,6 +1223,8 @@ */ if (conn->sslrootcert && strlen(conn->sslrootcert) > 0) strlcpy(fnbuf, conn->sslrootcert, sizeof(fnbuf)); + else if (have_custom_homedir) + snprintf(fnbuf, sizeof(fnbuf), "%s/%s", custom_homedir, ROOT_CERT_FILE); else if (have_homedir) snprintf(fnbuf, sizeof(fnbuf), "%s/%s", homedir, ROOT_CERT_FILE); else @@ -1245,6 +1263,8 @@ { if (conn->sslcrl && strlen(conn->sslcrl) > 0) strlcpy(fnbuf, conn->sslcrl, sizeof(fnbuf)); + else if (have_custom_homedir) + snprintf(fnbuf, sizeof(fnbuf), "%s/%s", custom_homedir, ROOT_CRL_FILE); else if (have_homedir) snprintf(fnbuf, sizeof(fnbuf), "%s/%s", homedir, ROOT_CRL_FILE); else