summaryrefslogtreecommitdiff
path: root/src/conf_mode/tftp_server.py
diff options
context:
space:
mode:
authorChristian Poessinger <christian@poessinger.com>2019-02-24 23:02:45 +0100
committerChristian Poessinger <christian@poessinger.com>2019-02-24 23:02:45 +0100
commit583975299c625d6049be6561d70e4cadc9976242 (patch)
tree0319d53be535e69dbcf1db45414df3f66375cf77 /src/conf_mode/tftp_server.py
parentfbfe43b5ae7692e6ee6ce6d5517efdb2cdf8f022 (diff)
downloadvyos-1x-583975299c625d6049be6561d70e4cadc9976242.tar.gz
vyos-1x-583975299c625d6049be6561d70e4cadc9976242.zip
[tftp] T1261: always adjust directory permissions of tftproot
Diffstat (limited to 'src/conf_mode/tftp_server.py')
-rwxr-xr-xsrc/conf_mode/tftp_server.py15
1 files 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']: