summaryrefslogtreecommitdiffstats
path: root/data/ad/mountscript
diff options
context:
space:
mode:
Diffstat (limited to 'data/ad/mountscript')
-rw-r--r--data/ad/mountscript49
1 files changed, 49 insertions, 0 deletions
diff --git a/data/ad/mountscript b/data/ad/mountscript
new file mode 100644
index 0000000..2256904
--- /dev/null
+++ b/data/ad/mountscript
@@ -0,0 +1,49 @@
+###################################################################
+#
+# This script is a part of the pam_script_ses_open script
+# and is not stand-alone!
+#
+
+if ! grep -q "^${PAM_USER}:" "/etc/passwd"; then
+
+ # determine fileserver and share for home directories
+ touch "/tmp/ldapsearch.${PAM_USER}"
+ chmod 0600 "/tmp/ldapsearch.${PAM_USER}"
+ ldapsearch -x -LLL uid="${PAM_USER}" homeMount > "/tmp/ldapsearch.${PAM_USER}" || \
+ { slxlog "pam-ad-ldapquery" "Could not query LDAP server for parameters of user '${PAM_USER}'."; exit 1; }
+ VOLUME=$(cat "/tmp/ldapsearch.${PAM_USER}" | grep ^homeMount | head -n 1 | cut -d" " -f2)
+ [ -z "${VOLUME}" ] && slxlog "pam-ad-ldapvolume" "LDAP server did not provide 'homeMount'. Aborting mount for ${PAM_USER}." && exit 1
+
+ MOUNT_OPTS="-t cifs -o uid=${USER_UID},gid=${USER_GID},forceuid,forcegid,sec=ntlm"
+
+ SIGNAL=$(mktemp)
+ rm -f -- "${SIGNAL}"
+
+ export USER="${PAM_USER}"
+ export PASSWD="${PAM_AUTHTOK}"
+
+ ( mount ${MOUNT_OPTS} "${VOLUME}" "${PERSISTENT_HOME_DIR}" > "/tmp/home.$PAM_USER" 2>&1 || touch "${SIGNAL}" ) &
+ MOUNT_PID=$!
+ for COUNTER in 1 2 4 4; do
+ kill -0 "${MOUNT_PID}" 2>/dev/null || break
+ sleep "${COUNTER}"
+ done
+
+ if [ -e "${SIGNAL}" ]; then
+ slxlog "pam-reutlingen" "Mount of '${FILESERVER}/${PAM_USER}' to '${PERSISTENT_HOME_DIR}' failed. (Args: ${MOUNT_OPTS})" "/tmp/home.$PAM_USER"
+ sleep 1
+ rm -f -- "${SIGNAL}"
+ elif kill -9 "${MOUNT_PID}" 2>/dev/null; then
+ slxlog "pam-reutlingen" "Mount of '${FILESERVER}/${PAM_USER}' to '${PERSISTENT_HOME_DIR}' timed out. (Args: ${MOUNT_OPTS})" "/tmp/home.$PAM_USER"
+ sleep 1
+ else
+ PERSISTENT_OK=yes
+ chmod -R u+rw "${PERSISTENT_HOME_DIR}" 2>/dev/null
+ fi
+
+ unset USER
+ unset PASSWD
+
+ rm -f -- "/tmp/home.$PAM_USER"
+fi
+