2 # idmap script to map SIDs to UIDs/GIDs using NIS
3 # tridge@samba.org June 2009
10 ) >> /var
/log
/samba
/idmap.log
15 PATH
=/usr
/bin
:bin
:$PATH
17 shopt -s nocasematch ||
{
18 echo "shell option nocasematch not supported"
22 # map from a domain and name to a uid/gid
37 echo "ERR: bad name type $ntype"
41 id
=$
(ypmatch
"$name" "$map".byname
2>/dev
/null | cut
-d: -f3)
43 echo "ERR: bad match for $name in map $map"
49 # map from a unix id to a name
61 echo "ERR: bad name type $ntype"
65 name
="$(ypmatch "$id" "$map" 2>/dev/null | cut -d: -f1)"
67 echo "ERR: bad match for $name in map $map"
77 rid
=`echo $sid | cut -d- -f8`
79 echo "ERR: bad rid in SID $sid"
84 # oh, this is ugly. Shell is just not meant for parsing text
85 fullname
=`wbinfo -s $sid 2> /dev/null`
86 domain
=`echo $fullname | cut -d'\' -f1`
87 [[ "$domain" = $DOMAIN ]] ||
{
88 echo "ERR: bad domain $domain"
91 name
=`echo $fullname | cut -d'\' -f2`
92 nwords
=`echo $name | wc -w`
93 ntype
=`echo $name | cut -d' ' -f$nwords`
94 nminusone
=`expr $nwords - 1`
95 name
=`echo $name | cut -d' ' -f-$nminusone`
97 echo "ERR: bad name $fullname for SID $sid"
100 map_name
"$domain" "$name" "$ntype"
105 name
="$(map_id "$ntype" "$id")"
106 sid
="$(wbinfo -n "$name" 2>/dev/null | cut -d' ' -f1)"
108 echo "ERR: name $name not found in ADS"
114 echo "ERR: Unknown command $cmd"