Created
February 8, 2022 05:31
-
-
Save WeZZard/e7b0739522ff26f6d6d910d163feaa2e to your computer and use it in GitHub Desktop.
FreeBSD sshd for Phabricator rc script.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# | |
# $FreeBSD: releng/12.2/libexec/rc/rc.d/sshd 363553 2020-07-26 10:01:27Z 0mp $ | |
# | |
# PROVIDE: sshd | |
# REQUIRE: LOGIN FILESYSTEMS | |
# KEYWORD: shutdown | |
. /etc/rc.subr | |
name="sshd_phabricator" | |
desc="Secure Shell Daemon for Phabricator" | |
rcvar="sshd_enable" | |
config_file="/etc/ssh/sshd_config.phabricator" | |
command="/usr/sbin/sshd" | |
command_args="-f ${config_file}" | |
keygen_cmd="sshd_keygen" | |
start_precmd="sshd_precmd" | |
reload_precmd="sshd_configtest" | |
restart_precmd="sshd_configtest" | |
configtest_cmd="sshd_configtest" | |
pidfile="/var/run/${name}.pid" | |
extra_commands="configtest keygen reload" | |
: ${sshd_rsa_enable:="yes"} | |
: ${sshd_dsa_enable:="no"} | |
: ${sshd_ecdsa_enable:="yes"} | |
: ${sshd_ed25519_enable:="yes"} | |
sshd_keygen_alg() | |
{ | |
local alg=$1 | |
local ALG="$(echo $alg | tr a-z A-Z)" | |
local keyfile | |
if ! checkyesno "sshd_${alg}_enable" ; then | |
return 0 | |
fi | |
case $alg in | |
rsa|dsa|ecdsa|ed25519) | |
keyfile="/etc/ssh/ssh_host_${alg}_key" | |
;; | |
*) | |
return 1 | |
;; | |
esac | |
if [ -f "${keyfile}" ] ; then | |
info "$ALG host key exists." | |
return 0 | |
fi | |
if [ ! -x /usr/bin/ssh-keygen ] ; then | |
warn "/usr/bin/ssh-keygen does not exist." | |
return 1 | |
fi | |
echo "Generating $ALG host key." | |
/usr/bin/ssh-keygen -q -t $alg -f "$keyfile" -N "" | |
/usr/bin/ssh-keygen -l -f "$keyfile.pub" | |
} | |
sshd_keygen() | |
{ | |
sshd_keygen_alg rsa | |
sshd_keygen_alg dsa | |
sshd_keygen_alg ecdsa | |
sshd_keygen_alg ed25519 | |
} | |
sshd_configtest() | |
{ | |
echo "Performing sanity check on ${name} configuration." | |
eval ${command} ${command_args} ${sshd_phabricator_flags} -t | |
} | |
sshd_precmd() | |
{ | |
run_rc_command keygen | |
run_rc_command configtest | |
} | |
load_rc_config $name | |
run_rc_command "$1" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment