summaryrefslogtreecommitdiff
path: root/debian/postinst
diff options
context:
space:
mode:
authorColin Watson <cjwatson@debian.org>2003-09-01 00:51:03 +0000
committerColin Watson <cjwatson@debian.org>2003-09-01 00:51:03 +0000
commit79cf0b3654d7b597de323153eb57015cdfbd90a4 (patch)
tree274e78bc3369e218e59aa1fcc9b7e90697f424f1 /debian/postinst
parentd984a3c6658e950881edcfb2aae464add93f68d4 (diff)
Debian release 3.4p1-1.
Diffstat (limited to 'debian/postinst')
-rw-r--r--debian/postinst330
1 files changed, 330 insertions, 0 deletions
diff --git a/debian/postinst b/debian/postinst
new file mode 100644
index 000000000..34fee95d8
--- /dev/null
+++ b/debian/postinst
@@ -0,0 +1,330 @@
1#!/bin/sh -e
2
3action="$1"
4oldversion="$2"
5
6test -e /usr/share/debconf/confmodule && {
7 . /usr/share/debconf/confmodule
8 db_version 2.0
9}
10
11umask 022
12
13if [ "$action" != configure ]
14 then
15 exit 0
16fi
17
18
19
20check_idea_key() {
21 #check for old host_key files using IDEA, which openssh does not support
22 if [ -f /etc/ssh/ssh_host_key ] ; then
23 if ssh-keygen -p -N '' -f /etc/ssh/ssh_host_key 2>&1 | \
24 grep -q 'unknown cipher' 2>/dev/null ; then
25 mv /etc/ssh/ssh_host_key /etc/ssh/ssh_host_key.old
26 mv /etc/ssh/ssh_host_key.pub /etc/ssh/ssh_host_key.pub.old
27 fi
28 fi
29}
30
31
32create_key() {
33 local msg="$1"
34 shift
35 local file="$1"
36 shift
37
38 if [ ! -f "$file" ] ; then
39 echo -n $msg
40 ssh-keygen -f "$file" -N '' "$@" > /dev/null
41 echo
42 fi
43}
44
45
46create_keys() {
47 RET=true
48 test -e /usr/share/debconf/confmodule && {
49 db_get ssh/protocol2_only
50 }
51
52 if [ "$RET" = "false" ] ; then
53 create_key "Creating SSH1 key" /etc/ssh/ssh_host_key -t rsa1
54 fi
55
56 create_key "Creating SSH2 RSA key" /etc/ssh/ssh_host_rsa_key -t rsa
57 create_key "Creating SSH2 DSA key" /etc/ssh/ssh_host_dsa_key -t dsa
58}
59
60
61create_sshdconfig() {
62 if [ -e /etc/ssh/sshd_config ] ; then
63 if dpkg --compare-versions "$oldversion" lt-nl 1:1.3 ; then
64 RET=true
65 test -e /usr/share/debconf/confmodule && {
66 db_get ssh/new_config
67 }
68 if [ "$RET" = "false" ] ; then return 0; fi
69 else return 0
70 fi
71 fi
72 RET=true
73 test -e /usr/share/debconf/confmodule && {
74 db_get ssh/protocol2_only
75 }
76
77 #Preserve old sshd_config before generating a new on
78 if [ -e /etc/ssh/sshd_config ] ; then
79 mv /etc/ssh/sshd_config /etc/ssh/sshd_config.dpkg-old
80 fi
81
82 cat <<EOF > /etc/ssh/sshd_config
83# Package generated configuration file
84# See the sshd(8) manpage for defails
85
86# What ports, IPs and protocols we listen for
87Port 22
88# Use these options to restrict which interfaces/protocols sshd will bind to
89#ListenAddress ::
90#ListenAddress 0.0.0.0
91EOF
92if [ "$RET" = "false" ]; then
93 cat <<EOF >> /etc/ssh/sshd_config
94Protocol 2,1
95# HostKeys for protocol version 1
96HostKey /etc/ssh/ssh_host_key
97# HostKeys for protocol version 2
98HostKey /etc/ssh/ssh_host_rsa_key
99HostKey /etc/ssh/ssh_host_dsa_key
100EOF
101else
102 cat <<EOF >> /etc/ssh/sshd_config
103Protocol 2
104# HostKeys for protocol version 2
105HostKey /etc/ssh/ssh_host_rsa_key
106HostKey /etc/ssh/ssh_host_dsa_key
107EOF
108fi
109
110test -e /usr/share/debconf/confmodule && {
111 db_get ssh/privsep_ask
112}
113if [ "$RET" = "false" ]; then
114 cat <<EOF >> /etc/ssh/sshd_config
115#Explicitly set PrivSep off, as requested
116UsePrivilegeSeparation no
117
118# Use PAM authentication via keyboard-interactive so PAM modules can
119# properly interface with the user
120PAMAuthenticationViaKbdInt yes
121EOF
122else
123 cat <<EOF >> /etc/ssh/sshd_config
124#Privilege Separation is turned on for security
125UsePrivilegeSeparation yes
126
127# ...but breaks Pam auth via kbdint, so we have to turn it off
128# Use PAM authentication via keyboard-interactive so PAM modules can
129# properly interface with the user (off due to PrivSep)
130PAMAuthenticationViaKbdInt no
131EOF
132fi
133
134 cat <<EOF >> /etc/ssh/sshd_config
135# Lifetime and size of ephemeral version 1 server key
136KeyRegenerationInterval 3600
137ServerKeyBits 768
138
139# Logging
140SyslogFacility AUTH
141LogLevel INFO
142
143# Authentication:
144LoginGraceTime 600
145PermitRootLogin yes
146StrictModes yes
147
148RSAAuthentication yes
149PubkeyAuthentication yes
150#AuthorizedKeysFile %h/.ssh/authorized_keys
151
152# rhosts authentication should not be used
153RhostsAuthentication no
154# Don't read the user's ~/.rhosts and ~/.shosts files
155IgnoreRhosts yes
156# For this to work you will also need host keys in /etc/ssh_known_hosts
157RhostsRSAAuthentication no
158# similar for protocol version 2
159HostbasedAuthentication no
160# Uncomment if you don't trust ~/.ssh/known_hosts for RhostsRSAAuthentication
161#IgnoreUserKnownHosts yes
162
163# To enable empty passwords, change to yes (NOT RECOMMENDED)
164PermitEmptyPasswords no
165
166# Uncomment to disable s/key passwords
167#ChallengeResponseAuthentication no
168
169# To disable tunneled clear text passwords, change to no here!
170PasswordAuthentication yes
171
172
173# To change Kerberos options
174#KerberosAuthentication no
175#KerberosOrLocalPasswd yes
176#AFSTokenPassing no
177#KerberosTicketCleanup no
178
179# Kerberos TGT Passing does only work with the AFS kaserver
180#KerberosTgtPassing yes
181
182X11Forwarding no
183X11DisplayOffset 10
184PrintMotd no
185#PrintLastLog no
186KeepAlive yes
187#UseLogin no
188
189#MaxStartups 10:30:60
190#Banner /etc/issue.net
191#ReverseMappingCheck yes
192
193Subsystem sftp /usr/lib/sftp-server
194
195EOF
196}
197
198
199fix_rsh_diversion() {
200# get rid of mistaken rsh diversion (circa 1.2.27-1)
201
202 if [ -L /usr/bin/rsh ] &&
203 dpkg-divert --list '/usr/bin/rsh.real/rsh' | grep -q ' ssh$' ; then
204 for cmd in rlogin rsh rcp ; do
205 [ -L /usr/bin/$cmd ] && rm /usr/bin/$cmd
206 dpkg-divert --package ssh --remove --rename \
207 --divert /usr/bin/rsh.real/$cmd /usr/bin/$cmd
208
209 [ -L /usr/man/man1/$cmd.1.gz ] && rm /usr/man/man1/$$cmd.1.gz
210 dpkg-divert --package ssh --remove --rename \
211 --divert /usr/man/man1/$cmd.real.1.gz /usr/man/man1/$cmd.1.gz
212 done
213
214 rmdir /usr/bin/rsh.real
215 fi
216}
217
218
219fix_statoverride() {
220# Remove an erronous override for sshd (we should have overridden ssh)
221 if [ -x /usr/sbin/dpkg-statoverride ]; then
222 if dpkg-statoverride --list /usr/sbin/sshd 2>/dev/null ; then
223 dpkg-statoverride --remove /usr/sbin/sshd
224 fi
225 fi
226}
227
228
229create_alternatives() {
230# Create alternatives for the various r* tools
231# Make sure we don't change existing alternatives that a user might have
232# changed
233 for cmd in rsh rlogin rcp ; do
234 if ! update-alternatives --display $cmd | \
235 grep -q ssh ; then
236 update-alternatives --quiet --install /usr/bin/$cmd $cmd /usr/bin/ssh 20 \
237 --slave /usr/share/man/man1/$cmd.1.gz $cmd.1.gz /usr/share/man/man1/ssh.1.gz
238 fi
239 done
240
241}
242
243setup_sshd_user() {
244 if ! id sshd > /dev/null 2>&1 ; then
245 adduser --quiet --system --no-create-home --home /var/run/sshd sshd
246 fi
247}
248
249set_sshd_permissions() {
250 suid=false
251
252 if dpkg --compare-versions "$oldversion" lt-nl 1:3.4p1-1 ; then
253 if [ -x /usr/sbin/dpkg-statoverride ] ; then
254 if dpkg-statoverride --list /usr/bin/ssh >/dev/null; then
255 dpkg-statoverride --remove /usr/bin/ssh >/dev/null
256 fi
257 fi
258 fi
259
260 [ -e /usr/share/debconf/confmodule ] && {
261 db_get ssh/SUID_client
262 suid="$RET"
263 }
264 if [ -x /usr/sbin/dpkg-statoverride ] ; then
265 if ! dpkg-statoverride --list /usr/lib/ssh-keysign >/dev/null ; then
266 if [ "$suid" = "false" ] ; then
267 chmod 0755 /usr/lib/ssh-keysign
268 elif [ "$suid" = "true" ] ; then
269 chmod 4755 /usr/lib/ssh-keysign
270 fi
271 fi
272 else
273 if [ "$suid" = "false" ] ; then
274 chmod 0755 /usr/lib/ssh-keysign
275 elif [ "$suid" = "true" ] ; then
276 chmod 4755 /usr/lib/ssh-keysign
277 fi
278
279 fi
280}
281
282
283setup_startup() {
284 start=yes
285 [ -e /usr/share/debconf/confmodule ] && {
286 db_get ssh/run_sshd
287 start="$RET"
288 }
289
290 if [ "$start" != "true" ] ; then
291 /etc/init.d/ssh stop 2>&1 >/dev/null
292 touch /etc/ssh/sshd_not_to_be_run
293 else
294 rm -f /etc/ssh/sshd_not_to_be_run 2>/dev/null
295 fi
296}
297
298
299setup_init() {
300 if [ -e /etc/init.d/ssh ]; then
301 update-rc.d ssh defaults >/dev/null
302 /etc/init.d/ssh restart
303 fi
304}
305
306check_idea_key
307create_keys
308create_sshdconfig
309fix_rsh_diversion
310fix_statoverride
311create_alternatives
312setup_sshd_user
313set_sshd_permissions
314setup_startup
315setup_init
316
317
318# Automatically added by dh_installdocs
319if [ "$1" = "configure" ]; then
320 if [ -d /usr/doc -a ! -e /usr/doc/ssh -a -d /usr/share/doc/ssh ]; then
321 ln -sf ../share/doc/ssh /usr/doc/ssh
322 fi
323fi
324# End automatically added section
325
326
327[ -e /usr/share/debconf/confmodule ] && db_stop
328
329exit 0
330