Re: PostgreSQL 9.3.5 - Enable SSL

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



shyamkant.dhamke@xxxxxxxxx wrote:
> I need sample C program ( running on Unix )  to connect to PostgreSQL 9.3.5 (SSL Enabled) database.

#include <stdio.h>
#include <libpq-fe.h>

int main(int argc, char **argv) {
    PGconn *conn;

    conn = PQconnectdb("host=... port=... dbname=... user=... password=...");
    if (conn == NULL) {
        fprintf(stderr, "Out of memory.\n");
        return 1;
    }
    if (PQstatus(conn) != CONNECTION_OK) {
        fprintf(stderr, PQerrorMessage(conn));
        PQfinish(conn);
        return 1;
    }

    PQfinish(conn);
    return 0;
}


Essentially, there's nothing special to do in the C code.

You have to have the server set up for SSL (ssl=on) and the certificate and key in place.
On the client side, you can add "sslmode=require" as connection option to make sure that
no unencrypted connection is attempted.

Yours,
Laurenz Albe

-- 
Sent via pgsql-admin mailing list (pgsql-admin@xxxxxxxxxxxxxx)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-admin




[Index of Archives]     [KVM ARM]     [KVM ia64]     [KVM ppc]     [Virtualization Tools]     [Spice Development]     [Libvirt]     [Libvirt Users]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite Questions]     [Linux Kernel]     [Linux SCSI]     [XFree86]

  Powered by Linux