mirror of
https://github.com/kernelkit/infix.git
synced 2026-07-29 12:13:01 +02:00
This is a backport of the following commits from origin/main:3b24fabe6a04fb92e80b4ad969653e03ece21256a8b7d91e4d26e3110977ab4f83fbc6--- cli: fix 'copy FILE running-config' use-case When copying to the running datastore we cannot use sr_copy_config(), instead we must use sr_replace_config(). This fix covers both the case of 'copy startup-config running-config' and 'copy FILE running-config'. Fixes #1203 --- cli: add 'validate', or '-n', dry run to copy command This commit adds config file validation to the copy command, discussed in #373. Allowing users to test their config files before restoring a backup. The feature could also be used for the automatic rollback when downgrading to an earlier version of the OS. Fixes #373 --- cli: fix copy to missing startup-config file Fixes #981 --- cli: restrict copy and erase commands This is a follow-up to PR #717 where path traversal protection was discussed. A year later and it's clear that having a user-friendly copy tool in the shell is a good thing, but that we proably want to restrict what it can do when called from the CLI. A sanitize flag (-s) is added to control the behavior, when used in the shell without -s, both commands act like traditional UNIX tools and do assume . for relative paths, and allow ../, whereas when running from the CLI only /media/ is allowed and otherwise files are assumed to be in $HOME or /cfg --- cli: sanitize regular file to file copy The regular file-to-file copy, was missing calls to cfg_adjust(), this commit fixes that and adds some helpful comments for each use-case. Also, drop insecure mktemp() in favor of our own version which uses the basename of the remote source file. --- bin: add bash completion for copy command Add bash completion for the common datastores, like we already do in the CLI, and update the usage text accordingly. Also, make sure to install to /usr/bin, not /bin since we've now merged the hierarchies since a while back. --- bin: copy: Refactor copy() made some...creative...use of control flow that made it quite difficult to follow. Take a first priciples approach to simplify the logic. --- bin: copy: Always get startup from sysrepo This will make sure to apply NACM rules for all the data. It also makes it possible for a luser access a subset of the data, even if they to do not have read access to /cfg/startup-config.cfg. Signed-off-by: Joachim Wiberg <troglobit@gmail.com>