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

SF.net SVN: ledger-smb:[4383] branches/1.3



Revision: 4383
          http://ledger-smb.svn.sourceforge.net/ledger-smb/?rev=4383&view=rev
Author:   einhverfr
Date:     2012-03-06 01:36:28 +0000 (Tue, 06 Mar 2012)
Log Message:
-----------

Moved the LedgerSMB::Database->create() function from using createdb to using DBI to
connect to template1 and issue the CREATE DATABASE command directly.  The reasoning
for this is that createdb apparently connects to postgres db which makes things harder
and less intuitive to administer via the pg_hba.conf.

Modified Paths:
--------------
    branches/1.3/Changelog
    branches/1.3/LedgerSMB/Database.pm

Modified: branches/1.3/Changelog
===================================================================
--- branches/1.3/Changelog	2012-03-06 01:13:37 UTC (rev 4382)
+++ branches/1.3/Changelog	2012-03-06 01:36:28 UTC (rev 4383)
@@ -4,6 +4,7 @@
 
 Changelog for 1.3.13
 * Reduced log messages when upgrading/creating db, for some log levels (Chris T)
+* Changed db setup not to use createdb for simple admin of pg_hba.conf (Chris T)
 
 Changelog for 1.3.12
 * Corrected processing of <?lsmb tags in order/invoice numbers (Chris T)

Modified: branches/1.3/LedgerSMB/Database.pm
===================================================================
--- branches/1.3/LedgerSMB/Database.pm	2012-03-06 01:13:37 UTC (rev 4382)
+++ branches/1.3/LedgerSMB/Database.pm	2012-03-06 01:36:28 UTC (rev 4383)
@@ -394,9 +394,23 @@
     # We have to use template0 because of issues that Debian has with database 
     # encoding.  Apparently that causes problems for us, so template0 must be
     # used.
-    my $rc = system("createdb -T template0 -E UTF8 > $temp/dblog");
+    #
+    # Also moved away from createdb here because at least for some versions of
+    # PostgreSQL, it connects to the postgres db in order to issue the CREATE DATABASE
+    # command.  This makes it harder to adequately secure the platform via pg_hba.conf.
+    # 
+    # Hat tip:  irc user nwnw -- CT
+
+    use DBI;
+    my $dbh = DBI->connect('dbi:Pg:dbname=template1');
+
+    $dbh->{RaiseError} = 1;
+    $dbh->{AutoCommit} = 1;
+    my $dbn = $dbh->quote_identifier($ENV{PGDATABASE});
+    my $rc = $dbh->do("CREATE DATABASE $dbn WITH TEMPLATE template0 ENCODING 'UTF8'");
+
     $logger->trace("after create db \$rc=$rc");
-    if ($rc) {
+    if (!$rc) {
         return $rc;
     }
     my $rc2=0;

This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.