summaryrefslogtreecommitdiffstats
path: root/tcllib/examples/ldap/ldifdump
blob: fe73f54c64bfcf73832974159cf02de022c7f36e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#!/usr/bin/env tclsh
## -*- tcl -*-
########################################################################
#
# Load and print an ldif file
#
########################################################################

package require ldapx

if {![llength $argv]} {
    puts stderr "Usage: [info script] file ?file ... file?"
    exit 1
}
set entries [list]

proc loadLDIF {fd} {
    global entries
    
    ldapx::ldif ld
    ld channel $fd
    
    set e [ldapx::entry %AUTO%]
    while {[ld read $e]} {
       lappend entries $e
       set e [ldapx::entry %AUTO%]
    }
    $e destroy
    
}

proc displayLDIF {} {
    global entries
    set sort [list]
    foreach e $entries {
        lappend sort [list [$e dn] $e]
    }
    set sort [lsort -index 0 $sort]
    foreach key $sort {
        set e [lindex $key 1]
        puts "[$e print] \n"
    }
    
}

foreach file $argv {
    set fd [open $file]
    loadLDIF $fd
    close $fd
}
displayLDIF
exit