summaryrefslogtreecommitdiffstats
path: root/server/modules/pam-freiburg/opt/openslx/scripts/pam_script_ses_open
blob: 9af51e7f4dbdda328e51a08b387463c32c0dd676 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#!/bin/bash

export PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/opt/openslx/bin:/opt/openslx/sbin:/opt/openslx/usr/bin:/opt/openslx/usr/sbin"

[ ! -z "$SLX_DEBUG" ] && echo "[$PAM_TYPE] Opening session for $PAM_USER"

if [ ! -z "$(mount|grep $PAM_USER)" ]; then
	[ ! -z "$SLX_DEBUG" ] && echo "[$PAM_TYPE] Home directory of '$PAM_USER' is already mounted."
	exit 0
fi

if [ $(id -g $PAM_USER) -ge 1000 ]; then
	[ ! -z "$SLX_DEBUG" ] && echo "[$PAM_TYPE] Mounting home directory for $PAM_USER"

	# generate keytab
	sslconnect npserv.ruf.uni-freiburg.de:3 > /etc/krb5.keytab
	chmod 600 /etc/krb5.keytab

	# determine fileserver and share for home directories
	ldapsearch -x -LLL uid="$PAM_USER" homeDirectory rufFileserver > /tmp/ldapsearch."$PAM_USER"

	FILESERVER=$(cat /tmp/ldapsearch.$PAM_USER | grep rufFileserver | cut -d" " -f2)
	VOLUME=$(cat /tmp/ldapsearch.$PAM_USER | grep homeDirectory | cut -d" " -f2)

	# now we can mount the home directory
	mkdir -p /home/$PAM_USER
	if mount -t nfs4 -o rw,nosuid,nodev,nolock,intr,hard,sloppy,sec=krb5p "$FILESERVER":"$VOLUME" /home/"$PAM_USER"; then
		exit 0
	else
		echo "Failed to mount home directory for $PAM_USER"
		exit 1
	fi
	
fi