~ubuntu-branches/ubuntu/vivid/cctools/vivid

« back to all changes in this revision

Viewing changes to parrot/src/parrot_identity_box

  • Committer: Bazaar Package Importer
  • Author(s): Michael Hanke
  • Date: 2011-05-07 09:05:00 UTC
  • Revision ID: james.westby@ubuntu.com-20110507090500-lqpmdtwndor6e7os
Tags: upstream-3.3.2
ImportĀ upstreamĀ versionĀ 3.3.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/bin/sh
 
2
 
 
3
vid="$1"
 
4
shift
 
5
command="$@"
 
6
parrot=`which parrot_run`
 
7
 
 
8
if [ "X$vid" = X ]
 
9
then
 
10
        echo "Use: $0 <identity> [command]";
 
11
        exit 1
 
12
fi
 
13
 
 
14
# Clean up the VID so that it can be used in the passwd file.
 
15
cleanvid=`echo -n "$vid" | tr : _`
 
16
 
 
17
# Get the current user's real uid and gid
 
18
uid=`id -u`
 
19
gid=`id -g`
 
20
 
 
21
# Create a private home directory for this process.
 
22
mkdir -p /tmp/home.${uid}/$cleanvid
 
23
HOME=/tmp/home.${uid}/$cleanvid
 
24
 
 
25
# Create a private passwd file listing only this user.
 
26
cat > $HOME/.passwd << EOF
 
27
$cleanvid:x:$uid:$gid:Unknown:$HOME:$SHELL
 
28
EOF
 
29
cat /etc/passwd >> $HOME/.passwd
 
30
 
 
31
cat > $HOME/.group <<EOF
 
32
none:x:$gid:$cleanvid
 
33
EOF
 
34
cat /etc/group >> $HOME/.group
 
35
 
 
36
# Create a private ACL so that this user can read and write here.
 
37
cat > $HOME/.__acl << EOF
 
38
$vid rwlax
 
39
EOF
 
40
 
 
41
# If no command was given, run the user's shell in the home dir
 
42
if [ "X$command" = X ]
 
43
then
 
44
        command=$SHELL
 
45
        cd $HOME
 
46
fi
 
47
 
 
48
# Finally, fork off parrot with a private environment and password file.
 
49
exec /usr/bin/env -i HOME=${HOME} SHELL=${SHELL} LANG=${LANG} TERM=${TERM} ${parrot} -H -M/etc/passwd=${HOME}/.passwd -M/etc/group=${HOME}/.group -u $vid -- $command