ldap/admin/src/scripts/DSSharedLib.in | 58 ++++++++++------------------------
ldap/admin/src/scripts/DSUtil.pm.in | 15 ++++----
ldap/admin/src/scripts/db2ldif.in | 7 +---
3 files changed, 29 insertions(+), 51 deletions(-)
New commits:
commit e5c70f829a349aed7b185283d91e674f6f3918a2
Author: Mark Reynolds <mreynolds(a)redhat.com>
Date: Tue Apr 30 11:39:11 2013 -0400
Ticket 47299 - fix config file and server id processing
Bug Description: get_init_file() was not returning the config file,
normalize_server_id()
was not properly extracting the server ID, get_server_id()
was not
returning the default instance and need to remove the
newline character
from the CONFIG_DIR value, and fixed some wrong variable
names.
https://fedorahosted.org/389/ticket/47299
Reviewed by: richm(Thanks!)
(cherry picked from commit 694f914b8d4d149eb2021443e9fd4a21f064316b)
diff --git a/ldap/admin/src/scripts/DSSharedLib.in
b/ldap/admin/src/scripts/DSSharedLib.in
index 8d2edc4..3683696 100644
--- a/ldap/admin/src/scripts/DSSharedLib.in
+++ b/ldap/admin/src/scripts/DSSharedLib.in
@@ -4,30 +4,15 @@ libpath_add()
LD_LIBRARY_PATH=${LD_LIBRARY_PATH:+$LD_LIBRARY_PATH:}$1
}
-# pass in a string that ends in dirsrv-name or slapd-name
+# pass in a string that ends in dirsrv-name or slapd-name,
# and convert it to just "name"
-# the string could be a path name or not
-# if the string did not match @package_name@-name or slapd-name it
-# will be returned as is
-# want to be able to handle weird cases like /slapd-@package_name@-foo
-# that should normalize to the strange @package_name@-foo e.g.
-# someone named the instance "@package_name@-foo"
normalize_server_id()
{
- echo "$1" | sed '
-# save the current line
-h
-# delete leading path components if any (i.e. basename)
-s/^.*\///;ta
-:a
-# begins with @package_name@- ; remove it and exit
-s/^@package_name@-//;tx
-# begins with slapd- ; remove it and exit
-s/^slapd-//;tx
-# no match - return original string
-g
-:x
-'
+ servid=$1
+ servid=`echo "$servid" | sed 's/^.*\///'`
+ servid=`echo "$servid" | sed 's/^dirsrv-//'`
+ servid=`echo "$servid" | sed 's/^slapd-//'`
+ echo $servid
}
# look for all initconfig files in the given directory
@@ -40,6 +25,7 @@ g
# if not running as root, look for non-system instances in
# $HOME/.dirsrv
# ignore the dirsrv-admin admin server config file
+#
get_initconfig_files()
{
dir=${1:-@initconfigdir@}
@@ -101,7 +87,6 @@ get_init_file()
first="yes"
inst_count=0
instances="<none>"
- rc=0
# normalize servid, if given
if [ -n "$servid" ]
@@ -109,14 +94,14 @@ get_init_file()
servid=`normalize_server_id $servid`
fi
- for i in `get_initconfig_files $dir`
+ for configfile in `get_initconfig_files $dir`
do
inst_count=`expr $inst_count + 1`
- id=`normalize_server_id $i`
+ id=`normalize_server_id $configfile`
if [ -n "$servid" -a "$id" = "$servid" ]
then
# found it
- echo $i
+ echo $configfile
exit 0
fi
if [ $first == "yes" ]
@@ -126,27 +111,20 @@ get_init_file()
else
instances=$instances", $id"
fi
- name=$i
done
- if [ -n $servid ] ; then
- # if we got here, we did not find a match
- echo $instances
- exit 1
- fi
-
# server id not provided, check if there is only one instance
- if [ $inst_count -eq 1 ]
+ if [ -z "$servid" -a $inst_count -eq 1 ]
then
- servid=$name
+ # return the file
+ echo $configfile
+ exit 0
else
- # multiple instances, can not set server id. Return list of instances
- servid=$instances
- rc=1
+ # Either we have an invalid name, or more than one instance is available
+ # Return the available instances instead of the config file
+ echo $instances
+ exit 1;
fi
-
- echo $servid
- exit $rc
}
#
diff --git a/ldap/admin/src/scripts/DSUtil.pm.in b/ldap/admin/src/scripts/DSUtil.pm.in
index e439ea4..b971dac 100644
--- a/ldap/admin/src/scripts/DSUtil.pm.in
+++ b/ldap/admin/src/scripts/DSUtil.pm.in
@@ -1285,6 +1285,7 @@ sub get_server_id {
my $first = "yes";
my $instances = "<none>";
my $name;
+ my $inst;
my $file;
my @extra = ();
my $extradir = "";
@@ -1325,7 +1326,7 @@ sub get_server_id {
# skip admin server
if($file =~ m,/@package_name@-([^/]+)$, && $file !~
m,/@package_name@-admin$,){
$name = $file;
- my $inst = $1;
+ $inst = $1;
$instance_count++;
if ($servid && ($servid eq $inst)) {
$found = 1;
@@ -1351,21 +1352,20 @@ sub get_server_id {
exit (1);
}
- if ($instance_count > 1){
+ if (!$servid && $instance_count > 1){
print "You must supply a valid server instance identifier. Use -Z to
specify instance name\n";
print "Available instances: $instances\n";
exit (1);
}
-
- unless ( -e "$file" ){
+ unless ( -e "$name" ){
print (STDERR "Invalid server identifer: $servid\n");
print (STDERR "Available instances in $dir $extradir: $instances\n");
exit (1);
}
# now grab the CONFIG_DIR from the file $name
- if (open(INSTFILE, "$name")) {
- print (STDERR "Error: could not open $name: $!");
+ if (!open(INSTFILE, "$name")) {
+ print (STDERR "Error: could not open $name: ");
exit (1);
}
@@ -1375,6 +1375,7 @@ sub get_server_id {
s/^CONFIG_DIR=//;
s/ ; export CONFIG_DIR//;
$confdir = $_;
+ chomp($confdir);
last;
}
}
@@ -1385,7 +1386,7 @@ sub get_server_id {
exit (1);
}
- return ($servid, $confdir);
+ return ($inst, $confdir);
}
#
diff --git a/ldap/admin/src/scripts/db2ldif.in b/ldap/admin/src/scripts/db2ldif.in
index cca4e95..d7e0ff0 100755
--- a/ldap/admin/src/scripts/db2ldif.in
+++ b/ldap/admin/src/scripts/db2ldif.in
@@ -97,8 +97,8 @@ then
usage
exit 1
fi
-
-while getopts "hZ:n:s:x:a:NrCuUmM1qvd:D:ESt:oc:" flag
+
+while getopts "hZ:vd:D:ENa:rs:x:CSut:n:UmMo1qc:" flag
do
case $flag in
h) usage
@@ -110,8 +110,7 @@ do
required_param="yes";;
x) excludeSuffix="-x $OPTARG";;
a) outputFile="-a $OPTARG";;
- d) outputFile="-d $OPTARG";;
- t) outputFile="-t $OPTARG";;
+ d) args=$args" -d $OPTARG";;
D) args=$args" -D $OPTARG";;
N) args=$args" -N";;
E) args=$args" -E";;