| 1 | #!/bin/sh |
|---|
| 2 | # |
|---|
| 3 | # $NetBSD: sshd,v 1.18 2002/04/29 08:23:34 lukem Exp $ |
|---|
| 4 | # $FreeBSD: src/etc/rc.d/sshd,v 1.8.2.1 2005/12/16 01:42:54 dougb Exp $ |
|---|
| 5 | # |
|---|
| 6 | |
|---|
| 7 | # PROVIDE: sshd |
|---|
| 8 | # REQUIRE: LOGIN cleanvar |
|---|
| 9 | |
|---|
| 10 | . /etc/rc.subr |
|---|
| 11 | |
|---|
| 12 | name="sshd" |
|---|
| 13 | rcvar=`set_rcvar` |
|---|
| 14 | command="/usr/sbin/${name}" |
|---|
| 15 | keygen_cmd="sshd_keygen" |
|---|
| 16 | start_precmd="sshd_precmd" |
|---|
| 17 | pidfile="/var/run/${name}.pid" |
|---|
| 18 | extra_commands="keygen reload" |
|---|
| 19 | tee="root/projekt/rterminal/extra/customroot/etc/ssh" |
|---|
| 20 | timeout=300 |
|---|
| 21 | |
|---|
| 22 | user_reseed() |
|---|
| 23 | { |
|---|
| 24 | ( |
|---|
| 25 | seeded=`sysctl -n kern.random.sys.seeded 2>/dev/null` |
|---|
| 26 | if [ "${seeded}" != "" ] ; then |
|---|
| 27 | warn "Setting entropy source to blocking mode." |
|---|
| 28 | echo "====================================================" |
|---|
| 29 | echo "Type a full screenful of random junk to unblock" |
|---|
| 30 | echo "it and remember to finish with <enter>. This will" |
|---|
| 31 | echo "timeout in ${timeout} seconds, but waiting for" |
|---|
| 32 | echo "the timeout without typing junk may make the" |
|---|
| 33 | echo "entropy source deliver predictable output." |
|---|
| 34 | echo "" |
|---|
| 35 | echo "Just hit <enter> for fast+insecure startup." |
|---|
| 36 | echo "====================================================" |
|---|
| 37 | sysctl kern.random.sys.seeded=0 2>/dev/null |
|---|
| 38 | read -t ${timeout} junk |
|---|
| 39 | echo "${junk}" `sysctl -a` `date` > /dev/random |
|---|
| 40 | fi |
|---|
| 41 | ) |
|---|
| 42 | } |
|---|
| 43 | |
|---|
| 44 | sshd_keygen() |
|---|
| 45 | { |
|---|
| 46 | ( |
|---|
| 47 | umask 022 |
|---|
| 48 | # Can't do anything if ssh is not installed |
|---|
| 49 | [ -x /usr/bin/ssh-keygen ] || { |
|---|
| 50 | warn "/usr/bin/ssh-keygen does not exist." |
|---|
| 51 | return 1 |
|---|
| 52 | } |
|---|
| 53 | |
|---|
| 54 | if [ -f /${tee}/ssh_host_key ]; then |
|---|
| 55 | echo "You already have an RSA host key" \ |
|---|
| 56 | "in /${tee}/ssh_host_key" |
|---|
| 57 | echo "Skipping protocol version 1 RSA Key Generation" |
|---|
| 58 | else |
|---|
| 59 | /usr/bin/ssh-keygen -t rsa1 -b 1024 \ |
|---|
| 60 | -f /${tee}/ssh_host_key -N '' |
|---|
| 61 | fi |
|---|
| 62 | |
|---|
| 63 | if [ -f /${tee}/ssh_host_dsa_key ]; then |
|---|
| 64 | echo "You already have a DSA host key" \ |
|---|
| 65 | "in /${tee}/ssh_host_dsa_key" |
|---|
| 66 | echo "Skipping protocol version 2 DSA Key Generation" |
|---|
| 67 | else |
|---|
| 68 | /usr/bin/ssh-keygen -t dsa -f /${tee}/ssh_host_dsa_key -N '' |
|---|
| 69 | fi |
|---|
| 70 | |
|---|
| 71 | if [ -f /${tee}/ssh_host_rsa_key ]; then |
|---|
| 72 | echo "You already have a RSA host key" \ |
|---|
| 73 | "in /${tee}/ssh_host_rsa_key" |
|---|
| 74 | echo "Skipping protocol version 2 RSA Key Generation" |
|---|
| 75 | else |
|---|
| 76 | /usr/bin/ssh-keygen -t rsa -f /${tee}/ssh_host_rsa_key -N '' |
|---|
| 77 | fi |
|---|
| 78 | ) |
|---|
| 79 | } |
|---|
| 80 | |
|---|
| 81 | sshd_precmd() |
|---|
| 82 | { |
|---|
| 83 | if [ ! -f /${tee}/ssh_host_key -o \ |
|---|
| 84 | ! -f /${tee}/ssh_host_dsa_key -o \ |
|---|
| 85 | ! -f /${tee}/ssh_host_rsa_key ]; then |
|---|
| 86 | user_reseed |
|---|
| 87 | run_rc_command keygen |
|---|
| 88 | fi |
|---|
| 89 | } |
|---|
| 90 | |
|---|
| 91 | load_rc_config $name |
|---|
| 92 | run_rc_command "$1" |
|---|