@@ -2274,7 +2274,10 @@ if [[ -x "${PRIVILEGED_HELPER}" ]]; then
22742274 HELPER_INSTALL_SCRIPT=" $( head -n 1 " ${WEB_AWG_SCRIPT_MARKER} " ) "
22752275 HELPER_SCRIPT_BACKUP=" /tmp/amneziawg-helper-script-backup"
22762276 HELPER_PROTOCOL_CALLS=" /tmp/amneziawg-helper-protocol-calls"
2277+ HELPER_UNIT_BACKUP=" /tmp/amneziawg-helper-unit-backup"
2278+ HELPER_CUSTOM_ENV_ROOT=" /opt/amneziawg-web-helper-test"
22772279 cp -p " ${HELPER_INSTALL_SCRIPT} " " ${HELPER_SCRIPT_BACKUP} "
2280+ cp -p /etc/systemd/system/amneziawg-web.service " ${HELPER_UNIT_BACKUP} "
22782281 printf ' #!/bin/bash\nprintf "%%s\\n" "$1" >> %s\n' \
22792282 " ${HELPER_PROTOCOL_CALLS} " > " ${HELPER_INSTALL_SCRIPT} "
22802283 chmod 0755 " ${HELPER_INSTALL_SCRIPT} "
@@ -2287,8 +2290,41 @@ if [[ -x "${PRIVILEGED_HELPER}" ]]; then
22872290 [[ " $( sed -n ' 2p' " ${HELPER_PROTOCOL_CALLS} " ) " == " --disable-awg3" ]]; then
22882291 HELPER_PROTOCOL_DISPATCH_OK=1
22892292 fi
2293+
2294+ # The installer supports root-controlled custom --env-file locations. The
2295+ # privileged helper must find the ownership marker beside that effective
2296+ # EnvironmentFile without weakening its directory/file checks.
2297+ rm -rf " ${HELPER_CUSTOM_ENV_ROOT} "
2298+ install -d -m 0700 -o root -g root " ${HELPER_CUSTOM_ENV_ROOT} "
2299+ install -m 0600 -o root -g root " ${WEB_TEST_ENV_FILE} " \
2300+ " ${HELPER_CUSTOM_ENV_ROOT} /env.conf"
2301+ install -m 0600 -o root -g root " ${WEB_AWG_SCRIPT_MARKER} " \
2302+ " ${HELPER_CUSTOM_ENV_ROOT} /installed-awg-script.path"
2303+ sed -i " s#^EnvironmentFile=.*#EnvironmentFile=${HELPER_CUSTOM_ENV_ROOT} /env.conf#" \
2304+ /etc/systemd/system/amneziawg-web.service
2305+ HELPER_CUSTOM_ENV_OK=0
2306+ if grep -Fqx " EnvironmentFile=${HELPER_CUSTOM_ENV_ROOT} /env.conf" \
2307+ /etc/systemd/system/amneziawg-web.service && \
2308+ " ${PRIVILEGED_HELPER} " enable-awg3 && \
2309+ [[ " $( sed -n ' 3p' " ${HELPER_PROTOCOL_CALLS} " ) " == " --enable-awg3" ]]; then
2310+ HELPER_CUSTOM_ENV_OK=1
2311+ fi
2312+ chmod 0777 " ${HELPER_CUSTOM_ENV_ROOT} "
2313+ if " ${PRIVILEGED_HELPER} " disable-awg3 > /dev/null 2>&1 ; then
2314+ HELPER_CUSTOM_ENV_OK=0
2315+ fi
2316+ chmod 0700 " ${HELPER_CUSTOM_ENV_ROOT} "
2317+ cp -p " ${HELPER_UNIT_BACKUP} " /etc/systemd/system/amneziawg-web.service
2318+ rm -rf " ${HELPER_CUSTOM_ENV_ROOT} "
2319+ if [[ " ${HELPER_CUSTOM_ENV_OK} " -eq 1 ]]; then
2320+ echo " OK: Privileged helper supports secure custom EnvironmentFile directories"
2321+ else
2322+ echo " FAIL: Privileged helper did not safely support a custom EnvironmentFile directory"
2323+ FAILED=$(( FAILED + 1 ))
2324+ fi
2325+
22902326 cp -p " ${HELPER_SCRIPT_BACKUP} " " ${HELPER_INSTALL_SCRIPT} "
2291- rm -f " ${HELPER_SCRIPT_BACKUP} " " ${HELPER_PROTOCOL_CALLS} "
2327+ rm -f " ${HELPER_SCRIPT_BACKUP} " " ${HELPER_PROTOCOL_CALLS} " " ${HELPER_UNIT_BACKUP} "
22922328 if [[ " ${HELPER_PROTOCOL_DISPATCH_OK} " -eq 1 ]]; then
22932329 echo " OK: Privileged helper dispatches only fixed protocol migration flags"
22942330 else
0 commit comments