[Date Prev][Date Next] [Chronological] [Thread] [Top]

Tool: ldapedit


I wrote a small tool which might be interesting to others. Its a small
bourne-shell script that takes an LDAP filter, displays the result (only
one handled at the moment) in an editor ($VISUAL and $EDITOR are
evaluated) and writes back any changes and/or additions to the directory.
I wrote it because of the lack of a usable shell-level tool for editing a
directory. Its really very small and easy to write yourself, but why
re-invent the wheel :-)

Call it as "ldapedit <filter> <bind-dn> <bind-pw>"

If anyone uses it, please send me a mail and I'll post future versions,
too. Patches are welcome, of course (especially error handling could use

Better yet, if anyone has any other useful LDAP tools that he'd like to
share, send them to the list :-)

		Ingo Luetkebohle / 21st Century Digital Boy
dev/consulting Gesellschaft fuer Netzwerkentwicklung und -beratung mbH
url: http://www.devconsult.de/ - fon: 0521-1365800 - fax: 0521-1365803 
# ldapedit -- Liest Eintrag aus Verzeichnis, stellt ihn in Editor
#	      dar und schreibt die Änderungen zurück ins Verzeichnis
#		Copyright (C) 1998 by Ingo Lütkebohle <ingo@devcon.net>

if [ $# -ne 3 ]; then
	echo "Syntax: <filter> <bind-bn> <bind-pw>"
	exit 255

# create temp-file
TMPFILE=`mktemp /tmp/ldap_edit.XXXXXX`
if [ $? -ne 0 ]; then
	echo "Fehler beim Erstellen der Temporärdatei"
	exit 255

# read entry
ldapsearch -D "$2" -w $3 -b c=DE "($1)" -B -S ": "|grep -v -E '^(creatorsname|createtimestamp|modifytimestamp|modifiersname)' > $TMPFILE || ( rm -f $TMPFILE ; exit 255 )

if [ -f $TMPFILE ]; then
	exit 255

# modify entries
rewrite-to-replog < $TMPFILE | ldapmodify -D "$2" -w "$3"

#!/usr/bin/perl -w
# rewrite-to-replog -- reads ldapsearch output and converts it to replog format
#		Copyright (C) 1998 by Ingo Lütkebohle <ingo@devcon.net>

my %attrs;

# first line is DN -- modrdn not supported yet
my $dn = <STDIN>;
print "dn: $dn";

# read values
while(<STDIN>) {
	my ( $key, $val ) = m/^([^=]+)=(.*)$/;
	if($key && $val) {
		push @{$attrs{$key}}, $val;

# print out replog format
foreach $key ( sort keys %attrs ) {
	print "changetype: modify\nreplace: $key\n";
	foreach $entry ( @{$attrs{$key}} ) {
		print "$key: $entry\n";
	print "-\n";