Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix various permission issues #3216

Merged
merged 2 commits into from
Mar 18, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 38 additions & 22 deletions mk/spksrc.service.installer
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,22 @@ syno_group_remove ()
fi
}

# Add user to existing group
syno_user_add_to_group ()
{
ADD_USER=$1
ADD_GROUP=$2
# Check user already in group
if ! synogroup --get "$ADD_GROUP" | grep "^[0-9]:\[${ADD_USER}\]" &> /dev/null; then
# Add user, not in group yet
echo "Adding '${ADD_USER}' to '${ADD_GROUP}'" >> ${INST_LOG}
MEMBERS="$(synogroup --get $ADD_GROUP | grep '^[0-9]' | sed 's/.*\[\([^]]*\)].*/\1/' | tr '\n' ' ')"
# The "synogroup --member" command clears all users before adding new ones
# so all the users must be listed on the command line
synogroup --member "$ADD_GROUP" $MEMBERS "${ADD_USER}" >> ${INST_LOG}
fi
}

# Sets recursive permissions for ${GROUP} on specified directory
# Usage: set_syno_permissions "${SHARE_FOLDER}" "${GROUP}"
set_syno_permissions ()
Expand Down Expand Up @@ -146,14 +162,14 @@ set_syno_permissions ()

# Walk up the tree and set traverse execute permissions for GROUP up to VOLUME
while [ "${DIRNAME}" != "${VOLUME}" ]; do
if [ ! "`synoacltool -get \"${DIRNAME}\"| grep \"group:${GROUP}:allow:..x\"`" ]; then
if [ ! "`synoacltool -get \"${DIRNAME}\"| grep \"group:${GROUP}:allow:r.x\"`" ]; then
# Here we also need to make sure the admin can access data via File Station
if [ "`synoacltool -get \"${DIRNAME}\"| grep \"Linux mode\"`" ]; then
synoacltool -add "${DIRNAME}" "group:administrators:allow:rwxpdDaARWc--:fd--" >> ${INST_LOG} 2>&1
fi
# Add the new group permissions
echo "Granting '${GROUP}' group basic permissions on ${DIRNAME}" >> ${INST_LOG}
synoacltool -add "${DIRNAME}" "group:${GROUP}:allow:--x----------:---n" >> ${INST_LOG} 2>&1
synoacltool -add "${DIRNAME}" "group:${GROUP}:allow:r-x---a-R----:---n" >> ${INST_LOG} 2>&1
fi
DIRNAME="$(dirname "${DIRNAME}")"
done
Expand All @@ -162,12 +178,12 @@ set_syno_permissions ()
fi
}

