diff options
author | Colin Watson <cjwatson@debian.org> | 2003-09-01 00:51:03 +0000 |
---|---|---|
committer | Colin Watson <cjwatson@debian.org> | 2003-09-01 00:51:03 +0000 |
commit | 79cf0b3654d7b597de323153eb57015cdfbd90a4 (patch) | |
tree | 274e78bc3369e218e59aa1fcc9b7e90697f424f1 /debian/postinst | |
parent | d984a3c6658e950881edcfb2aae464add93f68d4 (diff) |
Debian release 3.4p1-1.
Diffstat (limited to 'debian/postinst')
-rw-r--r-- | debian/postinst | 330 |
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 | |||
3 | action="$1" | ||
4 | oldversion="$2" | ||
5 | |||
6 | test -e /usr/share/debconf/confmodule && { | ||
7 | . /usr/share/debconf/confmodule | ||
8 | db_version 2.0 | ||
9 | } | ||
10 | |||
11 | umask 022 | ||
12 | |||
13 | if [ "$action" != configure ] | ||
14 | then | ||
15 | exit 0 | ||
16 | fi | ||
17 | |||
18 | |||
19 | |||
20 | check_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 | |||
32 | create_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 | |||
46 | create_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 | |||
61 | create_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 | ||
87 | Port 22 | ||
88 | # Use these options to restrict which interfaces/protocols sshd will bind to | ||
89 | #ListenAddress :: | ||
90 | #ListenAddress 0.0.0.0 | ||
91 | EOF | ||
92 | if [ "$RET" = "false" ]; then | ||
93 | cat <<EOF >> /etc/ssh/sshd_config | ||
94 | Protocol 2,1 | ||
95 | # HostKeys for protocol version 1 | ||
96 | HostKey /etc/ssh/ssh_host_key | ||
97 | # HostKeys for protocol version 2 | ||
98 | HostKey /etc/ssh/ssh_host_rsa_key | ||
99 | HostKey /etc/ssh/ssh_host_dsa_key | ||
100 | EOF | ||
101 | else | ||
102 | cat <<EOF >> /etc/ssh/sshd_config | ||
103 | Protocol 2 | ||
104 | # HostKeys for protocol version 2 | ||
105 | HostKey /etc/ssh/ssh_host_rsa_key | ||
106 | HostKey /etc/ssh/ssh_host_dsa_key | ||
107 | EOF | ||
108 | fi | ||
109 | |||
110 | test -e /usr/share/debconf/confmodule && { | ||
111 | db_get ssh/privsep_ask | ||
112 | } | ||
113 | if [ "$RET" = "false" ]; then | ||
114 | cat <<EOF >> /etc/ssh/sshd_config | ||
115 | #Explicitly set PrivSep off, as requested | ||
116 | UsePrivilegeSeparation no | ||
117 | |||
118 | # Use PAM authentication via keyboard-interactive so PAM modules can | ||
119 | # properly interface with the user | ||
120 | PAMAuthenticationViaKbdInt yes | ||
121 | EOF | ||
122 | else | ||
123 | cat <<EOF >> /etc/ssh/sshd_config | ||
124 | #Privilege Separation is turned on for security | ||
125 | UsePrivilegeSeparation 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) | ||
130 | PAMAuthenticationViaKbdInt no | ||
131 | EOF | ||
132 | fi | ||
133 | |||
134 | cat <<EOF >> /etc/ssh/sshd_config | ||
135 | # Lifetime and size of ephemeral version 1 server key | ||
136 | KeyRegenerationInterval 3600 | ||
137 | ServerKeyBits 768 | ||
138 | |||
139 | # Logging | ||
140 | SyslogFacility AUTH | ||
141 | LogLevel INFO | ||
142 | |||
143 | # Authentication: | ||
144 | LoginGraceTime 600 | ||
145 | PermitRootLogin yes | ||
146 | StrictModes yes | ||
147 | |||
148 | RSAAuthentication yes | ||
149 | PubkeyAuthentication yes | ||
150 | #AuthorizedKeysFile %h/.ssh/authorized_keys | ||
151 | |||
152 | # rhosts authentication should not be used | ||
153 | RhostsAuthentication no | ||
154 | # Don't read the user's ~/.rhosts and ~/.shosts files | ||
155 | IgnoreRhosts yes | ||
156 | # For this to work you will also need host keys in /etc/ssh_known_hosts | ||
157 | RhostsRSAAuthentication no | ||
158 | # similar for protocol version 2 | ||
159 | HostbasedAuthentication 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) | ||
164 | PermitEmptyPasswords no | ||
165 | |||
166 | # Uncomment to disable s/key passwords | ||
167 | #ChallengeResponseAuthentication no | ||
168 | |||
169 | # To disable tunneled clear text passwords, change to no here! | ||
170 | PasswordAuthentication 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 | |||
182 | X11Forwarding no | ||
183 | X11DisplayOffset 10 | ||
184 | PrintMotd no | ||
185 | #PrintLastLog no | ||
186 | KeepAlive yes | ||
187 | #UseLogin no | ||
188 | |||
189 | #MaxStartups 10:30:60 | ||
190 | #Banner /etc/issue.net | ||
191 | #ReverseMappingCheck yes | ||
192 | |||
193 | Subsystem sftp /usr/lib/sftp-server | ||
194 | |||
195 | EOF | ||
196 | } | ||
197 | |||
198 | |||
199 | fix_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 | |||
219 | fix_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 | |||
229 | create_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 | |||
243 | setup_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 | |||
249 | set_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 | |||
283 | setup_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 | |||
299 | setup_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 | |||
306 | check_idea_key | ||
307 | create_keys | ||
308 | create_sshdconfig | ||
309 | fix_rsh_diversion | ||
310 | fix_statoverride | ||
311 | create_alternatives | ||
312 | setup_sshd_user | ||
313 | set_sshd_permissions | ||
314 | setup_startup | ||
315 | setup_init | ||
316 | |||
317 | |||
318 | # Automatically added by dh_installdocs | ||
319 | if [ "$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 | ||
323 | fi | ||
324 | # End automatically added section | ||
325 | |||
326 | |||
327 | [ -e /usr/share/debconf/confmodule ] && db_stop | ||
328 | |||
329 | exit 0 | ||
330 | |||