Add 'rm' for a fully qualified DN, instead of only working with RDN.
Reported by Lars Tauber <taeuber@bbaw.de>. FossilOrigin-Name: 018facf53aa8b6da5181afc3dafd8f02bb4274fd162cb430f91b96acb7041c78
This commit is contained in:
parent
577ee80285
commit
6a5a286c1e
2 changed files with 63 additions and 13 deletions
|
|
@ -6,6 +6,7 @@ Giacomo Tenaglia <Giacomo.Tenaglia@cern.ch>
|
||||||
Jonathan Rozes <jonathan@laika.com>
|
Jonathan Rozes <jonathan@laika.com>
|
||||||
Josef Wells <Josefwells@alumni.utexas.net>
|
Josef Wells <Josefwells@alumni.utexas.net>
|
||||||
Landry Breuil <landry@cvs.openbsd.org>
|
Landry Breuil <landry@cvs.openbsd.org>
|
||||||
|
Lars Täuber <taeuber@bbaw.de>
|
||||||
Michael Granger <ged@faeriemud.org>
|
Michael Granger <ged@faeriemud.org>
|
||||||
Michael Raitza <spacefrogg-devel@meterriblecrew.net>
|
Michael Raitza <spacefrogg-devel@meterriblecrew.net>
|
||||||
Mike Hix <m@hix.io>
|
Mike Hix <m@hix.io>
|
||||||
|
|
@ -14,3 +15,4 @@ Rick H. <rickh_shelldap@printstring.com>
|
||||||
Rong-En Fan <rafan@FreeBSD.org>
|
Rong-En Fan <rafan@FreeBSD.org>
|
||||||
Salvatore Bonaccorso <carnil@debian.org>
|
Salvatore Bonaccorso <carnil@debian.org>
|
||||||
Yann Cezard <yann.cezard@univ-pau.fr>
|
Yann Cezard <yann.cezard@univ-pau.fr>
|
||||||
|
|
||||||
|
|
|
||||||
74
shelldap
74
shelldap
|
|
@ -291,10 +291,12 @@ aliased to: touch
|
||||||
=item B<delete>
|
=item B<delete>
|
||||||
|
|
||||||
Remove an entry from the directory. Globbing is supported.
|
Remove an entry from the directory. Globbing is supported.
|
||||||
All deletes are sanity-prompted.
|
All deletes are sanity-prompted. The -v flag prints the entries out
|
||||||
|
for review before delete.
|
||||||
|
|
||||||
delete uid=mahlon
|
delete uid=mahlon
|
||||||
delete uid=ma*
|
delete uid=ma*
|
||||||
|
rm -v uid=mahlon,ou=People,dc=example,o=company l=office
|
||||||
|
|
||||||
aliased to: rm
|
aliased to: rm
|
||||||
|
|
||||||
|
|
@ -400,6 +402,8 @@ Modify various runtime variables normally set from the command line.
|
||||||
Show current auth credentials. Unless you specified a binddn, this
|
Show current auth credentials. Unless you specified a binddn, this
|
||||||
will just show an anonymous bind.
|
will just show an anonymous bind.
|
||||||
|
|
||||||
|
aliased to: id
|
||||||
|
|
||||||
=back
|
=back
|
||||||
|
|
||||||
=head1 TODO
|
=head1 TODO
|
||||||
|
|
@ -1450,31 +1454,76 @@ sub run_create
|
||||||
sub run_delete
|
sub run_delete
|
||||||
{
|
{
|
||||||
my $self = shift;
|
my $self = shift;
|
||||||
my @DNs = @_;
|
my @args = @_;
|
||||||
|
my @matches;
|
||||||
|
my $s;
|
||||||
|
my $verbose;
|
||||||
|
|
||||||
unless ( scalar @DNs ) {
|
unless ( scalar @args ) {
|
||||||
print "No dn specified.\n";
|
print "No dn specified.\n";
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
my $filter;
|
# Flags.
|
||||||
unless ( $DNs[0] eq '*' ) {
|
#
|
||||||
$filter = $self->make_filter( \@DNs ) or return;
|
if ( $args[0] =~ /^\-v/ ) {
|
||||||
|
$verbose = 1;
|
||||||
|
shift @args;
|
||||||
|
}
|
||||||
|
|
||||||
|
# Separate real args from filter arguments.
|
||||||
|
#
|
||||||
|
foreach my $dn ( @args ) {
|
||||||
|
if ( $dn eq '*' ) {
|
||||||
|
$s = $self->search({ scope => 'one' });
|
||||||
|
map { push @matches, $_ } @{ $s->{'entries'} } if $s->{'code'} == LDAP_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
# Search by filter
|
||||||
|
#
|
||||||
|
else {
|
||||||
|
|
||||||
|
my $filter = $self->make_filter( [$dn] ) or next;
|
||||||
|
$s = $self->search({ scope => 'one', filter => $filter });
|
||||||
|
if ( scalar @{$s->{'entries'}} != 0 ) {
|
||||||
|
map { push @matches, $_ } @{ $s->{'entries'} } if $s->{'code'} == LDAP_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
# Search by exact DN.
|
||||||
|
#
|
||||||
|
else {
|
||||||
|
$dn = $self->path_to_dn( $dn );
|
||||||
|
$s = $self->search({ base => $dn, vals => 0 });
|
||||||
|
my $e = ${ $s->{'entries'} }[0];
|
||||||
|
push @matches, $e if $s->{'code'} == LDAP_SUCCESS;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
my $s = $self->search({ scope => 'one', filter => $filter });
|
# Unique the matchset for a consistent count, keyed by DN.
|
||||||
unless ( $s->{'code'} == LDAP_SUCCESS ) {
|
#
|
||||||
print "$s->{'message'}\n";
|
my @uniq_matches = keys %{{ map { $_->dn => 1 } @matches }};
|
||||||
|
|
||||||
|
my $mcount = scalar @uniq_matches;
|
||||||
|
if ( $mcount == 0 ) {
|
||||||
|
print "Nothing matched.\n";
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
print "Are you sure? [Ny]: ";
|
if ( $verbose ) {
|
||||||
|
print "* $_\n" foreach @uniq_matches;
|
||||||
|
}
|
||||||
|
|
||||||
|
print "About to remove $mcount item(s). Are you sure? [Ny]: ";
|
||||||
chomp( my $resp = <STDIN> );
|
chomp( my $resp = <STDIN> );
|
||||||
return unless $resp =~ /^y/i;
|
return unless $resp =~ /^y/i;
|
||||||
|
|
||||||
foreach my $e ( @{ $s->{'entries'} } ) {
|
my %seen;
|
||||||
|
foreach my $e ( @matches ) {
|
||||||
my $dn = $e->dn();
|
my $dn = $e->dn();
|
||||||
|
next if $seen{ $dn };
|
||||||
my $rv = $self->ldap->delete( $dn );
|
my $rv = $self->ldap->delete( $dn );
|
||||||
|
$seen{ $dn }++;
|
||||||
print "$dn: ", $rv->error(), "\n";
|
print "$dn: ", $rv->error(), "\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1538,7 +1587,6 @@ sub run_edit
|
||||||
}
|
}
|
||||||
close LDIF;
|
close LDIF;
|
||||||
}
|
}
|
||||||
|
|
||||||
# checksum it, then open it in an editor
|
# checksum it, then open it in an editor
|
||||||
#
|
#
|
||||||
my $hash_orig = $self->chksum( $self->{'ldif_fname'} );
|
my $hash_orig = $self->chksum( $self->{'ldif_fname'} );
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue