免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1782 | 回复: 0
打印 上一主题 下一主题

[ldap] Useful script to extract LDAP based user posixGroup membersh [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2005-09-08 16:01 |只看该作者 |倒序浏览
Assuming you are using posixGroup objectclass and memberUid attribute to store your membership information, you may find my shell script useful and handy.

It works on Solaris LDAP Client with "ldapaddent" and "ldaplist" commands, and works against Fedora/RedHat DS, SUN ONE DS or OpenLDAP.

#! /bin/sh
#
# get_ldap_memberUids.sh
#
# Gary Tay, 08-Sep-2005, written
#
if [ $# -le 0 ]
then
echo ""
echo "Usage:"
echo "$0 [SHOW_UID_ONLY||SHOW_DN|SHOW_UIDNUMBER|SHOW__NAME"
echo ""
echo "urpose: get a list of memberships for LDAP posixGroups"
echo "Examples: "
echo "1) $0 SHOW_UID_ONLY"
echo "2) $0 SHOW_DN"
echo "3) $0 SHOW_UIDNUMBER"
echo "4) $0 SHOW_NAME"
echo ""
exit
fi
OPTION=$1
ldapaddent -d group | cut -d: -f1,3 >;groups.txt
for i in `cat groups.txt | cut -d: -f2 | sort -n`
do
GIDN=$i; GNAME=`grep $GIDN groups.txt | cut -d: -f1`
echo memberUids for Group $GNAME, gidNumber=$GIDN
ldapaddent -d passwd | sort -n -t: +3 -4 | cut -d: -f1,3,4 >;users.txt
cat users.txt | grep $GIDN | cut -d: -f1 >;uids.txt
case "$OPTION" in
"SHOW_UID_ONLY" cat uids.txt;;
"SHOW_DN" for j in `cat uids.txt`
do
ldaplist passwd $j
done;;
"SHOW_UIDNUMBER" for j in `cat uids.txt`
do
UIDN=`ldaplist -l passwd $j | grep -i 'uidNumber:' | cut -d: -f2`
echo $j,$UIDN
done;;
"SHOW_NAME" for j in `cat uids.txt`
do
NAME=`ldaplist -l passwd $j | grep -i 'cn:' | cut -d: -f2`
echo $j,$NAME
done;;
*) echo "$1 is an invalid option."; exit 1
esac
echo ""
done

Hope this helps.

Gary
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP