Skip to content

Instantly share code, notes, and snippets.

@usrme
Last active October 21, 2016 08:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save usrme/42cceb47d317e22a6db339b9dab976f3 to your computer and use it in GitHub Desktop.
Save usrme/42cceb47d317e22a6db339b9dab976f3 to your computer and use it in GitHub Desktop.
Non-PCRE-compliant one-liner/script for forming an LDAP UID search filter, supporting UID prefixes such as "p-" and "v-"
#!/usr/bin/env bash
# Üllar Seerme
#
# The input file should consist of LDAP UIDs on every line in the
# form of firstname.lastname. This input produces an output like:
# "(|(uid=first.last)(uid=first.last))" to STDOUT
#
# The pipe in the beginning denotes a boolean OR-operator, which
# specifies that at least one specified filter must be true. This
# kind of output is useful for constructing an LDAP search query
# where you need to check multiple UIDs. This one-liner can be
# adapted for other types of queries, and I will update this when
# their necessity will become apparent to me
#
# https://docs.oracle.com/cd/E19528-01/819-0997/gdxpo/index.html
paste -d "" -s <(sed 's/\([[:alpha:]]\{1\}-\w*\|\w*\)\.\(\w*\)/(uid=\1.\2)/g; 1 s/^/"(|/; $ s/$/)"/' $1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment