/usr/sbin/ldapgid is in ldapscripts 2.0.6-1ubuntu1.
This file is owned by root:root, with mode 0o755.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 | #!/bin/sh
# ldapgid : displays a group's list of IDs
# Copyright (C) 2009-2015 Ganaƫl LAPLANCHE
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
# USA.
if [ -z "$1" ] || [ "$1" = "-h" ] || [ "$1" = "--help" ]
then
echo "Usage : $0 [-P] <groupname | gid>"
exit 1
fi
# Source runtime file
_RUNTIMEFILE="/usr/share/ldapscripts/runtime"
. "$_RUNTIMEFILE"
# Parse options
case "$1" in
"-P")
# Passwd-like display requested
[ -z "$2" ] && end_die 'Please specify a GID or a group name'
_GROUP="$2"
;;
*)
# Standard display requested
_GROUP="$1"
;;
esac
# Check groupname
_findentry "$GSUFFIX,$SUFFIX" "(&(objectClass=$GCLASS)(|(cn=$_GROUP)(gidNumber=$_GROUP)))"
[ -z "$_ENTRY" ] && end_die "Group $_GROUP not found in LDAP"
# Get each (common) attribute
# gidNumber
_getattribute "$_ENTRY" "gidNumber"
[ -z "$_ATTRIBUTE" ] && end_die "Error getting group attribute from LDAP (gidNumber)"
_GIDNUMBER="$_ATTRIBUTE"
# cn
_getattribute "$_ENTRY" "cn"
[ -z "$_ATTRIBUTE" ] && end_die "Error getting group attribute from LDAP (cn)"
_CN="$_ATTRIBUTE"
case "$1" in
"-P")
# Passwd-like display requested
_OUTPUT="$_CN:*:$_GIDNUMBER:"
# User list (memberUids, posixGroup)
_SECONDARYUIDS=$(_ldapsearch "$_ENTRY" "" memberUid | grep "memberUid: " | sed "s|memberUid: ||")
_FIRSTPASS=""
for _SECONDARYUID in $_SECONDARYUIDS
do
if [ -z "$_FIRSTPASS" ]
then
_OUTPUT="$_OUTPUT$_SECONDARYUID"
_FIRSTPASS="done"
else
_OUTPUT="$_OUTPUT,$_SECONDARYUID"
fi
done
# User list (member DNs, groupOfNames/groupOfUniqueNames)
if [ "$GCLASS" != "posixGroup" ]
then
_SECONDARYDNS=$(_ldapsearch "$_ENTRY" "" $_GMEMBERATTR | grep "$_GMEMBERATTR: " | sed "s|$_GMEMBERATTR: ||")
_FIRSTPASS=""
for _SECONDARYDN in $_SECONDARYDNS
do
# Skip dummy member
[ "$_SECONDARYDN" = "$GDUMMYMEMBER" ] && continue
# Try to find entry
_getattribute "$_SECONDARYDN" "uid"
[ -z "$_ATTRIBUTE" ] && end_die "Could not find member $_SECONDARYDN in LDAP"
# Keep RDN (uid) only
_SECONDARYDN="$_ATTRIBUTE"
if [ -z "$_FIRSTPASS" ]
then
_OUTPUT="$_OUTPUT$_SECONDARYDN"
_FIRSTPASS="done"
else
_OUTPUT="$_OUTPUT,$_SECONDARYDN"
fi
done
fi
;;
*)
# Standard display requested
_OUTPUT="gid=$_GIDNUMBER($_CN)"
# User list (primary group)
_PRIMARYUIDS=$(_ldapsearch "$USUFFIX,$SUFFIX" "(&(objectClass=posixAccount)(gidNumber=$_GIDNUMBER))" uidNumber | grep "uidNumber: " | sed "s|uidNumber: ||")
_FIRSTPASS=""
for _PRIMARYUID in $_PRIMARYUIDS
do
_UID=$(_uidtouser "$_PRIMARYUID")
[ -z "$_UID" ] && end_die "Cannot resolve uid $_PRIMARYUID to user : not found"
if [ -z "$_FIRSTPASS" ]
then
_OUTPUT="$_OUTPUT users(primary)=$_PRIMARYUID($_UID)"
_FIRSTPASS="done"
else
_OUTPUT="$_OUTPUT,$_PRIMARYUID($_UID)"
fi
done
# User list (memberUids, posixGroup)
_SECONDARYUIDS=$(_ldapsearch "$_ENTRY" "" memberUid | grep "memberUid: " | sed "s|memberUid: ||")
_FIRSTPASS=""
for _SECONDARYUID in $_SECONDARYUIDS
do
_UID=$(_usertouid "$_SECONDARYUID")
[ -z "$_UID" ] && end_die "Cannot resolve user $_SECONDARYUID to uid : not found"
if [ -z "$_FIRSTPASS" ]
then
_OUTPUT="$_OUTPUT users(secondary)=$_UID($_SECONDARYUID)"
_FIRSTPASS="done"
else
_OUTPUT="$_OUTPUT,$_UID($_SECONDARYUID)"
fi
done
# User list (member DNs, groupOfNames/groupOfUniqueNames)
if [ "$GCLASS" != "posixGroup" ]
then
_SECONDARYDNS=$(_ldapsearch "$_ENTRY" "" $_GMEMBERATTR | grep "$_GMEMBERATTR: " | sed "s|$_GMEMBERATTR: ||")
_FIRSTPASS=""
for _SECONDARYDN in $_SECONDARYDNS
do
# Skip dummy member
[ "$_SECONDARYDN" = "$GDUMMYMEMBER" ] && continue
# Try to find entry and get uidNumber
_getattribute "$_SECONDARYDN" "uidNumber"
[ -z "$_ATTRIBUTE" ] && end_die "Could not find member $_SECONDARYDN in LDAP"
_UID="$_ATTRIBUTE"
# Get uid
_getattribute "$_SECONDARYDN" "uid"
[ -z "$_ATTRIBUTE" ] && end_die "Could not find member $_SECONDARYDN in LDAP"
# Keep RDN (uid) only
_SECONDARYDN="$_ATTRIBUTE"
if [ -z "$_FIRSTPASS" ]
then
_OUTPUT="$_OUTPUT users(members)=$_UID($_SECONDARYDN)"
_FIRSTPASS="done"
else
_OUTPUT="$_OUTPUT,$_UID($_SECONDARYDN)"
fi
done
fi
;;
esac
# Display result
echo $_OUTPUT && end_ok
|