]> andersk Git - gssapi-openssh.git/blob - setup/setup-openssh.pl
917f53d1258191c472eae0c74c2e80552ec129fa
[gssapi-openssh.git] / setup / setup-openssh.pl
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};
14 if (!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
26 require Grid::GPT::Setup;
27
28 my $globusdir = $gpath;
29 my $setupdir = "$globusdir/setup/globus";
30 my $myname = "setup-openssh.pl";
31
32 print "$myname: Configuring package 'gsi_openssh'...\n";
33
34 #
35 # Set up path prefixes for use in the path translations
36 #
37
38 $prefix = ${globusdir};
39 $exec_prefix = "${prefix}";
40 $bindir = "${exec_prefix}/bin";
41 $sbindir = "${exec_prefix}/sbin";
42 $mandir = "${prefix}/man";
43 $mansubdir = "man";
44 $libexecdir = "${exec_prefix}/libexec";
45 $sysconfdir = "${prefix}/etc";
46 $piddir = "/var/run";
47 $xauth_path = "/usr/bin/X11/xauth";
48
49 sub fixpaths
50 {
51     #
52     # Set up path translations for the installation files
53     #
54
55     %def = (
56         "/etc/ssh_config" => "${sysconfdir}/ssh_config",
57         "/etc/ssh_known_hosts" => "${sysconfdir}/ssh_known_hosts",
58         "/etc/sshd_config" => "${sysconfdir}/sshd_config",
59         "/usr/libexec" => "${libexecdir}",
60         "/etc/shosts.equiv" => "${sysconfdir}/shosts.equiv",
61         "/etc/ssh_host_key" => "${sysconfdir}/ssh_host_key",
62         "/etc/ssh_host_dsa_key" => "${sysconfdir}/ssh_host_dsa_key",
63         "/etc/ssh_host_rsa_key" => "${sysconfdir}/ssh_host_rsa_key",
64         "/var/run/sshd.pid" => "${piddir}/sshd.pid",
65         "/etc/moduli" => "${sysconfdir}/moduli",
66         "/etc/sshrc" => "${sysconfdir}/sshrc",
67         "/usr/X11R6/bin/xauth" => "${xauth_path}",
68         "/usr/bin:/bin:/usr/sbin:/sbin" => "/usr/bin:/bin:/usr/sbin:/sbin:${bindir}",
69         "/path/to/scp.real" => "${bindir}/scp.real",
70         "/path/to/ssh" => "${bindir}/ssh",
71         "/path/to/sftp.real" => "${bindir}/sftp.real",
72         "/path/to/sshd.real" => "${sbindir}/sshd.real",
73         "/path/to/ssh_config" => "${sysconfdir}/ssh_config",
74         "/path/to/sshd_config" => "${sysconfdir}/sshd_config",
75         );
76
77     #
78     # Files on which to perform path translations
79     #
80
81     @files = (
82         "${bindir}/scp",
83         "${bindir}/sftp",
84         "${sbindir}/sshd",
85         "${sysconfdir}/ssh_config",
86         "${sysconfdir}/sshd_config",
87         "${sysconfdir}/moduli",
88         "${mandir}/${mansubdir}1/scp.1",
89         "${mandir}/${mansubdir}1/ssh-add.1",
90         "${mandir}/${mansubdir}1/ssh-agent.1",
91         "${mandir}/${mansubdir}1/ssh-keygen.1",
92         "${mandir}/${mansubdir}1/ssh-keyscan.1",
93         "${mandir}/${mansubdir}1/ssh.1",
94         "${mandir}/${mansubdir}8/sshd.8",
95         "${mandir}/${mansubdir}8/sftp-server.8",
96         "${mandir}/${mansubdir}1/sftp.1",
97         );
98
99     print "Translating strings in config/man files...\n";
100     for $f (@files)
101     {
102         $f =~ /(.*\/)*(.*)$/;
103
104         #
105         # we really should create a random filename and make sure that it
106         # doesn't already exist (based off current time_t or something)
107         #
108
109         $g = "$f.tmp";
110
111         #
112         # Grab the current mode/uid/gid for use later
113         #
114
115         $mode = (stat($f))[2];
116         $uid = (stat($f))[4];
117         $gid = (stat($f))[5];
118
119         $result = system("mv $f $g");
120         if ($result != 0)
121         {
122             die "Failed to copy $f to $g!\n";
123         }
124
125         open(IN, "<$g") || die ("$0: input file $g missing!\n");
126         open(OUT, ">$f") || die ("$0: unable to open output file $f!\n");
127
128         while (<IN>)
129         {
130             for $s (keys(%def))
131             {
132                 s#$s#$def{$s}#;
133             } # for $s
134             print OUT "$_";
135         } # while <IN>
136
137         close(OUT);
138         close(IN);
139
140         $result = system("rm $g");
141         if ($result != 0)
142         {
143             die "Failed to remove $g\n";
144         }
145
146         #
147         # An attempt to revert the new file back to the original file's
148         # mode/uid/gid
149         #
150
151         chmod($mode, $f);
152         chown($uid, $gid, $f);
153     } # for $f
154
155     return 0;
156 }
157
158 fixpaths();
159
160 print "---------------------------------------------------------------------\n";
161 print "If you would also like to run the sshd binary that came with this\n";
162 print "package and you do not have host keys located in /etc, run (as root):\n";
163 print "\n";
164 print "  $setupdir/setup-openssh-keys\n";
165 print "\n";
166 print "This script creates machine-specific host keys in /etc that are\n";
167 print "required by sshd.\n";
168 print "---------------------------------------------------------------------\n";
169
170 my $metadata = new Grid::GPT::Setup(package_name => "gsi_openssh_setup");
171
172 $metadata->finish();
173
174 print "$myname: Finished configuring package 'gsi_openssh'.\n";
This page took 0.204996 seconds and 3 git commands to generate.