[Fedora-directory-commits] ldapserver/ldap/admin/src/scripts Util.pm.in, 1.5, 1.6

Noriko Hosoi (nhosoi) fedora-directory-commits at redhat.com
Fri Jul 6 17:39:38 UTC 2007


Author: nhosoi

Update of /cvs/dirsec/ldapserver/ldap/admin/src/scripts
In directory cvs-int.fedora.redhat.com:/tmp/cvs-serv794

Modified Files:
	Util.pm.in 
Log Message:
Resolves: #247215
Summary: Reimplement ds_remove without setuputil code (comment #1)
Description: 1) introduced delete entry operation.
2) cleaned up check_and_add code



Index: Util.pm.in
===================================================================
RCS file: /cvs/dirsec/ldapserver/ldap/admin/src/scripts/Util.pm.in,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- Util.pm.in	4 Jul 2007 01:28:17 -0000	1.5
+++ Util.pm.in	6 Jul 2007 17:39:36 -0000	1.6
@@ -233,21 +233,18 @@
     }
     do
     {
-        my $needtoadd;
         my @addtypes; # list of attr types for mod add
         my @reptypes; # list of attr types for mod replace
         my @deltypes; # list of attr types for mod delete
-        my $MOD_NONE = 0;
-        my $MOD_ADD = 1;
-        my $MOD_REPLACE = 2;
-        my $MOD_SPECIAL = 3;
-        # $needtomod stores either of the above $MOD_ values
-        # note: delete is not supported
-        my $needtomod;
+        my $OP_NONE = 0;
+        my $OP_ADD = 1;
+        my $OP_MOD = 2;
+        my $OP_DEL = 3;
+        # $op stores either of the above $OP_ values
+        my $op = $OP_NONE;
         if ( 0 > $#ctypes )    # aentry: complete entry
         {
-            $needtoadd = 1;
-            $needtomod = 0; #$MOD_NONE
+            $op = $OP_ADD;
 
             my $rc = -1;
             if ( $sentry && !$fresh )
@@ -258,13 +255,12 @@
             {
                 # the identical entry exists on the configuration DS.
                 # no need to add the entry.
-                $needtoadd = 0;
+                $op = $OP_NONE;
                 goto out;
             }
             elsif ( (1 == $rc) && !$fresh )
             {
-                $needtoadd = 0;
-                $needtomod = $MOD_ADD;
+                $op = $OP_MOD;
                 @addtypes = keys %{$aentry}; # add all attrs
             }
             elsif ( $sentry && $sentry->{dn} )
@@ -284,21 +280,27 @@
         }
         else    # aentry: modify format
         {
-            $needtoadd = 0;
             if ( $sentry )
             {
-                @addtypes = $aentry->getValues("add");
-                @reptypes = $aentry->getValues("replace");
-                @deltypes = $aentry->getValues("delete");
-                $needtomod = $MOD_REPLACE;
+                if ( "delete" eq lc($ctypes[0]) )
+                {
+                    $op = $OP_DEL;
+                }
+                else
+                {
+                    @addtypes = $aentry->getValues("add");
+                    @reptypes = $aentry->getValues("replace");
+                    @deltypes = $aentry->getValues("delete");
+                    $op = $OP_MOD;
+                }
             }
             else
             {
-                $needtomod = $MOD_NONE;
+                $op = $OP_NONE;
             }
         }
 
-        if ( 1 == $needtoadd )
+        if ( $OP_ADD == $op )
         {
             $conn->add($aentry);
             my $rc = $conn->getErrorCode();
@@ -313,20 +315,20 @@
             }
             debug(1, "Entry $aentry->{dn} is added\n");
         }
-        elsif ( 0 < $needtomod )    # $sentry exists
+        elsif ( $OP_DEL == $op )
         {
-            my $attr;
-            if ( $needtomod == $MOD_SPECIAL )
+            my $rc = delete_all($conn, $sentry);
+            if ( 0 != $rc )
             {
-                debug(3, "Doing MOD_SPECIAL for entry $aentry->{dn}\n");
-                foreach $attr ( keys %speciallist )
-                {
-                    foreach my $nval ( @{$aentry->{$attr}} )
-                    {
-                        $sentry->addValue( $attr, $nval );
-                    }
-                }
+                push @{$errs}, 'error_deleteall_entries', $sentry->{dn}, $conn->getErrorString();
+                debug(1, "Error deleting $sentry->{dn}\n");
+                return 0;
             }
+            debug(1, "Entry $aentry->{dn} is deleted\n");
+        }
+        elsif ( 0 < $op )    # $sentry exists
+        {
+            my $attr;
             foreach $attr ( @addtypes )
             {
                 debug(3, "Adding attr=$attr values=" . $aentry->getValues($attr) . " to entry $aentry->{dn}\n");
@@ -670,6 +672,8 @@
         else
         {
             # get the value from one of the Inf passed in
+            # they $value could be pure Key or Key:"default_value"
+            my ($key_value, $default_value) = split(/:/, $value, 2);
             my $infsection;
             foreach my $thisinf (@infdata)
             {
@@ -677,17 +681,25 @@
                 {
                     $infsection = $thisinf->{$section0};
                     next if (!ref($infsection));
-                    if (defined($infsection->{$value}))
+                    if (defined($infsection->{$key_value}))
                     {
-                        $mapper->{$key} = $infsection->{$value};
+                        $mapper->{$key} = $infsection->{$key_value};
                         next KEY;
                     }
                 }
             }
             if (!defined($infsection->{$value}))
             {
-                push @{$errs}, 'no_mapvalue_for_key', $value, $key;
-                return {};
+                if ($default_value ne "")
+                {
+                    $default_value =~ tr/\"//d; # default_value is a regular double quoted string - remove quotes
+                    $mapper->{$key} = $default_value;
+                }
+                else
+                {
+                    push @{$errs}, 'no_mapvalue_for_key', $value, $key;
+                    return {};
+                }
             }
         }
     }




More information about the Fedora-directory-commits mailing list