37 lines
953 B
Bash
37 lines
953 B
Bash
#/usr/bin/env bash
|
|
|
|
# You no longer need Windows for aquiring DCs GUID
|
|
IFS='
|
|
'
|
|
|
|
convertToHex() {
|
|
# Inspired by https://docs.microsoft.com/en-us/troubleshoot/windows-server/admin-development/convert-string-guid-to-hexadecimal-string
|
|
RAW="$1"
|
|
GUID=$(echo "$RAW" | sed 's/\-//g')
|
|
|
|
HEX="${GUID:6:2}"
|
|
HEX="${HEX}${GUID:4:2}"
|
|
HEX="${HEX}${GUID:2:2}"
|
|
HEX="${HEX}${GUID:0:2}"
|
|
HEX="${HEX}${GUID:10:2}"
|
|
HEX="${HEX}${GUID:8:2}"
|
|
HEX="${HEX}${GUID:14:2}"
|
|
HEX="${HEX}${GUID:12:2}"
|
|
len=${#HEX}
|
|
HEX="${HEX}${GUID:16:${len}}"
|
|
|
|
echo "$HEX"
|
|
}
|
|
|
|
|
|
# apt install ldb-tools
|
|
realm=$(grep -i realm /etc/samba/smb.conf | awk '{print $3}' | tr '[:upper:]' '[:lower:]')
|
|
dc=$(echo $realm | awk -F '.' '{for(i = 1; i <= NF; i++) {printf ",DC=" $i}}')
|
|
base="OU=Domain Controllers${dc}"
|
|
cn=$1
|
|
GUID=$(ldbsearch -H /var/lib/samba/private/sam.ldb --basedn="$base" "CN=${cn}" objectGUID \
|
|
| grep '^objectGUID:' \
|
|
| awk '{print $2}' \
|
|
)
|
|
convertToHex "$GUID"
|