]> andersk Git - gssapi-openssh.git/blob - setup/setup-openssh.pl
Fix file mode/uid/gid after they've been 'translated' by gsi-ssh setup script.
[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 $mandir = "${prefix}/man";
42 $mansubdir = "man";
43 $libexecdir = "${exec_prefix}/libexec";
44 $sysconfdir = "${prefix}/etc";
45 $piddir = "/var/run";
46 $xauth_path = "/usr/bin/X11/xauth";
47
48 sub fixpaths
49 {
50     #
51     # Set up path translations for the installation files
52     #
53
54     %def = (
55         "/etc/ssh_config" => "${sysconfdir}/ssh_config",
56         "/etc/ssh_known_hosts" => "${sysconfdir}/ssh_known_hosts",
57         "/etc/sshd_config" => "${sysconfdir}/sshd_config",
58         "/usr/libexec" => "${libexecdir}",
59         "/etc/shosts.equiv" => "${sysconfdir}/shosts.equiv",
60         "/etc/ssh_host_key" => "${sysconfdir}/ssh_host_key",
61         "/etc/ssh_host_dsa_key" => "${sysconfdir}/ssh_host_dsa_key",
62         "/etc/ssh_host_rsa_key" => "${sysconfdir}/ssh_host_rsa_key",
63         "/var/run/sshd.pid" => "${piddir}/sshd.pid",
64         "/etc/moduli" => "${sysconfdir}/moduli",
65         "/etc/sshrc" => "${sysconfdir}/sshrc",
66         "/usr/X11R6/bin/xauth" => "${xauth_path}",
67         "/usr/bin:/bin:/usr/sbin:/sbin" => "/usr/bin:/bin:/usr/sbin:/sbin:${bindir}",
68         "/path/to/scp.real" => "${bindir}/scp.real",
69         "/path/to/ssh" => "${bindir}/ssh",
70         );
71
72     #
73     # Files on which to perform path translations
74     #
75
76     @files = (
77         "${bindir}/scp",
78         "${sysconfdir}/ssh_config",
79         "${sysconfdir}/sshd_config",
80         "${sysconfdir}/moduli",
81         "${mandir}/${mansubdir}1/scp.1",
82         "${mandir}/${mansubdir}1/ssh-add.1",
83         "${mandir}/${mansubdir}1/ssh-agent.1",
84         "${mandir}/${mansubdir}1/ssh-keygen.1",
85         "${mandir}/${mansubdir}1/ssh-keyscan.1",
86         "${mandir}/${mansubdir}1/ssh.1",
87         "${mandir}/${mansubdir}8/sshd.8",
88         "${mandir}/${mansubdir}8/sftp-server.8",
89         "${mandir}/${mansubdir}1/sftp.1",
90         );
91
92     print "Translating strings in config/man files...\n";
93     for $f (@files)
94     {
95         $f =~ /(.*\/)*(.*)$/;
96
97         #
98         # we really should create a random filename and make sure that it
99         # doesn't already exist (based off current time_t or something)
100         #
101
102         $g = "$f.tmp";
103
104         #
105         # Grab the current mode/uid/gid for use later
106         #
107
108         $mode = (stat($f))[2];
109         $uid = (stat($f))[4];
110         $gid = (stat($f))[5];
111
112         $result = system("mv $f $g");
113         if ($result != 0)
114         {
115             die "Failed to copy $f to $g!\n";
116         }
117
118         open(IN, "<$g") || die ("$0: input file $g missing!\n");
119         open(OUT, ">$f") || die ("$0: unable to open output file $f!\n");
120
121         while (<IN>)
122         {
123             for $s (keys(%def))
124             {
125                 s#$s#$def{$s}#;
126             } # for $s
127             print OUT "$_";
128         } # while <IN>
129
130         close(OUT);
131         close(IN);
132
133         $result = system("rm $g");
134         if ($result != 0)
135         {
136             die "Failed to remove $g\n";
137         }
138
139         #
140         # An attempt to revert the new file back to the original file's
141         # mode/uid/gid
142         #
143
144         chmod($mode, $f);
145         chown($uid, $gid, $f);
146     } # for $f
147
148     return 0;
149 }
150
151 sub runkeygen
152 {
153     print "Generating ssh keys (if necessary)...\n";
154     if ( -e "${sysconfdir}/ssh_host_key" )
155     {
156         print "${sysconfdir}/ssh_host_key already exists, skipping.\n";
157     }
158     else
159     {
160         # if $sysconfdir/ssh_host_key doesn't exist..
161         system("$bindir/ssh-keygen -t rsa1 -f $sysconfdir/ssh_host_key -N \"\"");
162     }
163
164     if ( -e "${sysconfdir}/ssh_host_dsa_key" )
165     {
166         print "${sysconfdir}/ssh_host_dsa_key already exists, skipping.\n";
167     }
168     else
169     {
170         # if $sysconfdir/ssh_host_dsa_key doesn't exist..
171         system("$bindir/ssh-keygen -t dsa -f $sysconfdir/ssh_host_dsa_key -N \"\"");
172     }
173
174     if ( -e "${sysconfdir}/ssh_host_rsa_key" )
175     {
176         print "${sysconfdir}/ssh_host_rsa_key already exists, skipping.\n";
177     }
178     else
179     {
180         # if $sysconfdir/ssh_host_rsa_key doesn't exist..
181         system("$bindir/ssh-keygen -t rsa -f $sysconfdir/ssh_host_rsa_key -N \"\"");
182     }
183
184     return 0;
185 }
186
187 fixpaths();
188 runkeygen();
189
190 my $metadata = new Grid::GPT::Setup(package_name => "gsi-openssh-setup");
191
192 $metadata->finish();
This page took 0.060759 seconds and 5 git commands to generate.