sshd revision 140339
1254721Semaste#!/bin/sh 2254721Semaste# 3254721Semaste# $NetBSD: sshd,v 1.18 2002/04/29 08:23:34 lukem Exp $ 4254721Semaste# $FreeBSD: head/etc/rc.d/sshd 140339 2005-01-16 03:12:03Z obrien $ 5254721Semaste# 6254721Semaste 7254721Semaste# PROVIDE: sshd 8254721Semaste# REQUIRE: LOGIN cleanvar 9254721Semaste 10254721Semaste. /etc/rc.subr 11254721Semaste 12254721Semastename="sshd" 13254721Semastercvar=`set_rcvar` 14254721Semastekeygen_cmd="sshd_keygen" 15254721Semastestart_precmd="sshd_precmd" 16254721Semastepidfile="/var/run/${name}.pid" 17254721Semasteextra_commands="keygen reload" 18254721Semaste 19254721Semastetimeout=300 20254721Semaste 21254721Semasteuser_reseed() 22254721Semaste{ 23254721Semaste ( 24254721Semaste seeded=`sysctl -n kern.random.sys.seeded 2>/dev/null` 25254721Semaste if [ "${seeded}" != "" ] ; then 26254721Semaste warn "Setting entropy source to blocking mode." 27254721Semaste echo "====================================================" 28254721Semaste echo "Type a full screenful of random junk to unblock" 29254721Semaste echo "it and remember to finish with <enter>. This will" 30254721Semaste echo "timeout in ${timeout} seconds, but waiting for" 31254721Semaste echo "the timeout without typing junk may make the" 32254721Semaste echo "entropy source deliver predictable output." 33254721Semaste echo "" 34254721Semaste echo "Just hit <enter> for fast+insecure startup." 35254721Semaste echo "====================================================" 36254721Semaste sysctl kern.random.sys.seeded=0 2>/dev/null 37254721Semaste read -t ${timeout} junk 38254721Semaste echo "${junk}" `sysctl -a` `date` > /dev/random 39254721Semaste fi 40254721Semaste ) 41254721Semaste} 42254721Semaste 43254721Semastesshd_keygen() 44254721Semaste{ 45254721Semaste ( 46254721Semaste umask 022 47254721Semaste 48254721Semaste # Can't do anything if ssh is not installed 49254721Semaste [ -x /usr/bin/ssh-keygen ] || { 50254721Semaste warn "/usr/bin/ssh-keygen does not exist." 51254721Semaste return 1 52254721Semaste } 53254721Semaste 54254721Semaste if [ -f /etc/ssh/ssh_host_key ]; then 55254721Semaste echo "You already have an RSA host key" \ 56254721Semaste "in /etc/ssh/ssh_host_key" 57254721Semaste echo "Skipping protocol version 1 RSA Key Generation" 58254721Semaste else 59254721Semaste /usr/bin/ssh-keygen -t rsa1 -b 1024 \ 60254721Semaste -f /etc/ssh/ssh_host_key -N '' 61254721Semaste fi 62254721Semaste 63254721Semaste if [ -f /etc/ssh/ssh_host_dsa_key ]; then 64254721Semaste echo "You already have a DSA host key" \ 65254721Semaste "in /etc/ssh/ssh_host_dsa_key" 66254721Semaste echo "Skipping protocol version 2 DSA Key Generation" 67254721Semaste else 68254721Semaste /usr/bin/ssh-keygen -t dsa -f /etc/ssh/ssh_host_dsa_key -N '' 69254721Semaste fi 70254721Semaste 71254721Semaste if [ -f /etc/ssh/ssh_host_rsa_key ]; then 72254721Semaste echo "You already have a RSA host key" \ 73254721Semaste "in /etc/ssh/ssh_host_rsa_key" 74254721Semaste echo "Skipping protocol version 2 RSA Key Generation" 75254721Semaste else 76254721Semaste /usr/bin/ssh-keygen -t rsa -f /etc/ssh/ssh_host_rsa_key -N '' 77254721Semaste fi 78254721Semaste ) 79254721Semaste} 80254721Semaste 81254721Semastesshd_precmd() 82{ 83 if [ ! -f /etc/ssh/ssh_host_key -o \ 84 ! -f /etc/ssh/ssh_host_dsa_key -o \ 85 ! -f /etc/ssh/ssh_host_rsa_key ]; then 86 user_reseed 87 run_rc_command keygen 88 fi 89} 90 91load_rc_config $name 92run_rc_command "$1" 93