mutt/mutt_ldap_query
Petr Šabata a176eb9150 RHEL 9.0.0 Alpha bootstrap
The content of this branch was automatically imported from Fedora ELN
with the following as its source:
https://src.fedoraproject.org/rpms/mutt#36abf851051de8a3b6075959c3a5e285b3fbc8fd
2020-10-15 20:39:48 +02:00

43 lines
1.1 KiB
Bash

#!/bin/sh
#
# Last modified: 30 October 2000
#
FLAGS=
# Create two temporary files.
umask 077
TMPFILE=`mktemp /tmp/mutt.ldap.XXXXXX`
RESULTS=`mktemp /tmp/mutt.ldap.XXXXXX`
if [ -n "$LDAPSERVER" ]; then
FLAGS="$FLAGS -h $LDAPSERVER"
fi
if [ -n "$LDAPBASEDN" ]; then
FLAGS="$FLAGS -b $LDAPBASEDN"
fi
# Search.
ldapsearch $FLAGS '(&(objectclass=inetorgperson)(|(cn='"$1"'*)(givenname='"$1"'*)(surname='"$1"'*)(mail='"$1"'*)))' mail cn roomNumber 2> /dev/null >> $TMPFILE
ldapsearch -x $FLAGS '(&(objectclass=inetorgperson)(|(cn='"$1"'*)(givenname='"$1"'*)(surname='"$1"'*)(mail='"$1"'*)))' mail cn roomNumber 2> /dev/null >> $TMPFILE
# Parse.
cat $TMPFILE | awk '
/^mail:/ {MAIL=substr($0,6)}
/^cn:/ {NAME=substr($0,4)}
/^roomNumber:/ {ROOM=substr($0,12)}
/^$/ { MAIL=gensub("^ *| *$","","g",MAIL) }
/^$/ { NAME=gensub("^ *| *$","","g",NAME) }
/^$/ { ROOM=gensub("^ *| *$","","g",ROOM) }
/^$/ { if(length(NAME) > 0) print MAIL "\t" NAME "\t" ROOM}
/^$/ { NAME = "" }
' > $RESULTS
# Sort and present results.
sort -u $RESULTS > $TMPFILE
echo Querying ${LDAPSERVER}.... `cat $TMPFILE | wc -l` entries found.
cat $TMPFILE
# Clean up.
rm -f $TMPFILE $RESULTS