-
Notifications
You must be signed in to change notification settings - Fork 1
/
permit
executable file
·51 lines (35 loc) · 1.38 KB
/
permit
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#!/bin/bash
# The directory in which the home directories are
# assumed to be
location='/home'
if [[ $(id -u) -ne 0 ]]; then
echo "Please run as root"
exit 0
fi
# Base permissions for existing directories - execute bit
# is needed to search/list directories.
# Write bit is needed to be able to create subdirectories.
IFS=$'\n' chmod 711 $(find "$location" -type d)
# Base permissions for existing files - only users can access
# their own files, and nothing else.
IFS=$'\n' chmod 700 $(find "$location" -type f)
# Recursive write access for all the 'fees' directories (see README)
IFS=$'\n' chmod -R 777 $(find "$location" -name 'fees' -type d)
# HAD can view/edit all files
setfacl -m user:HAD:rwx -R "$location"
# fee-breakup must be SUID HAD (see README)
chown HAD:HAD /usr/local/bin/fee-breakup
chmod 4755 /usr/local/bin/fee-breakup
# All students can edit mess.txt
chmod 770 "$location"/HAD/mess.txt
setfacl -m group:inmates:rwx "$location"/HAD/mess.txt
mainfolders=($location/*)
hostels=(${mainfolders[@]/"${location}/HAD"/})
for hostel in "${hostels[@]}"; do
wardendir=$hostel/${hostel##*/} # this is how we had chosen to name
# the Wardens' home directories
wardenname=$(stat --format '%U' "$wardendir")
# Wardens can access any file in their own hostel
# directory
setfacl -m user:"$wardenname":rwx -R "$hostel"
done