windows: make rclone work with SeBackupPrivilege and/or SeRestorePrivilege

On Windows, this change includes the `FILE_FLAG_BACKUP_SEMANTICS` in
all calls to `CreateFile`.

Adding this flag allows is useful when rclone is running within a
security context that has `SeBackupPrivilege` and/or `SeRestorePrivilege`
token privileges enabled.

Without this flag, rclone cannot properly leverage special security
groups such as Backup Operators who possess the these privileges.

See: https://forum.rclone.org/t/rclone-sebackupprivilege-file-flag-backup-semantics/45339
See: https://github.com/rclone/rclone/pull/7877.
This commit is contained in:
Charles Hamilton 2024-06-07 08:26:30 -04:00 committed by GitHub
parent dac7f76b14
commit b778ec0142
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -61,7 +61,7 @@ func OpenFile(path string, mode int, perm os.FileMode) (*os.File, error) {
default: default:
createmode = syscall.OPEN_EXISTING createmode = syscall.OPEN_EXISTING
} }
h, e := syscall.CreateFile(pathp, access, sharemode, nil, createmode, syscall.FILE_ATTRIBUTE_NORMAL, 0) h, e := syscall.CreateFile(pathp, access, sharemode, nil, createmode, syscall.FILE_ATTRIBUTE_NORMAL|syscall.FILE_FLAG_BACKUP_SEMANTICS, 0)
if e != nil { if e != nil {
return nil, e return nil, e
} }