[X2Go-Commits] [x2goserver] 02/04: {X2Go/Server/DB/PostgreSQL.pm, x2goserver/sbin/x2godbadmin}: move /etc/x2go/x2gosql/passwords/x2goadmin or ${HOME}/.x2go/sqlpass to .../x2gopgadmin and .../pgsqlpass respectively.

git-admin at x2go.org git-admin at x2go.org
Fri Feb 23 23:17:41 CET 2018


This is an automated email from the git hooks/post-receive script.

x2go pushed a commit to branch feature/mysql-backend
in repository x2goserver.

commit 0cb02f9176945823275c278efac6a88004056d84
Author: Mihai Moldovan <ionic at ionic.de>
Date:   Fri Feb 23 22:09:59 2018 +0100

    {X2Go/Server/DB/PostgreSQL.pm,x2goserver/sbin/x2godbadmin}: move /etc/x2go/x2gosql/passwords/x2goadmin or ${HOME}/.x2go/sqlpass to .../x2gopgadmin and .../pgsqlpass respectively.
    
    Move is done at run-time, so no user interaction should be required.
    
    It requires one database operation to be carried out first in order to
    trigger the move, but x2godbadmin does not actually use that account
    information (only generates it), so we should be in the clear.
---
 X2Go/Server/DB/PostgreSQL.pm | 33 +++++++++++++++++++++++++++++++--
 debian/changelog             |  7 +++++++
 x2goserver/sbin/x2godbadmin  | 12 ++++++++----
 3 files changed, 46 insertions(+), 6 deletions(-)

diff --git a/X2Go/Server/DB/PostgreSQL.pm b/X2Go/Server/DB/PostgreSQL.pm
index 57c31cb..622489e 100644
--- a/X2Go/Server/DB/PostgreSQL.pm
+++ b/X2Go/Server/DB/PostgreSQL.pm
@@ -33,6 +33,7 @@ use strict;
 use DBI;
 use POSIX;
 use Sys::Syslog qw( :standard :macros );
+use File::Copy;
 
 use X2Go::Log qw( loglevel );
 use X2Go::Config qw( get_config get_sqlconfig );
@@ -85,16 +86,44 @@ sub init_db
 			$port='5432';
 		}
 		my $passfile;
+		my $old_location;
 		if ($uname eq 'root')
 		{
 			$dbuser='x2godbuser';
-			$passfile="/etc/x2go/x2gosql/passwords/x2goadmin";
+			$old_location = "/etc/x2go/x2gosql/passwords/x2goadmin";
+			$passfile="/etc/x2go/x2gosql/passwords/x2gopgadmin";
 		}
 		else
 		{
 			$dbuser="x2gouser_$uname";
-			$passfile="$homedir/.x2go/sqlpass";
+			$old_location = "$homedir/.x2go/sqlpass";
+			$passfile="$homedir/.x2go/pgsqlpass";
 		}
+
+		my $move_file = 0;
+
+		if ((-e $old_location) && (-e $passfile))
+		{
+			if (-z $passfile)
+			{
+				$move_file = 1;
+			}
+			else
+			{
+				die "Detected existing files in both the legacy location '$old_location' and new location '$passfile'. New location file is non-empty, aborting.<br>";
+			}
+		}
+
+		if ((-e $old_location) && (! -e $passfile))
+		{
+			$move_file = 1;
+		}
+
+		if ($move_file)
+			# Password file needs move.
+			move($old_location, $passfile) or die "Unable to move PostgreSQL user password file from '$old_location' to '$passfile'<br>";
+		}
+
 		$sslmode=$SqlConfig->param("postgres.ssl");
 		if (!$sslmode)
 		{
diff --git a/debian/changelog b/debian/changelog
index fc4a885..f6646a9 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -67,6 +67,13 @@ x2goserver (4.1.0.1-0x2go1) UNRELEASED; urgency=medium
       which currently does not yet exist.
     - x2goserver/sbin/x2godbadmin: wrap PostgreSQL code in own block, should
       not have any functional impact.
+    - {X2Go/Server/DB/PostgreSQL.pm,x2goserver/sbin/x2godbadmin}: move
+      /etc/x2go/x2gosql/passwords/x2goadmin or ${HOME}/.x2go/sqlpass to
+      .../x2gopgadmin and .../pgsqlpass respectively. Move is done at
+      run-time, so no user interaction should be required. It requires one
+      database operation to be carried out first in order to trigger the move,
+      but x2godbadmin does not actually use that account information (only
+      generates it), so we should be in the clear.
   * debian/{control,compat}:
     + Bump DH compat level to 9.
   * debian/:
diff --git a/x2goserver/sbin/x2godbadmin b/x2goserver/sbin/x2godbadmin
index 1a2683e..ae6a914 100755
--- a/x2goserver/sbin/x2godbadmin
+++ b/x2goserver/sbin/x2godbadmin
@@ -443,6 +443,10 @@ if ($Config->param("backend") eq 'postgres')
 		{
 			return;
 		}
+		if ( -e "$dir/.x2go/pgsqlpass" )
+		{
+			unlink("$dir/.x2go/pgsqlpass");
+		}
 		if ( -e "$dir/.x2go/sqlpass" )
 		{
 			unlink("$dir/.x2go/sqlpass");
@@ -517,13 +521,13 @@ if ($Config->param("backend") eq 'postgres')
 		}
 
 		#save user password
-		open (FL,"> $dir/.x2go/sqlpass") or die "Can't open password file $dir/.x2go/sqlpass";
+		open (FL,"> $dir/.x2go/pgsqlpass") or die "Can't open password file $dir/.x2go/pgsqlpass";
 		print FL $pass;
 		close(FL);
 		chmod(0700,"$dir/.x2go");
 		chown($uid,$pgid,"$dir/.x2go");
-		chmod(0600,"$dir/.x2go/sqlpass");
-		chown($uid,$pgid,"$dir/.x2go/sqlpass");
+		chmod(0600,"$dir/.x2go/pgsqlpass");
+		chown($uid,$pgid,"$dir/.x2go/pgsqlpass");
 	}
 
 	sub create_tables()
@@ -722,7 +726,7 @@ if ($Config->param("backend") eq 'postgres')
 		$sth=$dbh->prepare("create USER $x2goadmin WITH ENCRYPTED PASSWORD '$x2goadminpass'");
 		$sth->execute() or die;
 		#save x2goadmin password
-		open (FL,"> /etc/x2go/x2gosql/passwords/x2goadmin ") or die "Can't write password file /etc/x2go/x2gosql/passwords/x2goadmin";
+		open (FL,"> /etc/x2go/x2gosql/passwords/x2gopgadmin ") or die "Can't write password file /etc/x2go/x2gosql/passwords/x2gopgadmin";
 		print FL $x2goadminpass;
 		close(FL);
 		$sth->finish();

--
Alioth's /home/x2go-admin/maintenancescripts/git/hooks/post-receive-email on /srv/git/code.x2go.org/x2goserver.git


More information about the x2go-commits mailing list