Skip to content

Commit

Permalink
Merge branch 'fix/permissions-after-unpack' of github.com:nzbgetcom/n…
Browse files Browse the repository at this point in the history
…zbget into feature/test-fix-permissions
  • Loading branch information
phnzb committed Apr 10, 2024
2 parents e64099c + 524552b commit 1f5b10c
Show file tree
Hide file tree
Showing 30 changed files with 1,817 additions and 897 deletions.
3 changes: 1 addition & 2 deletions Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -365,8 +365,7 @@ webui_FILES = \
webui/lib/raphael.min.js \
webui/lib/elycharts.js \
webui/lib/elycharts.min.js \
webui/img/house-16.ico \
webui/img/download-16.ico \
webui/lib/material-icons.woff2 \
webui/img/icons.png \
webui/img/icons-2x.png \
webui/img/transmit.gif \
Expand Down
9 changes: 7 additions & 2 deletions daemon/postprocess/Unpack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
* This file is part of nzbget. See <https://nzbget.com>.
*
* Copyright (C) 2013-2018 Andrey Prygunkov <hugbug@users.sourceforge.net>
*
* Copyright (C) 2023-2024 Denis <denis@nzbget.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
Expand All @@ -14,7 +15,7 @@
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/


Expand Down Expand Up @@ -732,6 +733,10 @@ bool UnpackController::Cleanup()
ok = false;
}

#ifndef WIN32
FileSystem::SetFilePermissionsWithUmask(dstFile.Str(), g_Options->GetUMask());
#endif

extractedFiles.push_back(filename);
}
}
Expand Down
11 changes: 11 additions & 0 deletions daemon/util/FileSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
* This file is part of nzbget. See <https://nzbget.com>.
*
* Copyright (C) 2007-2017 Andrey Prygunkov <hugbug@users.sourceforge.net>
* Copyright (C) 2024 Denis <denis@nzbget.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -956,6 +957,16 @@ void FileSystem::FixExecPermission(const char* filename)
chmod(filename, buffer.st_mode);
}
}

void FileSystem::SetFilePermissionsWithUmask(const char* filename, mode_t umask)
{
struct stat buffer;
if (!stat(filename, &buffer))
{
mode_t permissions = buffer.st_mode & ~umask;
chmod(filename, permissions);
}
}
#endif

#ifdef WIN32
Expand Down
4 changes: 3 additions & 1 deletion daemon/util/FileSystem.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
* This file is part of nzbget. See <https://nzbget.com>.
*
* Copyright (C) 2007-2017 Andrey Prygunkov <hugbug@users.sourceforge.net>
* Copyright (C) 2024 Denis <denis@nzbget.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand All @@ -14,7 +15,7 @@
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/


Expand Down Expand Up @@ -61,6 +62,7 @@ class FileSystem
#ifndef WIN32
static CString ExpandHomePath(const char* filename);
static void FixExecPermission(const char* filename);
static void SetFilePermissionsWithUmask(const char* filename, mode_t umask);
#endif
static CString ExpandFileName(const char* filename);
static CString GetExeFileName(const char* argv0);
Expand Down
26 changes: 15 additions & 11 deletions docker/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,22 @@ if [ -f /downloads/nzbget.lock ]; then
rm /downloads/nzbget.lock
fi

# change userid and groupid
PUID=${PUID:-1000}
PGID=${PGID:-1000}
groupmod -o -g "$PGID" users >/dev/null
usermod -o -u "$PUID" user >/dev/null

# create default config if not exist
if [ ! -f /config/nzbget.conf ]; then
cp /app/nzbget/share/nzbget/nzbget.conf /config/nzbget.conf
chown user:users /config/nzbget.conf
fi

# create scripts dir
if [ ! -d /downloads/scripts ]; then
mkdir -p /downloads/scripts
chown user:users /downloads/scripts
fi

# parse env vars to options
Expand All @@ -25,21 +38,12 @@ if [ ! -z "${NZBGET_PASS}" ]; then
OPTIONS="${OPTIONS}-o ControlPassword=${NZBGET_PASS} "
fi

# create scripts dir
mkdir -p /downloads/scripts

# change userid and groupid
PUID=${PUID:-1000}
PGID=${PGID:-1000}
groupmod -o -g "$PGID" users >/dev/null
usermod -o -u "$PUID" user >/dev/null

chown -R user:users /config || CONFIG_CHOWN_STATUS=$?
chown user:users /config || CONFIG_CHOWN_STATUS=$?
if [ ! -z $CONFIG_CHOWN_STATUS ]; then
echo "*** Could not set permissions on /config ; this container may not work as expected ***"
fi

chown -R user:users /downloads || DOWNLOADS_CHOWN_STATUS=$?
chown user:users /downloads || DOWNLOADS_CHOWN_STATUS=$?
if [ ! -z $DOWNLOADS_CHOWN_STATUS ]; then
echo "*** Could not set permissions on /downloads ; this container may not work as expected ***"
fi
Expand Down
Binary file modified osx/Resources/Images/mainicon.icns
Binary file not shown.
2 changes: 1 addition & 1 deletion tests/util/JsonTest.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* This file is part of nzbget. See <https://nzbget.com>.
*
* CCopyright (C) 2023 Denis <denis@nzbget.com>
* Copyright (C) 2023 Denis <denis@nzbget.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand Down
Loading

0 comments on commit 1f5b10c

Please sign in to comment.