shelldap
changeset 54 0cc20d93ff50
parent 51 27bbe75233a3
child 56 32e313d5d2d2
equal deleted inserted replaced
53:ae62c24653ef 54:0cc20d93ff50
  1509 	# detect a total lack of change
  1509 	# detect a total lack of change
  1510 	#
  1510 	#
  1511 	if ( $hash_orig eq $self->chksum($self->{'ldif_fname'}) ) {
  1511 	if ( $hash_orig eq $self->chksum($self->{'ldif_fname'}) ) {
  1512 		print "Entry not modified.\n";
  1512 		print "Entry not modified.\n";
  1513 		unlink $self->{'ldif_fname'};
  1513 		unlink $self->{'ldif_fname'};
       
  1514 		$self->{'edit_again'} = undef;
  1514 		return;
  1515 		return;
  1515 	}
  1516 	}
  1516 
  1517 
  1517 	# check changes for basic LDIF validity
  1518 	# check changes for basic LDIF validity
  1518 	#
  1519 	#
  1521 		if ( $self->prompt_edit_again() ) {
  1522 		if ( $self->prompt_edit_again() ) {
  1522 			system( $self->{'editor'}, $self->{'ldif_fname'} );
  1523 			system( $self->{'editor'}, $self->{'ldif_fname'} );
  1523 		}
  1524 		}
  1524 		else {
  1525 		else {
  1525 			unlink $self->{'ldif_fname'};
  1526 			unlink $self->{'ldif_fname'};
       
  1527 			$self->{'edit_again'} = undef;
  1526 			return;
  1528 			return;
  1527 		}
  1529 		}
  1528 	}
  1530 	}
  1529 
  1531 
  1530 	# load changes into a new array for comparison
  1532 	# load changes into a new array for comparison
  1552 	while ( $diff->Next() ) {
  1554 	while ( $diff->Next() ) {
  1553 		next if $diff->Same();
  1555 		next if $diff->Same();
  1554 		my $diff_bit = $diff->Diff();
  1556 		my $diff_bit = $diff->Diff();
  1555 		my %seen_attr;
  1557 		my %seen_attr;
  1556 
  1558 
  1557 		# attr removals
  1559 		# attr removal hunk
  1558 		#
  1560 		#
  1559 		if ( $diff_bit == 1 ) {
  1561 		if ( $diff_bit == 1 ) {
  1560 			foreach ( $diff->Items(1) ) {
  1562 			foreach ( $diff->Items(1) ) {
  1561 				my ( $attr, $val ) = $parse->( $_ ) or next;
  1563 				my ( $attr, $val ) = $parse->( $_ ) or next;
  1562 				$self->debug("DELETE: $_");
  1564 				$self->debug("DELETE: $_");
  1563 				$e->delete( $attr => [ $val ] );
  1565 				$e->delete( $attr => [ $val ] );
  1564 			}
  1566 			}
  1565 		}
  1567 		}
  1566 
  1568 
  1567 		# attr insertions
  1569 		# attr insertion hunk
  1568 		#
  1570 		#
  1569 		if ( $diff_bit == 2 ) {
  1571 		if ( $diff_bit == 2 ) {
  1570 			foreach ( $diff->Items(2) ) {
  1572 			foreach ( $diff->Items(2) ) {
  1571 				my ( $attr, $val ) = $parse->( $_ ) or next;
  1573 				my ( $attr, $val ) = $parse->( $_ ) or next;
  1572 				$self->debug("INSERT: $_");
  1574 				$self->debug("INSERT: $_");
  1573 				$e->add( $attr => $val );
  1575 				$e->add( $attr => $val );
  1574 			}
  1576 			}
  1575 		}
  1577 		}
  1576 
  1578 
  1577 		# attr change
  1579 		# attr change hunk
  1578 		#
  1580 		#
  1579 		if ( $diff_bit == 3 ) {
  1581 		if ( $diff_bit == 3 ) {
       
  1582 
       
  1583 			# modification to existing line
       
  1584 			#
  1580 			foreach ( $diff->Items(2) ) {
  1585 			foreach ( $diff->Items(2) ) {
  1581 				my ( $attr, $val ) = $parse->( $_ ) or next;
  1586 				my ( $attr, $val ) = $parse->( $_ ) or next;
  1582 				$self->debug("MODIFY: $_");
  1587 				$self->debug("MODIFY: $_");
  1583 
  1588 
  1584 				my $cur_vals = $e->get_value( $attr, asref => 1 ) || [];
  1589 				my $cur_vals = $e->get_value( $attr, asref => 1 ) || [];
  1606 					}
  1611 					}
  1607 
  1612 
  1608 					$e->replace( $attr => \@new_vals );
  1613 					$e->replace( $attr => \@new_vals );
  1609 				}
  1614 				}
  1610 			}
  1615 			}
       
  1616 
       
  1617 			# deletion within the same hunk
       
  1618 			#
       
  1619 			foreach ( $diff->Items(1) ) {
       
  1620 				my ( $attr, $val ) = $parse->( $_ ) or next;
       
  1621 				next if $seen_attr{ $attr };
       
  1622 				$self->debug("DELETE: $_");
       
  1623 				$e->delete( $attr => [ $val ] );
       
  1624 			}
  1611 		}
  1625 		}
  1612 	}
  1626 	}
  1613 
  1627 
  1614 	my $update = sub { return $e->update( $self->ldap ); };
  1628 	my $update = sub { return $e->update( $self->ldap ); };
  1615 	my $rv = $self->with_retry( $update );
  1629 	my $rv = $self->with_retry( $update );
  2141 package main;
  2155 package main;
  2142 use strict;
  2156 use strict;
  2143 use warnings;
  2157 use warnings;
  2144 
  2158 
  2145 $0 = 'shelldap';
  2159 $0 = 'shelldap';
  2146 my $VERSION = '1.0.0';
  2160 my $VERSION = '1.0.1';
  2147 
  2161 
  2148 use Getopt::Long;
  2162 use Getopt::Long;
  2149 use YAML::Syck;
  2163 use YAML::Syck;
  2150 use Pod::Usage;
  2164 use Pod::Usage;
  2151 eval 'use Term::ReadLine::Gnu';
  2165 eval 'use Term::ReadLine::Gnu';