summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJonathan Bauer2014-10-07 16:22:18 +0200
committerJonathan Bauer2014-10-07 16:22:18 +0200
commit9c388786c9071e7fc2f37d146bdde558a2a7499a (patch)
treee0d338aa97c62331ef533324950589b37100030a
parent[pam] support for common share mounting script in pam_script_auth (diff)
downloadtm-scripts-9c388786c9071e7fc2f37d146bdde558a2a7499a.tar.gz
tm-scripts-9c388786c9071e7fc2f37d146bdde558a2a7499a.tar.xz
tm-scripts-9c388786c9071e7fc2f37d146bdde558a2a7499a.zip
[pam-common-share] dummy module with pam-script file to mount a common share
-rw-r--r--remote/modules/pam-common-share/data/opt/openslx/scripts/pam_script_mount_common_share82
-rw-r--r--remote/modules/pam-common-share/module.build11
-rw-r--r--remote/modules/pam-common-share/module.conf3
3 files changed, 96 insertions, 0 deletions
diff --git a/remote/modules/pam-common-share/data/opt/openslx/scripts/pam_script_mount_common_share b/remote/modules/pam-common-share/data/opt/openslx/scripts/pam_script_mount_common_share
new file mode 100644
index 00000000..e11a3681
--- /dev/null
+++ b/remote/modules/pam-common-share/data/opt/openslx/scripts/pam_script_mount_common_share
@@ -0,0 +1,82 @@
+###################################################################
+#
+# This script is a part of the pam_script_auth script
+# and is not stand-alone!
+#
+# It will try to mount the common share as specified in the
+# variables SLX_COMMON_SHARE_PATH and SLX_COMMON_SHARE_AUTH of
+# the global slx config '/opt/openslx/config'. Supported AUTH
+# are 'guest' and 'user'. First is self-explanatory, second
+# will use the user's credentials to authorize the mount.
+#
+# Example:
+# SLX_COMMON_SHARE_PATH='//windows.server/sharename'
+# SLX_COMMON_SHARE_AUTH='user'
+#
+#
+
+mount_common_share {
+ # at this point we need the slx config to do anything
+ [ -e "/opt/openslx/config" ] || \
+ { slxlog "pam-share-noconfig" "File '/opt/openslx/config' not found."; return; }
+
+ # we have it as we should, source it
+ . /opt/openslx/config || \
+ { slxlog "pam-share-sourceconfig" "Could not source '/opt/openslx/config'."; return; }
+
+ # lets check if we have our variables
+ [ "x${SLX_COMMON_SHARE_PATH}" != "x" ] || \
+ { slxlog "pam-share-noconfig" "No variable 'SLX_COMMON_SHARE_PATH' found in config!"; return; }
+ [ "x${SLX_COMMON_SHARE_AUTH}" != "x" ] || \
+ { slxlog "pam-share-noconfig" "No variable 'SLX_COMMON_SHARE_AUTH' found in config!"; return; }
+
+ # all good: now we can mount depending on the type
+ # supports: cifs?/nfs?
+ if [ "${SLX_COMMON_SHARE_PATH:0:2}" = "//" ]; then
+ # '//' prefixed, assume windows share
+ # prepare common mount options for either authentication type
+ MOUNT_OPTS="-t cifs"
+
+ # flag for failure
+ SIGNAL=$(mktemp)
+ rm -f -- "${SIGNAL}"
+ # output of command
+ MOUNT_OUTPUT=$(mktemp)
+ # now see if the share needs credentials
+ if [ "${SLX_COMMON_SHARE_AUTH}" = "guest" ]; then
+ MOUNT_OPTS="${MOUNT_OPTS} -o guest"
+ elif [ "${SLX_COMMON_SHARE_AUTH}" = "user" ]; then
+ export USER="{PAM_USER}"
+ export PASSWD="{PAM_AUTHTOK}"
+ MOUNT_OPTS="${MOUNT_OPTS} -o uid=${USER_GID},gid=${USER_GID},forceuid,forcegid,nobrl,noacl"
+ else
+ slxlog "pam-share-auth" "Auth type '${SLX_COMMON_SHARE_AUTH}' not supported."
+ return;
+ fi
+
+ # now try to mount it
+ ( mount ${MOUNT_OPTS} "${SLX_COMMON_SHARE_PATH}" "${COMMON_SHARE_MOUNT_POINT}" > "${MOUNT_OUTPUT}" 2>&1 || touch "${SIGNAL}" ) &
+ MOUNT_PID=$!
+ for COUNTER in 1 1 2 4; do
+ kill -0 "${MOUNT_PID}" 2>/dev/null || break
+ sleep "${COUNTER}"
+ done
+
+ # check for failures
+ if [ -e "${SIGNAL}" ]; then
+ slxlog "pam-share-mount" "Mount of '${SLX_COMMON_SHARE_PATH}' to '${COMMON_SHARE_MOUNT_POINT}' failed. (Args: ${MOUNT_OPTS}" "${MOUNT_OUTPUT}"
+ rm -f -- "${SIGNAL}"
+ elif kill -9 "${MOUNT_PID}" 2>/dev/null; then
+ slxlog "pam-share-mount" "Mount of '${SLX_COMMON_SHARE_PATH}' to '${COMMON_SHARE_MOUNT_POINT}' timed out. (Args: ${MOUNT_OPTS}" "${MOUNT_OUTPUT}"
+ fi
+ ( sleep 2; rm -f -- "${MOUNT_OUTPUT}" ) &
+
+ # always unset credentials
+ unset USER
+ unset PASSWD
+ fi
+
+ # TODO support more than CIFS? NFS maybe?
+}
+
+mount_common_share
diff --git a/remote/modules/pam-common-share/module.build b/remote/modules/pam-common-share/module.build
new file mode 100644
index 00000000..62d96224
--- /dev/null
+++ b/remote/modules/pam-common-share/module.build
@@ -0,0 +1,11 @@
+fetch_source() {
+ :
+}
+
+build() {
+ pinfo "Static module, nothing to build."
+}
+
+post_copy() {
+ :
+}
diff --git a/remote/modules/pam-common-share/module.conf b/remote/modules/pam-common-share/module.conf
new file mode 100644
index 00000000..0cd03752
--- /dev/null
+++ b/remote/modules/pam-common-share/module.conf
@@ -0,0 +1,3 @@
+REQUIRED_BINARIES=""
+REQUIRED_LIBRARIES=""
+REQUIRED_DIRECTORIES=""