Skip to content

Instantly share code, notes, and snippets.

@ChatchaiJ
Created December 25, 2017 08:39
Show Gist options
  • Select an option

  • Save ChatchaiJ/518236e231bdf155876593441a85c8d1 to your computer and use it in GitHub Desktop.

Select an option

Save ChatchaiJ/518236e231bdf155876593441a85c8d1 to your computer and use it in GitHub Desktop.
#!/bin/sh
[ `id -u` != 0 ] && echo "Need root privileges" && exit
DOMAIN="DOMAIN"
DOMAINSID=`sudo net getdomainsid | grep $DOMAIN | awk '{ print $6 }'`
GID="513"
SID="${DOMAINSID}-${GID}"
SMB_TDB="smb.conf-tdb-backend"
SMB_AD="smb.conf-ad-backend"
TDBDUMP="/usr/bin/tdbdump"
TDBTOOL="/usr/bin/tdbtool"
GENCACHETDB="/var/cache/samba/gencache.tdb"
systemctl stop winbind
rm -f /var/{cache,lib}/samba/*.tdb
cd /etc/samba
cp $SMB_TDB smb.conf
systemctl start winbind
getent passwd > /tmp/getent-passwd-`date +%s`
systemctl stop winbind
cd /var/cache/samba
KEY=` $TDBDUMP $GENCACHETDB |\
tr '\n' ' ' |\
sed 's/} /}\n/g' |\
grep $SID |\
grep GID2SID |\
cut -f2 -d\" `
TIME=` $TDBDUMP $GENCACHETDB |\
tr '\n' ' ' |\
sed 's/} /}\n\g' |\
grep $SID |\
grep GID2SID |\
cut -f4 -d\" |\
cut -f1 -d/ |\
awk '{ print $1 }' `
$TDBTOOL $GENCACHETDB delete "$KEY"
$TDBTOOL $GENCACHETDB store "IDMAP/$SID\0" " ${TIME}/${GID}:G\0"
$TDBTOOL $GENCACHETDB store "IDMAP/GID2SID/${GID}\0" " ${TIME}/$SID\0"
cd /etc/samba
cp $SMB_AD smb.conf
systemctl start winbind
ls -l /home/$DOMAIN/ > /dev/null
getent passwd > /tmp/getent-passwd-`date +%s`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment