4
echo "You must run this script as root. Do not use sudo; either log in"
5
echo "as root or use 'su -'"
7
echo "This script applies to Open Client systems only with the IBM-security-compliance RPM installed"
10
whoami | grep "^root$" &> /dev/null
12
echo "Please run this script as root"
18
echo " # ecryptfs-setup-pam-wrapped.sh [username] [mount passphrase] [wrapping passphrase]"
20
echo "Be sure to properly escape your parameters according to your shell's special character nuances, and also surround the parameters by double quotes, if need be."
22
echo "No special characters allowed in the username."
25
if test "x$1" == "x"; then
26
echo "Must provide a username"
31
if test "x$2" == "x"; then
32
echo "Must provide a mount passphrase"
37
if test "x$3" == "x"; then
38
echo "Must provide a wrapping passphrase"
43
echo "Using username [$1]"
44
echo "Using mount passphrase [$2]"
45
echo "Using wrapping passphrase [$3]"
47
echo "This script will attempt to set up your system to mount eCryptfs"
48
echo "automatically on login, using your login passphrase."
52
mkdir /home/$1/Confidential
53
chown $1:$1 /home/$1/Confidential
54
chmod 700 /home/$1/Confidential
55
grep -v "ecryptfs_sig" /etc/fstab > /tmp/fstab
56
mv -f /tmp/fstab /etc/fstab
57
umount /home/$1/Confidential
58
mount | grep "/home/$1/Confidential type ecryptfs"
60
echo "ERROR: /home/$1/Confidential still mounted after umount; cannot continue with setup"
63
mount -t ecryptfs /home/$1/Confidential /home/$1/Confidential -o key=passphrase:passwd="$2",cipher=aes,ecryptfs_key_bytes=16,passthrough=n,no_sig_cache
64
grep ecryptfs_sig /etc/mtab | sed 's/ecryptfs_cipher\=aes,ecryptfs_key_bytes\=16/ecryptfs_cipher\=aes,ecryptfs_key_bytes\=16,user,noauto,/' >> /etc/fstab
65
umount /home/$1/Confidential
66
cp -f /etc/pam.d/system-auth /etc/pam.d/.system-auth-before-pam_ecryptfs
67
grep -v "pam_ecryptfs" /etc/pam.d/system-auth > /tmp/system-auth
68
mv -f /tmp/system-auth /etc/pam.d/system-auth
69
grep -v "auth.*pam_deny" /etc/pam.d/system-auth > /tmp/system-auth
70
mv -f /tmp/system-auth /etc/pam.d/system-auth
71
cat /etc/pam.d/system-auth | sed 's/auth.*pam_unix\.so\(.*\)/auth required pam_unix.so\1\nauth required pam_ecryptfs.so unwrap/' > /tmp/system-auth
72
mv -f /tmp/system-auth /etc/pam.d/system-auth
73
cat /etc/pam.d/system-auth | sed 's/password\s*sufficient\s*pam_unix\.so\(.*\)/password required pam_ecryptfs.so\npassword sufficient pam_unix.so\1/' > /tmp/system-auth
74
mv -f /tmp/system-auth /etc/pam.d/system-auth
75
grep "Confidential type ecryptfs" /home/$1/.bash_profile
77
cp -f /home/$1/.bash_profile /home/$1/.bash_profile-before-pam_ecryptfs
78
echo "if test -e \$HOME/.ecryptfs/auto-mount; then" >> /home/$1/.bash_profile
79
echo " mount | grep \"\$HOME/Confidential type ecryptfs\"" >> /home/$1/.bash_profile
80
echo " if test \$? != 0; then" >> /home/$1/.bash_profile
81
echo " mount -i \$HOME/Confidential" >> /home/$1/.bash_profile
82
echo " fi" >> /home/$1/.bash_profile
83
echo "fi" >> /home/$1/.bash_profile
84
echo "ecryptfs-zombie-kill" >> /home/$1/.bash_profile
86
mkdir -p /home/$1/.ecryptfs
87
chown $1:$1 /home/$1/.ecryptfs
88
touch /home/$1/.ecryptfs/auto-mount
89
chown $1:$1 /home/$1/.ecryptfs/auto-mount
90
rm -f /home/$1/.ecryptfs/wrapped-passphrase
91
/usr/bin/ecryptfs-wrap-passphrase /home/$1/.ecryptfs/wrapped-passphrase "$2" "$3"
92
chown $1:$1 /home/$1/.ecryptfs/wrapped-passphrase