From 18083249048c818c2458bed7247e5868255ff9a6 Mon Sep 17 00:00:00 2001 From: Alexander Lutay Date: Thu, 17 Oct 2019 10:23:13 +0200 Subject: [PATCH] TT#69050 ngcp-sync-constants: request 'root' user DB password if cannot connect without password Sipwise recommends to set password for MariaDB user 'root'. It brakes ngcp-reset-db which drops database, upload/create the new one and cannot connect MariaDB using user 'root' to initialize all DB passwords using ngcp-sync-constants. ngcp-sync-constants has to use user 'root' to initialize DB user 'sipwise' from constants.yml. We have to request user to provide password for DB user 'root' as it is NOT stored on NGCP platform anywhere. P.S. also performed 'wrap-and-sort -sat' here. Change-Id: I15467ef37d6765e972c8c482a2dbe86eececd0ca --- debian/control | 1 + debian/ngcp-ngcpcfg.install | 2 +- sbin/ngcp-sync-constants | 19 ++++++++++++++++--- 3 files changed, 18 insertions(+), 4 deletions(-) diff --git a/debian/control b/debian/control index df65de07..9421a4d8 100644 --- a/debian/control +++ b/debian/control @@ -16,6 +16,7 @@ Build-Depends: libdbi-perl, libhash-merge-perl, libio-interface-perl, + libio-prompter-perl, libipc-system-simple-perl, libnet-netmask-perl, libreadonly-perl, diff --git a/debian/ngcp-ngcpcfg.install b/debian/ngcp-ngcpcfg.install index 61f13f92..7bde6fde 100644 --- a/debian/ngcp-ngcpcfg.install +++ b/debian/ngcp-ngcpcfg.install @@ -26,8 +26,8 @@ scripts/clean usr/share/ngcp-ngcpcfg/scripts/ scripts/commit usr/share/ngcp-ngcpcfg/scripts/ scripts/del usr/share/ngcp-ngcpcfg/scripts/ scripts/diff usr/share/ngcp-ngcpcfg/scripts/ -scripts/get usr/share/ngcp-ngcpcfg/scripts/ scripts/etckeeper usr/share/ngcp-ngcpcfg/scripts/ +scripts/get usr/share/ngcp-ngcpcfg/scripts/ scripts/initialise usr/share/ngcp-ngcpcfg/scripts/ scripts/log usr/share/ngcp-ngcpcfg/scripts/ scripts/patch usr/share/ngcp-ngcpcfg/scripts/ diff --git a/sbin/ngcp-sync-constants b/sbin/ngcp-sync-constants index 160caed1..3db587c8 100755 --- a/sbin/ngcp-sync-constants +++ b/sbin/ngcp-sync-constants @@ -11,6 +11,7 @@ use YAML::XS; use Getopt::Long; use IPC::System::Simple qw(system capturex); use Readonly; +use IO::Prompter; #---------------------------------------------------------------------- Readonly my $CONSTANTS_YML => "/etc/ngcp-config/constants.yml"; Readonly my $SIPWISE_EXTRA_CNF => "/etc/mysql/sipwise_extra.cnf"; @@ -98,9 +99,21 @@ sub connect_db { $dsn .= ";mysql_read_default_file=$SIPWISE_EXTRA_CNF"; } - $dbh = DBI->connect($dsn, $dbuser, $dbpass, { PrintError => 1 }) - or die "Can't connect to MySQL database 'mysql' using $dbauthmsg: ". $DBI::errstr; - log_debug("connected to $dbhost:$dbport using $dbauthmsg"); + if ( $dbh = DBI->connect($dsn, $dbuser, $dbpass, { PrintError => 1 }) ) { + log_debug("connected to $dbhost:$dbport using $dbauthmsg"); + } else { + printf "Can't connect to MySQL database 'mysql' using $dbauthmsg.\n". $DBI::errstr; + if ($mysql_root) { + printf "\nPlease provide valid password for MariaDB user '$dbuser': "; + $dbpass = prompt('', -echo=>'*', -v, -hNONE); + + $dbh = DBI->connect($dsn, $dbuser, $dbpass, { PrintError => 1 }) + or die "Can't connect to MySQL database 'mysql' using $dbauthmsg with provided password.\n". $DBI::errstr; + log_debug("connected to $dbhost:$dbport using $dbauthmsg with provided password."); + } else { + exit 1; + } + } $dbh->do("SET sql_log_bin=0") or die "Cannot set sql_log_bin=0: ".$DBI::errstr;