~mrooney/ecryptfs/nautilus-integration

« back to all changes in this revision

Viewing changes to src/utils/ecryptfs-setup-pam-wrapped.sh

  • Committer: mhalcrow@us.ibm.com
  • Date: 2007-11-06 22:56:01 UTC
  • Revision ID: git-v1:f8357de9d554b274497b5cce9db4347254b7e7eb
Initial import of eCryptfs filesystem userspace utilities (mount helper, daemon component,
etc.)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/bin/sh
 
2
 
 
3
echo
 
4
echo "You must run this script as root. Do not use sudo; either log in"
 
5
echo "as root or use 'su -'"
 
6
echo
 
7
echo "This script applies to Open Client systems only with the IBM-security-compliance RPM installed"
 
8
echo
 
9
 
 
10
whoami | grep "^root$" &> /dev/null
 
11
if test $? == 1; then
 
12
  echo "Please run this script as root"
 
13
  echo
 
14
  exit
 
15
fi
 
16
 
 
17
echo "USAGE:"
 
18
echo " # ecryptfs-setup-pam-wrapped.sh [username] [mount passphrase] [wrapping passphrase]"
 
19
echo
 
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."
 
21
echo
 
22
echo "No special characters allowed in the username."
 
23
echo
 
24
 
 
25
if test "x$1" == "x"; then
 
26
    echo "Must provide a username"
 
27
    echo
 
28
    exit
 
29
fi
 
30
 
 
31
if test "x$2" == "x"; then
 
32
    echo "Must provide a mount passphrase"
 
33
    echo
 
34
    exit
 
35
fi
 
36
 
 
37
if test "x$3" == "x"; then
 
38
    echo "Must provide a wrapping passphrase"
 
39
    echo
 
40
    exit
 
41
fi
 
42
 
 
43
echo "Using username [$1]"
 
44
echo "Using mount passphrase [$2]"
 
45
echo "Using wrapping passphrase [$3]"
 
46
echo
 
47
echo "This script will attempt to set up your system to mount eCryptfs"
 
48
echo "automatically on login, using your login passphrase."
 
49
echo
 
50
 
 
51
modprobe ecryptfs
 
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"
 
59
if test $? == 0; then
 
60
 echo "ERROR: /home/$1/Confidential still mounted after umount; cannot continue with setup"
 
61
 exit 1
 
62
fi
 
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
 
76
if test $? != 0; then
 
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
 
85
fi
 
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