summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Gabriel <mike.gabriel@das-netzwerkteam.de>2020-02-10 13:27:15 +0100
committerMike Gabriel <mike.gabriel@das-netzwerkteam.de>2020-02-10 13:27:15 +0100
commit0c43f0d42ee5a13bd008801c2c66cf7cc67f2365 (patch)
tree4f37d4b46d1518155a930f71e7c9c579127193cf
parent2344e2d43ab5baad1ce7c0609f3db1f6c5215cb3 (diff)
downloaditzks-systems-0c43f0d42ee5a13bd008801c2c66cf7cc67f2365.tar.gz
itzks-systems-0c43f0d42ee5a13bd008801c2c66cf7cc67f2365.tar.bz2
itzks-systems-0c43f0d42ee5a13bd008801c2c66cf7cc67f2365.zip
etc/mklocaluser.d/60-itzks-systems-roamingworkstation_smb-bookmarks: Obtain SMB domain from user object and domain object in LDAP; various tests.
-rwxr-xr-xetc/mklocaluser.d/60-itzks-systems-roamingworkstation_smb-bookmarks61
1 files changed, 37 insertions, 24 deletions
diff --git a/etc/mklocaluser.d/60-itzks-systems-roamingworkstation_smb-bookmarks b/etc/mklocaluser.d/60-itzks-systems-roamingworkstation_smb-bookmarks
index d7b79f9..dc850e0 100755
--- a/etc/mklocaluser.d/60-itzks-systems-roamingworkstation_smb-bookmarks
+++ b/etc/mklocaluser.d/60-itzks-systems-roamingworkstation_smb-bookmarks
@@ -4,33 +4,46 @@ set -e
# Create GTK/Gnome places bookmark for easy access.
add_gtk3_place() {
- SERVER="$1"
- USER="$2"
- GROUP="$3"
- TITLE="$4"
- SMBPATH="$5"
- if [ ! grep -q "$SMBPATH $TITLE" "/home/$USER/.config/gtk-3.0/bookmarks" ]; then
- echo "$SMBPATH $TITLE" >> /home/$USER/.config/gtk-3.0/bookmarks
- chown $USER:$GROUP /home/$USER/.config/gtk-3.0/bookmarks
- fi
+ SERVER="$1"
+ USER="$2"
+ GROUP="$3"
+ TITLE="$4"
+ SMBPATH="$5"
+ if [ ! -e /home/$USER/.config/gtk-3.0/bookmarks ] || ! grep -q "$SMBPATH $TITLE" "/home/$USER/.config/gtk-3.0/bookmarks"; then
+ su - "$USER" -c "mkdir -p \"/home/$USER/.config/gtk-3.0\""
+ echo "$SMBPATH $TITLE" >> "/home/$USER/.config/gtk-3.0/bookmarks"
+ chown $USER:$GROUP "/home/$USER/.config/gtk-3.0/bookmarks"
+ fi
}
-# FIXME Would be nice if the same bookmark file could be used for both
-# KDE and Gnome
case "$ORIGHOMEDIR" in
- /*/*/*)
- homepath="$(ldapsearch -LLL -x '(&(uid=$USER)(sambaHomePath=*))' sambaHomePath | awk '/sambaHomePath: / { print $2 }')"
- if [ "$homepath" ] ; then
- SMBPATH=$(echo "smb:$homepath" | tr '\' /)
- SERVER="$(echo $SMBPATH | cut -d/ -f3)"
- else
- # Extract FQDN from home directory path
- SERVER="$(getent hosts $(echo $ORIGHOMEDIR | cut -d/ -f3) | awk '{print $2}')"
- SMBPATH="smb://$SERVER/$USER/"
- fi
+ /*/*/*)
+ homepath="$(ldapsearch -LLL -x "(&(uid=$USER)(sambaHomePath=*))" sambaHomePath | awk '/sambaHomePath: / { print $2 }')"
+ if [ "$homepath" ] ; then
+
+ sambaSID="$(ldapsearch -LLL -x "(&(uid=$USER)(sambaSID=*))" sambaSID | awk '/sambaSID: / { print $2 }')"
+ if [ "$sambaSID" ]; then
+ sambaDomainSID=$(echo $sambaSID | cut -d"-" -f1-7)
+ SMBDOMAIN="$(ldapsearch -LLL -x "(&(sambaDomainName=*)(sambaSID=$sambaSID))" sambaDomainName | awk '/sambaDomainName: / { print $2 }');"
+ fi
+
+ SMBPATH=$(echo "smb:$homepath" | sed -e "s|\\\\|//|" -e "s|\\\\|/|" | sed -e "s|smb://|smb://$SMBDOMAIN$USER@|")
+ SERVER="$(echo $SMBPATH | cut -d "@" -f2 | cut -d/ -f1)"
+
+ else
+ # Extract FQDN from home directory path
+ SERVER="$(getent hosts $(echo $ORIGHOMEDIR | cut -d/ -f3) | awk '{print $2}')"
+
+ # get the SMBDOMAIN fallback from smb.conf first, but try LDAP later on
+ if [ -e /etc/samba/smb.conf ] && grep -q -i "\s*workgroup\s*=\s*" /etc/samba/smb.conf; then
+ SMBDOMAIN="$(grep -i -E '\s*workgroup\s*=' /etc/samba/smb.conf | sed -re 's/\s*workgroup\s*=\s*(.*)\s*$/\1/' -e "s/\s+//g");"
+ fi
+
+ SMBPATH="smb://$SMBDOMAIN$USER@$SERVER/$USER"
+ fi
- GROUP="$(id -ng $USER)"
- TITLE="$USER on $SERVER via SMB"
- add_gtk3_place "$SERVER" "$USER" "$GROUP" "$TITLE" "$SMBPATH"
+ GROUP="$(id -ng $USER)"
+ TITLE="$USER on $SERVER via SMB"
+ add_gtk3_place "$SERVER" "$USER" "$GROUP" "$TITLE" "$SMBPATH"
;;
esac