Skip to content

Conversation

troglobit
Copy link
Contributor

Description

Fixes #977

Checklist

Tick relevant boxes, this PR is-a or has-a:

  • Bugfix
    • Regression tests
    • ChangeLog updates (for next release)
  • Feature
    • YANG model change => revision updated?
    • Regression tests added?
    • ChangeLog updates (for next release)
    • Documentation added?
  • Test changes
    • Checked in changed Readme.adoc (make test-spec)
    • Added new test to group Readme.adoc and yaml file
  • Code style update (formatting, renaming)
  • Refactoring (please detail in commit messages)
  • Build related changes
  • Documentation content changes
    • ChangeLog updated (for major changes)
  • Other (please describe):

For future readers, the user paramenter to the copy() function is
actually the remote user in any curl command.

Also, realign columns in infix_config[].

Signed-off-by: Joachim Wiberg <[email protected]>
When copying a file to a directory, the file should be accessible (read
+ write) by all members of the group that are allowed write access.

E.g., an 'admin' level user creating a new file /cfg/foo.cfg should
result in the file being owned by $LOGNAME:wheel with 0660 perms,
because /cfg is root:wheel.

Writing to already existing file, e.g., created by 'root' at first boot,
say /cfg/startup-config.cfg should be possible by all members of the
'wheel' group.  In this case thef file already exists as root:wheel and
any user trying to chgrp it will fail, this is fine.

Fixes #977

Signed-off-by: Joachim Wiberg <[email protected]>
As per earlier decsision, the .cfg suffix is no longer implied when a
user copy to a regular file, so we should allow tab completion in the
copy command to show foo.cfg, otherwise the copy command will fail.

Skip /cfg/startup-config.cfg since it's treated as a special case and
added to the list by the infix_datastore() plugin function.

Signed-off-by: Joachim Wiberg <[email protected]>
@troglobit troglobit requested a review from jovatn March 9, 2025 15:50
@troglobit troglobit mentioned this pull request Mar 9, 2025
17 tasks
Comment on lines +90 to +92
* E.g., writing to /cfg/foo, where /cfg is owned by root:wheel,
* should result in the file being owned by $LOGNAME:wheel with
* 0660 perms for other users in same group.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we made sure that we create startup with g+s, could we rely on the kernel to handle this logic for us?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we made sure that we create startup with g+s, could we rely on the kernel to handle this logic for us?

You mean on /cfg, I assume. Yes, but I was worrying about bind + overlay mounts, as well as external media with vfat/exfat file systems.

@jovatn jovatn requested review from rical and removed request for jovatn March 10, 2025 07:21
return 0;
}

getgrouplist(user, pw->pw_gid, groups, &num);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't there's a theoretical race here, if the user is added to a group after the last call to getgrouplist()? If so, perhaps it's worth wrapping this in an if (..... != -1).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is, wrapping it with a realloc() is probably a good idea to be safer.

src/bin/copy.c Outdated
return 0;

strlcpy(dir, fn, sizeof(dir));
ptr = strrchr(dir, '/');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this block use dirname() to make it easier to understand?

@jovatn jovatn added this to the Infix v25.02 milestone Mar 10, 2025
@troglobit
Copy link
Contributor Author

CCB: assigning to @rical to fix the comments. Thanks!

rical added 5 commits March 10, 2025 14:52
Avoid a theoretical race between getting the number of groups a user
belongs to and actually processing them. We should not need to check
the return value of getgrouplist() as we know the number of groups fit
inside the buffer.

Signed-off-by: Richard Alpe <[email protected]>
Cosmetic change intended to improve code readability.

Signed-off-by: Richard Alpe <[email protected]>
Prior to this patch the errno value was overwritten by getgrgid()
making the printouts invalid:

Error: setting group owner wheel (10) on /cfg/startup-config.cfg:
Success

Signed-off-by: Richard Alpe <[email protected]>
The code assumes both SRC and DST is passed, here we ensure this
early.

Prior to this patch:
root@host:~$ copy foo
Segmentation fault (core dumped)

Signed-off-by: Richard Alpe <[email protected]>
Copy link
Contributor Author

@troglobit troglobit left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work, looks good to me!

Unfortunately our policies prevent me from approving my own PR, so maybe @jovatn can make the formal approval?

Copy link
Contributor

@mattiaswal mattiaswal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor comment

Copy link
Contributor

@mattiaswal mattiaswal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@mattiaswal mattiaswal merged commit 2291e9f into main Mar 11, 2025
6 checks passed
@mattiaswal mattiaswal deleted the copy-owner branch March 11, 2025 15:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Permission error message when 'copy running-config startup-config'

5 participants