Skip to content

Commit bb7cc6f

Browse files
[#590] Fallback to $HOME/tmp dir as a temp if instance root is mounted as noexec (#591)
Co-authored-by: Valery Kharseko <vharseko@3a-systems.ru>
1 parent 54c54fd commit bb7cc6f

1 file changed

Lines changed: 56 additions & 2 deletions

File tree

opendj-server-legacy/resource/bin/_script-util.sh

Lines changed: 56 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
#
1515
# Copyright 2008-2010 Sun Microsystems, Inc.
1616
# Portions Copyright 2010-2016 ForgeRock AS.
17-
# Portions Copyright 2019-2025 3A Systems, LLC.
17+
# Portions Copyright 2019-2026 3A Systems, LLC.
1818
#
1919
# Display an error message
2020
#
@@ -83,8 +83,62 @@ set_opendj_java_bin() {
8383
export OPENDJ_JAVA_BIN
8484
}
8585

86+
check_noexec() { #returns 0 if can execute files in the directory, otherwise 1
87+
local DIR_TO_TEST=$1
88+
local res=0
89+
local remove_dir=0
90+
91+
if [ ! -d "${DIR_TO_TEST}" ]; then
92+
remove_dir=1
93+
mkdir ${DIR_TO_TEST}
94+
fi
95+
96+
local TMP_FILE=`mktemp ${DIR_TO_TEST}/temp.XXXXXX`
97+
98+
chmod +x ${TMP_FILE}
99+
if ! ${TMP_FILE} 2>/dev/null; then
100+
res=1
101+
fi
102+
103+
rm -rf ${TMP_FILE}
104+
105+
if [ $remove_dir = 1 ]; then
106+
rm -rf $DIR_TO_TEST
107+
fi
108+
109+
return $res
110+
}
111+
112+
set_bc_dir() {
113+
if echo "$OPENDJ_JAVA_ARGS" | grep -q -o "\-Dorg.bouncycastle.native.loader.install_dir=[^ ]*"; then
114+
return # bc install dir already set
115+
fi
116+
117+
check_noexec "${OPENDJ_TMP_DIR}"
118+
local res=$?
119+
if [ $res = 1 ]; then
120+
if [ "$SCRIPT_NAME" = "setup" ]; then
121+
echo "WARNING: $OPENDJ_TMP_DIR is mounted as noexec, try switching to $HOME for org.bouncycastle.native.loader.install_dir"
122+
fi
123+
check_noexec "${HOME}"
124+
res=$?
125+
if [ $res = 0 ]; then
126+
OPENDJ_JAVA_ARGS="${OPENDJ_JAVA_ARGS} -Dorg.bouncycastle.native.loader.install_dir=${HOME}"
127+
elif [ "$SCRIPT_NAME" = "setup" ]; then
128+
echo "WARNING: $HOME is mounted as noexec, the OpenDJ installation could cause errors"
129+
fi
130+
fi
131+
}
132+
86133
set_temp_dir() {
134+
135+
if echo "$OPENDJ_JAVA_ARGS" | grep -q -o "\-Djava.io.tmpdir=[^ ]*"; then
136+
OPENDJ_TMP_DIR=$(echo "$OPENDJ_JAVA_ARGS" | grep -o "\-Djava.io.tmpdir=[^ ]*" | cut -d'=' -f2)
137+
return # temp dir already set
138+
fi
139+
87140
OPENDJ_TMP_DIR="${INSTANCE_ROOT}/tmp"
141+
88142
if [ ! -d "${OPENDJ_TMP_DIR}" ]; then
89143
mkdir ${OPENDJ_TMP_DIR}
90144
fi
@@ -110,6 +164,7 @@ set_java_home_and_args() {
110164
fi
111165
fi
112166
set_temp_dir
167+
set_bc_dir
113168
set_opendj_java_bin
114169
}
115170

@@ -333,4 +388,3 @@ elif test "${SCRIPT_UTIL_CMD}" = "test-java"
333388
then
334389
test_java
335390
fi
336-

0 commit comments

Comments
 (0)