Ticket #121: 0002-more-flexible-postgresql-connection-specification-in.patch

File 0002-more-flexible-postgresql-connection-specification-in.patch, 3.5 KB (added by hacker, 18 months ago)

patch from my local git repo addressing the issue.

  • etc/c2s.xml.dist.in

    From f0699a31cf14571c22fd9bf0d1a266b3e1e9eb6e Mon Sep 17 00:00:00 2001
    From: Michael Krelin <hacker@klever.net>
    Date: Sat, 28 Jul 2007 20:36:13 +0200
    Subject: [PATCH] more flexible postgresql connection specification in c2s.xml
    
     This connection info specifications schema uses PQconnectdb semantics, as
     opossed to its predecessor PQsetdbLogin. It is more flexible and allows for
     specifying various connection options including those that may appear in
     future postgresql versions. The old connection specification schema is still
     honored in the absence of 'conninfo'. Of course, it should be done for other
     postgresql modules as well, but I'm not yet using postgresql for all services,
     so it's yet to come. And since the patch maintains compatibility it shouldn't
     hurt.
    
    Signed-off-by: Michael Krelin <hacker@klever.net>
    ---
     etc/c2s.xml.dist.in     |    5 +++++
     storage/authreg_pgsql.c |   25 ++++++++++++++++---------
     2 files changed, 21 insertions(+), 9 deletions(-)
    
    diff --git a/etc/c2s.xml.dist.in b/etc/c2s.xml.dist.in
    index 873a133..0589ada 100644
    a b  
    325325 
    326326    <!-- PostgreSQL module configuration --> 
    327327    <pgsql> 
     328      <!-- PostgreSQL connection info --> 
     329      <conninfo>dbname=jabberd2 user=jabberd2 password=secret</conninfo> 
     330 
     331      <!-- The rest of connection settings are used only in absence of 'conninfo' --> 
     332 
    328333      <!-- Database server host and port --> 
    329334      <host>localhost</host> 
    330335      <port>5432</port> 
  • storage/authreg_pgsql.c

    diff --git a/storage/authreg_pgsql.c b/storage/authreg_pgsql.c
    index 1f15e83..cb68e7d 100644
    a b  
    304304 
    305305/** start me up */ 
    306306int ar_init(authreg_t ar) { 
    307     char *host, *port, *dbname, *user, *pass; 
     307    char *host, *port, *dbname, *user, *pass, *conninfo; 
    308308    char *create, *select, *setpassword, *delete; 
    309309    char *table, *username, *realm; 
    310310    char *template; 
     
    391391    free(setpassword); 
    392392    free(delete); 
    393393 
    394     host = config_get_one(ar->c2s->config, "authreg.pgsql.host", 0); 
    395     port = config_get_one(ar->c2s->config, "authreg.pgsql.port", 0); 
    396     dbname = config_get_one(ar->c2s->config, "authreg.pgsql.dbname", 0); 
    397     user = config_get_one(ar->c2s->config, "authreg.pgsql.user", 0); 
    398     pass = config_get_one(ar->c2s->config, "authreg.pgsql.pass", 0); 
    399  
    400     log_debug( ZONE, "pgsql connecting as '%s' to database '%s' on %s:%s", user, dbname, host, port ); 
     394    conninfo = config_get_one(ar->c2s->config,"authreg.pgsql.conninfo",0); 
     395    if(conninfo) { 
     396        /* don't log connection info for it can contain password */ 
     397        log_debug( ZONE, "pgsql connecting to the databse"); 
     398        conn = PQconnectdb(conninfo); 
     399    }else{ 
     400        /* compatibility settings */ 
     401        host = config_get_one(ar->c2s->config, "authreg.pgsql.host", 0); 
     402        port = config_get_one(ar->c2s->config, "authreg.pgsql.port", 0); 
     403        dbname = config_get_one(ar->c2s->config, "authreg.pgsql.dbname", 0); 
     404        user = config_get_one(ar->c2s->config, "authreg.pgsql.user", 0); 
     405        pass = config_get_one(ar->c2s->config, "authreg.pgsql.pass", 0); 
     406        log_debug( ZONE, "pgsql connecting as '%s' to database '%s' on %s:%s", user, dbname, host, port ); 
     407        conn = PQsetdbLogin(host, port, NULL, NULL, dbname, user, pass); 
     408    } 
    401409 
    402     conn = PQsetdbLogin(host, port, NULL, NULL, dbname, user, pass); 
    403410    if(conn == NULL) { 
    404411        log_write(ar->c2s->log, LOG_ERR, "pgsql: unable to allocate database connection state"); 
    405412        return 1;