-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
convert negative uid and gid to 0o7777777 #4102
convert negative uid and gid to 0o7777777 #4102
Conversation
Substitute negative uid and gid that is returned from os.Getuid and os.Getgid in Windows with maximum value that is allowed in v7 and ustar tar formats, i.e., 0o7777777. See: https://www.gnu.org/software/tar/manual/html_section/Formats.html This fixes the issue of a 32-bit binary restic dump that creates a tar file containing negative uid and gid files: restic#4101
Good catch, but I think fixing the dump command is a better idea. This changes the repo format, so it won't work with existing repositories. |
Thanks @greatroar. Unless I am missing something, I have not changed anything in the repository format. The uid and gid in the node are still of type As for your suggestion for changing dump, I agree that it is a good idea and can be done orthogonally to this pull request. One has to decide what to do in case the uid/gid is more than what can be stored in an |
They're still uint32, but the meaning of that uint32 for dumps from Windows changes. It's not documented anywhere that ^uint32(0) means -1, but there are many repos where that is the case. |
I see that with the code in this pull request the repository node that is created is different than before. If some person's code relies on the specific old value of 4294967295, then there could be a problem. Should this person's code rely on this specific value? Probably not. Moreover, if you backup an actual file of the Windows filesystem and not stdin, the uid and gid are set to 0. Continuing the example in #4101:
Here is the file snapshot:
Here is the stdin snapshot:
Is it nice to have such a uid/gid discrepancy between a normal file backup and a stdin backup in Windows? Maybe both should have uid/gid of 0. Maybe zero is also a better value for this commit (instead of 0o7777777). |
From a quick look around Linux, FreeBSD, Solaris (https://docs.oracle.com/cd/E19082-01/820-0543/gfraf/index.html) and macOS the standard seems to be uid_t == uint32 nowadays. Thus, we can assume that Even the POSIX man page for As uids above 2^31 are apparently a not particularly portable mess, I'd prefer to keep the fix minimally invasive and just convert from uid
stdin-backups fall back to the uid / gid of the current user. On Windows this just defaults to -1. After fixing the dump command, the current behavior should work fine, so it's probably not worth the effort of changing it. |
Thanks for the answer @MichaelEischer! So we can close this and maybe move to #4103. |
Yes, let's take the route of #4103 instead (although still limited to only the -1 uid) |
Substitute negative uid and gid that is returned from os.Getuid
and os.Getgid in Windows with maximum value that is allowed in
v7 and ustar tar formats, i.e., 0o7777777. See:
https://www.gnu.org/software/tar/manual/html_section/Formats.html
This fixes the issue of a 32-bit binary restic dump that creates
a tar file containing negative uid and gid files:
#4101
What does this PR change? What problem does it solve?
#4101
Was the change previously discussed in an issue or on the forum?
I have only created the relevant issue #4101.
Checklist
Comments on checklist: I did not write a new test, because the change is simple. I have run the tests though. The change is internal, so there is no change in the manual.
changelog/unreleased/
that describes the changes for our users (see template).gofmt
on the code in all commits.