1#!/usr/bin/env tclsh
2########################################################################
3#
4# Load and print an ldif file
5#
6########################################################################
7
8package require ldapx
9
10if {![llength $argv]} {
11    puts stderr "Usage: [info script] file ?file ... file?"
12    exit 1
13}
14set entries [list]
15
16proc loadLDIF {fd} {
17    global entries
18    
19    ldapx::ldif ld
20    ld channel $fd
21    
22    set e [ldapx::entry %AUTO%]
23    while {[ld read $e]} {
24       lappend entries $e
25       set e [ldapx::entry %AUTO%]
26    }
27    $e destroy
28    
29}
30
31proc displayLDIF {} {
32    global entries
33    set sort [list]
34    foreach e $entries {
35        lappend sort [list [$e dn] $e]
36    }
37    set sort [lsort -index 0 $sort]
38    foreach key $sort {
39        set e [lindex $key 1]
40        puts "[$e print] \n"
41    }
42    
43}
44
45foreach file $argv {
46    set fd [open $file]
47    loadLDIF $fd
48    close $fd
49}
50displayLDIF
51exit
52