Maybe it's about time to close this one...

Could someone test if NDB likes this acfilter.sh instead of the current
one?  In the tests where NDB works, anyway.  I don't know which ones.

The current acfilter depends on awk being GNU awk, which can be wrong
even on Linux.  Ubuntu has awk = mawk.  This variant uses perl instead.

back-ldif passes most tests with this acfilter and a few additions of
BACKEND2SORT="ldif=e".

#! /bin/sh
# $OpenLDAP: pkg/ldap/tests/scripts/acfilter.sh,v 1.15 2009/01/21 23:40:44 kurt 
Exp $
## This work is part of OpenLDAP Software <http://www.openldap.org/>.
##
## Copyright 1998-2009 The OpenLDAP Foundation.
## All rights reserved.
##
## Redistribution and use in source and binary forms, with or without
## modification, are permitted only as authorized by the OpenLDAP
## Public License.
##
## A copy of this license is available in the file LICENSE in the
## top-level directory of the distribution or, alternatively, at
## <http://www.OpenLDAP.org/license.html>.

# Strip LDIF comments, or strip everything when $BACKEND=null.
# Optionally sort attrs/entries according to $BACKEND2SORT:
#   BACKEND2SORT="<backend>=[a][e],<backend>=[a][e],..." says whether
#   to sort attributes in an entry, and whether to sort entries.
#   2+ empty input lines separate each list of entries to be sorted.
#   This feature needs Perl, otherwise any sorting is just by lines.

# Defaults, used when $BACKEND2SORT does not mention $BACKEND
acfilter_b2s="ndb=a"

case ,$BACKEND2SORT in *,$BACKEND=*) acfilter_b2s=$BACKEND2SORT ;; esac

case $BACKEND,$acfilter_b2s in
null,*) : ;;
*,$BACKEND=[ae]*)
  if (perl -e 0) 2>/dev/null; then perl -we '
        ($end, $sort, @e, @out) = ("", $ARGV[0] =~ /,\Q$ARGV[1]\E=(\w*)/);
        sub lsort { shift(@_) =~ /[$sort]/o ? sort(@_) : @_; }
        foreach (<STDIN>, "", "") {
          if (/^ /s) { $e[-1] .= $_; next; }
          if (/./m)  { push @e, $_ unless /^\#/s; next; }
          if (!...@out) { print $end; $end = ""; }
          if (@e) { push @out, join "", shift(@e), &lsort("a", splice @e); }
             else { print join("\n", &lsort("e", splice @out)), $end; }
          $end = $_;
        }' ",$acfilter_b2s" "$BACKEND"
  else grep -v '^#' | sort ; fi ;;
*)     grep -v '^#' ;;
esac


Reply via email to