0N/A#!/bin/sh
0N/A
0N/A#
2362N/A# Copyright (c) 2004, Oracle and/or its affiliates. All rights reserved.
0N/A# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A#
0N/A# This code is free software; you can redistribute it and/or modify it
0N/A# under the terms of the GNU General Public License version 2 only, as
0N/A# published by the Free Software Foundation.
0N/A#
0N/A# This code is distributed in the hope that it will be useful, but WITHOUT
0N/A# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A# version 2 for more details (a copy is included in the LICENSE file that
0N/A# accompanied this code).
0N/A#
0N/A# You should have received a copy of the GNU General Public License version
0N/A# 2 along with this work; if not, write to the Free Software Foundation,
0N/A# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A#
2362N/A# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A# or visit www.oracle.com if you need additional information or have any
2362N/A# questions.
0N/A#
0N/A
0N/A
0N/A# @test
0N/A# @bug 5008047
0N/A# @summary Check password file permission for out-of-the-box management
0N/A#
0N/A# @run shell PasswordFilePermissionTest.sh
0N/A
0N/AcreateJavaFile()
0N/A{
0N/A cat << EOF > $1/$2.java
0N/A class $2 {
0N/A public static void main(String[] args) {
0N/A System.out.println("Inside main method...");
0N/A }
0N/A }
0N/AEOF
0N/A}
0N/A
0N/AcreateConfigFile() {
0N/A cat << EOF > $1
0N/A# management.properties
0N/Acom.sun.management.jmxremote.ssl=false
0N/Acom.sun.management.jmxremote.password.file=$2
0N/AEOF
0N/A}
0N/A
0N/AcreatePasswordFile() {
0N/A if [ -f "$1" ] ; then
0N/A rm -f $1 || echo WARNING: $1 already exists - unable to remove old copy
0N/A fi
0N/A cat << EOF > $1
0N/A# jmxremote.password
0N/AEOF
0N/A}
0N/A
0N/A
0N/A# Check we are run from jtreg
0N/Aif [ -z "${TESTCLASSES}" ]; then
0N/A echo "Test is designed to be run from jtreg only"
0N/A exit 0
0N/Afi
0N/A
0N/A
0N/A# Test not suitable for Windows as chmod may not be able to
0N/A# security the password file.
0N/A
0N/Aos=`uname -s`
0N/Aif [ "$os" != "Linux" -a "$os" != "SunOS" ]; then
0N/A echo "Test not designed to run on this operating system, skipping..."
0N/A exit 0
0N/Afi
0N/A
0N/A
0N/A# Create configuration file and dummy password file
0N/A
0N/ALIBDIR=${TESTCLASSES}/lib
0N/ACONFIG=${LIBDIR}/management.properties
0N/APASSWD=${LIBDIR}/jmxremote.password
0N/Arm -f ${CONFIG}
0N/Arm -f ${PASSWD}
0N/Amkdir ${LIBDIR} 2>&1
0N/AcreateJavaFile ${TESTCLASSES} Null
0N/AcreateConfigFile ${CONFIG} ${PASSWD}
0N/AcreatePasswordFile ${PASSWD}
0N/A
0N/A# Compile test
0N/A
0N/A${TESTJAVA}/bin/javac -d ${TESTCLASSES} ${TESTCLASSES}/Null.java
0N/A
0N/A
0N/AJAVA=${TESTJAVA}/bin/java
0N/ACLASSPATH=${TESTCLASSES}
0N/Aexport CLASSPATH
0N/A
0N/Afailures=0
0N/A
0N/Amp=-Dcom.sun.management.config.file=${CONFIG}
0N/App=-Dcom.sun.management.jmxremote.port=4888
0N/A
0N/Ago() {
0N/A echo ''
0N/A sh -xc "$JAVA $1 $2 $3 $4 $5 $6 $7 $8" 2>&1
0N/A if [ $? != 0 ]; then failures=`expr $failures + 1`; fi
0N/A}
0N/A
0N/A# Test 1 - password file is secure - VM should start
0N/Achmod 700 ${PASSWD}
0N/Ash -xc "$JAVA $mp $pp Null" 2>&1
0N/Aif [ $? != 0 ]; then failures=`expr $failures + 1`; fi
0N/A
0N/A# Test 2 - password file is not secure - VM should fail to start
0N/Achmod o+rx ${PASSWD}
0N/Ash -xc "$JAVA $mp $pp Null" 2>&1
0N/Aif [ $? = 0 ]; then failures=`expr $failures + 1`; fi
0N/A
0N/A# Reset the file permissions on the generated password file
0N/Achmod 777 ${PASSWD}
0N/A
0N/A#
0N/A# Results
0N/A#
0N/Aecho ''
0N/Aif [ $failures -gt 0 ];
0N/A then echo "$failures test(s) failed";
0N/A else echo "All test(s) passed"; fi
0N/Aexit $failures
0N/A
0N/A
0N/A