# + rfc o ldap patrz https://tools.ietf.org/html/rfc4510
# to jest spis innych rfc...
# + spoza wmi trzeba tunelowac przez ssh
# + do czego to sie moze przydac???
# 1. uwierzytelnianie studentow/pracownikow wmi
# 2. info o strukturze wmi (zaklady itp?)
# 3. ???
#
lappend auto_path ~/tcl/tcllib
package re ldap
#% 1.8
package re dict
#% 8.5.2
set h [ldap::connect ldap.wmi.amu.edu.pl]
#% ::ldap::ldapsock7
set x [ldap::search $h "DC=labs,DC=wmi,DC=amu,DC=edu,DC=pl" "(CN=mh*)" ""]
llength $x
#% 2
lindex $x 0 0
#% CN=mhanckow,OU=Faculty,OU=People,DC=labs,DC=wmi,DC=amu,DC=edu,DC=pl
lindex $x 1 0
#% CN=mhoffmann,OU=Faculty,OU=People,DC=labs,DC=wmi,DC=amu,DC=edu,DC=pl
# + DN czyli DistinguishedName
dict keys [lindex $x 0 1]
#% sAMAccountType unixHomeDirectory givenName uSNCreated primaryGroupID department memberOf displayName countryCode uSNChanged msSFU30NisDomain homeDrive codePage logonCount uid userParameters distinguishedName objectClass homeDirectory lastLogonTimestamp logonHours lockoutTime lastLogoff userPrincipalName c description gidNumber accountExpires objectCategory instanceType objectSid loginShell cn name whenCreated co lastLogon pwdLastSet l streetAddress physicalDeliveryOfficeName objectGUID uidNumber mail whenChanged userAccountControl postalCode dSCorePropagationData sAMAccountName sn badPasswordTime badPwdCount profilePath company
# + klucze slownika z atrybutami ob. CN=mhanckow,...
dict get [lindex $x 0 1] mail
#% mhanckow@amu.edu.pl
encoding convertfrom utf-8 [dict get [lindex $x 0 1] company]
#% {Wydzia³ Matematyki i Informatyki UAM}
encoding convertfrom utf-8 [dict get [lindex $x 0 1] department]
#% {Zak³ad Matematyki Dyskretnej}
# + odczytujemy atrybuty z tego slownika
encoding convertfrom utf-8 [dict get [lindex $x 0 1] memberOf]
#% CN=Zaklad_Teorii_Algorytmow_i_Bezpieczenstwa_Danych,OU=Departments,OU=Groups,DC=labs,DC=wmi,DC=amu,DC=edu,DC=pl CN=public,OU=Groups,DC=labs,DC=wmi,DC=amu,DC=edu,DC=pl CN=faculty_research,OU=Groups,DC=labs,DC=wmi,DC=amu,DC=edu,DC=pl CN=faculty,OU=Groups,DC=labs,DC=wmi,DC=amu,DC=edu,DC=pl
join [encoding convertfrom utf-8 [dict get [lindex $x 0 1] memberOf]] \n
#% CN=Zaklad_Teorii_Algorytmow_i_Bezpieczenstwa_Danych,OU=Departments,OU=Groups,DC=labs,DC=wmi,DC=amu,DC=edu,DC=pl
CN=public,OU=Groups,DC=labs,DC=wmi,DC=amu,DC=edu,DC=pl
CN=faculty_research,OU=Groups,DC=labs,DC=wmi,DC=amu,DC=edu,DC=pl
CN=faculty,OU=Groups,DC=labs,DC=wmi,DC=amu,DC=edu,DC=pl
# + troche ulepszony wydruk...
ldap::disconnect $h
exit