Browse Source

Ticket #47299 - allow cmdline scripts to work with non-root user

https://fedorahosted.org/389/ticket/47299
Reviewed by: nhosoi (Thanks!)
Branch: master
Fix Description: Handle the case where the directory server userid is a real
user on the system, and allow that user to run the command line scripts against
that server without using sudo.  I also centralized the handling of the
initconfig (/etc/sysconfig/dirsrv-*) files in DSSharedLib and DSUtil.pm.
I changed the way the scripts work - the sh scripts need the "normalized"
server id and the CONFIG_DIR (/etc/dirsrv/slapd-$servid) - we first find the
initconfig file for the given instance, then we just source it - CONFIG_DIR
is one of the settings in the file - no need to parse in sh because source
does that.
In perl, do the same thing, except have to parse the initconfig file to get
the CONFIG_DIR.
Platforms tested: RHEL6 x86_64
Flag Day: no
Doc impact: no
Rich Megginson 12 years ago
parent
commit
6fb5b261d8
36 changed files with 359 additions and 288 deletions
  1. 117 60
      ldap/admin/src/scripts/DSSharedLib.in
  2. 83 32
      ldap/admin/src/scripts/DSUtil.pm.in
  3. 6 6
      ldap/admin/src/scripts/bak2db.in
  4. 2 2
      ldap/admin/src/scripts/bak2db.pl.in
  5. 2 2
      ldap/admin/src/scripts/cleanallruv.pl.in
  6. 7 6
      ldap/admin/src/scripts/db2bak.in
  7. 3 3
      ldap/admin/src/scripts/db2bak.pl.in
  8. 8 7
      ldap/admin/src/scripts/db2index.in
  9. 2 2
      ldap/admin/src/scripts/db2index.pl.in
  10. 8 7
      ldap/admin/src/scripts/db2ldif.in
  11. 2 2
      ldap/admin/src/scripts/db2ldif.pl.in
  12. 6 6
      ldap/admin/src/scripts/dbverify.in
  13. 7 6
      ldap/admin/src/scripts/dn2rdn.in
  14. 2 2
      ldap/admin/src/scripts/fixup-linkedattrs.pl.in
  15. 2 2
      ldap/admin/src/scripts/fixup-memberof.pl.in
  16. 6 6
      ldap/admin/src/scripts/ldif2db.in
  17. 2 2
      ldap/admin/src/scripts/ldif2db.pl.in
  18. 7 5
      ldap/admin/src/scripts/ldif2ldap.in
  19. 6 5
      ldap/admin/src/scripts/monitor.in
  20. 2 2
      ldap/admin/src/scripts/ns-accountstatus.pl.in
  21. 2 2
      ldap/admin/src/scripts/ns-activate.pl.in
  22. 2 2
      ldap/admin/src/scripts/ns-inactivate.pl.in
  23. 2 2
      ldap/admin/src/scripts/ns-newpwpolicy.pl.in
  24. 6 22
      ldap/admin/src/scripts/restart-dirsrv.in
  25. 8 5
      ldap/admin/src/scripts/restoreconfig.in
  26. 7 6
      ldap/admin/src/scripts/saveconfig.in
  27. 2 2
      ldap/admin/src/scripts/schema-reload.pl.in
  28. 10 28
      ldap/admin/src/scripts/start-dirsrv.in
  29. 9 24
      ldap/admin/src/scripts/stop-dirsrv.in
  30. 6 6
      ldap/admin/src/scripts/suffix2instance.in
  31. 2 2
      ldap/admin/src/scripts/syntax-validate.pl.in
  32. 7 6
      ldap/admin/src/scripts/upgradedb.in
  33. 6 6
      ldap/admin/src/scripts/upgradednformat.in
  34. 2 2
      ldap/admin/src/scripts/usn-tombstone-cleanup.pl.in
  35. 2 2
      ldap/admin/src/scripts/verify-db.pl.in
  36. 6 6
      ldap/admin/src/scripts/vlvindex.in

+ 117 - 60
ldap/admin/src/scripts/DSSharedLib.in

@@ -4,23 +4,45 @@ libpath_add()
     LD_LIBRARY_PATH=${LD_LIBRARY_PATH:+$LD_LIBRARY_PATH:}$1
 }
 
-#
-#  get_server_id()
-#
-#  First grab all the server instances
-#  Then check if a server id was provided, if not, set
-#  the server id if there is only one instance. 
-#  If a servid was provided, make sure its a valid instance name.
-#
-get_server_id()
+# 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()
 {
-    dir=$1
-    servid=$2
-    first="yes"
-    inst_count=0
-    instances="<none>"
-    rc=0
+    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
+'
+}
 
+# look for all initconfig files in the given directory
+# the initconfig files are the files used in the startup scripts
+# to start each instance
+# e.g. /etc/sysconfig/dirsrv-INST
+# these scripts contain the pointer CONFIG_DIR to where the instance
+# configuration files are to be found
+# if the given directory is empty, look in @initconfigdir@
+# 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@}
     # convert
     # uid=0(root) gid=0(root) groups=0(root),1(bin),2(daemon),3(sys),.....
     # to
@@ -29,61 +51,96 @@ get_server_id()
     userid=`id | awk -F'[=(]+' '{print $2}'`
     if [ "$userid" -ne 0 ] ; then
         # magic - see start-dirsrv, DSCreate.pm::get_initconfigdir, etc.
-        dir=$HOME/.@package_name@
+        extradir=$HOME/.@package_name@
+        if [ -d $extradir ] ; then
+            extra="$extradir/@package_name@-*"
+        fi
     fi
+    # setting the env var forces the use of it and nothing else
     if [ -n "$INITCONFIGDIR" ] ; then
         dir=$INITCONFIGDIR
+        extra=
     fi
-
-    # look first in user provided INITCONFIGDIR, then in the system/build location,
-    # then in the users home dir - cases
-    # 1. system install but running as non-root user
-    #    in this case, we want to use the instance from $dir - it will
-    #    fallback to $homedir in that case, and if that is a problem, the user will
-    #    just have to temporarily move $homedir/dirsrv-sysinstancename out of the way
-    #    while working on the system instance
-    # 2. prefix/non-system install
-    #    in this case, we want to use $homedir - if for some reason there is a system
-    #    instance in $dir with the same name, the user can use INITCONFIGDIR to
-    #    override that and force the use of the one from $homedir
-    for i in `ls $dir/@package_name@-* 2>/dev/null`
-    do
-        if [ $i != "$dir/@package_name@-admin" ]
-        then
-            inst_count=`expr $inst_count + 1`
-            id=$(expr "$i" : ".*@package_name@-\([^)]*\).*")
-            if  [ $first == "yes" ]
-            then
-                instances=$id
-                first="no"
-            else
-                instances=$instances", $id"
-            fi
-            name=$id
+    retfiles=
+    found=1
+    for file in $dir/@package_name@-* $extra ; do
+        if [ ! -r "$file" ] ; then continue ; fi
+        case "$file" in */@package_name@-admin) continue ;; esac
+        if [ -z "$retfiles" ] ; then
+            retfiles=$file
+        else
+            retfiles="$retfiles $file"
         fi
