Browse Source

Ticket 433 - multiple bugs in start-dirsrv, stop-dirsrv, restart-dirsrv scripts

Bug Description:  These scripts check /etc/sysconfig/ to for DS instances.  The
                  issue is that when you install 389-admin it creates a file
                  called dirsrv-admin.  Then these scripts report errors when
                  trying to start/stop/restart.

Fix Description:  First, ignore instances that use "admin" for the indentifier.
                  Second, don't allow setup-ds.pl to use "admin" as the ID.  I
                  also needed to add extra checks for silent installations(which
                  do not use the DSDialogs.pm).  Also ensured the correct/detailed
                  error is displayed and logged when there is a failure.

https://fedorahosted.org/389/ticket/433

Reviewed by: Noriko(Thanks!)
Mark Reynolds 13 năm trước cách đây
mục cha
commit
6ddfaa021a

+ 3 - 1
ldap/admin/src/scripts/DSCreate.pm.in

@@ -122,7 +122,9 @@ sub sanityCheckParams {
         }
     }
 
-    if (!isValidServerID($inf->{slapd}->{ServerIdentifier})) {
+    if($inf->{slapd}->{ServerIdentifier} eq "admin"){
+        return ('error_invalid_serverid - "admin" is reserved for the Admininstration Server, please choose a different server identifier');
+    } elsif (!isValidServerID($inf->{slapd}->{ServerIdentifier})) {
         return ('error_invalid_serverid', $inf->{slapd}->{ServerIdentifier});
     } elsif (-d $inf->{slapd}->{config_dir}) {
         return ('error_server_already_exists', $inf->{slapd}->{config_dir});

+ 5 - 1
ldap/admin/src/scripts/DSDialogs.pm

@@ -99,7 +99,11 @@ my $dsserverid = new Dialog (
         my $res = $DialogManager::SAME;
         my $path = $self->{manager}->{setup}->{configdir} . "/slapd-" . $ans;
         if (!isValidServerID($ans)) {
-            $self->{manager}->alert("error_invalid_serverid", $ans);
+            if($ans eq "admin"){
+                $self->{manager}->alert("error_reserved_serverid", $ans);
+            } else {
+                $self->{manager}->alert("error_invalid_serverid", $ans);
+            }
         } elsif (-d $path) {
             $self->{manager}->alert("error_server_already_exists", $path);
         } else {

+ 6 - 1
ldap/admin/src/scripts/DSUtil.pm.in

@@ -137,7 +137,12 @@ sub isValidDN {
 sub isValidServerID {
     my $servid = shift;
     my $validchars = '#%:\w@_-';
-    return $servid =~ /^[$validchars]+$/o;
+    if($servid eq "admin"){
+        # "admin" is reserved for the admin server
+        return 0;
+    } else {
+        return $servid =~ /^[$validchars]+$/o;
+    }
 }
 
 # we want the name of the effective user id of this process e.g. if someone did

+ 4 - 0
ldap/admin/src/scripts/restart-dirsrv.in

@@ -50,6 +50,10 @@ if [ "$#" -eq 0 ]; then
     for i in $initconfig_dir/@package_name@-*; do
         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
         echo Restarting instance \"$inst\"
         restart_instance $inst
         if [ "$?" -ne 0 ]; then

+ 7 - 1
ldap/admin/src/scripts/setup-ds.pl.in

@@ -88,8 +88,14 @@ if (@errs) {
     if ($setup->{update}) {
         $setup->msg($FATAL, 'error_updating');
     } else {
-        $setup->msg($FATAL, 'error_creating_dsinstance',
+        if($setup->{inf}->{slapd}->{ServerIdentifier} eq "admin"){
+            # 'admin' is reserved for the admin server - log the correct error 
+            $setup->msg($FATAL, 'error_creating_dsinstance_adminid',
                     $setup->{inf}->{slapd}->{ServerIdentifier});
+        } else {
+            $setup->msg($FATAL, 'error_creating_dsinstance',
+                    $setup->{inf}->{slapd}->{ServerIdentifier});
+        }
     }
     $setup->doExit(1);
 } else {

+ 2 - 0
ldap/admin/src/scripts/setup-ds.res.in

@@ -88,6 +88,7 @@ error_creating_suffix = Could not create the suffix '%s'.  Error: %s\n\n
 
 setup_exiting = Exiting . . .\nLog file is '%s'\n\n
 error_creating_dsinstance = Error: Could not create directory server instance '%s'.\n
+error_creating_dsinstance_adminid = Error: Could not create directory server instance '%s', instance name 'admin' reserved for the Administration Server.\n
 created_dsinstance = Your new DS instance '%s' was successfully created.\n
 no_mapvalue_for_key = The map value '%s' for key '%s' did not map to a value in any of the given information files.\n
 error_opening_ldiftmpl = Could not open the LDIF template file '%s'.  Error: %s\n
@@ -104,6 +105,7 @@ program, or low port restriction.  Please choose another value for\
 ServerPort.  Error: $!\n
 error_invalid_serverid = The ServerIdentifier '%s' contains invalid characters.  It must\
 contain only alphanumeric characters and the following: #%:@_-\n\n
+error_reserved_serverid = The ServerIdentifier '%s" is reserved for the Administration Server, please choose a different server identifier.\n
 error_opening_scripttmpl = Could not open the script template file '%s'.  Error: %s\n
 error_creating_directory = Could not create directory '%s'.  Error: %s\n
 error_chowning_directory = Could not change ownership of directory '%s' to userid '%s': Error: %s\n

+ 4 - 0
ldap/admin/src/scripts/start-dirsrv.in

@@ -127,6 +127,10 @@ if [ "$#" -eq 0 ]; then
     for i in $initconfig_dir/@package_name@-*; do
         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
         echo Starting instance \"$inst\"
         start_instance $inst
         if [ "$?" -ne 0 ]; then

+ 4 - 0
ldap/admin/src/scripts/stop-dirsrv.in

@@ -75,6 +75,10 @@ if [ "$#" -eq 0 ]; then
     for i in $initconfig_dir/@package_name@-*; do
         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
         echo Stopping instance \"$inst\"
         stop_instance $inst
         if [ "$?" -ne 0 ]; then