From dc1d2b808967757083119e3fbf0582896a053ad5 Mon Sep 17 00:00:00 2001 From: Noriko Hosoi Date: Wed, 29 Apr 2015 22:39:49 -0700 Subject: [PATCH] Ticket #48171 - remove-ds-admin.pl removes files in the rpm Description: remove-ds-admin.pl expects /etc/dirsrv/admin-serv/bakup contains the original config files from rpm to replace with. If setup-ds-admin.pl fails for some reason, it quits without backing up the files. In the case, remove-ds-admin.pl just removes the config files since there is no way to restore them. This patch moves the backup code before the operation that has a possibility to fail. This allows setup-ds-admin.pl to create the backups even if the setup fails. Also, read_conf and update_conf in cgi-src40/config.c uses given path and file name instead of the generated full path which is set up an empty string if the file is not accessible or not a plain file. --- admserv/cgi-src40/config.c | 4 ++-- admserv/newinst/src/AdminServer.pm.in | 34 ++++++++++++++++++---------------- 2 files changed, 20 insertions(+), 18 deletions(-) diff --git a/admserv/cgi-src40/config.c b/admserv/cgi-src40/config.c index ddb4af3..8b16737 100644 --- a/admserv/cgi-src40/config.c +++ b/admserv/cgi-src40/config.c @@ -714,7 +714,7 @@ static char * read_conf(char *file, char *name) { f = fopen(filename, "r"); if (f==NULL) { char msg[BIG_LINE]; - PR_snprintf(msg, BIG_LINE, "Cannot open file %s for reading", filename); + PR_snprintf(msg, BIG_LINE, "Cannot open file %s/%s for reading", configdir, file); rpt_err(SYSTEM_ERROR, msg, NULL, NULL); } @@ -752,7 +752,7 @@ static int update_conf(char *file, char *name, char *val) { f = fopen(filename, "r"); if (f==NULL) { char msg[BIG_LINE]; - PR_snprintf(msg, BIG_LINE, "Cannot open file %s for reading", filename); + PR_snprintf(msg, BIG_LINE, "Cannot open file %s/%s for reading", configdir, file); rpt_err(SYSTEM_ERROR, msg, NULL, NULL); } diff --git a/admserv/newinst/src/AdminServer.pm.in b/admserv/newinst/src/AdminServer.pm.in index 0c98a6e..a141596 100644 --- a/admserv/newinst/src/AdminServer.pm.in +++ b/admserv/newinst/src/AdminServer.pm.in @@ -384,6 +384,23 @@ sub updateHttpConfFiles { libpath_add("@LIBPATH@"); libpath_add("$savepath"); $ENV{SHLIB_PATH} = $ENV{LD_LIBRARY_PATH}; + + if (! -d "$admConf->{configdir}/bakup") { + if (system ("mkdir -p $admConf->{configdir}/bakup")) { + debug(0, "Error backing up $admConf->{configdir}/console.conf failed: $!"); + } + } + # backup the savefiles for "remove-ds-admin.pl -a" + foreach my $savefile (@saveconffiles, @savesecfiles) { + if (! -f "$admConf->{configdir}/bakup/$savefile") { + if (-e "$admConf->{configdir}/$savefile"){ + if(system ("cp -p $admConf->{configdir}/$savefile $admConf->{configdir}/bakup")) { + debug(0, "Error backing up $admConf->{configdir}/$savefile failed: $!\n"); + } + } + } + } + my $cmd = "@cgibindir@/config op=set configuration.nsSuiteSpotUser=\"$user\""; if (!defined($origport) or ($port != $origport)) { # need to change the port number $cmd .= " configuration.nsServerPort=\"$port\""; @@ -391,7 +408,7 @@ sub updateHttpConfFiles { if ($serverAddress) { $cmd .= " configuration.nsServerAddress=\"$serverAddress\""; } - + debug(1, "Running $cmd ..."); $? = 0; # clear error my $output = `$cmd 2>&1`; # Check the output of the config CGI to see if something bad happened. @@ -423,21 +440,6 @@ sub updateHttpConfFiles { print CONSOLECONF @contents; close (CONSOLECONF); } - if (! -d "$admConf->{configdir}/bakup") { - if (system ("mkdir -p $admConf->{configdir}/bakup")) { - debug(0, "Error backing up $admConf->{configdir}/console.conf failed: $!"); - } - } - # backup the savefiles for "remove-ds-admin.pl -a" - foreach my $savefile (@saveconffiles, @savesecfiles) { - if (! -f "$admConf->{configdir}/bakup/$savefile") { - if (-e "$admConf->{configdir}/$savefile"){ - if(system ("cp -p $admConf->{configdir}/$savefile $admConf->{configdir}/bakup")) { - debug(0, "Error backing up $admConf->{configdir}/$savefile failed: $!\n"); - } - } - } - } return 1; } -- 1.9.3