2
|
1 |
#!/bin/sh
|
|
2 |
|
|
3 |
#
|
|
4 |
# Copyright 2004 Sun Microsystems, Inc. All Rights Reserved.
|
|
5 |
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
|
6 |
#
|
|
7 |
# This code is free software; you can redistribute it and/or modify it
|
|
8 |
# under the terms of the GNU General Public License version 2 only, as
|
|
9 |
# published by the Free Software Foundation.
|
|
10 |
#
|
|
11 |
# This code is distributed in the hope that it will be useful, but WITHOUT
|
|
12 |
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
13 |
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
14 |
# version 2 for more details (a copy is included in the LICENSE file that
|
|
15 |
# accompanied this code).
|
|
16 |
#
|
|
17 |
# You should have received a copy of the GNU General Public License version
|
|
18 |
# 2 along with this work; if not, write to the Free Software Foundation,
|
|
19 |
# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
20 |
#
|
|
21 |
# Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
|
|
22 |
# CA 95054 USA or visit www.sun.com if you need additional information or
|
|
23 |
# have any questions.
|
|
24 |
#
|
|
25 |
|
|
26 |
|
|
27 |
# @test
|
|
28 |
# @bug 5008047
|
|
29 |
# @summary Check password file permission for out-of-the-box management
|
|
30 |
#
|
|
31 |
# @run shell PasswordFilePermissionTest.sh
|
|
32 |
|
|
33 |
createJavaFile()
|
|
34 |
{
|
|
35 |
cat << EOF > $1/$2.java
|
|
36 |
class $2 {
|
|
37 |
public static void main(String[] args) {
|
|
38 |
System.out.println("Inside main method...");
|
|
39 |
}
|
|
40 |
}
|
|
41 |
EOF
|
|
42 |
}
|
|
43 |
|
|
44 |
createConfigFile() {
|
|
45 |
cat << EOF > $1
|
|
46 |
# management.properties
|
|
47 |
com.sun.management.jmxremote.ssl=false
|
|
48 |
com.sun.management.jmxremote.password.file=$2
|
|
49 |
EOF
|
|
50 |
}
|
|
51 |
|
|
52 |
createPasswordFile() {
|
|
53 |
if [ -f "$1" ] ; then
|
|
54 |
rm -f $1 || echo WARNING: $1 already exists - unable to remove old copy
|
|
55 |
fi
|
|
56 |
cat << EOF > $1
|
|
57 |
# jmxremote.password
|
|
58 |
EOF
|
|
59 |
}
|
|
60 |
|
|
61 |
|
|
62 |
# Check we are run from jtreg
|
|
63 |
if [ -z "${TESTCLASSES}" ]; then
|
|
64 |
echo "Test is designed to be run from jtreg only"
|
|
65 |
exit 0
|
|
66 |
fi
|
|
67 |
|
|
68 |
|
|
69 |
# Test not suitable for Windows as chmod may not be able to
|
|
70 |
# security the password file.
|
|
71 |
|
|
72 |
os=`uname -s`
|
|
73 |
if [ "$os" != "Linux" -a "$os" != "SunOS" ]; then
|
|
74 |
echo "Test not designed to run on this operating system, skipping..."
|
|
75 |
exit 0
|
|
76 |
fi
|
|
77 |
|
|
78 |
|
|
79 |
# Create configuration file and dummy password file
|
|
80 |
|
|
81 |
LIBDIR=${TESTCLASSES}/lib
|
|
82 |
CONFIG=${LIBDIR}/management.properties
|
|
83 |
PASSWD=${LIBDIR}/jmxremote.password
|
|
84 |
rm -f ${CONFIG}
|
|
85 |
rm -f ${PASSWD}
|
|
86 |
mkdir ${LIBDIR} 2>&1
|
|
87 |
createJavaFile ${TESTCLASSES} Null
|
|
88 |
createConfigFile ${CONFIG} ${PASSWD}
|
|
89 |
createPasswordFile ${PASSWD}
|
|
90 |
|
|
91 |
# Compile test
|
|
92 |
|
|
93 |
${TESTJAVA}/bin/javac -d ${TESTCLASSES} ${TESTCLASSES}/Null.java
|
|
94 |
|
|
95 |
|
|
96 |
JAVA=${TESTJAVA}/bin/java
|
|
97 |
CLASSPATH=${TESTCLASSES}
|
|
98 |
export CLASSPATH
|
|
99 |
|
|
100 |
failures=0
|
|
101 |
|
|
102 |
mp=-Dcom.sun.management.config.file=${CONFIG}
|
|
103 |
pp=-Dcom.sun.management.jmxremote.port=4888
|
|
104 |
|
|
105 |
go() {
|
|
106 |
echo ''
|
|
107 |
sh -xc "$JAVA $1 $2 $3 $4 $5 $6 $7 $8" 2>&1
|
|
108 |
if [ $? != 0 ]; then failures=`expr $failures + 1`; fi
|
|
109 |
}
|
|
110 |
|
|
111 |
# Test 1 - password file is secure - VM should start
|
|
112 |
chmod 700 ${PASSWD}
|
|
113 |
sh -xc "$JAVA $mp $pp Null" 2>&1
|
|
114 |
if [ $? != 0 ]; then failures=`expr $failures + 1`; fi
|
|
115 |
|
|
116 |
# Test 2 - password file is not secure - VM should fail to start
|
|
117 |
chmod o+rx ${PASSWD}
|
|
118 |
sh -xc "$JAVA $mp $pp Null" 2>&1
|
|
119 |
if [ $? = 0 ]; then failures=`expr $failures + 1`; fi
|
|
120 |
|
|
121 |
# Reset the file permissions on the generated password file
|
|
122 |
chmod 777 ${PASSWD}
|
|
123 |
|
|
124 |
#
|
|
125 |
# Results
|
|
126 |
#
|
|
127 |
echo ''
|
|
128 |
if [ $failures -gt 0 ];
|
|
129 |
then echo "$failures test(s) failed";
|
|
130 |
else echo "All test(s) passed"; fi
|
|
131 |
exit $failures
|
|
132 |
|
|
133 |
|
|
134 |
|