# Sets recurivse permissions using chown
# Set recursive permissions using chown
set_unix_permissions ()
{
DIRNAME=$1
if [ -n "${EFF_USER}" ]; then
echo "Granting '${EFF_USER}' unix permissions on ${DIRNAME}" >> ${INST_LOG}
echo "Granting '${EFF_USER}' unix ownership on ${DIRNAME}" >> ${INST_LOG}
if [ $SYNOPKG_DSM_VERSION_MAJOR -lt 6 ]; then
chown -R ${EFF_USER}:root "${DIRNAME}" >> $INST_LOG 2>&1
else
Expand Down Expand Up @@ -229,14 +245,22 @@ postinst ()
servicetool --install-configure-file --package "${FWPORTS_FILE}" >> ${INST_LOG} 2>&1
fi

# DSM 5 specific operations
if [ $SYNOPKG_DSM_VERSION_MAJOR -lt 6 ] && [ -n "${EFF_USER}" ]; then
# Create prefixed synouser
if ! cat /etc/passwd | grep "${EFF_USER}:x:" &> /dev/null; then
synouser --add "${EFF_USER}" "" "$USER_DESC" 0 "" 0 >> ${INST_LOG} 2>&1
BACKUP_PASSWD="/tmp/install_${SYNOPKG_PKGNAME}_passwd"
cp /etc/passwd ${BACKUP_PASSWD}
sed -i "s#/var/services/homes/${EFF_USER}#/var/packages/${SYNOPKG_PKGNAME}/target/var#" /etc/passwd
# Service user management
if [ -n "${EFF_USER}" ]; then
if [ $SYNOPKG_DSM_VERSION_MAJOR -lt 6 ]; then
# DSM 5 specific operations
# Create prefixed synouser
if ! cat /etc/passwd | grep "${EFF_USER}:x:" &> /dev/null; then
synouser --add "${EFF_USER}" "" "$USER_DESC" 0 "" 0 >> ${INST_LOG} 2>&1
# Set HOME for consistency with DSM 6, location available even if homes not enabled
BACKUP_PASSWD="/tmp/install_${SYNOPKG_PKGNAME}_passwd"
cp /etc/passwd ${BACKUP_PASSWD}
sed -i "s#/var/services/homes/${EFF_USER}#/var/packages/${SYNOPKG_PKGNAME}/target#" /etc/passwd
fi
fi
# Register service in "users" group to access any content
if [ "$ADD_USER_IN_USERS" = "yes" ]; then
syno_user_add_to_group "${EFF_USER}" "users"
fi
fi

Expand All @@ -248,15 +272,7 @@ postinst ()
syno_group_create "${EFF_USER}"
fi
if synogroup --get "$GROUP" &> /dev/null; then
# Check user already in group
if ! synogroup --get "$GROUP" | grep "^[0-9]:\[${EFF_USER}\]" &> /dev/null; then
# Add user, not in group yet
echo "Adding '${EFF_USER}' to '${GROUP}'" >> ${INST_LOG}
MEMBERS="$(synogroup --get $GROUP | grep '^[0-9]' | sed 's/.*\[\([^]]*\)].*/\1/' | tr '\n' ' ')"
# The "synogroup --member" command clears all users before adding new ones
# so all the users must be listed on the command line
synogroup --member "$GROUP" $MEMBERS "${EFF_USER}" >> ${INST_LOG}
fi
syno_user_add_to_group "${EFF_USER}" "${GROUP}"
fi
# Not sure but invoked with hope DSM is updated
synogroup --rebuild all
Expand Down Expand Up @@ -295,7 +311,7 @@ postinst ()
echo "Installation log: ${INST_VAR}/${SYNOPKG_PKGNAME}_install.log" >> ${LOG_FILE}
fi
if [ $SYNOPKG_DSM_VERSION_MAJOR -lt 6 ]; then
# On DSM 5 set package files permissions
# On DSM 5 set package files permissions for consistency with DSM 6
set_unix_permissions "${SYNOPKG_PKGDEST}"
else
# On DSM 6 only var is concerned
Expand Down
6 changes: 4 additions & 2 deletions mk/spksrc.service.start-stop-status
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ start_daemon ()
fi
if [ -n "${SVC_WRITE_PID}" -a -n "${SVC_BACKGROUND}" -a -n "${PID_FILE}" ]; then
echo "$!" > "${PID_FILE}"
else
wait_for_status 0 ${SVC_WAIT_TIMEOUT}
fi
fi
}
Expand All @@ -66,7 +68,7 @@ stop_daemon ()
echo "Stopping ${DNAME} service ${PID} " >> ${LOG_FILE}
fi
kill -TERM $PID >> ${LOG_FILE} 2>&1
wait_for_status 1 20 || kill -KILL $PID >> ${LOG_FILE} 2>&1
wait_for_status 1 ${SVC_WAIT_TIMEOUT} || kill -KILL $PID >> ${LOG_FILE} 2>&1
if [ -f "${PID_FILE}" ]; then
rm -f "${PID_FILE}" > /dev/null
fi
Expand All @@ -88,7 +90,7 @@ daemon_status ()

wait_for_status ()
{
counter=$2
counter=${2:=20}
while [ ${counter} -gt 0 ]; do
daemon_status
[ $? -eq $1 ] && return
Expand Down
2 changes: 1 addition & 1 deletion spk/radarr/Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
SPK_NAME = radarr
SPK_VERS = $(shell date +%Y%m%d)
SPK_REV = 6
SPK_REV = 7
SPK_ICON = src/radarr.png

REQUIRED_DSM = 5.0
Expand Down
1 change: 1 addition & 0 deletions spk/radarr/src/service-setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ service_postinst ()

# If nessecary, add user also to the old group before removing it
syno_user_add_to_legacy_group "${EFF_USER}" "${USER}" "${LEGACY_GROUP}"
syno_user_add_to_legacy_group "${EFF_USER}" "${USER}" "users"

# Discard legacy obsolete busybox user account
BIN=${SYNOPKG_PKGDEST}/bin
Expand Down
2 changes: 1 addition & 1 deletion spk/sonarr/Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
SPK_NAME = nzbdrone
SPK_VERS = $(shell date +%Y%m%d)
SPK_REV = 13
SPK_REV = 14
SPK_ICON = src/sonarr.png

REQUIRED_DSM = 5.0
Expand Down
1 change: 1 addition & 0 deletions spk/sonarr/src/service-setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ service_postinst ()

# If nessecary, add user also to the old group before removing it
syno_user_add_to_legacy_group "${EFF_USER}" "${USER}" "${LEGACY_GROUP}"
syno_user_add_to_legacy_group "${EFF_USER}" "${USER}" "users"

# Discard legacy obsolete busybox user account
BIN=${SYNOPKG_PKGDEST}/bin
Expand Down
2 changes: 1 addition & 1 deletion spk/transmission/Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
SPK_NAME = transmission
SPK_VERS = 2.93
SPK_REV = 13
SPK_REV = 14
SPK_ICON = src/transmission.png

DEPENDS = cross/busybox cross/$(SPK_NAME)
Expand Down
1 change: 0 additions & 1 deletion spk/transmission/src/service-setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ GROUP="sc-download"

SERVICE_COMMAND="${TRANSMISSION} -g ${SYNOPKG_PKGDEST}/var/ -x ${PID_FILE} -e ${LOG_FILE}"


service_preinst ()
{
if [ "${SYNOPKG_PKG_STATUS}" == "INSTALL" ]; then
Expand Down