summaryrefslogtreecommitdiffstats
path: root/pki/base/common/scripts/pkicomplete
blob: 083475ce4eaa773c447c8ecfea53739c7e6050ae (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
#!/usr/bin/perl
#
# --- BEGIN COPYRIGHT BLOCK ---
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; version 2 of the License.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#
# Copyright (C) 2007 Red Hat, Inc.
# All rights reserved.
# --- END COPYRIGHT BLOCK ---
#

##############################################################
# This script is used to complete setting up the framework
# that is required prior to creating various PKI instances.
#
# Objects placed in here consist of items that can only be
# determined at runtime (not at buildtime).
#
#     NOTE:  The steps completed by this script are only
#            needed by non-TPS (Java-based) PKI subsystems.
#
# Sample Invocation (for CA, KRA, OCSP, or TKS):
#
#    ./pkicomplete
#
##############################################################


##############################################################
# Perl Version
##############################################################

my $MINIMUM_PERL_VERSION = "5.006001";

my $perl_version_error_message = "ERROR:  Using Perl version $] ...\n"
                               . "        Must use Perl version "
                               . "$MINIMUM_PERL_VERSION or later to "
                               . "run this script!\n";

die "$perl_version_error_message" if $] < $MINIMUM_PERL_VERSION;


##############################################################
# Environment Variables
##############################################################

# untaint called subroutines
if( ( $^O ne 'Windows_NT' ) && ( $^O ne 'MSWin32' ) ) {
    $> = $<;   # set effective user ID to real UID
    $) = $(;   # set effective group ID to real GID
    $ENV{ 'PATH' } = '/bin:/usr/bin';
    $ENV{ 'ENV' } = '' if $ENV{ 'ENV' } ne '';
}


##############################################################
# Shared Common Perl Data and Subroutines
##############################################################

# Compute "flavor" of Operating System
my $pki_flavor = "";
if( $^O eq "linux" ) {
    $pki_flavor = `pkiflavor`;
} elsif( $^O eq "solaris" ) {
    $pki_flavor = `pkiflavor`;
} else {
    print( STDERR
           "ERROR:  Unsupported platform '$^O'!\n" );
    print( STDOUT "\n" );
    exit 255;
}

$pki_flavor =~ s/\s+$//g;

# Establish path to scripts
my $pki_subsystem_common_area = "/usr/share/$pki_flavor";
my $common_path = "/usr/share/pki/scripts";

if( ! -d "$common_path" ) {
    print( STDERR
           "ERROR:  The path '$common_path' does not exist!\n"
         . "        Unable to load shared Common Perl Data "
         . "and Subroutines!\n" );
    print( STDOUT "\n" );
    exit 255;
}

if( ! -e "$common_path/pkicommon" ) {
    print( STDERR
           "ERROR:  The file '$common_path/pkicommon' does not exist!\n"
         . "        Unable to load shared Common Perl Data "
         . "and Subroutines!\n" );
    print( STDOUT "\n" );
    exit 255;
}

eval( "use lib '" . $common_path . "'" );
require( 'pkicommon' );


##############################################################
# Local Constants
##############################################################

# Links created for initial "tomcat" installation that MUST exist!!!
my $jss4_common_symlink   = "/var/lib/tomcat5/common/lib/jss4.jar";
my $osutil_common_symlink = "/var/lib/tomcat5/common/lib/osutil.jar";
my $symkey_common_symlink = "/var/lib/tomcat5/common/lib/symkey.jar";
my $jss4_server_symlink   = "/var/lib/tomcat5/server/lib/jss4.jar";

# Locations of the actual files that the symlinks reference
#     first, try looking for the JSS jar file in a 32-bit directory
my $jss4_jar_file = "$default_system_jni_java_path/jss4.jar";
if (! file_exists($jss4_jar_file)) {
    # not found, try looking for it in a 32-bit dirsec directory
    $jss4_jar_file = "$default_system_jni_java_path/dirsec/jss4.jar";
    if (! file_exists($jss4_jar_file)) {
        # still not found, try looking for it in a 64-bit directory
        $jss4_jar_file = "$default_system_user_libraries/java/jss4.jar";
        if (! file_exists($jss4_jar_file)) {
            # as a last resort, try looking for it in a 64-bit dirsec directory
            $jss4_jar_file = "$default_system_user_libraries/java/dirsec/jss4.jar";
            if (! file_exists($jss4_jar_file)) {
                # unable to find 'jss4.jar' JNI file anywhere
                print( STDERR
                       "ERROR:  Unable to find a 'jss4.jar' JNI jar file!\n" );
                print( STDOUT "\n" );
                exit 255;
            }
        }
    }
}
my $osutil_jar_file = "$default_system_jni_java_path/osutil.jar";
my $symkey_jar_file = "$default_system_jni_java_path/symkey.jar";


##############################################################
# Main Program
##############################################################

# no args
# no return value
sub main()
{
    my $result          = 0;
    my $root_user       = "";
    my $root_group      = "";

    chdir( "/tmp" );

    # On Linux/UNIX, insure that this script is being run as "root".
    $result = check_for_root_UID();
    if( !$result ) {
        exit 255;
    }

    # Establish "root" usr/group based upon platform
    if( $^O eq "linux" ) {
        # Superuser and group to give to PKI installed files
        $root_user = "root";
        $root_group = "root";
    } elsif( $^O eq "solaris" ) {
        # Superuser and group to give to PKI installed files
        $root_user = "root";
        $root_group = "other";
    }

    # Complete setting up PKI framework . . .
    if( !symbolic_link_exists( $jss4_common_symlink ) ) {
        $result = create_symbolic_link( $jss4_common_symlink,
                                        $jss4_jar_file );
        if( !$result ) {
            exit 255;
        }

        $result = give_symbolic_link_to( $jss4_common_symlink,
                                         $root_user,
                                         $root_group );
        if( !$result ) {
            exit 255;
        }
    }

    if( !symbolic_link_exists( $osutil_common_symlink ) ) {
        $result = create_symbolic_link( $osutil_common_symlink,
                                        $osutil_jar_file );
        if( !$result ) {
            exit 255;
        }

        $result = give_symbolic_link_to( $osutil_common_symlink,
                                         $root_user,
                                         $root_group );
        if( !$result ) {
            exit 255;
        }
    }

    if( !symbolic_link_exists( $symkey_common_symlink ) ) {
        $result = create_symbolic_link( $symkey_common_symlink,
                                        $symkey_jar_file );
        if( !$result ) {
            exit 255;
        }

        $result = give_symbolic_link_to( $symkey_common_symlink,
                                         $root_user,
                                         $root_group );
        if( !$result ) {
            exit 255;
        }
    }

    if( !symbolic_link_exists( $jss4_server_symlink ) ) {
        $result = create_symbolic_link( $jss4_server_symlink,
                                        $jss4_jar_file );
        if( !$result ) {
            exit 255;
        }

        $result = give_symbolic_link_to( $jss4_server_symlink,
                                         $root_user,
                                         $root_group );
        if( !$result ) {
            exit 255;
        }
    }

    return;
}


##############################################################
# PKI Instance Removal
##############################################################

main();

exit 0;