Page MenuHomeVyOS Platform

No OneTemporary

Size
9 KB
Referenced Files
None
Subscribers
None
diff --git a/debian/rules b/debian/rules
index 663aff4d9..a24d0280a 100755
--- a/debian/rules
+++ b/debian/rules
@@ -1,70 +1,74 @@
#!/usr/bin/make -f
DIR := debian/vyos-1x
VYOS_SBIN_DIR := usr/sbin/
VYOS_BIN_DIR := usr/bin/
VYOS_LIBEXEC_DIR := usr/libexec/vyos
VYOS_DATA_DIR := /usr/share/vyos
VYOS_CFG_TMPL_DIR := /opt/vyatta/share/vyatta-cfg/templates
VYOS_OP_TMPL_DIR := /opt/vyatta/share/vyatta-op/templates
MIGRATION_SCRIPTS_DIR := /opt/vyatta/etc/config-migrate/migrate/
SYSTEM_SCRIPTS_DIR := usr/libexec/vyos/system
%:
dh $@ --with python3, --with quilt
override_dh_auto_build:
make all
override_dh_auto_install:
dh_install -pvyos-1x
cd python; python3 setup.py install --install-layout=deb --root ../$(DIR); cd ..
# Install scripts
mkdir -p $(DIR)/$(VYOS_SBIN_DIR)
mkdir -p $(DIR)/$(VYOS_BIN_DIR)
cp -r src/utils/* $(DIR)/$(VYOS_BIN_DIR)
# Install conf mode scripts
mkdir -p $(DIR)/$(VYOS_LIBEXEC_DIR)/conf_mode
cp -r src/conf_mode/* $(DIR)/$(VYOS_LIBEXEC_DIR)/conf_mode
# Install op mode scripts
mkdir -p $(DIR)/$(VYOS_LIBEXEC_DIR)/op_mode
cp -r src/op_mode/* $(DIR)/$(VYOS_LIBEXEC_DIR)/op_mode
# Install validators
mkdir -p $(DIR)/$(VYOS_LIBEXEC_DIR)/validators
cp -r src/validators/* $(DIR)/$(VYOS_LIBEXEC_DIR)/validators
# Install completion helpers
mkdir -p $(DIR)/$(VYOS_LIBEXEC_DIR)/completion
cp -r src/completion/* $(DIR)/$(VYOS_LIBEXEC_DIR)/completion
# Install helper scripts
cp -r src/helpers/* $(DIR)/$(VYOS_LIBEXEC_DIR)/
# Install migration scripts
mkdir -p $(DIR)/$(MIGRATION_SCRIPTS_DIR)
cp -r src/migration-scripts/* $(DIR)/$(MIGRATION_SCRIPTS_DIR)
# Install system scripts
mkdir -p $(DIR)/$(SYSTEM_SCRIPTS_DIR)
cp -r src/system/* $(DIR)/$(SYSTEM_SCRIPTS_DIR)
# Install configuration command definitions
mkdir -p $(DIR)/$(VYOS_CFG_TMPL_DIR)
cp -r templates-cfg/* $(DIR)/$(VYOS_CFG_TMPL_DIR)
# Install operational command definitions
mkdir -p $(DIR)/$(VYOS_OP_TMPL_DIR)
cp -r templates-op/* $(DIR)/$(VYOS_OP_TMPL_DIR)
# Install data files
mkdir -p $(DIR)/$(VYOS_DATA_DIR)
cp -r data/* $(DIR)/$(VYOS_DATA_DIR)
# Install etc configuration files
mkdir -p $(DIR)/etc
cp -r src/etc/* $(DIR)/etc
+
+ # Install systemd service units
+ mkdir -p $(DIR)/lib/systemd/system
+ cp -r src/systemd/* $(DIR)/lib/systemd/system
diff --git a/src/conf_mode/tftp_server.py b/src/conf_mode/tftp_server.py
index 0984b4545..5f119be3a 100755
--- a/src/conf_mode/tftp_server.py
+++ b/src/conf_mode/tftp_server.py
@@ -1,155 +1,147 @@
#!/usr/bin/env python3
#
# Copyright (C) 2018 VyOS maintainers and contributors
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 2 or later as
# published by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# 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/>.
#
#
import sys
import os
import stat
import pwd
+import copy
+import glob
import jinja2
import vyos.validate
from vyos.config import Config
from vyos import ConfigError
-config_file = r'/etc/default/tftpd-hpa'
+config_file = r'/etc/default/tftpd'
# Please be careful if you edit the template.
config_tmpl = """
### Autogenerated by tftp_server.py ###
+DAEMON_ARGS="--listen --user tftp --address {% for a in listen-%}{{ a }}{% endfor %} --secure{% if allow_upload %} --create --umask 000{% endif %} {{ directory }}"
-# See manual at https://linux.die.net/man/8/tftpd
-
-TFTP_USERNAME="tftp"
-TFTP_DIRECTORY="{{ directory }}"
-{% if listen_ipv4 and listen_ipv6 -%}
-TFTP_ADDRESS="{% for a in listen_ipv4 -%}{{ a }}:{{ port }}{{- " --address " if not loop.last -}}{% endfor -%} {% for a in listen_ipv6 %} --address [{{ a }}]:{{ port }}{% endfor -%}"
-{% elif listen_ipv4 -%}
-TFTP_ADDRESS="{% for a in listen_ipv4 -%}{{ a }}:{{ port }}{{- " --address " if not loop.last -}}{% endfor %} -4"
-{% elif listen_ipv6 -%}
-TFTP_ADDRESS="{% for a in listen_ipv6 -%}[{{ a }}]:{{ port }}{{- " --address " if not loop.last -}}{% endfor %} -6"
-{%- endif %}
-
-TFTP_OPTIONS="--secure {% if allow_upload %}--create --umask 000{% endif %}"
"""
default_config_data = {
'directory': '',
'allow_upload': False,
'port': '69',
- 'listen_ipv4': [],
- 'listen_ipv6': []
+ 'listen': []
}
def get_config():
- tftpd = default_config_data
+ tftpd = copy.deepcopy(default_config_data)
conf = Config()
if not conf.exists('service tftp-server'):
return None
else:
conf.set_level('service tftp-server')
if conf.exists('directory'):
tftpd['directory'] = conf.return_value('directory')
- if conf.exists('allow-upload'):
+ if conf.exists('allow_upload'):
tftpd['allow_upload'] = True
if conf.exists('port'):
tftpd['port'] = conf.return_value('port')
- if conf.exists('listen-address'):
- for addr in conf.return_values('listen-address'):
- if vyos.validate.is_ipv4(addr):
- tftpd['listen_ipv4'].append(addr)
- else:
- tftpd['listen_ipv6'].append(addr)
+ tftpd['listen'] = conf.return_values('listen-address')
return tftpd
def verify(tftpd):
# bail out early - looks like removal from running config
if tftpd is None:
return None
# Configuring allowed clients without a server makes no sense
if not tftpd['directory']:
raise ConfigError('TFTP root directory must be configured!')
- if not (tftpd['listen_ipv4'] or tftpd['listen_ipv6']):
+ if not tftpd['listen']:
raise ConfigError('TFTP server listen address must be configured!')
- for addr in tftpd['listen_ipv4']:
- # we always bind to localhost
- if '127.0.0.1' not in tftpd['listen_ipv4']:
- tftpd['listen_ipv4'].append('127.0.0.1')
-
- if not vyos.validate.is_addr_assigned(addr):
- print('WARNING: TFTP server listen address {0} not configured!'.format(addr))
-
- for addr in tftpd['listen_ipv6']:
- # we always bind to localhost
- if '::1' not in tftpd['listen_ipv6']:
- tftpd['listen_ipv6'].append('::1')
-
+ for addr in tftpd['listen']:
if not vyos.validate.is_addr_assigned(addr):
- print('WARNING: TFTP server listen address {0} not configured!'.format(addr))
+ print('WARNING: TFTP server listen address {0} not assigned to any interface!'.format(addr))
return None
def generate(tftpd):
+ # cleanup any available configuration file
+ # files will be recreated on demand
+ for i in glob.glob(config_file + '*'):
+ os.unlink(i)
+
# bail out early - looks like removal from running config
if tftpd is None:
return None
- tmpl = jinja2.Template(config_tmpl)
- config_text = tmpl.render(tftpd)
- with open(config_file, 'w') as f:
- f.write(config_text)
+ idx = 0
+ for listen in tftpd['listen']:
+ config = copy.deepcopy(tftpd)
+ if vyos.validate.is_ipv4(listen):
+ config['listen'] = [listen + ":" + tftpd['port'] + " -4"]
+ else:
+ config['listen'] = ["[" + listen + "]" + tftpd['port'] + " -6"]
+
+ tmpl = jinja2.Template(config_tmpl)
+ config_text = tmpl.render(config)
+ file = config_file + str(idx)
+ with open(file, 'w') as f:
+ f.write(config_text)
+
+ idx = idx + 1
return None
def apply(tftpd):
- if tftpd is not None:
+ # stop all services first - then we will decide
+ os.system('sudo systemctl stop tftpd@{0..20}')
- tftp_root = tftpd['directory']
- 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)
+ # bail out early - e.g. service deletion
+ if tftpd is None:
+ return None
- os.system('sudo systemctl restart tftpd-hpa.service')
- else:
- # TFTP server support is removed in the commit
- os.system('sudo systemctl stop tftpd-hpa.service')
- os.unlink(config_file)
+ tftp_root = tftpd['directory']
+ 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)
+
+ idx = 0
+ for listen in tftpd['listen']:
+ os.system('sudo systemctl restart tftpd@{0}.service'.format(idx))
+ idx = idx + 1
return None
if __name__ == '__main__':
try:
c = get_config()
verify(c)
generate(c)
apply(c)
except ConfigError as e:
print(e)
sys.exit(1)
diff --git a/src/systemd/tftpd@.service b/src/systemd/tftpd@.service
new file mode 100644
index 000000000..e5c289466
--- /dev/null
+++ b/src/systemd/tftpd@.service
@@ -0,0 +1,14 @@
+[Unit]
+Description=TFTP server
+After=network.target
+RequiresMountsFor=/run
+
+[Service]
+Type=forking
+#NotifyAccess=main
+EnvironmentFile=-/etc/default/tftpd%I
+ExecStart=/usr/sbin/in.tftpd "$DAEMON_ARGS"
+Restart=on-failure
+
+[Install]
+WantedBy=multi-user.target

File Metadata

Mime Type
text/x-diff
Expires
Sat, Sep 26, 11:16 AM (1 d, 16 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
4285012
Default Alt Text
(9 KB)

Event Timeline