Skip to content

Commit

Permalink
Command line flag to set the sslmode for PostgreSQL (Closes: akopytov…
Browse files Browse the repository at this point in the history
…#326)

The flag name and its values match libpq's sslmode connection parameter.
The default value (prefer) will first try an SSL connection; if that
fails, it will try a non-SSL connection.

Libpq documentation: https://www.postgresql.org/docs/14/libpq-connect.html#LIBPQ-CONNECT-SSLMODE
  • Loading branch information
ddinu committed Nov 19, 2021
1 parent ead2689 commit 1947e53
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
11 changes: 10 additions & 1 deletion src/drivers/pgsql/drv_pgsql.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ static sb_arg_t pgsql_drv_args[] =
SB_OPT("pgsql-user", "PostgreSQL user", "sbtest", STRING),
SB_OPT("pgsql-password", "PostgreSQL password", "", STRING),
SB_OPT("pgsql-db", "PostgreSQL database name", "sbtest", STRING),
SB_OPT("pgsql-sslmode", "PostgreSQL SSL mode (disable, allow, prefer, require, verify-ca, verify-full)", "prefer", STRING),

SB_OPT_END
};
Expand Down Expand Up @@ -180,7 +181,15 @@ int pgsql_drv_init(void)
args.port = sb_get_value_string("pgsql-port");
args.user = sb_get_value_string("pgsql-user");
args.password = sb_get_value_string("pgsql-password");
args.db = sb_get_value_string("pgsql-db");

char * dbname = sb_get_value_string("pgsql-db");
char * sslmode = sb_get_value_string("pgsql-sslmode");

args.db = malloc(strlen("dbname= sslmode=") +
strlen(dbname) +
strlen(sslmode) +
1);
sprintf(args.db, "dbname=%s sslmode=%s", dbname, sslmode);

use_ps = 0;
pgsql_drv_caps.prepared_statements = 1;
Expand Down
3 changes: 2 additions & 1 deletion tests/t/help_drv_pgsql.t
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@ Skip test if the PostgreSQL driver is not available.
--pgsql-user=STRING PostgreSQL user [sbtest]
--pgsql-password=STRING PostgreSQL password []
--pgsql-db=STRING PostgreSQL database name [sbtest]

--pgsql-sslmode=STRING PostgreSQL SSL mode (disable, allow, prefer, require, verify-ca, verify-full) [prefer]

0 comments on commit 1947e53

Please sign in to comment.