]> andersk Git - gssapi-openssh.git/blame_incremental - setup/setup-openssh.pl
o Change formatting of standard output to user.
[gssapi-openssh.git] / setup / setup-openssh.pl
... / ...
CommitLineData
1#
2# setup-openssh.pl:
3# Adapts the installed gsi-ssh environment to the current machine,
4# performing actions that originally occurred during the package's
5# 'make install' phase.
6#
7# Large parts adapted from 'fixpath', a tool found in openssh-3.0.2p1.
8#
9# Send comments/fixes/suggestions to:
10# Chase Phillips <cphillip@ncsa.uiuc.edu>
11#
12
13$gpath = $ENV{GLOBUS_LOCATION};
14if (!defined($gpath))
15{
16 die "GLOBUS_LOCATION needs to be set before running this script"
17}
18
19#
20# i'm including this because other perl scripts in the gpt setup directories
21# do so
22#
23
24@INC = (@INC, "$gpath/lib/perl");
25
26require Grid::GPT::Setup;
27
28my $globusdir = $gpath;
29my $setupdir = "$globusdir/setup/globus";
30my $myname = "setup-openssh.pl";
31
32#
33# Set up path prefixes for use in the path translations
34#
35
36$prefix = ${globusdir};
37$exec_prefix = "${prefix}";
38$bindir = "${exec_prefix}/bin";
39$sbindir = "${exec_prefix}/sbin";
40$mandir = "${prefix}/man";
41$mansubdir = "man";
42$libexecdir = "${exec_prefix}/libexec";
43$sysconfdir = "/etc/ssh";
44$piddir = "/var/run";
45$xauth_path = "/usr/bin/X11/xauth";
46
47#
48# Backup-related variables
49#
50
51$curr_time = time();
52$backupdir = "globus_backup_${curr_time}";
53$confbackupdir = "$backupdir/s1_conf";
54$transbackupdir = "$backupdir/s3_trans";
55
56#
57# We need to make sure it's okay to copy our setup files (if some files are already
58# present). If we do copy any files, we backup the old files so the user can (possibly)
59# reverse any damage.
60#
61
62sub test_dirs
63{
64 my $composite;
65
66 print "\nPreparatory: checking for existence of critical directories\n";
67
68 #
69 # Remember to put in check for /etc
70 #
71
72 #
73 # Test for /etc/ssh
74 #
75
76 $composite = $sysconfdir;
77 if ( ! -d "$composite" )
78 {
79 print "Could not find directory: '${composite}'.. creating.\n";
80 mkdir($composite, 16877);
81 # 16877 should be 755, or drwxr-xr-x
82 }
83
84 #
85 # Test for /etc/ssh/globus_backup_<curr>
86 #
87
88 $composite = "$sysconfdir/$backupdir";
89 if ( ! -d "${composite}" )
90 {
91 print "Could not find directory: '${composite}'.. creating.\n";
92 mkdir($composite, 16877);
93 }
94
95 #
96 # Test for /etc/ssh/globus_backup_<curr>/s1_conf
97 #
98
99 $composite = "$sysconfdir/$confbackupdir";
100 if ( ! -d "${composite}" )
101 {
102 print "Could not find directory: '${composite}'.. creating.\n";
103 mkdir($composite, 16877);
104 }
105
106 #
107 # Test for /etc/ssh/globus_backup_<curr>/s2_trans
108 #
109
110 $composite = "$sysconfdir/$transbackupdir";
111 if ( ! -d "${composite}" )
112 {
113 print "Could not find directory: '${composite}'.. creating.\n";
114 mkdir($composite, 16877);
115 }
116
117 return 0;
118}
119
120sub copy_setup_files
121{
122 my $response;
123
124 print "\nStage 1: Copying configuration files into '${sysconfdir}'..\n";
125
126 $response = "y";
127 if ( -e "${sysconfdir}/ssh_config" )
128 {
129 $response = query_boolean("${sysconfdir}/ssh_config already exists. Overwrite?", "n");
130 if ($response eq "y")
131 {
132 action("cp ${sysconfdir}/ssh_config ${sysconfdir}/${confbackupdir}/ssh_config");
133 }
134 }
135
136 if ($response eq "y")
137 {
138 action("cp ${globusdir}/setup/globus/ssh_config ${sysconfdir}/ssh_config");
139 }
140
141 #
142 # Reset response for our new query
143 #
144
145 $response = "y";
146 if ( -e "${sysconfdir}/sshd_config" )
147 {
148 $response = query_boolean("${sysconfdir}/sshd_config already exists. Overwrite?", "n");
149 if ($response eq "y")
150 {
151 action("cp ${sysconfdir}/sshd_config ${sysconfdir}/${confbackupdir}/sshd_config");
152 }
153 }
154
155 if ($response eq "y")
156 {
157 action("cp ${globusdir}/setup/globus/sshd_config ${sysconfdir}/sshd_config");
158 }
159
160 #
161 # Reset response for our new query
162 #
163
164 $response = "y";
165 if ( -e "${sysconfdir}/moduli" )
166 {
167 $response = query_boolean("${sysconfdir}/moduli already exists. Overwrite?", "n");
168 if ($response eq "y")
169 {
170 action("cp ${sysconfdir}/moduli ${sysconfdir}/${confbackupdir}/moduli");
171 }
172 }
173
174 if ($response eq "y")
175 {
176 action("cp ${globusdir}/setup/globus/moduli ${sysconfdir}/moduli");
177 }
178}
179
180sub runkeygen
181{
182 print "\nStage 2: Generating ssh host keys..\n";
183
184 if ( ! -d "${sysconfdir}" )
185 {
186 print "Could not find ${sysconfdir} directory... creating\n";
187 mkdir($sysconfdir, 16877);
188 # 16877 should be 755, or drwxr-xr-x
189 }
190
191 if ( -e "${sysconfdir}/ssh_host_key" )
192 {
193 print "${sysconfdir}/ssh_host_key already exists, skipping.\n";
194 }
195 else
196 {
197 # if $sysconfdir/ssh_host_key doesn't exist..
198 action("$bindir/ssh-keygen -t rsa1 -f $sysconfdir/ssh_host_key -N \"\"");
199 }
200
201 if ( -e "${sysconfdir}/ssh_host_dsa_key" )
202 {
203 print "${sysconfdir}/ssh_host_dsa_key already exists, skipping.\n";
204 }
205 else
206 {
207 # if $sysconfdir/ssh_host_dsa_key doesn't exist..
208 action("$bindir/ssh-keygen -t dsa -f $sysconfdir/ssh_host_dsa_key -N \"\"");
209 }
210
211 if ( -e "${sysconfdir}/ssh_host_rsa_key" )
212 {
213 print "${sysconfdir}/ssh_host_rsa_key already exists, skipping.\n";
214 }
215 else
216 {
217 # if $sysconfdir/ssh_host_rsa_key doesn't exist..
218 action("$bindir/ssh-keygen -t rsa -f $sysconfdir/ssh_host_rsa_key -N \"\"");
219 }
220
221 return 0;
222}
223
224sub fixpaths
225{
226 my $g, $h;
227
228 #
229 # Set up path translations for the installation files
230 #
231
232 %def = (
233 "/etc/ssh_config" => "${sysconfdir}/ssh_config",
234 "/etc/ssh_known_hosts" => "${sysconfdir}/ssh_known_hosts",
235 "/etc/sshd_config" => "${sysconfdir}/sshd_config",
236 "/usr/libexec" => "${libexecdir}",
237 "/etc/shosts.equiv" => "${sysconfdir}/shosts.equiv",
238 "/etc/ssh_host_key" => "${sysconfdir}/ssh_host_key",
239 "/etc/ssh_host_dsa_key" => "${sysconfdir}/ssh_host_dsa_key",
240 "/etc/ssh_host_rsa_key" => "${sysconfdir}/ssh_host_rsa_key",
241 "/var/run/sshd.pid" => "${piddir}/sshd.pid",
242 "/etc/moduli" => "${sysconfdir}/moduli",
243 "/etc/sshrc" => "${sysconfdir}/sshrc",
244 "/usr/X11R6/bin/xauth" => "${xauth_path}",
245 "/usr/bin:/bin:/usr/sbin:/sbin" => "/usr/bin:/bin:/usr/sbin:/sbin:${bindir}",
246 "(/path/to/scp.real)" => "${bindir}/scp.real",
247 "(/path/to/ssh)" => "${bindir}/ssh",
248 "(/path/to/sftp.real)" => "${bindir}/sftp.real",
249 "(/path/to/sshd.real)" => "${sbindir}/sshd.real",
250 "(/path/to/ssh_config)" => "${sysconfdir}/ssh_config",
251 "(/path/to/sshd_config)" => "${sysconfdir}/sshd_config",
252 );
253
254 #
255 # Files on which to perform path translations
256 #
257
258 %files = (
259 "${bindir}/scp" => 0,
260 "${bindir}/sftp" => 0,
261 "${sbindir}/sshd" => 0,
262 "${sysconfdir}/ssh_config" => 1,
263 "${sysconfdir}/sshd_config" => 1,
264 "${sysconfdir}/moduli" => 1,
265 "${mandir}/${mansubdir}1/scp.1" => 0,
266 "${mandir}/${mansubdir}1/ssh-add.1" => 0,
267 "${mandir}/${mansubdir}1/ssh-agent.1" => 0,
268 "${mandir}/${mansubdir}1/ssh-keygen.1" => 0,
269 "${mandir}/${mansubdir}1/ssh-keyscan.1" => 0,
270 "${mandir}/${mansubdir}1/ssh.1" => 0,
271 "${mandir}/${mansubdir}8/sshd.8" => 0,
272 "${mandir}/${mansubdir}8/sftp-server.8" => 0,
273 "${mandir}/${mansubdir}1/sftp.1" => 0,
274 );
275
276 print "\nStage 3: Translating strings in config and man files...\n";
277
278 for my $f (keys %files)
279 {
280 $f =~ /(.*\/)*(.*)$/;
281
282 #
283 # we really should create a random filename and make sure that it
284 # doesn't already exist (based off current time_t or something)
285 #
286
287 $g = "$f.tmp";
288
289 #
290 # get the filename for $f and place it in $h.
291 #
292
293 $h = $f;
294 $h =~ s#^.*/##;
295
296 #
297 # Grab the current mode/uid/gid for use later
298 #
299
300 $mode = (stat($f))[2];
301 $uid = (stat($f))[4];
302 $gid = (stat($f))[5];
303
304 #
305 # Move $f into a .tmp file for the translation step
306 #
307
308 $result = system("mv $f $g 2>&1");
309 if ($result or $?)
310 {
311 die "ERROR: Unable to execute command: $!\n";
312 }
313
314 #
315 # Create a backup of this file if it's flagged
316 #
317
318 if ($files{$f} == 1)
319 {
320 $result = system("cp $g ${sysconfdir}/${transbackupdir}/$h 2>&1");
321
322 if ($result or $?)
323 {
324 die "ERROR: Unable to execute command: $!\n";
325 }
326 }
327
328 open(IN, "<$g") || die ("$0: input file $g missing!\n");
329 open(OUT, ">$f") || die ("$0: unable to open output file $f!\n");
330
331 while (<IN>)
332 {
333 for $s (keys(%def))
334 {
335 s#$s#$def{$s}#;
336 } # for $s
337 print OUT "$_";
338 } # while <IN>
339
340 close(OUT);
341 close(IN);
342
343 #
344 # Remove the old .tmp file
345 #
346
347 $result = system("rm $g 2>&1");
348
349 if ($result or $?)
350 {
351 die "ERROR: Unable to execute command: $!\n";
352 }
353
354 #
355 # An attempt to revert the new file back to the original file's
356 # mode/uid/gid
357 #
358
359 chmod($mode, $f);
360 chown($uid, $gid, $f);
361 } # for $f
362
363 print "complete.\n";
364
365 return 0;
366}
367
368print "------------------------------------------------------\n";
369print "$myname: Configuring package 'gsi_openssh'..\n";
370print "\n";
371print "--> NOTE: Run this as root for the intended effect. <--\n";
372
373test_dirs();
374copy_setup_files();
375runkeygen();
376fixpaths();
377
378my $metadata = new Grid::GPT::Setup(package_name => "gsi_openssh_setup");
379
380$metadata->finish();
381
382print "\n";
383print "$myname: Finished configuring package 'gsi_openssh'.\n";
384print "------------------------------------------------------\n";
385
386#
387# Just need a minimal action() subroutine for now..
388#
389
390sub action
391{
392 my ($command) = @_;
393
394 printf "$command\n";
395
396 my $result = system("$command 2>&1");
397
398 if (($result or $?) and $command !~ m!patch!)
399 {
400 die "ERROR: Unable to execute command: $!\n";
401 }
402}
403
404sub query_boolean
405{
406 my ($query_text, $default) = @_;
407 my $nondefault, $foo, $bar;
408
409 #
410 # Set $nondefault to the boolean opposite of $default.
411 #
412
413 if ($default eq "n")
414 {
415 $nondefault = "y";
416 }
417 else
418 {
419 $nondefault = "n";
420 }
421
422 print "${query_text} ";
423 print "[$default] ";
424
425 $foo = <STDIN>;
426 ($bar) = split //, $foo;
427
428 if ($bar ne $nondefault)
429 {
430 $bar = $default;
431 }
432
433 return $bar;
434}
435
This page took 0.085549 seconds and 5 git commands to generate.