1 #
   2 # Copyright (c) 2003, 2020, Oracle and/or its affiliates. All rights reserved.
   3 # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4 #
   5 # This code is free software; you can redistribute it and/or modify it
   6 # under the terms of the GNU General Public License version 2 only, as
   7 # published by the Free Software Foundation.
   8 #
   9 # This code is distributed in the hope that it will be useful, but WITHOUT
  10 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11 # FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12 # version 2 for more details (a copy is included in the LICENSE file that
  13 # accompanied this code).
  14 #
  15 # You should have received a copy of the GNU General Public License version
  16 # 2 along with this work; if not, write to the Free Software Foundation,
  17 # Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18 #
  19 # Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20 # or visit www.oracle.com if you need additional information or have any
  21 # questions.
  22 #
  23 
  24 #
  25 # Utility Shell Script for generating .properties files or .password files
  26 # or .access files from a list of input .in files.
  27 #
  28 # Source in this GeneratePropertyPassword.sh and call the function
  29 # generatePropertyPasswordFiles.
  30 # Call restoreFilePermissions to restore file permissions after the test completes
  31 #
  32 
  33 
  34 OS=`uname -s`
  35 UMASK=`umask`
  36 
  37 case $OS in
  38 CYGWIN_NT*)
  39     OS="Windows_NT"
  40     if [ -z "$SystemRoot" ] ;  then
  41         SystemRoot=`cygpath $SYSTEMROOT`
  42     fi
  43 esac
  44 
  45 case $OS in
  46 Linux | Darwin | AIX )
  47     PATHSEP=":"
  48     FILESEP="/"
  49     DFILESEP=$FILESEP
  50     TMP_FILE=${TESTCLASSES}${FILESEP}${TESTCLASS}.sed.tmpfile
  51 
  52 cat <<EOF > ${TMP_FILE}
  53 s^@TEST-SRC@/^${TESTCLASSES}${DFILESEP}^g
  54 EOF
  55     ;;
  56 Windows_95 | Windows_98 | Windows_NT | Windows_ME | CYGWIN*)
  57     PATHSEP=";"
  58     FILESEP="\\"
  59     DFILESEP=$FILESEP$FILESEP
  60     TMP_FILE=${TESTCLASSES}${FILESEP}${TESTCLASS}.sed.tmpfile
  61 
  62 cat <<EOF > ${TMP_FILE}0
  63 s^@TEST-SRC@/^${TESTCLASSES}${DFILESEP}^g
  64 EOF
  65     # Need to put double backslash in the .properties files
  66     cat ${TMP_FILE}0 | sed -e 's^\\\\^ZZZZ^g' | \
  67         sed -e 's^\\^ZZZZ^g' | \
  68         sed -e 's^ZZZZ^\\\\\\\\^g' > ${TMP_FILE}
  69 
  70     if [ "$OS" = "Windows_NT" ]; then
  71         USER=`id -u -n`
  72         CACLS="$SystemRoot/system32/cacls.exe"
  73         REVOKEALL="$TESTNATIVEPATH/revokeall.exe"
  74         if [ ! -x "$REVOKEALL" ] ; then
  75             echo "$REVOKEALL doesn't exist or is not executable"
  76             exit 1
  77         fi
  78     fi
  79     ;;
  80 *)
  81     echo "Unrecognized system! $OS"
  82     exit 1
  83     ;;
  84 esac
  85 
  86 generatePropertyPasswordFiles()
  87 {
  88    for f in $@
  89    do
  90         echo processing $f
  91         suffix=`basename $f .in`
  92         f2="${TESTCLASSES}${FILESEP}${suffix}"
  93 
  94         if [ -f "$f2" ] ; then
  95             rm -f $f2 || echo WARNING: $f2 already exits - unable to remove old copy
  96         fi
  97 
  98         echo creating $f2
  99         sed -f $TMP_FILE $f > $f2
 100 
 101         if [ "$OS" = "Windows_NT" ]; then
 102             chown $USER $f2
 103             # Grant this user full access
 104             echo Y|$CACLS $f2 \/E \/G $USER:F
 105             # Revoke everyone else
 106             $REVOKEALL $f2
 107             # Display ACLs
 108             $CACLS $f2
 109         else
 110             chmod 600 $f2
 111         fi
 112    done
 113 }
 114 
 115 restoreFilePermissions()
 116 {
 117     for f in $@
 118     do
 119         suffix=`basename $f .in`
 120         f2="${TESTCLASSES}${FILESEP}${suffix}"
 121 
 122         if [ "$OS" = "Windows_NT" ]; then
 123             # Grant everyone full control
 124             $CACLS $f2 \/E \/G Everyone:F
 125         else
 126             chmod 777 $f2
 127         fi
 128 
 129     done
 130 }
 131