2016-12-31 07:00:46 +03:00
|
|
|
#!/bin/sh
|
|
|
|
|
|
|
|
# Find suitable PAM config file
|
|
|
|
|
|
|
|
rules="$1"
|
|
|
|
srcdir="$2"
|
|
|
|
outfile="$3"
|
|
|
|
|
|
|
|
service="xrdp-sesman"
|
|
|
|
pamdir="/etc/pam.d"
|
2022-11-08 13:05:55 +03:00
|
|
|
pamdir_suse="/usr/lib/pam.d"
|
|
|
|
if [ ! -d $pamdir_suse ]; then
|
|
|
|
# Older SUSE distros uses /usr/etc/pam.d
|
|
|
|
pamdir_suse="/usr/etc/pam.d"
|
|
|
|
fi
|
2016-12-31 07:00:46 +03:00
|
|
|
|
2020-04-26 19:27:19 +03:00
|
|
|
# Modules needed by xrdp-sesman.unix, if we get to that
|
|
|
|
unix_modules_needed="pam_unix.so pam_env.so pam_nologin.so"
|
|
|
|
|
|
|
|
# Directories where pam modules might be installed
|
|
|
|
# Add to this list as platforms are added
|
|
|
|
pam_module_dir_searchpath="/lib*/security /usr/lib*/security /lib/*/security /usr/lib/*/security"
|
|
|
|
|
|
|
|
find_pam_module_dir()
|
|
|
|
{
|
|
|
|
# Looks for the pam security module directory
|
|
|
|
set -- $pam_module_dir_searchpath
|
|
|
|
for d in "$@"; do
|
2022-09-03 03:50:56 +03:00
|
|
|
if [ -s "$d/pam_unix.so" ]; then
|
|
|
|
echo "$d"
|
2020-04-26 19:27:19 +03:00
|
|
|
break
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
|
|
|
can_apply_unix_config()
|
|
|
|
{
|
|
|
|
result=0
|
|
|
|
module_dir="$1"
|
|
|
|
for m in $unix_modules_needed; do
|
2022-09-03 03:50:56 +03:00
|
|
|
if [ ! -s "$module_dir/$m" ]; then
|
2020-04-26 19:27:19 +03:00
|
|
|
echo " ** $m not found" >&2
|
|
|
|
result=1
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
|
|
|
return $result
|
|
|
|
}
|
|
|
|
|
2016-12-31 07:00:46 +03:00
|
|
|
guess_rules ()
|
|
|
|
{
|
2020-04-26 19:27:19 +03:00
|
|
|
rules=
|
|
|
|
if [ -s "$pamdir/password-auth" ]; then
|
2016-12-31 07:00:46 +03:00
|
|
|
rules="redhat"
|
|
|
|
|
2020-04-26 19:27:19 +03:00
|
|
|
elif [ -s "$pamdir_suse/common-account" ]; then
|
2019-11-13 06:06:42 +03:00
|
|
|
rules="suse"
|
|
|
|
|
2020-04-26 19:27:19 +03:00
|
|
|
elif [ -s "$pamdir/common-account" ]; then
|
2016-12-31 07:00:46 +03:00
|
|
|
if grep "^@include" "$pamdir/passwd" >/dev/null 2>&1; then
|
|
|
|
rules="debian"
|
|
|
|
else
|
|
|
|
rules="suse"
|
|
|
|
fi
|
|
|
|
|
2020-04-26 19:27:19 +03:00
|
|
|
elif [ ! -f "$pamdir/system-auth" -a -s "$pamdir/system" ]; then
|
2017-07-19 09:17:10 +03:00
|
|
|
rules="freebsd"
|
|
|
|
|
2020-04-26 19:27:19 +03:00
|
|
|
elif [ -s "$pamdir/authorization" ]; then
|
2018-01-30 12:42:42 +03:00
|
|
|
rules="macos"
|
|
|
|
|
2020-04-26 19:27:19 +03:00
|
|
|
elif [ -s "$pamdir/system-remote-login" ]; then
|
2018-03-23 21:34:23 +03:00
|
|
|
rules="arch"
|
|
|
|
|
2020-04-26 19:27:19 +03:00
|
|
|
elif [ -s "$pamdir/system-auth" ]; then
|
|
|
|
rules="system"
|
|
|
|
|
|
|
|
else
|
|
|
|
module_dir=`find_pam_module_dir`
|
|
|
|
if [ -d "$module_dir" ]; then
|
|
|
|
#echo "- Found pam modules in $module_dir" >&2
|
|
|
|
if can_apply_unix_config "$module_dir" ; then
|
|
|
|
rules="unix"
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
fi
|
2016-12-31 07:00:46 +03:00
|
|
|
}
|
|
|
|
|
2020-04-26 19:27:19 +03:00
|
|
|
if [ "$rules" = "auto" ]; then
|
2016-12-31 07:00:46 +03:00
|
|
|
guess_rules
|
2020-04-26 19:27:19 +03:00
|
|
|
if [ -z "$rules" ]; then
|
|
|
|
echo "** Can't guess PAM rules for this system"
|
|
|
|
exit 1
|
|
|
|
fi
|
2016-12-31 07:00:46 +03:00
|
|
|
fi
|
|
|
|
|
2020-04-26 19:27:19 +03:00
|
|
|
if [ -s "$srcdir/$service.$rules" ]; then
|
2016-12-31 07:00:46 +03:00
|
|
|
ln -nsf "$srcdir/$service.$rules" "$outfile"
|
|
|
|
else
|
|
|
|
echo "Cannot find $srcdir/$service.$rules"
|
|
|
|
exit 1
|
|
|
|
fi
|