Conversation
Add a simple script that verifies all the common use-cases of copy.
copy() made some...creative...use of control flow that made it quite difficult to follow. Take a first priciples approach to simplify the logic.
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.
troglobit
approved these changes
Oct 31, 2025
Contributor
troglobit
left a comment
There was a problem hiding this comment.
Nice work cleaning this up, and thank you for taking the time! 🙇
Only minor thing I found, that's a regression from my version, is this:
admin@ix-00-00-00:~$ copy operational-state fozza
admin@ix-00-00-00:~$ ll
total 20
drwxr-sr-x 3 admin admin 4096 Oct 31 09:59 ./
drwxr-xr-x 1 root root 4096 Oct 28 18:19 ../
-rw-r--r-- 1 admin admin 183 Oct 31 09:55 .klish_history
-rw------- 1 admin admin 20 Oct 31 09:59 .lesshst
drwxr-s--- 2 root admin 4096 Oct 31 08:23 .ssh/
admin@ix-00-00-00:~$ copy operational-state fozza.cfg
Overwrite existing file /cfg//fozza.cfg (y/N)?
But if I give an absolute path it works. This is not important enough to block this PR.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Refactor
copyto make it easier to follow. NACM should now also actually be applied, before this PR,sr_nacm_set_user()was called without first callingsr_nacm_init(), but this was not detected as the return code was not checked. Also plug some Bobby Droptables vectors by invokingcurlwithout shell expansion.I also added a small test script to test the most common use-cases. Its execution is not automated, but then again we do not muck about in this code that often. Please have a look if there are any glaring holes in that. I would also appreciate some free testing to make sure I have not missed anything major.
Checklist