From 799dc834e0fe94ed62c0d6bb65e6d15a639ab668 Mon Sep 17 00:00:00 2001 From: Lexi Winter Date: Sat, 12 Jul 2025 07:52:42 +0100 Subject: initial commit --- lfldap-update.sh | 57 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 lfldap-update.sh (limited to 'lfldap-update.sh') diff --git a/lfldap-update.sh b/lfldap-update.sh new file mode 100644 index 0000000..50c067f --- /dev/null +++ b/lfldap-update.sh @@ -0,0 +1,57 @@ +#! /bin/sh + +PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin + +FILTER="(&(objectClass=lfNetwork))" +DBDIR="/var/db/lfldap" +PREFIX="/usr/local" +HOOKDIR="${PREFIX}/share/lfldap/hooks" +NETWORKS_FILE="${DBDIR}/networks" +NETWORKS_TEMP="${DBDIR}/networks.tmp" + +trap cleanup 0 +cleanup() +{ + rm -f "$NETWORKS_TEMP" +} + +mkdir -p "$DBDIR" +rm -f "$NETWORKS_TEMP" + +if [ ! -f "$NETWORKS_FILE" ]; then + touch "$NETWORKS_FILE" +fi + +ldapsearch \ + -x -s sub \ + "$FILTER" \ + cidrPrefix \ + | awk '/^cidrPrefix: / { print $2 }' >${NETWORKS_TEMP} + +if ! [ -s "$NETWORKS_TEMP" ]; then + printf >&2 '%s: no networks returned; configuration error?\n' "$0" + exit 1 +fi + +if ! cmp -s "$NETWORKS_FILE" "$NETWORKS_TEMP"; then + printf '%s updated:\n\n' "$NETWORKS_FILE" + diff "$NETWORKS_FILE" "$NETWORKS_TEMP" + printf '\n' + + mv "$NETWORKS_TEMP" "$NETWORKS_FILE" +else + rm -f "$NETWORKS_TEMP" +fi + +# Run hooks even if the networks didn't change, since the user might want +# new hooks to run. + +exit=0 + +export NETWORKS_FILE + +for hook in ${HOOKDIR}/*.sh; do + sh $hook || exit=1 +done + +exit $exit -- cgit v1.2.3