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

Support UNIX domain socket connection



Please accept the attached patch.  It allows connecting to the database
via UNIX domain socket (in the case that the DB is on the same host as
the web server and the user leaves DBhost and DBport empty in
/etc/ledgersmb/ledgersmb.conf, as well as leave the port and host blank
in the individual user config).

Regards,

-Roberto

-- 
Roberto C. Sánchez
http://people.connexer.com/~roberto
http://www.connexer.com
diff -uNr ledgersmb-1.2.15.orig/LedgerSMB/Sysconfig.pm ledgersmb-1.2.15/LedgerSMB/Sysconfig.pm
--- ledgersmb-1.2.15.orig/LedgerSMB/Sysconfig.pm	2008-09-01 14:38:19.000000000 -0400
+++ ledgersmb-1.2.15/LedgerSMB/Sysconfig.pm	2008-09-01 15:48:59.000000000 -0400
@@ -122,9 +122,18 @@
 
 #putting this in an if clause for now so not to break other devel users
 if ( $config{globaldb}{DBname} ) {
-    my $dbconnect = "dbi:Pg:dbname=$globalDBname host=$globalDBhost
-		port=$globalDBport user=$globalDBUserName
-		password=$globalDBPassword";    # for easier debugging
+    my $dbconnect = "dbi:Pg:dbname=$globalDBname ";
+    if ( $globalDBhost ) {
+        $dbconnect .= " host=$globalDBhost";
+	if ( $globalDBport ) {
+            $dbconnect .= " port=$globalDBport";
+	} else {
+            $dbconnect .= " port=5432";
+	}
+    }
+    $dbconnect .= " user=$globalDBUserName" if $globalDBUserName;
+    $dbconnect .= " password=$globalDBPassword" if $globalDBPassword;
+
     $GLOBALDBH = DBI->connect($dbconnect);
     if ( !$GLOBALDBH ) {
         $form = new Form;
diff -uNr ledgersmb-1.2.15.orig/LedgerSMB/User.pm ledgersmb-1.2.15/LedgerSMB/User.pm
--- ledgersmb-1.2.15.orig/LedgerSMB/User.pm	2008-08-18 14:15:07.000000000 -0400
+++ ledgersmb-1.2.15/LedgerSMB/User.pm	2008-09-01 22:46:10.000000000 -0400
@@ -74,13 +74,15 @@
         chomp( $self->{dbname} );
         chomp( $self->{dbhost} );
 
-        $self->{dbconnect} =
-            'dbi:Pg:dbname='
-          . $self->{dbname}
-          . ';host='
-          . $self->{dbhost}
-          . ';port='
-          . $self->{dbport};
+        $self->{dbconnect} = 'dbi:Pg:dbname=' . $self->{dbname};
+        if ( $self->{dbhost} ) {
+            $self->{dbconnect} .= ';host=' . $self->{dbhost};
+            if ( $self->{dbport} ) {
+                $self->{dbconnect} .= ';port=' . $self->{dbport};
+            } else {
+                $self->{dbconnect} .= ';port=5432';
+            }
+        }
 
         if ( $self->{username} ) {
             $self->{login} = $login;
@@ -160,13 +162,15 @@
     chomp( $myconfig{'dbhost'} );
 
     $myconfig{'login'} = $login;
-    $myconfig{'dbconnect'} =
-        'dbi:Pg:dbname='
-      . $myconfig{'dbname'}
-      . ';host='
-      . $myconfig{'dbhost'}
-      . ';port='
-      . $myconfig{'dbport'};
+    $myconfig{'dbconnect'} = 'dbi:Pg:dbname=' . $myconfig{'dbname'};
+    if ( $myconfig{'dbhost'} ) {
+        $myconfig{'dbconnect'} .= ';host=' . $myconfig{'dbhost'};
+        if ( $myconfig{'dbport'} ) {
+            $myconfig{'dbconnect'} .= ';port=' . $myconfig{'dbport'};
+        } else {
+            $myconfig{'dbconnect'} .= ';port=5432';
+        }
+    }
 
     return \%myconfig;
 }
@@ -295,8 +299,14 @@
     $form->{dboptions} = $dboptions{ $form->{dbdriver} }{ $form->{dateformat} };
 
     $form->{dbconnect} = "dbi:$form->{dbdriver}:dbname=$db";
-    $form->{dbconnect} .= ";host=$form->{dbhost}";
-    $form->{dbconnect} .= ";port=$form->{dbport}";
+    if ( $form->{dbhost} ) {
+        $form->{dbconnect} .= ";host=$form->{dbhost}";
+        if ( $form->{dbport} ) {
+            $form->{dbconnect} .= ";port=$form->{dbport}";
+        } else {
+            $form->{dbconnect} .= ";port=5432";
+        }
+    }
 
 }
 

Attachment: signature.asc
Description: Digital signature