]>
Commit | Line | Data |
---|---|---|
20d3226a | 1 | # |
1eab725d | 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. | |
701aa556 | 6 | # |
1eab725d | 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> | |
701aa556 | 11 | # |
20d3226a | 12 | |
4f276ad7 | 13 | $gpath = $ENV{GLOBUS_LOCATION}; |
ad71c979 | 14 | if (!defined($gpath)) |
15 | { | |
53a54c67 | 16 | die "GLOBUS_LOCATION needs to be set before running this script" |
ad71c979 | 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 | ||
4f276ad7 | 26 | require Grid::GPT::Setup; |
27 | ||
ad71c979 | 28 | my $globusdir = $gpath; |
29 | my $setupdir = "$globusdir/setup/globus"; | |
30 | my $myname = "setup-openssh.pl"; | |
31 | ||
9ef2f439 | 32 | print "$myname: Configuring package 'gsi_openssh'...\n"; |
1a1f62a4 | 33 | print "Run this as root for the intended effect...\n"; |
ad71c979 | 34 | |
20d3226a | 35 | # |
36 | # Set up path prefixes for use in the path translations | |
37 | # | |
38 | ||
d0a1bda7 | 39 | $prefix = ${globusdir}; |
40 | $exec_prefix = "${prefix}"; | |
41 | $bindir = "${exec_prefix}/bin"; | |
7c25a6d7 | 42 | $sbindir = "${exec_prefix}/sbin"; |
d0a1bda7 | 43 | $mandir = "${prefix}/man"; |
44 | $mansubdir = "man"; | |
45 | $libexecdir = "${exec_prefix}/libexec"; | |
1a1f62a4 | 46 | $sysconfdir = "/etc/ssh"; |
20d3226a | 47 | $piddir = "/var/run"; |
48 | $xauth_path = "/usr/bin/X11/xauth"; | |
49 | ||
1a1f62a4 | 50 | # |
ac083f7a | 51 | # We need to make sure it's okay to copy our setup files (if some files are already |
52 | # present). If we do copy any files, we backup the old files so the user can (possibly) | |
53 | # reverse any damage. | |
1a1f62a4 | 54 | # |
55 | ||
ac083f7a | 56 | sub copy_setup_files |
1a1f62a4 | 57 | { |
ac083f7a | 58 | my $response, $curr_time; |
1a1f62a4 | 59 | |
ac083f7a | 60 | $curr_time = time(); |
1a1f62a4 | 61 | |
ac083f7a | 62 | $response = "y"; |
1a1f62a4 | 63 | if ( -e "${sysconfdir}/ssh_config" ) |
64 | { | |
ac083f7a | 65 | $response = query_boolean("${sysconfdir}/ssh_config already exists. Overwrite? ", "n"); |
1a1f62a4 | 66 | } |
ac083f7a | 67 | |
68 | if ($response eq "y") | |
1a1f62a4 | 69 | { |
ac083f7a | 70 | action("cp ${sysconfdir}/ssh_config ${sysconfdir}/ssh_config.bak_${curr_time}"); |
1a1f62a4 | 71 | action("cp ${globusdir}/setup/globus/ssh_config ${sysconfdir}/ssh_config"); |
72 | } | |
73 | ||
ac083f7a | 74 | # |
75 | # Reset response for our new query | |
76 | # | |
77 | ||
78 | $response = "y"; | |
1a1f62a4 | 79 | if ( -e "${sysconfdir}/sshd_config" ) |
80 | { | |
ac083f7a | 81 | $response = query_boolean("${sysconfdir}/sshd_config already exists. Overwrite? ", "n"); |
1a1f62a4 | 82 | } |
ac083f7a | 83 | |
84 | if ($response eq "y") | |
1a1f62a4 | 85 | { |
ac083f7a | 86 | action("cp ${sysconfdir}/sshd_config ${sysconfdir}/sshd_config.bak_${curr_time}"); |
1a1f62a4 | 87 | action("cp ${globusdir}/setup/globus/sshd_config ${sysconfdir}/sshd_config"); |
88 | } | |
ac083f7a | 89 | |
90 | # | |
91 | # Reset response for our new query | |
92 | # | |
93 | ||
94 | $response = "y"; | |
95 | if ( -e "${sysconfdir}/moduli" ) | |
96 | { | |
97 | $response = query_boolean("${sysconfdir}/moduli already exists. Overwrite? ", "n"); | |
98 | } | |
99 | ||
100 | if ($response eq "y") | |
101 | { | |
102 | action("cp ${sysconfdir}/moduli ${sysconfdir}/moduli.bak_${curr_time}"); | |
103 | action("cp ${globusdir}/setup/globus/moduli ${sysconfdir}/moduli"); | |
104 | } | |
1a1f62a4 | 105 | } |
106 | ||
107 | sub runkeygen | |
108 | { | |
109 | if ( ! -d "${sysconfdir}" ) | |
110 | { | |
111 | print "Could not find ${sysconfdir} directory... creating\n"; | |
27b0f197 | 112 | mkdir($sysconfdir, 16877); |
113 | # 16877 should be 755, or drwxr-xr-x | |
1a1f62a4 | 114 | } |
115 | ||
116 | print "Generating ssh keys (if necessary)...\n"; | |
117 | if ( -e "${sysconfdir}/ssh_host_key" ) | |
118 | { | |
119 | print "${sysconfdir}/ssh_host_key already exists, skipping.\n"; | |
120 | } | |
121 | else | |
122 | { | |
123 | # if $sysconfdir/ssh_host_key doesn't exist.. | |
11b9a41c | 124 | action("$bindir/ssh-keygen -t rsa1 -f $sysconfdir/ssh_host_key -N \"\""); |
1a1f62a4 | 125 | } |
126 | ||
127 | if ( -e "${sysconfdir}/ssh_host_dsa_key" ) | |
128 | { | |
129 | print "${sysconfdir}/ssh_host_dsa_key already exists, skipping.\n"; | |
130 | } | |
131 | else | |
132 | { | |
133 | # if $sysconfdir/ssh_host_dsa_key doesn't exist.. | |
11b9a41c | 134 | action("$bindir/ssh-keygen -t dsa -f $sysconfdir/ssh_host_dsa_key -N \"\""); |
1a1f62a4 | 135 | } |
136 | ||
137 | if ( -e "${sysconfdir}/ssh_host_rsa_key" ) | |
138 | { | |
139 | print "${sysconfdir}/ssh_host_rsa_key already exists, skipping.\n"; | |
140 | } | |
141 | else | |
142 | { | |
143 | # if $sysconfdir/ssh_host_rsa_key doesn't exist.. | |
11b9a41c | 144 | action("$bindir/ssh-keygen -t rsa -f $sysconfdir/ssh_host_rsa_key -N \"\""); |
1a1f62a4 | 145 | } |
146 | ||
147 | return 0; | |
148 | } | |
149 | ||
20d3226a | 150 | sub fixpaths |
151 | { | |
152 | # | |
153 | # Set up path translations for the installation files | |
154 | # | |
155 | ||
156 | %def = ( | |
157 | "/etc/ssh_config" => "${sysconfdir}/ssh_config", | |
158 | "/etc/ssh_known_hosts" => "${sysconfdir}/ssh_known_hosts", | |
159 | "/etc/sshd_config" => "${sysconfdir}/sshd_config", | |
160 | "/usr/libexec" => "${libexecdir}", | |
161 | "/etc/shosts.equiv" => "${sysconfdir}/shosts.equiv", | |
162 | "/etc/ssh_host_key" => "${sysconfdir}/ssh_host_key", | |
163 | "/etc/ssh_host_dsa_key" => "${sysconfdir}/ssh_host_dsa_key", | |
164 | "/etc/ssh_host_rsa_key" => "${sysconfdir}/ssh_host_rsa_key", | |
165 | "/var/run/sshd.pid" => "${piddir}/sshd.pid", | |
166 | "/etc/moduli" => "${sysconfdir}/moduli", | |
167 | "/etc/sshrc" => "${sysconfdir}/sshrc", | |
168 | "/usr/X11R6/bin/xauth" => "${xauth_path}", | |
169 | "/usr/bin:/bin:/usr/sbin:/sbin" => "/usr/bin:/bin:/usr/sbin:/sbin:${bindir}", | |
44c96d90 | 170 | "(/path/to/scp.real)" => "${bindir}/scp.real", |
171 | "(/path/to/ssh)" => "${bindir}/ssh", | |
172 | "(/path/to/sftp.real)" => "${bindir}/sftp.real", | |
173 | "(/path/to/sshd.real)" => "${sbindir}/sshd.real", | |
174 | "(/path/to/ssh_config)" => "${sysconfdir}/ssh_config", | |
175 | "(/path/to/sshd_config)" => "${sysconfdir}/sshd_config", | |
20d3226a | 176 | ); |
177 | ||
20d3226a | 178 | # |
179 | # Files on which to perform path translations | |
180 | # | |
181 | ||
1a1f62a4 | 182 | %files = ( |
11b9a41c | 183 | "${bindir}/scp" => 0, |
184 | "${bindir}/sftp" => 0, | |
185 | "${sbindir}/sshd" => 0, | |
186 | "${sysconfdir}/ssh_config" => 1, | |
187 | "${sysconfdir}/sshd_config" => 1, | |
188 | "${sysconfdir}/moduli" => 1, | |
189 | "${mandir}/${mansubdir}1/scp.1" => 0, | |
190 | "${mandir}/${mansubdir}1/ssh-add.1" => 0, | |
191 | "${mandir}/${mansubdir}1/ssh-agent.1" => 0, | |
192 | "${mandir}/${mansubdir}1/ssh-keygen.1" => 0, | |
193 | "${mandir}/${mansubdir}1/ssh-keyscan.1" => 0, | |
194 | "${mandir}/${mansubdir}1/ssh.1" => 0, | |
195 | "${mandir}/${mansubdir}8/sshd.8" => 0, | |
196 | "${mandir}/${mansubdir}8/sftp-server.8" => 0, | |
197 | "${mandir}/${mansubdir}1/sftp.1" => 0, | |
20d3226a | 198 | ); |
199 | ||
4f276ad7 | 200 | print "Translating strings in config/man files...\n"; |
1a1f62a4 | 201 | for my $f (keys %files) |
20d3226a | 202 | { |
203 | $f =~ /(.*\/)*(.*)$/; | |
7536fc6f | 204 | |
205 | # | |
206 | # we really should create a random filename and make sure that it | |
207 | # doesn't already exist (based off current time_t or something) | |
208 | # | |
209 | ||
d0a1bda7 | 210 | $g = "$f.tmp"; |
20d3226a | 211 | |
7536fc6f | 212 | # |
213 | # Grab the current mode/uid/gid for use later | |
214 | # | |
215 | ||
216 | $mode = (stat($f))[2]; | |
217 | $uid = (stat($f))[4]; | |
218 | $gid = (stat($f))[5]; | |
219 | ||
1a1f62a4 | 220 | action("mv $f $g"); |
20d3226a | 221 | |
d0a1bda7 | 222 | open(IN, "<$g") || die ("$0: input file $g missing!\n"); |
223 | open(OUT, ">$f") || die ("$0: unable to open output file $f!\n"); | |
224 | ||
225 | while (<IN>) | |
226 | { | |
227 | for $s (keys(%def)) | |
20d3226a | 228 | { |
d0a1bda7 | 229 | s#$s#$def{$s}#; |
230 | } # for $s | |
231 | print OUT "$_"; | |
232 | } # while <IN> | |
20d3226a | 233 | |
d0a1bda7 | 234 | close(OUT); |
20d3226a | 235 | close(IN); |
d0a1bda7 | 236 | |
1a1f62a4 | 237 | if ($file{$f} eq 0) |
238 | { | |
239 | action("rm $g"); | |
240 | } | |
241 | else | |
d0a1bda7 | 242 | { |
1a1f62a4 | 243 | print "Left backup config file '$g'\n"; |
d0a1bda7 | 244 | } |
7536fc6f | 245 | |
246 | # | |
247 | # An attempt to revert the new file back to the original file's | |
248 | # mode/uid/gid | |
249 | # | |
250 | ||
251 | chmod($mode, $f); | |
252 | chown($uid, $gid, $f); | |
20d3226a | 253 | } # for $f |
254 | ||
255 | return 0; | |
256 | } | |
257 | ||
11b9a41c | 258 | copy_setup_files(); |
1a1f62a4 | 259 | runkeygen(); |
11b9a41c | 260 | fixpaths(); |
ad71c979 | 261 | |
472ec086 | 262 | my $metadata = new Grid::GPT::Setup(package_name => "gsi_openssh_setup"); |
4f276ad7 | 263 | |
53a54c67 | 264 | $metadata->finish(); |
9ef2f439 | 265 | |
266 | print "$myname: Finished configuring package 'gsi_openssh'.\n"; | |
ac083f7a | 267 | |
268 | # | |
269 | # Just need a minimal action() subroutine for now.. | |
270 | # | |
271 | ||
272 | sub action | |
273 | { | |
274 | my ($command) = @_; | |
275 | ||
276 | printf "$command\n"; | |
277 | ||
278 | my $result = system("$command 2>&1"); | |
279 | ||
280 | if (($result or $?) and $command !~ m!patch!) | |
281 | { | |
282 | die "ERROR: Unable to execute command: $!\n"; | |
283 | } | |
284 | } | |
285 | ||
286 | sub query_boolean | |
287 | { | |
288 | my ($query_text, $default) = @_; | |
289 | my $nondefault, $foo, $bar; | |
290 | ||
291 | # | |
292 | # Set $nondefault to the boolean opposite of $default. | |
293 | # | |
294 | ||
295 | if ($default eq "n") | |
296 | { | |
297 | $nondefault = "y"; | |
298 | } | |
299 | else | |
300 | { | |
301 | $nondefault = "n"; | |
302 | } | |
303 | ||
304 | print "${query_text} "; | |
305 | print "[$default] "; | |
306 | ||
307 | $foo = getc(STDIN); | |
308 | $bar = <STDIN>; | |
309 | ||
310 | if ($foo ne $nondefault) | |
311 | { | |
312 | $foo = $default; | |
313 | } | |
314 | ||
315 | return $foo; | |
316 | } | |
317 |