Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/sun/management/jmxremote/bootstrap/PasswordFilePermissionTest.sh
38867 views
#!/bin/sh12#3# Copyright (c) 2004, Oracle and/or its affiliates. All rights reserved.4# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.5#6# This code is free software; you can redistribute it and/or modify it7# under the terms of the GNU General Public License version 2 only, as8# published by the Free Software Foundation.9#10# This code is distributed in the hope that it will be useful, but WITHOUT11# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13# version 2 for more details (a copy is included in the LICENSE file that14# accompanied this code).15#16# You should have received a copy of the GNU General Public License version17# 2 along with this work; if not, write to the Free Software Foundation,18# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19#20# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21# or visit www.oracle.com if you need additional information or have any22# questions.23#242526# @test27# @bug 500804728# @summary Check password file permission for out-of-the-box management29#30# @run shell PasswordFilePermissionTest.sh3132createJavaFile()33{34cat << EOF > $1/$2.java35class $2 {36public static void main(String[] args) {37System.out.println("Inside main method...");38}39}40EOF41}4243createConfigFile() {44cat << EOF > $145# management.properties46com.sun.management.jmxremote.ssl=false47com.sun.management.jmxremote.password.file=$248EOF49}5051createPasswordFile() {52if [ -f "$1" ] ; then53rm -f $1 || echo WARNING: $1 already exists - unable to remove old copy54fi55cat << EOF > $156# jmxremote.password57EOF58}596061# Check we are run from jtreg62if [ -z "${TESTCLASSES}" ]; then63echo "Test is designed to be run from jtreg only"64exit 065fi666768# Test not suitable for Windows as chmod may not be able to69# security the password file.7071os=`uname -s`72if [ "$os" != "Linux" -a "$os" != "SunOS" ]; then73echo "Test not designed to run on this operating system, skipping..."74exit 075fi767778# Create configuration file and dummy password file7980LIBDIR=${TESTCLASSES}/lib81CONFIG=${LIBDIR}/management.properties82PASSWD=${LIBDIR}/jmxremote.password83rm -f ${CONFIG}84rm -f ${PASSWD}85mkdir ${LIBDIR} 2>&186createJavaFile ${TESTCLASSES} Null87createConfigFile ${CONFIG} ${PASSWD}88createPasswordFile ${PASSWD}8990# Compile test9192${COMPILEJAVA}/bin/javac ${TESTJAVACOPTS} ${TESTTOOLVMOPTS} -d ${TESTCLASSES} ${TESTCLASSES}/Null.java939495JAVA=${TESTJAVA}/bin/java96CLASSPATH=${TESTCLASSES}97export CLASSPATH9899failures=0100101mp=-Dcom.sun.management.config.file=${CONFIG}102pp=-Dcom.sun.management.jmxremote.port=4888103104go() {105echo ''106sh -xc "$JAVA ${TESTVMOPTS} $1 $2 $3 $4 $5 $6 $7 $8" 2>&1107if [ $? != 0 ]; then failures=`expr $failures + 1`; fi108}109110# Test 1 - password file is secure - VM should start111chmod 700 ${PASSWD}112sh -xc "$JAVA ${TESTVMOPTS} $mp $pp Null" 2>&1113if [ $? != 0 ]; then failures=`expr $failures + 1`; fi114115# Test 2 - password file is not secure - VM should fail to start116chmod o+rx ${PASSWD}117sh -xc "$JAVA ${TESTVMOPTS} $mp $pp Null" 2>&1118if [ $? = 0 ]; then failures=`expr $failures + 1`; fi119120# Reset the file permissions on the generated password file121chmod 777 ${PASSWD}122123#124# Results125#126echo ''127if [ $failures -gt 0 ];128then echo "$failures test(s) failed";129else echo "All test(s) passed"; fi130exit $failures131132133134135136