From b39a444c787a60f16e52b7c27cc09aab2e39cbf4 Mon Sep 17 00:00:00 2001 From: Christian Poessinger Date: Sun, 24 Feb 2019 23:02:45 +0100 Subject: [tftp] T1261: always adjust directory permissions of tftproot (cherry picked from commit 583975299c625d6049be6561d70e4cadc9976242) --- src/conf_mode/tftp_server.py | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/conf_mode/tftp_server.py b/src/conf_mode/tftp_server.py index d0df6126e..ff7cad0c9 100755 --- a/src/conf_mode/tftp_server.py +++ b/src/conf_mode/tftp_server.py @@ -125,9 +125,18 @@ def apply(tftpd): if not os.path.exists(tftp_root): os.makedirs(tftp_root) os.chmod(tftp_root, stat.S_IRUSR|stat.S_IWUSR|stat.S_IXUSR|stat.S_IRGRP|stat.S_IXGRP|stat.S_IROTH|stat.S_IXOTH) - # get UNIX uid for user 'tftp' - tftp_uid = pwd.getpwnam('tftp').pw_uid - os.chown(tftp_root, tftp_uid, -1) + + # get UNIX uid for user 'tftp' + tftp_uid = pwd.getpwnam('tftp').pw_uid + tftp_gid = pwd.getpwnam('tftp').pw_gid + + # get UNIX uid for tftproot directory + dir_uid = os.stat(tftp_root).st_uid + dir_gid = os.stat(tftp_root).st_gid + + # adjust uid/gid of tftproot directory if files don't belong to user tftp + if (tftp_uid != dir_uid) or (tftp_gid != dir_gid): + os.chown(tftp_root, tftp_uid, tftp_gid) idx = 0 for listen in tftpd['listen']: -- cgit v1.2.3