Subversion Repositories

?revision_form?Rev ?revision_input??revision_submit??revision_endform?

Rev 75 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
2 magnus 1
#!/bin/sh
2
# postinst script for lsh-server
3
#
4
# see: dh_installdeb(1)
5
 
6
set -e
7
 
8
# summary of how this script can be called:
9
#        * <postinst> `configure' <most-recently-configured-version>
10
#        * <old-postinst> `abort-upgrade' <new version>
11
#        * <conflictor's-postinst> `abort-remove' `in-favour' <package>
12
#          <new-version>
13
#        * <deconfigured's-postinst> `abort-deconfigure' `in-favour'
14
#          <failed-install-package> <version> `removing'
15
#          <conflicting-package> <version>
16
# for details, see http://www.debian.org/doc/debian-policy/ or
17
# the debian-policy package
18
#
19
# quoting from the policy:
20
#     Any necessary prompting should almost always be confined to the
21
#     post-installation script, and should be protected with a conditional
22
#     so that unnecessary prompting doesn't happen if a package's
23
#     installation fails and the `postinst' is called with `abort-upgrade',
24
#     `abort-remove' or `abort-deconfigure'.
25
 
61 magnus 26
create_seed_and_key() {
27
    RANDOM_SEED="/var/spool/lsh/yarrow-seed-file"
28
    HOST_KEY="/etc/lsh_host_key"
29
    OPENSSH_HOST_KEY="/etc/ssh/ssh_host_rsa_key"
2 magnus 30
 
61 magnus 31
    if [ ! -f "$RANDOM_SEED" ]; then
32
	echo -n "Creating lsh random seed file (this may take a while) ..."
33
	DIR=$(dirname "$RANDOM_SEED")
34
	if install -d -m 700 "$DIR" &&
35
	    dd if=/dev/random "of=$RANDOM_SEED" bs=1 count=32 2>/dev/null &&
36
	    chmod 600 "$RANDOM_SEED"; then
37
	    echo " done."
38
	else
39
	    echo " failed!"
40
	    return 1
41
	fi
42
    fi
43
 
44
    if [ ! -f "$HOST_KEY" ]; then
45
	if [ -r "$OPENSSH_HOST_KEY" ]; then
46
	    echo -n "Converting existing OpenSSH RSA host key ... "
47
	    if pkcs1-conv < "$OPENSSH_HOST_KEY" | lsh-writekey --server &&
62 magnus 48
		[ -f "$HOST_KEY" -a -f "$HOST_KEY.pub" ]; then
49
		chmod +r "$HOST_KEY.pub"
50
		echo "done."
61 magnus 51
		return 0
52
	    fi
62 magnus 53
	    rm -f "$HOST_KEY" "$HOST_KEY.pub"
61 magnus 54
	    echo "failed. Will generate a new key instead."
55
	fi
56
	echo -n "Creating lsh host key ... "
57
	if lsh-keygen --server | lsh-writekey --server &&
62 magnus 58
	    [ -f "$HOST_KEY" -a -f "$HOST_KEY.pub" ]; then
59
	    chmod +r "$HOST_KEY.pub"
60
	    echo "done."
61 magnus 61
	else
62 magnus 62
	    echo "failed!"
61 magnus 63
	    return 1
64
	fi
65
    fi
66
    return 0
67
}
68
 
2 magnus 69
LSHD_DEFAULTS=/etc/default/lsh-server
70
 
71
case "$1" in
72
    configure)
73
 
74
	# This needs to be fixed. If we do stuff this way, strange things will
75
	# happen ... the user can specify stuff to debconf and old options can
76
	# still be written to the config file :-(
77
	# First, get default options
78
	#[ -e "$LSHD_DEFAULTS" ] && . "$LSHD_DEFAULTS"
79
 
80
	# Fall back to default options if necessary
81
	LSHD_PORT=${LSHD_PORT:-2222}
82
	ENABLE_SFTP=${ENABLE_SFTP:-false}
83
 
84
	# Make sure ENABLE_SFTP is either "true" or "false", set up option
85
	case "$ENABLE_SFTP" in
86
	    true|TRUE|y*|Y*)
87
		ENABLE_SFTP=true
88
		;;
89
	    *)
90
		ENABLE_SFTP=false
91
		;;
92
	esac
93
 
94
	. /usr/share/debconf/confmodule
95
 
96
	db_get "lsh-server/lshd_port"; LSHD_PORT="$RET"
97
	db_get "lsh-server/sftp"; ENABLE_SFTP="$RET"
99 magnus 98
	db_get "lsh-server/extra_args"; EXTRA_ARGS="$RET"
75 magnus 99
	exec 3>&-
2 magnus 100
 
101
	# OK, now make the config file
102
 
103
	cat <<"EOF" >"$LSHD_DEFAULTS"
40 magnus 104
# Configuration file generated by lsh-server.postinst.
2 magnus 105
# You can change the lsh-server configuration either by editing
40 magnus 106
# this file, or by running dpkg-reconfigure lsh-server.
2 magnus 107
#
108
EOF
109
 
110
	echo "LSHD_PORT=\"$LSHD_PORT\"" >>"$LSHD_DEFAULTS"
111
	echo "ENABLE_SFTP=\"$ENABLE_SFTP\"" >> "$LSHD_DEFAULTS"
99 magnus 112
	echo "EXTRA_ARGS=\"$EXTRA_ARGS\"" >> "$LSHD_DEFAULTS"
2 magnus 113
 
114
	# Versions before 2.0.1cdbs-4 have a security issue, therefore
115
	# have the random seed regenerated.
116
	if [ "$2" ] && [ -e "/var/spool/lsh/yarrow-seed-file" ] \
117
		&& dpkg --compare-versions "$2" lt "2.0.1cdbs-4"; then
118
		echo " Removing /var/spool/lsh/yarrow-seed-file, because of you are upgrading from a"
119
		echo " version with a known security bug, so we can't trust the seed any more."
120
		echo " It will be automatically regenerated from /dev/random."
121
		rm /var/spool/lsh/yarrow-seed-file
122
	fi
123
 
124
	# Disable ssh if needed
125
	if [ "$LSHD_PORT" -eq 22 ] ; then
126
	    if [ ! -d /etc/ssh ] ; then
127
		mkdir -p /etc/ssh
128
	    fi
129
 
130
	    file=/etc/ssh/sshd_not_to_be_run
131
	    if [ ! -f "$file" ] ; then
132
# stop ssh from starting at bootup
133
		cat  <<"EOF" >"$file"
134
LSH_SERVER_CONFIG_GENERATED
40 magnus 135
# Generated by lsh-server.postinst
2 magnus 136
# Please don't remove this file unless you have first disabled lsh, and don't
137
# change the first line ... otherwise lsh-server won't recognise it!!!
138
EOF
74 magnus 139
 
140
		if [ -x "/etc/init.d/ssh" ]; then
141
		    if [ -x "`which invoke-rc.d 2>/dev/null`" ]; then
142
			invoke-rc.d ssh stop || true
143
		    else
144
			/etc/init.d/ssh stop || true
145
		    fi
146
		fi
2 magnus 147
	    fi
148
	fi
61 magnus 149
 
150
	create_seed_and_key
2 magnus 151
    ;;
152
 
153
    abort-upgrade|abort-remove|abort-deconfigure)
154
 
155
    ;;
156
 
157
    *)
158
        echo "postinst called with unknown argument \`$1'" >&2
159
        exit 1
160
    ;;
161
esac
162
 
163
# dh_installdeb will replace this with shell code automatically
164
# generated by other debhelper scripts
165
 
166
#DEBHELPER#
167
 
168
exit 0