48 lines
2.2 KiB
Bash
Executable File
48 lines
2.2 KiB
Bash
Executable File
#!/bin/sh
|
|
# Installs program files only; authentication must be configured as documented.
|
|
set -eu
|
|
umask 077
|
|
[ "$(id -u)" -eq 0 ] || { echo 'Run as root.' >&2; exit 1; }
|
|
cd "$(dirname "$0")"
|
|
command -v cc >/dev/null
|
|
command -v python3 >/dev/null
|
|
for file in /usr/local/lib/security/pam_duo_ssh.so /usr/local/libexec/duo-ssh/duo_ssh.py; do
|
|
[ ! -e "$file" ] && [ ! -L "$file" ] || { echo "Already exists: $file. Stop and review the existing installation." >&2; exit 1; }
|
|
done
|
|
# Refuse unsafe source files or ancestors before executing or installing anything.
|
|
python3 - <<'PY'
|
|
import os,stat
|
|
for path in (os.getcwd(), os.path.join(os.getcwd(), 'pam_duo_ssh.c'), os.path.join(os.getcwd(), 'duo_ssh.py'), '/usr/local/lib', '/usr/local/libexec', '/etc', '/var/lib'):
|
|
path=os.path.abspath(path)
|
|
while path != '/':
|
|
s=os.lstat(path)
|
|
if stat.S_ISLNK(s.st_mode) or s.st_uid != 0 or s.st_mode & 0o022:
|
|
raise SystemExit('Unsafe ownership, permissions, or symlink: '+path)
|
|
path=os.path.dirname(path)
|
|
PY
|
|
work=$(mktemp -d)
|
|
trap 'rm -rf "$work"' EXIT HUP INT TERM
|
|
cc -O2 -Wall -Wextra -Werror -fstack-protector-strong -D_FORTIFY_SOURCE=2 -fPIC -fvisibility=hidden -shared -Wl,-z,relro,-z,now -o "$work/pam_duo_ssh.so" pam_duo_ssh.c
|
|
for dir in /usr/local/libexec/duo-ssh /etc/duo-ssh /var/lib/duo-ssh; do
|
|
if [ -e "$dir" ] || [ -L "$dir" ]; then
|
|
echo "Directory exists: $dir. Stop and review before proceeding." >&2
|
|
exit 1
|
|
fi
|
|
done
|
|
if [ -e /usr/local/lib/security ] || [ -L /usr/local/lib/security ]; then
|
|
python3 - <<'PY'
|
|
import os, stat
|
|
p = "/usr/local/lib/security"
|
|
s = os.lstat(p)
|
|
if not stat.S_ISDIR(s.st_mode) or s.st_uid != 0 or s.st_mode & 0o022:
|
|
raise SystemExit("Unsafe directory: " + p)
|
|
PY
|
|
else
|
|
install -d -o root -g root -m 0755 /usr/local/lib/security
|
|
fi
|
|
install -d -o root -g root -m 0755 /usr/local/libexec/duo-ssh
|
|
install -d -o root -g root -m 0700 /etc/duo-ssh /var/lib/duo-ssh
|
|
install -o root -g root -m 0755 "$work/pam_duo_ssh.so" /usr/local/lib/security/pam_duo_ssh.so
|
|
install -o root -g root -m 0755 duo_ssh.py /usr/local/libexec/duo-ssh/duo_ssh.py
|
|
echo 'Program files installed. SSH authentication is unchanged. Continue with README.md.'
|