WIP working group managemnt using echo to pipe LDIF directly to ldap commands

This commit is contained in:
2020-04-22 21:09:40 +00:00
parent cd0e5b39a2
commit d708ba8ab3
2 changed files with 77 additions and 0 deletions

70
seqs/ldap.sh Executable file
View File

@@ -0,0 +1,70 @@
#!/bin/bash
toolName=ldap
# Get script working directory
# (when called from a different directory)
WDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >>/dev/null 2>&1 && pwd )"
CONFIG=0
CONFIG_FILE_NAME="${toolName}.cfg"
CONFIG_FILE_TEMPLATE="$WDIR/${CONFIG_FILE_NAME}.example"
step_config() {
initSeqConfig "$CONFIG_FILE_NAME" "$CONFIG_FILE_TEMPLATE"
if [ $? -eq 0 ] ; then
CONFIG=1
fi
}
step_100_info() { echo "Add group <GROUP NAME> <MEMBER DN>"; }
step_100_alias() { ALIAS="addgroup"; }
step_100() {
local groupName=g2
local memberDn="uid=ldaptest,${LDAP_OU_USERS},${LDAP_DC}"
variable2Ldif add "$addGroup"
}
addGroup="dn: cn=\${groupName},\${LDAP_OU_GROUPS},\${LDAP_DC}
objectClass: groupofnames
cn: \${groupName}
description: Created by $0
member: \${memberDn}
"
step_110_info() { echo "Remove group <GROUP NAME>"; }
step_110_alias() { ALIAS="rmgroup"; }
step_110() {
local groupName=g2
variable2Ldif modify "$rmGroup"
}
rmGroup="dn: cn=\${groupName},\${LDAP_OU_GROUPS},\${LDAP_DC}
changetype: delete
"
step_104_info() { echo "List available groups"; }
step_104_alias() { ALIAS="listgroups"; }
step_104() {
echo " [I] Available groups:"
ldapsearch -x -LLL -H ldap:/// -b ${LDAP_OU_GROUPS},${LDAP_DC} dn gidNumber $2
}
step_106_info() { echo "List available users"; }
step_106_alias() { ALIAS="listusers"; }
step_106() {
echo " [I] Available user:"
ldapsearch -x -LLL -H ldap:/// -b ${LDAP_OU_USERS},${LDAP_DC} dn uidNumber gidNumber $2
}
variable2Ldif() {
local cmd="ldapmodify"
local tempLdif=`eval "echo \"$2\""`
case $1 in
add)
cmd="ldapadd"
;;
esac
exep "echo \"$tempLdif\" | $cmd -x -D cn=admin,${LDAP_DC} -W"
}
VERSION_SEQREV=10
. /usr/local/bin/sequencer.sh