+        found=0
     done
+    echo $retfiles
+    return $found # 0 return means success - at least one found
+}
+
+#
+#  get_init_file()
+#  
+#  The init file is the instance specific file under
+#  the @initconfig@ directory e.g.
+#  /etc/sysconfig/dirsrv-instance
+#  The presence and readability of this file means this is a
+#  valid instance of directory server (except @package_name@-admin)
+#  The CONFIG_DIR directive in this file tells us where to
+#  look for the main server config
+#  First grab all the @package_name@ init files
+#  Then check if a server id was provided, if not, return the
+#  one found if there is only one
+#  If a servid was provided, make sure there is an init file
+#  for that instance
+#  Return the @initconfigdir@/@package_name@-$servid file name
+#
+get_init_file()
+{
+    dir=$1
+    servid=$2
+    first="yes"
+    inst_count=0
+    instances="<none>"
+    rc=0
 
-    if [ -z $servid ]
+    # normalize servid, if given
+    if [ -n "$servid" ]
     then
-        # server id not provided, check if there is only one instance
-        if [ $inst_count -eq 1 ]
+        servid=`normalize_server_id $servid`
+    fi
+
+    for i in `get_initconfig_files $dir`
+    do
+        inst_count=`expr $inst_count + 1`
+        id=`normalize_server_id $i`
+        if [ -n "$servid" -a "$id" = "$servid" ]
         then
-            servid=$name
-        else 
-            # multiple instances, can not set server id.  Return list of instances
-            servid=$instances
-            rc=1;
+            # found it
+            echo $i
+            exit 0
         fi
-    elif [ $servid == slapd-* ]
-    then
-        servid=`echo "$servid" | sed -e 's/slapd-//'`
-    elif [ $servid == @package_name@-* ]
-    then
-        servid=`echo "$servid" | sed -e 's/@package_name@-//'`
+        if  [ $first == "yes" ]
+        then
+            instances=$id
+            first="no"
+        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
-    if ! [ -a "$dir/@package_name@-$servid" ]
+
+    # server id not provided, check if there is only one instance
+    if [ $inst_count -eq 1 ]
     then
-        # invalid instance name, return the "valid" instance names
+        servid=$name
+    else 
+        # multiple instances, can not set server id.  Return list of instances
         servid=$instances
         rc=1
     fi
@@ -97,9 +154,9 @@ get_server_id()
 #
 process_dse ()
 {
-    servid=$1
+    configdir=$1
     pid=$2
-    file="@instconfigdir@/slapd-$servid/dse.ldif"
+    file="$configdir/dse.ldif"
     shopt -s nocasematch
     OLD_IFC=$IFC
     IFS=""

+ 83 - 32
ldap/admin/src/scripts/DSUtil.pm.in

@@ -1205,11 +1205,10 @@ sub libpath_add {
 sub get_info {
     my %info = ();
     my $dir = shift;
-    my $servID = shift;
     $info{host} = shift;
     $info{port} = shift; 
     $info{rootdn} = shift;
-    my $dse_file = "$dir/slapd-$servID/dse.ldif";
+    my $dse_file = "$dir/dse.ldif";
     my $foundcfg = "no";
     my $value;
     my $entry;
@@ -1277,7 +1276,7 @@ sub get_info {
 }
 
 #
-# Grab the server instance ID
+# return the normalized server id and the server config dir (contains dse.ldif)
 #
 sub get_server_id {
     my $servid = shift;
@@ -1287,54 +1286,106 @@ sub get_server_id {
     my $instances = "<none>";
     my $name;
     my $file;
+    my @extra = ();
+    my $extradir = "";
 
     if (getLogin ne 'root') {
-        $dir = "$ENV{HOME}/.@package_name@";
+        $extradir = "$ENV{HOME}/.@package_name@";
+        if (-d $extradir) {
+            opendir(EXTRADIR, $extradir);
+            @extra = map {$_ = "$extradir/$_"} readdir(EXTRADIR);
+            closedir(EXTRADIR);
+        }
     }
 
     if (defined $ENV{INITCONFIGDIR}) {
         $dir = $ENV{INITCONFIGDIR};
+        @extra = (); # only use what was provided
+        $extradir = "";
     }
-    
-    opendir(DIR, "$dir");
-    my @files = readdir(DIR);
-    foreach $file (@files){
-        if($file =~ /^@package_name@-/ && $file ne "@package_name@-admin"){
-            $instance_count++;
-            if($file =~ /@package_name@-(.*)/){
-                if($first eq "yes"){
-                    $instances=$1;
-                    $first = "no";
-                } else {
-                    $instances=$instances . ", $1";
-                }
-                $name = $1;
-            }
-        }
-    }
-    if($servid eq ""){
-        if ($instance_count == 1){
-            $servid = $name;
-        } else {
-            print "You must supply a valid server instance identifier.  Use -Z to specify instance name\n";
-            print "Available instances: $instances\n";
-            exit (1);
-        }
+
+    # normalize the given servid
+    if (!$servid) {
+        # not given
     } elsif ($servid =~ /^@package_name@-/){
         # strip off "@package_name@-"
         $servid =~ s/^@package_name@-//;
     } elsif ($servid =~ /^slapd-/){
         # strip off "slapd-"
         $servid =~ s/^slapd-//;
+    } # else assume already normalized
+
+    opendir(DIR, "$dir");
+    my @files = map {$_ = "$dir/$_"} readdir(DIR);
+    closedir(DIR);
+    push @files, @extra;
+    my $found = 0;
+    foreach $file (@files){
+        next if(! -r $file); # skip unreadable files
+        # skip admin server
+        if($file =~ m,/@package_name@-([^/]+)$, && $file !~ m,/@package_name@-admin$,){
+            $name = $file;
+            my $inst = $1;
+            $instance_count++;
+            if ($servid && ($servid eq $inst)) {
+                $found = 1;
+                last;
+            }
+            if($first eq "yes"){
+                $instances=$inst;
+                $first = "no";
+            } else {
+                $instances=$instances . ", $inst";
+            }
+        }
+    }
+
+    if ($servid && !$found) { # if we got here, did not find given serverid
+        print (STDERR "Invalid server identifer: $servid\n");
+        print (STDERR "Available instances in $dir $extradir: $instances\n");
+        exit (1);
+    }
+        
+    if ($instance_count == 0){
+        print "No instances found in $dir\n";
+        exit (1);
+    }
+    
+    if ($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 "$dir/@package_name@-$servid" ){
+    unless ( -e "$file" ){
         print (STDERR "Invalid server identifer: $servid\n");
-        print (STDERR "Available instances in $dir: $instances\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: $!");
+        exit (1);
+    }
+
+    my $confdir;
+    while (<INSTFILE>) {
+        if (/^CONFIG_DIR=/) {
+            s/^CONFIG_DIR=//;
+            s/ ; export CONFIG_DIR//;
+            $confdir = $_;
+            last;
+        }
+    }
+    close INSTFILE;
+
+    if (!$confdir) {
+        print (STDERR "Error: no CONFIG_DIR found in $name\n");
         exit (1);
     }
     
-    return $servid;
+    return ($servid, $confdir);
 }
 
 #

+ 6 - 6
ldap/admin/src/scripts/bak2db.in

@@ -1,8 +1,8 @@
 #!/bin/sh
 
-source @datadir@/dirsrv/data/DSSharedLib
+source @datadir@/@package_name@/data/DSSharedLib
 
-libpath_add "@libdir@/dirsrv/"
+libpath_add "@libdir@/@package_name@/"
 libpath_add "@nss_libdir@"
 libpath_add "@libdir@"
 libpath_add "@pcre_libdir@"
@@ -54,16 +54,16 @@ do
     esac
 done
 
-servid=$(get_server_id "@initconfigdir@" $servid)
+initfile=$(get_init_file "@initconfigdir@" $servid)
 if [ $? == 1 ]
 then
     usage
     echo "You must supply a valid server instance identifier.  Use -Z to specify instance name"
-    echo "Available instances: $servid"
+    echo "Available instances: $initfile"
     exit 1
 fi
 
-configdir="@instconfigdir@/slapd-$servid"
+. $initfile
 
 if [ 1 = `expr $archivedir : "\/"` ]
 then
@@ -73,4 +73,4 @@ else
     archivedir=`pwd`/$archivedir
 fi
 
-@sbindir@/ns-slapd archive2db -D $configdir -a $archivedir $args
+@sbindir@/ns-slapd archive2db -D $CONFIG_DIR -a $archivedir $args

+ 2 - 2
ldap/admin/src/scripts/bak2db.pl.in

@@ -99,8 +99,8 @@ while ($i <= $#ARGV) {
 # 
 # Gather all our config settings
 #
-$servid = DSUtil::get_server_id($servid, "@initconfigdir@");
-%info = DSUtil::get_info("@instconfigdir@", $servid, $host, $port, $rootdn);
+($servid, $confdir) = DSUtil::get_server_id($servid, "@initconfigdir@");
+%info = DSUtil::get_info($confdir, $host, $port, $rootdn);
 $info{rootdnpw} = DSUtil::get_password_from_file($passwd, $passwdfile);
 $info{protocol} = $protocol;
 if ($verbose == 1){

+ 2 - 2
ldap/admin/src/scripts/cleanallruv.pl.in

@@ -108,8 +108,8 @@ while ($i <= $#ARGV)
 #
 # Gather all our config settings
 #
-$servid = DSUtil::get_server_id($servid, "@initconfigdir@");
-%info = DSUtil::get_info("@instconfigdir@", $servid, $host, $port, $rootdn);
+($servid, $confdir) = DSUtil::get_server_id($servid, "@initconfigdir@");
+%info = DSUtil::get_info($confdir, $host, $port, $rootdn);
 $info{rootdnpw} = DSUtil::get_password_from_file($passwd, $passwdfile);
 $info{protocol} = $protocol;
 if ($verbose == 1){

+ 7 - 6
ldap/admin/src/scripts/db2bak.in

@@ -1,8 +1,8 @@
 #!/bin/sh
 
-source @datadir@/dirsrv/data/DSSharedLib
+source @datadir@/@package_name@/data/DSSharedLib
 
-libpath_add "@libdir@/dirsrv/"
+libpath_add "@libdir@/@package_name@/"
 libpath_add "@nss_libdir@"
 libpath_add "@libdir@"
 libpath_add "@pcre_libdir@"
@@ -55,16 +55,17 @@ do
 done
 
 
-servid=$(get_server_id "@initconfigdir@" $servid)
+initfile=$(get_init_file "@initconfigdir@" $servid)
 if [ $? == 1 ]
 then
     usage
     echo "You must supply a valid server instance identifier.  Use -Z to specify instance name"
-    echo "Available instances: $servid"
+    echo "Available instances: $initfile"
     exit 1
 fi
 
-configdir="@instconfigdir@/slapd-$servid"
+servid=`normalize_server_id $initfile`
+. $initfile
 
 if [ -z $bak_dir ]
 then
@@ -72,4 +73,4 @@ then
 fi
 
 echo "Back up directory: $bak_dir"
-@sbindir@/ns-slapd db2archive -D $configdir -a $bak_dir $args
+@sbindir@/ns-slapd db2archive -D $CONFIG_DIR -a $bak_dir $args

+ 3 - 3
ldap/admin/src/scripts/db2bak.pl.in

@@ -96,8 +96,8 @@ while ($i <= $#ARGV) {
 #
 # Gather all our config settings
 #
-$servid = DSUtil::get_server_id($servid, "@initconfigdir@");
-%info = DSUtil::get_info("@instconfigdir@", $servid, $host, $port, $rootdn);
+($servid, $confdir) = DSUtil::get_server_id($servid, "@initconfigdir@");
+%info = DSUtil::get_info($confdir, $host, $port, $rootdn);
 $info{rootdnpw} = DSUtil::get_password_from_file($passwd, $passwdfile);
 $info{protocol} = $protocol;
 if ($verbose == 1){
@@ -136,4 +136,4 @@ if($rc == 0){
     print "Failed to add task entry \"$dn\" error ($rc)\n";
 }
 
-exit($rc);
+exit($rc);

+ 8 - 7
ldap/admin/src/scripts/db2index.in

@@ -1,8 +1,8 @@
 #!/bin/sh
 
-source @datadir@/dirsrv/data/DSSharedLib
+source @datadir@/@package_name@/data/DSSharedLib
 
-libpath_add "@libdir@/dirsrv/"
+libpath_add "@libdir@/@package_name@/"
 libpath_add "@nss_libdir@"
 libpath_add "@libdir@"
 libpath_add "@pcre_libdir@"
@@ -58,25 +58,26 @@ then
     exit 1;
 fi
 
-servid=$(get_server_id "@initconfigdir@" $servid)
+initfile=$(get_init_file "@initconfigdir@" $servid)
 if [ $? == 1 ]
 then
     usage
     echo "You must supply a valid server instance identifier.  Use -Z to specify instance name"
-    echo "Available instances: $servid"
+    echo "Available instances: $initfile"
     exit 1
 fi
 
-configdir="@instconfigdir@/slapd-$servid"
+servid=`normalize_server_id $initfile`
+. $initfile
 
 if [ $# -eq 0 ]
 then
     bak_dir=@localstatedir@/lib/@PACKAGE_NAME@/slapd-$servid/bak/reindex_`date +%Y_%m_%d_%H_%M_%S`
-    @sbindir@/ns-slapd upgradedb -D $configdir -a "$bak_dir"
+    @sbindir@/ns-slapd upgradedb -D $CONFIG_DIR -a "$bak_dir"
 elif [ $# -lt 2 ]
 then
     usage
     exit 1
 else
-    @sbindir@/ns-slapd db2index -D $configdir $args
+    @sbindir@/ns-slapd db2index -D $CONFIG_DIR $args
 fi

+ 2 - 2
ldap/admin/src/scripts/db2index.pl.in

@@ -105,8 +105,8 @@ while ($i <= $#ARGV) {
 #
 # Gather all our config settings
 #
-$servid = DSUtil::get_server_id($servid, "@initconfigdir@");
-%info = DSUtil::get_info("@instconfigdir@", $servid, $host, $port, $rootdn);
+($servid, $confdir) = DSUtil::get_server_id($servid, "@initconfigdir@");
+%info = DSUtil::get_info($confdir, $host, $port, $rootdn);
 $info{rootdnpw} = DSUtil::get_password_from_file($passwd, $passwdfile);
 $info{protocol} = $protocol;
 if ($verbose){

+ 8 - 7
ldap/admin/src/scripts/db2ldif.in

@@ -1,8 +1,8 @@
 #!/bin/sh
 
-source @datadir@/dirsrv/data/DSSharedLib
+source @datadir@/@package_name@/data/DSSharedLib
 
-libpath_add "@libdir@/dirsrv/"
+libpath_add "@libdir@/@package_name@/"
 libpath_add "@nss_libdir@"
 libpath_add "@libdir@"
 libpath_add "@pcre_libdir@"
@@ -137,16 +137,17 @@ then
     exit 1
 fi
 
-servid=$(get_server_id "@initconfigdir@" $servid)
+initfile=$(get_init_file "@initconfigdir@" $servid)
 if [ $? == 1 ]
 then
     usage
     echo "You must supply a valid server instance identifier.  Use -Z to specify instance name"
-    echo "Available instances: $servid"
+    echo "Available instances: $initfile"
     exit 1
 fi
 
-configdir="@instconfigdir@/slapd-$servid"
+servid=`normalize_server_id $initfile`
+. $initfile
 
 ldif_file=`make_ldiffile $@`
 rn=$?
@@ -154,7 +155,7 @@ rn=$?
 echo "Exported ldif file: $ldif_file"
 if [ $rn -eq 1 ]
 then
-    @sbindir@/ns-slapd db2ldif -D $configdir $benameopt $includeSuffix $excludeSuffix $outputFile $args
+    @sbindir@/ns-slapd db2ldif -D $CONFIG_DIR $benameopt $includeSuffix $excludeSuffix $outputFile $args
 else
-    @sbindir@/ns-slapd db2ldif -D $configdir $benameopt $includeSuffix $excludeSuffix $args -a $ldif_file
+    @sbindir@/ns-slapd db2ldif -D $CONFIG_DIR $benameopt $includeSuffix $excludeSuffix $args -a $ldif_file
 fi

+ 2 - 2
ldap/admin/src/scripts/db2ldif.pl.in

@@ -190,8 +190,8 @@ while ($i <= $#ARGV) {
 #
 # Gather all our config settings
 #
-$servid = DSUtil::get_server_id($servid, "@initconfigdir@");
-%info = DSUtil::get_info("@instconfigdir@", $servid, $host, $port, $rootdn);
+($servid, $confdir) = DSUtil::get_server_id($servid, "@initconfigdir@");
+%info = DSUtil::get_info($confdir, $host, $port, $rootdn);
 $ldifdir = "@localstatedir@/lib/@PACKAGE_NAME@/slapd-$servid/ldif";
 $info{rootdnpw} = DSUtil::get_password_from_file($passwd, $passwdfile);
 $info{protocol} = $protocol;

+ 6 - 6
ldap/admin/src/scripts/dbverify.in

@@ -1,8 +1,8 @@
 #!/bin/sh
 
-source @datadir@/dirsrv/data/DSSharedLib
+source @datadir@/@package_name@/data/DSSharedLib
 
-libpath_add "@libdir@/dirsrv/"
+libpath_add "@libdir@/@package_name@/"
 libpath_add "@nss_libdir@"
 libpath_add "@libdir@"
 libpath_add "@pcre_libdir@"
@@ -44,18 +44,18 @@ do
     esac
 done
 
-servid=$(get_server_id "@initconfigdir@" $servid)
+initfile=$(get_init_file "@initconfigdir@" $servid)
 if [ $? == 1 ]
 then
     usage
     echo "You must supply a valid server instance identifier.  Use -Z to specify instance name"
-    echo "Available instances: $servid"
+    echo "Available instances: $initfile"
     exit 1
 fi
 
-configdir="@instconfigdir@/slapd-$servid"
+. $initfile
 
-@sbindir@/ns-slapd dbverify -D $configdir $args
+@sbindir@/ns-slapd dbverify -D $CONFIG_DIR $args
 if [ $display_version == "yes" ]; then
     exit 0
 fi

+ 7 - 6
ldap/admin/src/scripts/dn2rdn.in

@@ -1,8 +1,8 @@
 #!/bin/sh
 
-source @datadir@/dirsrv/data/DSSharedLib
+source @datadir@/@package_name@/data/DSSharedLib
 
-libpath_add "@libdir@/dirsrv/"
+libpath_add "@libdir@/@package_name@/"
 libpath_add "@nss_libdir@"
 libpath_add "@libdir@"
 
@@ -38,20 +38,21 @@ do
     esac
 done
 
-servid=$(get_server_id "@initconfigdir@" $servid)
+initfile=$(get_init_file "@initconfigdir@" $servid)
 if [ $? == 1 ]
 then
     usage
     echo "You must supply a valid server instance identifier.  Use -Z to specify instance name"
-    echo "Available instances: $servid"
+    echo "Available instances: $initfile"
     exit 1
 fi
 
-configdir="@instconfigdir@/slapd-$servid"
+servid=`normalize_server_id $initfile`
+. $initfile
 
 if [ "$archive" != "provided" ]; then
     bak_dir=@localstatedir@/lib/@PACKAGE_NAME@/slapd-$servid/bak/reindex_`date +%Y_%m_%d_%H_%M_%S`
     args=$args"-a $bak_dir"
 fi
 
-@sbindir@/ns-slapd upgradedb -D $configdir -r $args
+@sbindir@/ns-slapd upgradedb -D $CONFIG_DIR -r $args

+ 2 - 2
ldap/admin/src/scripts/fixup-linkedattrs.pl.in

@@ -102,8 +102,8 @@ while ($i <= $#ARGV)
 #
 # Gather all our config settings
 #
-$servid = DSUtil::get_server_id($servid, "@initconfigdir@");
-%info = DSUtil::get_info("@instconfigdir@", $servid, $host, $port, $rootdn);
+($servid, $confdir) = DSUtil::get_server_id($servid, "@initconfigdir@");
+%info = DSUtil::get_info($confdir, $host, $port, $rootdn);
 $info{rootdnpw} = DSUtil::get_password_from_file($passwd, $passwdfile);
 $info{protocol} = $protocol;
 if ($verbose == 1){

+ 2 - 2
ldap/admin/src/scripts/fixup-memberof.pl.in

@@ -106,8 +106,8 @@ while ($i <= $#ARGV)
 #
 # Gather all our config settings
 #
-$servid = DSUtil::get_server_id($servid, "@initconfigdir@");
-%info = DSUtil::get_info("@instconfigdir@", $servid, $host, $port, $rootdn);
+($servid, $confdir) = DSUtil::get_server_id($servid, "@initconfigdir@");
+%info = DSUtil::get_info($confdir, $host, $port, $rootdn);
 $info{rootdnpw} = DSUtil::get_password_from_file($passwd, $passwdfile);
 $info[9] = $protocol;
 if ($verbose == 1){

+ 6 - 6
ldap/admin/src/scripts/ldif2db.in

@@ -1,8 +1,8 @@
 #!/bin/sh
 
-source @datadir@/dirsrv/data/DSSharedLib
+source @datadir@/@package_name@/data/DSSharedLib
 
-libpath_add "@libdir@/dirsrv/"
+libpath_add "@libdir@/@package_name@/"
 libpath_add "@nss_libdir@"
 libpath_add "@libdir@"
 libpath_add "@pcre_libdir@"
@@ -81,16 +81,16 @@ do
     esac
 done
 
-servid=$(get_server_id "@initconfigdir@" $servid)
+initfile=$(get_init_file "@initconfigdir@" $servid)
 if [ $? == 1 ]
 then
     usage
     echo "You must supply a valid server instance identifier.  Use -Z to specify instance name"
-    echo "Available instances: $servid"
+    echo "Available instances: $initfile"
     exit 1
 fi
 
-configdir="@instconfigdir@/slapd-$servid"
+. $initfile
 
 if [ $# -lt 4 ]
 then
@@ -104,6 +104,6 @@ if [ $quiet -eq 0 ]; then
     echo importing data ...
 fi
 
-@sbindir@/ns-slapd ldif2db -D $configdir $args 2>&1
+@sbindir@/ns-slapd ldif2db -D $CONFIG_DIR $args 2>&1
 
 exit $?

+ 2 - 2
ldap/admin/src/scripts/ldif2db.pl.in

@@ -175,8 +175,8 @@ while ($i <= $#ARGV) {
 #
 # Gather all our config settings
 #
-$servid = DSUtil::get_server_id($servid, "@initconfigdir@");
-%info = DSUtil::get_info("@instconfigdir@", $servid, $host, $port, $rootdn);
+($servid, $confdir) = DSUtil::get_server_id($servid, "@initconfigdir@");
+%info = DSUtil::get_info($confdir, $host, $port, $rootdn);
 $info{rootdnpw} = DSUtil::get_password_from_file($passwd, $passwdfile);
 $info{protocol} = $protocol;
 if ($verbose == 1){

+ 7 - 5
ldap/admin/src/scripts/ldif2ldap.in

@@ -1,11 +1,11 @@
 #!/bin/sh
 
-source @datadir@/dirsrv/data/DSSharedLib
+source @datadir@/@package_name@/data/DSSharedLib
 
 libpath_add "@ldapsdk_libdir@"
 libpath_add "@libdir@"
 libpath_add "@nss_libdir@"
-libpath_add "@libdir@/dirsrv/"
+libpath_add "@libdir@/@package_name@/"
 
 export LD_LIBRARY_PATH
 SHLIB_PATH=$LD_LIBRARY_PATH
@@ -46,16 +46,18 @@ then
     exit 1
 fi
 
-servid=$(get_server_id "@initconfigdir@" $servid)
+initfile=$(get_init_file "@initconfigdir@" $servid)
 if [ $? == 1 ]
 then
     usage
     echo "You must supply a valid server instance identifier.  Use -Z to specify instance name"
-    echo "Available instances: $servid"
+    echo "Available instances: $initfile"
     exit 1
 fi
 
-process_dse $servid $$
+. $initfile
+
+process_dse $CONFIG_DIR $$
 file="/tmp/DSSharedLib.$$"
 port=$(grep -i 'nsslapd-port' $file | awk '{print $2}' )
 host=$(grep -i 'nsslapd-localhost' $file | awk '{print $2}' )

+ 6 - 5
ldap/admin/src/scripts/monitor.in

@@ -1,8 +1,8 @@
 #!/bin/sh
 
-source @datadir@/dirsrv/data/DSSharedLib
+source @datadir@/@package_name@/data/DSSharedLib
 
-libpath_add "@libdir@/dirsrv/"
+libpath_add "@libdir@/@package_name@/"
 libpath_add "@ldapsdk_libdir@"
 libpath_add "@libdir@"
 libpath_add "@nss_libdir@"
@@ -40,12 +40,12 @@ do
     esac
 done
 
-servid=$(get_server_id "@initconfigdir@" $servid)
+initfile=$(get_init_file "@initconfigdir@" $servid)
 if [ $? == 1 ]
 then
     usage
     echo "You must supply a valid server instance identifier.  Use -Z to specify instance name"
-    echo "Available instances: $servid"
+    echo "Available instances: $initfile"
     exit 1
 fi
 
@@ -54,8 +54,9 @@ then
     MDN="cn=monitor"
 fi
 
+. $initfile
 
-process_dse $servid $$
+process_dse $CONFIG_DIR $$
 file="/tmp/DSSharedLib.$$"
 port=$(grep -i 'nsslapd-port' $file | awk '{print $2}' )
 host=$(grep -i 'nsslapd-localhost' $file | awk '{print $2}' )

+ 2 - 2
ldap/admin/src/scripts/ns-accountstatus.pl.in

@@ -413,8 +413,8 @@ while( $arg = shift){
 #
 # Gather all our config settings
 #
-$servid = DSUtil::get_server_id($servid, "@initconfigdir@");
-%info = DSUtil::get_info("@instconfigdir@", $servid, $host, $port, $rootdn);
+($servid, $confdir) = DSUtil::get_server_id($servid, "@initconfigdir@");
+%info = DSUtil::get_info($confdir, $host, $port, $rootdn);
 $info{rootdnpw} = DSUtil::get_password_from_file($rootpw, $pwfile);
 $info{protocol} = $protocol;
 $info{args} = "-c -a";

+ 2 - 2
ldap/admin/src/scripts/ns-activate.pl.in

@@ -413,8 +413,8 @@ while( $arg = shift)
 #
 # Gather all our config settings
 #
-$servid = DSUtil::get_server_id($servid, "@initconfigdir@");
-%info = DSUtil::get_info("@instconfigdir@", $servid, $host, $port, $rootdn);
+($servid, $confdir) = DSUtil::get_server_id($servid, "@initconfigdir@");
+%info = DSUtil::get_info($confdir, $host, $port, $rootdn);
 $info{rootdnpw} = DSUtil::get_password_from_file($rootpw, $pwfile);
 $info{protocol} = $protocol;
 $info{args} = "-c";

+ 2 - 2
ldap/admin/src/scripts/ns-inactivate.pl.in

@@ -413,8 +413,8 @@ while( $arg = shift)
 #
 # Gather all our config settings
 #
-$servid = DSUtil::get_server_id($servid, "@initconfigdir@");
-%info = DSUtil::get_info("@instconfigdir@", $servid, $host, $port, $rootdn);
+($servid, $confdir) = DSUtil::get_server_id($servid, "@initconfigdir@");
+%info = DSUtil::get_info($confdir, $host, $port, $rootdn);
 $info{rootdnpw} = DSUtil::get_password_from_file($rootpw, $pwfile);
 $info{protocol} = $protocol;
 $info{args} = "-c";

+ 2 - 2
ldap/admin/src/scripts/ns-newpwpolicy.pl.in

@@ -97,8 +97,8 @@ sub usage {
 {
     usage() if (!getopts('vD:w:j:p:P:h:U:S:Z:'));
 
-    $opt_Z = DSUtil::get_server_id($opt_Z, "@initconfigdir@");
-    %info = DSUtil::get_info("@instconfigdir@", $opt_Z, $opt_h, $opt_p, $opt_D);
+    ($opt_Z, $confdir) = DSUtil::get_server_id($opt_Z, "@initconfigdir@");
+    %info = DSUtil::get_info($confdir, $opt_h, $opt_p, $opt_D);
     $info{rootdnpw} = $opt_w;
     $info{protocol} = $opt_P;
     if ($opt_j ne ""){

+ 6 - 22
ldap/admin/src/scripts/restart-dirsrv.in

@@ -7,6 +7,8 @@
 #       2: Server started successfully (was not running)
 #       3: Server could not be stopped
 
+source @datadir@/@package_name@/data/DSSharedLib
+
 restart_instance() {
     SERV_ID=$1
 
@@ -37,33 +39,15 @@ done
 shift $(($OPTIND-1))
 
 if [ "$initconfig_dir" = "" ]; then
-    # convert
-    # uid=0(root) gid=0(root) groups=0(root),1(bin),2(daemon),3(sys),.....
-    # to
-    # 0
-    # this is the only portable, secure way to determine the id number
-    userid=`id | awk -F'[=(]+' '{print $2}'`
-    if [ "$userid" -eq 0 ] ; then
-        initconfig_dir=@initconfigdir@
-    else
-        initconfig_dir=$HOME/.@package_name@
-    fi
+    initconfig_dir=@initconfigdir@
 fi
 
 if [ "$#" -eq 0 ]; then
     # We're restarting all instances.
     ret=0
-    for i in $initconfig_dir/@package_name@-*; do
-        if [ ! -f "$i" ] ; then
-            echo No instances found in $initconfig_dir
-            exit 1
-        fi
-        regex=s,$initconfig_dir/@package_name@-,,g
-        inst=`echo $i | sed -e $regex`
-        # check for admin server ID used by 389-admin pkg, and ignore it
-        if [ "$inst" = "admin" ]; then
-            continue
-        fi
+    initfiles=`get_initconfig_files $initconfig_dir` || { echo No instances found in $initconfig_dir ; exit 1 ; }
+    for i in $initfiles; do
+        inst=`normalize_server_id $i`
         echo Restarting instance \"$inst\"
         restart_instance $inst
         rv=$?

+ 8 - 5
ldap/admin/src/scripts/restoreconfig.in

@@ -1,8 +1,8 @@
 #!/bin/sh
 
-source @datadir@/dirsrv/data/DSSharedLib
+source @datadir@/@package_name@/data/DSSharedLib
 
-libpath_add "@libdir@/dirsrv/"
+libpath_add "@libdir@/@package_name@/"
 libpath_add "@nss_libdir@"
 libpath_add "@libdir@"
 libpath_add "@pcre_libdir@"
@@ -30,20 +30,23 @@ do
     esac
 done
 
-servid=$(get_server_id "@initconfigdir@" $servid)
+initfile=$(get_init_file "@initconfigdir@" $servid)
 if [ $? == 1 ]
 then
     usage
     echo "You must supply a valid server instance identifier.  Use -Z to specify instance name"
-    echo "Available instances: $servid"
+    echo "Available instances: $initfile"
     exit 1
 fi
 
+servid=`normalize_server_id $initfile`
+. $initfile
+
 conf_ldif=`ls -1t @localstatedir@/lib/@PACKAGE_NAME@/slapd-$servid/bak/$servid-*.ldif 2>/dev/null | head -1 `
 if [ -z "$conf_ldif" ]
 then
     echo No configuration to restore in @localstatedir@/lib/@PACKAGE_NAME@/slapd-$servid/bak/ ; exit 1
 fi
 echo Restoring $conf_ldif...
-@sbindir@/ns-slapd ldif2db -D $configdir -i $conf_ldif -n NetscapeRoot 2>&1
+@sbindir@/ns-slapd ldif2db -D $CONFIG_DIR -i $conf_ldif -n NetscapeRoot 2>&1
 exit $?

+ 7 - 6
ldap/admin/src/scripts/saveconfig.in

@@ -1,8 +1,8 @@
 #!/bin/sh
 
-source @datadir@/dirsrv/data/DSSharedLib
+source @datadir@/@package_name@/data/DSSharedLib
 
-libpath_add "@libdir@/dirsrv/"
+libpath_add "@libdir@/@package_name@/"
 libpath_add "@libdir@"
 libpath_add "@nss_libdir@"
 libpath_add "@pcre_libdir@"
@@ -30,20 +30,21 @@ do
     esac
 done
 
-servid=$(get_server_id "@initconfigdir@" $servid)
+initfile=$(get_init_file "@initconfigdir@" $servid)
 if [ $? == 1 ]
 then
     usage
     echo "You must supply a valid server instance identifier.  Use -Z to specify instance name"
-    echo "Available instances: $servid"
+    echo "Available instances: $initfile"
     exit 1
 fi
 
-configdir="@instconfigdir@/slapd-$servid"
+servid=`normalize_server_id $initfile`
+. $initfile
 
 echo saving configuration...
 conf_ldif=@localstatedir@/lib/@PACKAGE_NAME@/slapd-$servid/bak/$servid-`date +%Y_%m_%d_%H%M%S`.ldif
-@sbindir@/ns-slapd db2ldif -N -D $configdir -s "o=NetscapeRoot" -a $conf_ldif -n NetscapeRoot 2>&1
+@sbindir@/ns-slapd db2ldif -N -D $CONFIG_DIR -s "o=NetscapeRoot" -a $conf_ldif -n NetscapeRoot 2>&1
 if [ "$?" -ge 1 ] 
 then
     echo Error occurred while saving configuration

+ 2 - 2
ldap/admin/src/scripts/schema-reload.pl.in

@@ -101,8 +101,8 @@ while ($i <= $#ARGV)
 #
 # Gather all our config settings
 #
-$servid = DSUtil::get_server_id($servid, "@initconfigdir@");
-%info = DSUtil::get_info("@instconfigdir@", $servid, $host, $port, $rootdn);
+($servid, $confdir) = DSUtil::get_server_id($servid, "@initconfigdir@");
+%info = DSUtil::get_info($confdir, $host, $port, $rootdn);
 $info{rootdnpw} = DSUtil::get_password_from_file($passwd, $passwdfile);
 $info{protocol} = $protocol; 
 if ($verbose == 1){

+ 10 - 28
ldap/admin/src/scripts/start-dirsrv.in

@@ -6,10 +6,7 @@
 #       1: Server could not be started
 #       2: Server already running
 
-libpath_add() {
-    [ -z "$1" ] && return
-    LD_LIBRARY_PATH=${LD_LIBRARY_PATH:+$LD_LIBRARY_PATH:}$1
-}
+source @datadir@/@package_name@/data/DSSharedLib
 
 # Starts a single instance
 start_instance() {
@@ -18,9 +15,11 @@ start_instance() {
     SERV_ID=$1
     shift
 
+    initfile=`get_init_file $initconfig_dir $SERV_ID` || { echo Instance $SERV_ID not found. ; return 1 ; }
+
     # source env. for this instance
-    if [ -f $initconfig_dir/@package_name@-$SERV_ID ] ; then
-        . $initconfig_dir/@package_name@-$SERV_ID
+    if [ -f $initfile ] ; then
+        . $initfile
     else
         echo Instance $SERV_ID not found.
         return 1
@@ -115,33 +114,16 @@ done
 shift $(($OPTIND-1))
 
 if [ "$initconfig_dir" = "" ]; then
-    # convert
-    # uid=0(root) gid=0(root) groups=0(root),1(bin),2(daemon),3(sys),.....
-    # to
-    # 0
-    # this is the only portable, secure way to determine the id number
-    userid=`id | awk -F'[=(]+' '{print $2}'`
-    if [ "$userid" -eq 0 ] ; then
-        initconfig_dir=@initconfigdir@
-    else
-        initconfig_dir=$HOME/.@package_name@
-    fi
+    initconfig_dir=@initconfigdir@
 fi
 
+found=0
 if [ "$#" -eq 0 ]; then
     # We're starting all instances.
     ret=0
-    for i in $initconfig_dir/@package_name@-*; do
-        if [ ! -f "$i" ] ; then
-            echo No instances found in $initconfig_dir
-            exit 1
-        fi
-        regex=s,$initconfig_dir/@package_name@-,,g
-        inst=`echo $i | sed -e $regex`
-        # check for admin server ID used by 389-admin pkg, and ignore it
-        if [ "$inst" = "admin" ]; then
-            continue
-        fi
+    initfiles=`get_initconfig_files $initconfig_dir` || { echo No instances found in $initconfig_dir ; exit 1 ; }
+    for i in $initfiles; do
+        inst=`normalize_server_id $i`
         echo Starting instance \"$inst\"
         start_instance $inst
         rv=$?

+ 9 - 24
ldap/admin/src/scripts/stop-dirsrv.in

@@ -6,17 +6,16 @@
 #       1: Server could not be stopped
 #       2: Server was not running
 
-libpath_add() {
-    [ -z "$1" ] && return
-    LD_LIBRARY_PATH=${LD_LIBRARY_PATH:+$LD_LIBRARY_PATH:}$1
-}
+source @datadir@/@package_name@/data/DSSharedLib
 
 stop_instance() {
     SERV_ID=$1
 
+    initfile=`get_init_file $initconfig_dir $SERV_ID` || { echo Instance $SERV_ID not found. ; return 1 ; }
+
     # source env. for this instance
-    if [ -f $initconfig_dir/@package_name@-$SERV_ID ] ; then
-        . $initconfig_dir/@package_name@-$SERV_ID
+    if [ -f $initfile ] ; then
+        . $initfile
     else
         echo Instance $SERV_ID not found.
         return 1
@@ -67,33 +66,19 @@ done
 shift $(($OPTIND-1))
 
 if [ "$initconfig_dir" = "" ]; then
-    # convert
-    # uid=0(root) gid=0(root) groups=0(root),1(bin),2(daemon),3(sys),.....
-    # to
-    # 0
-    # this is the only portable, secure way to determine the id number
-    userid=`id | awk -F'[=(]+' '{print $2}'`
-    if [ "$userid" -eq 0 ] ; then
-        initconfig_dir=@initconfigdir@
-    else
-        initconfig_dir=$HOME/.@package_name@
-    fi
+    initconfig_dir=@initconfigdir@
 fi
 
 if [ "$#" -eq 0 ]; then
     # We're stopping all instances.
     ret=0
-    for i in $initconfig_dir/@package_name@-*; do
+    initfiles=`get_initconfig_files $initconfig_dir` || { echo No instances found in $initconfig_dir ; exit 1 ; }
+    for i in $initfiles; do
         if [ ! -f "$i" ] ; then
             echo No instances found in $initconfig_dir
             exit 1
         fi
-        regex=s,$initconfig_dir/@package_name@-,,g
-        inst=`echo $i | sed -e $regex`
-        # check for admin server ID used by 389-admin pkg, and ignore it
-        if [ "$inst" = "admin" ]; then
-            continue
-        fi
+        inst=`normalize_server_id $i`
         echo Stopping instance \"$inst\"
         stop_instance $inst
         rv=$?

+ 6 - 6
ldap/admin/src/scripts/suffix2instance.in

@@ -1,8 +1,8 @@
 #!/bin/sh
 
-source @datadir@/dirsrv/data/DSSharedLib
+source @datadir@/@package_name@/data/DSSharedLib
 
-libpath_add "@libdir@/dirsrv/"
+libpath_add "@libdir@/@package_name@/"
 libpath_add "@libdir@"
 libpath_add "@nss_libdir@"
 libpath_add "@pcre_libdir@"
@@ -38,16 +38,16 @@ then
     exit 1
 fi
 
-servid=$(get_server_id "@initconfigdir@" $servid)
+initfile=$(get_init_file "@initconfigdir@" $servid)
 if [ $? == 1 ]
 then
     usage
     echo "You must supply a valid server instance identifier.  Use -Z to specify instance name"
-    echo "Available instances: $servid"
+    echo "Available instances: $initfile"
     exit 1
 fi
 
-configdir="@instconfigdir@/slapd-$servid"
+. $initfile
 
 if [ $# -lt 2 ]
 then
@@ -55,4 +55,4 @@ then
     exit 1
 fi
 
-@sbindir@/ns-slapd suffix2instance -D $configdir $args 2>&1
+@sbindir@/ns-slapd suffix2instance -D $CONFIG_DIR $args 2>&1

+ 2 - 2
ldap/admin/src/scripts/syntax-validate.pl.in

@@ -108,8 +108,8 @@ while ($i <= $#ARGV)
 #
 # Gather all our config settings
 #
-$servid = DSUtil::get_server_id($servid, "@initconfigdir@");
-%info = DSUtil::get_info("@instconfigdir@", $servid, $host, $port, $rootdn);
+($servid, $confdir) = DSUtil::get_server_id($servid, "@initconfigdir@");
+%info = DSUtil::get_info($confdir, $host, $port, $rootdn);
 $info{rootdnpw} = DSUtil::get_password_from_file($passwd, $passwdfile);
 $info{protocol} = $protocol;
 if ($verbose == 1){

+ 7 - 6
ldap/admin/src/scripts/upgradedb.in

@@ -1,8 +1,8 @@
 #!/bin/sh
 
-source @datadir@/dirsrv/data/DSSharedLib
+source @datadir@/@package_name@/data/DSSharedLib
 
-libpath_add "@libdir@/dirsrv/"
+libpath_add "@libdir@/@package_name@/"
 libpath_add "@libdir@"
 libpath_add "@nss_libdir@"
 libpath_add "@pcre_libdir@"
@@ -38,15 +38,16 @@ do
     esac
 done
 
-servid=$(get_server_id "@initconfigdir@" $servid)
+initfile=$(get_init_file "@initconfigdir@" $servid)
 if [ $? == 1 ]
 then
     echo "You must supply a valid server instance identifier.  Use -Z to specify instance name"
-    echo "Available instances: $servid"
+    echo "Available instances: $initfile"
     exit 1
 fi
 
-configdir="@instconfigdir@/slapd-$servid"
+servid=`normalize_server_id $initfile`
+. $initfile
 
 if [ "$archive_provided" != "yes" ]
 then
@@ -55,4 +56,4 @@ then
 fi
 
 echo upgrade index files ...
-@sbindir@/ns-slapd upgradedb -D $configdir $args
+@sbindir@/ns-slapd upgradedb -D $CONFIG_DIR $args

+ 6 - 6
ldap/admin/src/scripts/upgradednformat.in

@@ -1,6 +1,6 @@
 #!/bin/sh
 
-source @datadir@/dirsrv/data/DSSharedLib
+source @datadir@/@package_name@/data/DSSharedLib
 
 # upgradednformat -- upgrade DN format to the new style (RFC 4514)
 # Usgae: upgradednformat [-N] -n backend_instance -a db_instance_directory
@@ -10,7 +10,7 @@ source @datadir@/dirsrv/data/DSSharedLib
 #        -a db_instance_directory -- full path to the db instance dir
 #                                    e.g., /var/lib/dirsrv/slapd-ID/db/userRoot
 
-libpath_add "@libdir@/dirsrv/"
+libpath_add "@libdir@/@package_name@/"
 libpath_add "@nss_libdir@"
 libpath_add "@libdir@"
 libpath_add "@pcre_libdir@"
@@ -54,18 +54,18 @@ if [ "$be" = "" ] || [ "$dir" = "" ]; then
     exit 1
 fi
 
-servid=$(get_server_id "@initconfigdir@" $servid)
+initfile=$(get_init_file "@initconfigdir@" $servid)
 if [ $? == 1 ]
 then
     usage
     echo "You must supply a valid server instance identifier.  Use -Z to specify instance name"
-    echo "Available instances: $servid"
+    echo "Available instances: $initfile"
     exit 1
 fi
 
-configdir="@instconfigdir@/slapd-$servid"
+. $initfile
 
-@sbindir@/ns-slapd upgradednformat -D $configdir $args
+@sbindir@/ns-slapd upgradednformat -D $CONFIG_DIR $args
 rc=$?
 
 exit $rc

+ 2 - 2
ldap/admin/src/scripts/usn-tombstone-cleanup.pl.in

@@ -109,8 +109,8 @@ while ($i <= $#ARGV)
 #
 # Gather all our config settings
 #
-$servid = DSUtil::get_server_id($servid, "@initconfigdir@");
-%info = DSUtil::get_info("@instconfigdir@", $servid, $host, $port, $rootdn);
+($servid, $confdir) = DSUtil::get_server_id($servid, "@initconfigdir@");
+%info = DSUtil::get_info($confdir, $host, $port, $rootdn);
 $info{rootdnpw} = DSUtil::get_password_from_file($passwd, $passwdfile);
 $info{protocol} = $protocol;
 if ($verbose == 1){

+ 2 - 2
ldap/admin/src/scripts/verify-db.pl.in

@@ -43,7 +43,7 @@ use DSUtil;
 
 DSUtil::libpath_add("@db_libdir@");
 DSUtil::libpath_add("@libdir@");
-$ENV{'PATH'} = "@libdir@/dirsrv/slapd-$servid:@db_bindir@:/usr/bin:/";
+$ENV{'PATH'} = "@libdir@/@package_name@/slapd-$servid:@db_bindir@:/usr/bin:/";
 $ENV{'SHLIB_PATH'} = "$ENV{'LD_LIBRARY_PATH'}";
 
 my $i = 0;
@@ -167,7 +167,7 @@ while ($i <= $#ARGV) {
   $i++;
 }
 
-$servid = DSUtil::get_server_id($servid, "@initconfigdir@");
+($servid, $notused_configdir) = DSUtil::get_server_id($servid, "@initconfigdir@");
 
 print("*****************************************************************\n");
 print("verify-db: This tool should only be run if recovery start fails\n" .

+ 6 - 6
ldap/admin/src/scripts/vlvindex.in

@@ -1,8 +1,8 @@
 #!/bin/sh
 
-source @datadir@/dirsrv/data/DSSharedLib
+source @datadir@/@package_name@/data/DSSharedLib
 
-libpath_add "@libdir@/dirsrv/"
+libpath_add "@libdir@/@package_name@/"
 libpath_add "@libdir@"
 libpath_add "@nss_libdir@"
 libpath_add "@pcre_libdir@"
@@ -44,16 +44,16 @@ do
     esac
 done
 
-servid=$(get_server_id "@initconfigdir@" $servid)
+initfile=$(get_init_file "@initconfigdir@" $servid)
 if [ $? == 1 ]
 then
     usage
     echo "You must supply a valid server instance identifier.  Use -Z to specify instance name"
-    echo "Available instances: $servid"
+    echo "Available instances: $initfile"
     exit 1
 fi
 
-configdir="@instconfigdir@/slapd-$servid"
+. $initfile
 
 if [ $# -lt 4 ]
 then
@@ -61,4 +61,4 @@ then
     exit 1
 fi
 
-@sbindir@/ns-slapd db2index -D $configdir $args
+@sbindir@/ns-slapd db2index -D $CONFIG_DIR $args