Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100755 64 lines (46 sloc) 1.466 kb
d0b4f87 @gbarr Added contrib/ldapmodify.pl from Kartik Subbarao
gbarr authored
1 #! /usr/bin/perl
2
3 # $Id: ldapmodify.pl,v 1.1 2001/10/23 15:07:41 gbarr Exp $
4
5 =head1 NAME
6
7 ldapmodify.pl - A (simplified) ldapmodify clone written in Perl.
8
9 =head1 DESCRIPTION
10
11 ldapmodify.pl is a simplified ldapmodify clone written in Perl.
12
13 =head1 SYNOPSIS
14
15 ldapmodify.pl [B<-a>] [B<-c>] [B<-e errors>] [B<-f file>] [B<-D binddn>]
16 [B<-w passwd>] [B<-h ldaphost>] [B<-p port>]
17
18 The options have the same meaning as those for the standard ldapmodify command.
19
20 =cut
21
22 use Net::LDAP;
23 use Net::LDAP::LDIF;
24
25 use Getopt::Std;
26 use IO::File;
27
28 use vars qw(%opt);
29 use strict;
30
31 getopts('acD:e:f:h:p:P:w:', \%opt);
32 $opt{h} ||= 'localhost';
33 my $conn = Net::LDAP->new($opt{h}) or die "$opt{h}: $!\n";
0188e71 @marschap use current methods and parameters, add binmode where necessary
marschap authored
34 my $result = $conn->bind($opt{D}, password => $opt{w});
d0b4f87 @gbarr Added contrib/ldapmodify.pl from Kartik Subbarao
gbarr authored
35 $result->code && die("$opt{h}: bind: ", $result->error, "\n");
36 my $ldif = Net::LDAP::LDIF->new($opt{f}, "r");
37 $ldif->{changetype} = 'add' if $opt{a};
38 my $ldiferr;
39
0188e71 @marschap use current methods and parameters, add binmode where necessary
marschap authored
40 while (my $change = $ldif->read_entry()) {
d0b4f87 @gbarr Added contrib/ldapmodify.pl from Kartik Subbarao
gbarr authored
41 print "dn: ", $change->dn, "\n";
42 my $result = $change->update($conn);
43 if ($result->code) {
44 print STDERR "ldapmodify: ", $result->error, "\n";
45 if ($opt{e}) {
46 if (!$ldiferr) {
0188e71 @marschap use current methods and parameters, add binmode where necessary
marschap authored
47 $ldiferr = Net::LDAP::LDIF->new($opt{e}, 'a', change => 1)
d0b4f87 @gbarr Added contrib/ldapmodify.pl from Kartik Subbarao
gbarr authored
48 or die "$opt{e}: $!\n";
49 }
50 print { $ldiferr->{fh} } "# Error: ", $result->error;
0188e71 @marschap use current methods and parameters, add binmode where necessary
marschap authored
51 $ldiferr->write_entry($change);
d0b4f87 @gbarr Added contrib/ldapmodify.pl from Kartik Subbarao
gbarr authored
52 print { $ldiferr->{fh} } "\n";
53 }
54 last unless $opt{c};
55 }
56 print "\n";
57 }
58
59 =head1 AUTHOR
60
61 Kartik Subbarao <subbarao@computer.org>
62
63 =cut
Something went wrong with that request. Please try again.