summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Poessinger <christian@poessinger.com>2020-04-02 21:37:13 +0200
committerChristian Poessinger <christian@poessinger.com>2020-04-02 21:37:13 +0200
commite794aacfa50370e686420d5412456eaea8ae9df5 (patch)
tree8a02f2ded88352eca7d32c2f29c7e3ac1087b290
parenta71452ebc50699c7a8c4d67304d4a935c1e03920 (diff)
downloadvyos-1x-e794aacfa50370e686420d5412456eaea8ae9df5.tar.gz
vyos-1x-e794aacfa50370e686420d5412456eaea8ae9df5.zip
pppoe: migrate to new new helpers in vyos.util
Commit d2cf287 ("vyos.util: add chown_file and chmod_x_file helpers") added common helper functions to chown or chmod +x a file. Make use of those helpers.
-rwxr-xr-xsrc/conf_mode/interfaces-pppoe.py16
1 files changed, 5 insertions, 11 deletions
diff --git a/src/conf_mode/interfaces-pppoe.py b/src/conf_mode/interfaces-pppoe.py
index 806e362fd..aa3cebc42 100755
--- a/src/conf_mode/interfaces-pppoe.py
+++ b/src/conf_mode/interfaces-pppoe.py
@@ -20,12 +20,10 @@ from sys import exit
from copy import deepcopy
from jinja2 import Template
from subprocess import Popen, PIPE
-from pwd import getpwnam
-from grp import getgrnam
-from stat import S_IRUSR, S_IWUSR, S_IXUSR, S_IRGRP, S_IXGRP, S_IROTH, S_IXOTH
from vyos.config import Config
from vyos.ifconfig import Interface
+from vyos.util import chown_file, chmod_x_file
from vyos import ConfigError
from netifaces import interfaces
@@ -356,10 +354,9 @@ def generate(pppoe):
with open(ipv6_if_up_script_file, 'w') as f:
f.write(config_text)
- bitmask = S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IXGRP | \
- S_IROTH | S_IXOTH
- os.chmod(ip_pre_up_script_file, bitmask)
- os.chmod(ipv6_if_up_script_file, bitmask)
+ # make generated script file executable
+ chmod_x_file(ip_up_script_file)
+ chmod_x_file(ipv6_if_up_script_file)
return None
@@ -374,10 +371,7 @@ def apply(pppoe):
subprocess_cmd(cmd)
# make logfile owned by root / vyattacfg
- if os.path.isfile(pppoe['logfile']):
- uid = getpwnam('root').pw_uid
- gid = getgrnam('vyattacfg').gr_gid
- os.chown(pppoe['logfile'], uid, gid)
+ chown_file(pppoe['logfile'], 'root', 'vyattacfg')
return None