Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions contrib/extract-ldapsearch-command.sh
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what is ./contrib/?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a directory with some random bonus scripts that are useful. It's pretty common in FOSS projects; often plugins and other related things not part of the main codebase make it in there, too.

Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#!/bin/sh
#
# A small script to convert famedly-sync configuration into its
# equivalent `ldapsearch` command; this can help find out what
# `famedly-sync` sees in practice when performing a sync.
#
# Usage:
#
# ./extract-ldapsearch-command.sh CONFIG

config="$1"

if ! [ -e "$config" ]; then
echo "Please give the famedly-sync configuration file as the first argument"
exit 1
fi

grep_from_yaml() {
grep "$1" "$config" | cut -f 2 -d ':' | tr -d '" '
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sadly the simple approach doesn't work very well in practice; various attributes used in DNs and filters often contain spaces and :. tr-ing and cut-ing all of them breaks.

We'd need to do a more thorough yaml parse to not run into this, sadly non-greedy matches are hard to do with just POSIX utilities.

}

base_dn="$(grep_from_yaml base_dn)"
bind_dn="$(grep_from_yaml bind_dn)"
user_filter="$(grep_from_yaml user_filter)"
start_tls=""
if [ "$(grep_from_yaml danger_use_start_tls)" = "true" ]; then
start_tls="-Z "
fi
if [ "$(grep_from_yaml use_attribute_filter)" = "true" ]; then
echo "This command will not include the attribute filter"
echo "To reproduce the search exactly, add every attribute name space-separated to the end of the command"
echo
fi

echo "Please read the password from the config file yourself :)"
echo "ldapsearch $start_tls-W -b '$base_dn' -D '$bind_dn' '$user_filter'"
Loading