[Date Prev][Date Next] [Chronological] [Thread] [Top]

Solved: Shell Backend -- Multiple Answers to a Search using * in the Search String



	With a small modification to the example script, it works. The
example was meant to return one result per request using __a standard Unix
/etc/passwd file__. Because two identical user names can not exist in this
file. It took me a while to realise this.

#!/bin/sh
#
# Example Shell Backend for Search Operation
#
LOG=/home/shinro/shell_backend/log/ldap_shell.log
TIME=`date`
echo "" >> $LOG
echo "======================== $TIME =======================" >> $LOG

while [ l ]; do
  read TAG VALUE
  if [ $? -ne 0 ]; then
  break
  fi
  case "$TAG" in
     msgid:)
     MSGID=$VALUE
     echo "msgid: $MSGID" >> $LOG
     ;;
     base:)
     BASE=$VALUE
     echo "base: $BASE" >> $LOG
     ;;
     scope:)
     SCOPE=$VALUE
     echo "scope: $SCOPE" >> $LOG
     ;;
     deref:)
     DEREF=$VALUE
     echo "deref: $DEREF" >> $LOG
     ;;
     sizelimit:)
     SIZELIMIT=$VALUE
     echo "sizelimit: $SIZELIMIT" >> $LOG
     ;;
     timelimit:)
     TIMELIMIT=$VALUE
     echo "timelimit: $TIMELIMIT" >> $LOG
     ;;	
     filter:)
     FILTER=$VALUE
     echo "filter: $FILTER" >> $LOG
     ;;
     attrsonly:)
     ATTRSONLY=$VALUE
     echo "attrsonly: $ATTRSONLY" >> $LOG
     ;;
     attrs:)
     ATTRS=$VALUE
     echo "attrs: $ATTRS" >> $LOG
     ;;
  esac
done
SEARCH=`echo $FILTER | sed -e 's/.*=\(.*\))/\1/'`
LINE=`grep -i "^$SEARCH" /home/shinro/shell_backend/fake`
echo "" >> $LOG
echo "What we are searching for is $SEARCH." >> $LOG
echo "The matched entries are;" >> $LOG
echo "$LINE" >> $LOG
echo "" >> $LOG
echo "The search results:" >> $LOG
echo "" >> $LOG
if [ $? = 0 ]; then
IFS='
'
   for MULTIPL in $LINE; do
      echo $MULTIPL >> $LOG
      echo $MULTIPL | awk -F: '{
          printf("dn: cn=%s,%s\n", $1, base);
          printf("cn: %s\n", $1);
          printf("cn: %s\n", $5);
          printf("sn: %s\n", $1);
          printf("uid: %s\n", $1);
          }' base="$BASE" >> $LOG
      echo $MULTIPL | awk -F: '{
          printf("dn: cn=%s,%s\n", $1, base);
          printf("cn: %s\n", $1);
          printf("cn: %s\n", $5);
          printf("sn: %s\n", $1);
          printf("uid: %s\n", $1);
          }' base="$BASE"
      echo "" >> $LOG
      echo ""
   done
fi
echo "RESULT" >> $LOG
echo "RESULT"
echo "code: 0" >> $LOG
echo "code: 0"
exit 0


> I believe it can as demonstrated by shell-backend/passwd-shell.c.
> I also believe the recently posted (on openldap-general) ldap->ph
> gateway (which is implemented as a shell backend) likewise can
> return multiple entries per request.
> 
> http://www.OpenLDAP.org/lists/openldap-general/200006/msg00045.html