summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorChristian Poessinger <christian@poessinger.com>2020-04-08 22:07:58 +0200
committerChristian Poessinger <christian@poessinger.com>2020-04-08 22:08:57 +0200
commit12a67646986e89d94d1e41d410c7314488aa1cbe (patch)
treeb06662806a977ef9dac00bb7970727ebc20d75c1 /src
parent2d33cf656f5856fb06e8390fc2250bb99ea0206b (diff)
downloadvyos-1x-12a67646986e89d94d1e41d410c7314488aa1cbe.tar.gz
vyos-1x-12a67646986e89d94d1e41d410c7314488aa1cbe.zip
vyos-util: rename chown_file() > chown()
... to make it clear also directories can be chown(-ed)
Diffstat (limited to 'src')
-rwxr-xr-xsrc/conf_mode/interfaces-pppoe.py4
-rwxr-xr-xsrc/conf_mode/interfaces-wireguard.py17
-rwxr-xr-xsrc/conf_mode/interfaces-wireless.py8
-rwxr-xr-xsrc/conf_mode/interfaces-wirelessmodem.py4
4 files changed, 17 insertions, 16 deletions
diff --git a/src/conf_mode/interfaces-pppoe.py b/src/conf_mode/interfaces-pppoe.py
index 407547175..26441838e 100755
--- a/src/conf_mode/interfaces-pppoe.py
+++ b/src/conf_mode/interfaces-pppoe.py
@@ -24,7 +24,7 @@ from netifaces import interfaces
from vyos.config import Config
from vyos.defaults import directories as vyos_data_dir
from vyos.ifconfig import Interface
-from vyos.util import chown_file, chmod_x, cmd
+from vyos.util import chown, chmod_x, cmd
from vyos import ConfigError
default_config_data = {
@@ -240,7 +240,7 @@ def apply(pppoe):
cmd(f'systemctl start ppp@{intf}.service')
# make logfile owned by root / vyattacfg
- chown_file(pppoe['logfile'], 'root', 'vyattacfg')
+ chown(pppoe['logfile'], 'root', 'vyattacfg')
return None
diff --git a/src/conf_mode/interfaces-wireguard.py b/src/conf_mode/interfaces-wireguard.py
index 585045863..4ff9f1395 100755
--- a/src/conf_mode/interfaces-wireguard.py
+++ b/src/conf_mode/interfaces-wireguard.py
@@ -24,7 +24,7 @@ from netifaces import interfaces
from vyos.config import Config
from vyos.configdict import list_diff
from vyos.ifconfig import WireGuardIf
-from vyos.util import run, is_bridge_member
+from vyos.util import chown, run, is_bridge_member
from vyos import ConfigError
kdir = r'/config/auth/wireguard'
@@ -55,14 +55,15 @@ def _check_kmod():
def _migrate_default_keys():
if os.path.exists(f'{kdir}/private.key') and not os.path.exists(f'{kdir}/default/private.key'):
- old_umask = os.umask(0o027)
location = f'{kdir}/default'
- run(f'sudo mkdir -p {location}')
- run(f'sudo chgrp vyattacfg {location}')
+ if not os.path.exists(location):
+ os.makedirs(location)
+
+ chown(location, 'root', 'vyattacfg')
run(f'sudo chmod 750 {location}')
+
os.rename(f'{kdir}/private.key', f'{location}/private.key')
os.rename(f'{kdir}/public.key', f'{location}/public.key')
- os.umask(old_umask)
def get_config():
@@ -293,10 +294,10 @@ def apply(wg):
# preshared-key - needs to be read from a file
if peer['psk']:
psk_file = '/config/auth/wireguard/psk'
- old_umask = os.umask(0o077)
- open(psk_file, 'w').write(str(c['peer'][p]['psk']))
- os.umask(old_umask)
+ with open(psk_file, 'w') as f:
+ f.write(peer['psk']))
w.config['psk'] = psk_file
+
w.update()
# Enable/Disable interface
diff --git a/src/conf_mode/interfaces-wireless.py b/src/conf_mode/interfaces-wireless.py
index 709085b0f..138f27755 100755
--- a/src/conf_mode/interfaces-wireless.py
+++ b/src/conf_mode/interfaces-wireless.py
@@ -29,7 +29,7 @@ from vyos.configdict import list_diff, vlan_to_dict
from vyos.defaults import directories as vyos_data_dir
from vyos.ifconfig import WiFiIf
from vyos.ifconfig_vlan import apply_vlan_config, verify_vlan_config
-from vyos.util import process_running, chmod_x, chown_file, run, is_bridge_member
+from vyos.util import process_running, chmod_x, chown, run, is_bridge_member
from vyos import ConfigError
user = 'root'
@@ -121,7 +121,7 @@ def get_conf_file(conf_type, intf):
if not os.path.exists(cfg_dir):
os.mkdir(cfg_dir)
chmod_x(cfg_dir)
- chown_file(cfg_dir, user, group)
+ chown(cfg_dir, user, group)
cfg_file = cfg_dir + r'/{}.cfg'.format(intf)
return cfg_file
@@ -133,7 +133,7 @@ def get_pid(conf_type, intf):
if not os.path.exists(cfg_dir):
os.mkdir(cfg_dir)
chmod_x(cfg_dir)
- chown_file(cfg_dir, user, group)
+ chown(cfg_dir, user, group)
cfg_file = cfg_dir + r'/{}.pid'.format(intf)
return cfg_file
@@ -146,7 +146,7 @@ def get_wpa_suppl_config_name(intf):
if not os.path.exists(cfg_dir):
os.mkdir(cfg_dir)
chmod_x(cfg_dir)
- chown_file(cfg_dir, user, group)
+ chown(cfg_dir, user, group)
cfg_file = cfg_dir + r'/{}.cfg'.format(intf)
return cfg_file
diff --git a/src/conf_mode/interfaces-wirelessmodem.py b/src/conf_mode/interfaces-wirelessmodem.py
index 49445aaa4..e5af37b8f 100755
--- a/src/conf_mode/interfaces-wirelessmodem.py
+++ b/src/conf_mode/interfaces-wirelessmodem.py
@@ -23,7 +23,7 @@ from netifaces import interfaces
from vyos.config import Config
from vyos.defaults import directories as vyos_data_dir
-from vyos.util import chown_file, chmod_x, cmd, run, is_bridge_member
+from vyos.util import chown, chmod_x, cmd, run, is_bridge_member
from vyos import ConfigError
default_config_data = {
@@ -219,7 +219,7 @@ def apply(wwan):
intf = wwan['intf']
cmd(f'systemctl start ppp@{intf}.service')
# make logfile owned by root / vyattacfg
- chown_file(wwan['logfile'], 'root', 'vyattacfg')
+ chown(wwan['logfile'], 'root', 'vyattacfg')
return None