#!/bin/bash if [ -e /etc/ldap-utils.conf ]; then . /etc/ldap-utils.conf else exit 1 fi user_exists() { res=$($PEOPLESEARCHCMD "(&(uid=$1)(objectClass=inetOrgPerson))" | grep uid: | cut -f2 -d' ') [ -n "$res" ] } group_exists() { res=$($GROUPSEARCHCMD "(cn=$1)" | grep cn: | cut -f2 -d' ') [ -n "$res" ] } mail_exists() { res=$($PEOPLESEARCHCMD "(|(mail=$1)(mailAlias=$1))") [ -n "$res" ] } user_is_posix() { res=$($PEOPLESEARCHCMD "(&(uid=$1)(objectClass=posixAccount))" | grep uid: | cut -f2 -d' ') [ -n "$res" ] } user_is_postfix() { res=$($PEOPLESEARCHCMD "(&(uid=$1)(objectClass=PostfixBookMailAccount))" | grep uid: | cut -f2 -d' ') [ -n "$res" ] } group_is_posix() { res=$($GROUPSEARCHCMD "(&(cn=$1)(objectClass=posixGroup))" | grep cn: | cut -f2 -d' ') [ -n "$res" ] } get_posixGroups() { $GROUPSEARCHCMD "(&(memberUid=$1)(objectClass=posixGroup))" | grep cn: | cut -f2 -d' ' } # get the list of currently used uid numbers and add 1 to get the next one # uids between 2000 and 2999 are used for users. If the need to manage # more than 1000 users arises, consider using something else than a few bash scripts # to manage your directory. get_posix_number() { echo $(( $($PEOPLESEARCHCMD "(objectClass=posixAccount)" | grep 'uidNumber: 2' | cut -d' ' -f2 | sort -u | tail -n 1) +1)) } vf() { ldapvi --discover -Z -w $BINDPW -h localhost -D $BINDDN "($1)" } vu() { vf "uid=$1" } vg() { vf "cn=$1" }