mutt/mutt_ldap_query
Miroslav Lichvar c9d9f8cab0 - fix sending long commands when using gnutls (#438275)
- glob tilde in smime_keys (#424311)
- fix awk script in mutt_ldap_query
- force building with libdb
- make enabling/disabling features in spec easier
2008-04-04 11:50:26 +00: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