1270096Strasz#!/bin/sh 2270096Strasz# 3270096Strasz# $FreeBSD: releng/11.0/etc/autofs/include_ldap 280321 2015-03-21 09:42:37Z trasz $ 4270096Strasz# 5270096Strasz 6270096Strasz# Modify this to suit your needs. The "$1" is the map name, eg. "auto_master". 7270096Strasz# To debug, simply run this script with map name as the only parameter. It's 8270096Strasz# supposed to output map contents ("key location" pairs) to standard output. 9270096StraszSEARCHBASE="ou=$1,dc=example,dc=com" 10270096StraszENTRY_ATTRIBUTE="cn" 11270096StraszVALUE_ATTRIBUTE="automountInformation" 12270096Strasz 13270096Strasz/usr/local/bin/ldapsearch -LLL -x -o ldif-wrap=no -b "$SEARCHBASE" "$ENTRY_ATTRIBUTE" "$VALUE_ATTRIBUTE" | awk ' 14270096Strasz$1 == "'$ENTRY_ATTRIBUTE':" { 15270096Strasz key = $2 16270096Strasz} 17270096Strasz 18280321Strasz$1 == "'$VALUE_ATTRIBUTE':" { 19280321Strasz for (i = 2; i <= NF; i++) { 20280321Strasz value[i] = $(i) 21270096Strasz } 22280321Strasz nvalues = NF 23280321Strasz b64 = 0 24270096Strasz} 25270096Strasz 26270096Strasz# Double colon after attribute name means the value is in Base64. 27280321Strasz$1 == "'$VALUE_ATTRIBUTE'::" { 28280321Strasz for (i = 2; i <= NF; i++) { 29280321Strasz value[i] = $(i) 30280321Strasz } 31280321Strasz nvalues = NF 32280321Strasz b64 = 1 33280321Strasz} 34280321Strasz 35280321Strasz# Empty line - end of record. 36280321StraszNF == 0 && key != "" && nvalues > 0 { 37270096Strasz printf "%s%s", key, OFS 38280321Strasz for (i = 2; i < nvalues; i++) { 39280321Strasz printf "%s%s", value[i], OFS 40270096Strasz } 41280321Strasz if (b64 == 1) { 42280321Strasz printf "%s", value[nvalues] | "b64decode -rp" 43280321Strasz close("b64decode -rp") 44280321Strasz printf "%s", ORS 45280321Strasz } else { 46280321Strasz printf "%s%s", value[nvalues], ORS 47280321Strasz } 48270096Strasz} 49280321Strasz 50280321StraszNF == 0 { 51280321Strasz key = "" 52280321Strasz nvalues = 0 53280321Strasz delete value 54280321Strasz} 55270096Strasz' 56