Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
This adds support for syncing ownership on Unixes and on Windows. The scanner always picks up ownership information, but it is not applied unless the new folder option "Sync Ownership" is set. Ownership data is stored in a new FileInfo field called "platform data". This is intended to hold further platform-specific data in the future (specifically, extended attributes), which is why the whole design is a bit overkill for just ownership.
- Loading branch information
Showing
35 changed files
with
1,895 additions
and
499 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains 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
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// Copyright (C) 2022 The Syncthing Authors. | ||
// | ||
// This Source Code Form is subject to the terms of the Mozilla Public | ||
// License, v. 2.0. If a copy of the MPL was not distributed with this file, | ||
// You can obtain one at https://mozilla.org/MPL/2.0/. | ||
|
||
//go:build !windows | ||
// +build !windows | ||
|
||
package fs | ||
|
||
import ( | ||
"github.com/syncthing/syncthing/lib/protocol" | ||
) | ||
|
||
func (f *BasicFilesystem) PlatformData(name string) (protocol.PlatformData, error) { | ||
return unixPlatformData(f, name) | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
// Copyright (C) 2022 The Syncthing Authors. | ||
// | ||
// This Source Code Form is subject to the terms of the Mozilla Public | ||
// License, v. 2.0. If a copy of the MPL was not distributed with this file, | ||
// You can obtain one at https://mozilla.org/MPL/2.0/. | ||
|
||
package fs | ||
|
||
import ( | ||
"fmt" | ||
"os/user" | ||
|
||
"github.com/syncthing/syncthing/lib/protocol" | ||
"golang.org/x/sys/windows" | ||
) | ||
|
||
func (f *BasicFilesystem) PlatformData(name string) (protocol.PlatformData, error) { | ||
rootedName, err := f.rooted(name) | ||
if err != nil { | ||
return protocol.PlatformData{}, fmt.Errorf("rooted for %s: %w", name, err) | ||
} | ||
hdl, err := openReadOnlyWithBackupSemantics(rootedName) | ||
if err != nil { | ||
return protocol.PlatformData{}, fmt.Errorf("open %s: %w", rootedName, err) | ||
} | ||
defer windows.Close(hdl) | ||
|
||
// GetSecurityInfo returns an owner SID. | ||
sd, err := windows.GetSecurityInfo(hdl, windows.SE_FILE_OBJECT, windows.OWNER_SECURITY_INFORMATION) | ||
if err != nil { | ||
return protocol.PlatformData{}, fmt.Errorf("get security info for %s: %w", rootedName, err) | ||
} | ||
owner, _, err := sd.Owner() | ||
if err != nil { | ||
return protocol.PlatformData{}, fmt.Errorf("get owner for %s: %w", rootedName, err) | ||
} | ||
|
||
// The owner SID might represent a user or a group. We try to look it up | ||
// as both, and set the appropriate fields in the OS data. | ||
pd := &protocol.WindowsData{} | ||
if us, err := user.LookupId(owner.String()); err == nil { | ||
pd.OwnerName = us.Username | ||
} else if gr, err := user.LookupGroupId(owner.String()); err == nil { | ||
pd.OwnerName = gr.Name | ||
pd.OwnerIsGroup = true | ||
} else { | ||
l.Debugf("Failed to resolve owner for %s: %v", rootedName, err) | ||
} | ||
|
||
return protocol.PlatformData{Windows: pd}, nil | ||
} | ||
|
||
func openReadOnlyWithBackupSemantics(path string) (fd windows.Handle, err error) { | ||
// This is windows.Open but simplified to read-only only, and adding | ||
// FILE_FLAG_BACKUP_SEMANTICS which is required to open directories. | ||
if len(path) == 0 { | ||
return windows.InvalidHandle, windows.ERROR_FILE_NOT_FOUND | ||
} | ||
pathp, err := windows.UTF16PtrFromString(path) | ||
if err != nil { | ||
return windows.InvalidHandle, err | ||
} | ||
var access uint32 = windows.GENERIC_READ | ||
var sharemode uint32 = windows.FILE_SHARE_READ | windows.FILE_SHARE_WRITE | ||
var sa *windows.SecurityAttributes | ||
var createmode uint32 = windows.OPEN_EXISTING | ||
var attrs uint32 = windows.FILE_ATTRIBUTE_READONLY | windows.FILE_FLAG_BACKUP_SEMANTICS | ||
return windows.CreateFile(pathp, access, sharemode, sa, createmode, attrs, 0) | ||
} |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Oops, something went wrong.