-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathupdate-mapping.sh
executable file
·47 lines (40 loc) · 973 Bytes
/
update-mapping.sh
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
#!/bin/bash
# Verify running as root
if [[ $(/usr/bin/id -u) -ne 0 ]]; then
echo "Please execute script as root"
exit 1
fi
# List of services to update policy for
SERVICES=(
lightdm
sudo
sudo-i
su
chsh
login
polkit-1
xscreensaver
gdm-password
gdm-smartcard-sssd-or-password
ppp
unity
cinnamon-screensaver
)
cd /etc/pam.d || exit 1
echo 'auth sufficient pam_u2f.so authfile=/etc/u2f_mappings cue' > common-u2f
for f in "${SERVICES[@]}"; do
# Starting with Ubuntu 24.04, polkit-1 is no longer in /etc/pam.d and has to be copied over first.
if [[ ! -f "polkit-1" && -f "/usr/lib/pam.d/polkit-1" ]]; then
cp /usr/lib/pam.d/polkit-1 .
fi
if [ ! -f "$f" ]; then
echo "[SKIP] $f does not exist"
continue
fi
if grep -Fxq "@include common-u2f" "$f"; then
echo "[SKIP] Updated policy exists in $f"
else
mv "$f" "$f~"
awk '/@include common-auth/ {print "@include common-u2f"}; {print}' "$f~" > "$f"
fi
done