mirror of
https://github.com/tailscale/tailscale.git
synced 2024-11-25 19:15:34 +00:00
paths: remove wasm file, no-op stubs, make OS-specific funcs consistent
Some OS-specific funcs were defined in init. Another used build tags and required all other OSes to stub it out. Another one could just be in the portable file. Simplify it a bit, removing a file and some stubs in the process. Updates #5794 Change-Id: I51df8772cc60a9335ac4c1dc0ab59b8a0d236961 Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
This commit is contained in:
parent
d58ba59fd5
commit
a5dcc4c87b
@ -45,7 +45,14 @@ func DefaultTailscaledSocket() string {
|
||||
return "tailscaled.sock"
|
||||
}
|
||||
|
||||
var stateFileFunc func() string
|
||||
// Overridden in init by OS-specific files.
|
||||
var (
|
||||
stateFileFunc func() string
|
||||
|
||||
// ensureStateDirPerms applies a restrictive ACL/chmod
|
||||
// to the provided directory.
|
||||
ensureStateDirPerms = func(string) error { return nil }
|
||||
)
|
||||
|
||||
// DefaultTailscaledStateFile returns the default path to the
|
||||
// tailscaled state file, or the empty string if there's no reasonable
|
||||
@ -67,6 +74,16 @@ func MkStateDir(dirPath string) error {
|
||||
if err := os.MkdirAll(dirPath, 0700); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return ensureStateDirPerms(dirPath)
|
||||
}
|
||||
|
||||
// LegacyStateFilePath returns the legacy path to the state file when
|
||||
// it was stored under the current user's %LocalAppData%.
|
||||
//
|
||||
// It is only called on Windows.
|
||||
func LegacyStateFilePath() string {
|
||||
if runtime.GOOS == "windows" {
|
||||
return filepath.Join(os.Getenv("LocalAppData"), "Tailscale", "server-state.conf")
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
// Copyright (c) Tailscale Inc & AUTHORS
|
||||
// SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
//go:build !windows && !js && !wasip1
|
||||
//go:build !windows && !wasm && !plan9
|
||||
|
||||
package paths
|
||||
|
||||
@ -17,6 +17,7 @@
|
||||
|
||||
func init() {
|
||||
stateFileFunc = stateFileUnix
|
||||
ensureStateDirPerms = ensureStateDirPermsUnix
|
||||
}
|
||||
|
||||
func statePath() string {
|
||||
@ -65,7 +66,7 @@ func xdgDataHome() string {
|
||||
return filepath.Join(os.Getenv("HOME"), ".local/share")
|
||||
}
|
||||
|
||||
func ensureStateDirPerms(dir string) error {
|
||||
func ensureStateDirPermsUnix(dir string) error {
|
||||
if filepath.Base(dir) != "tailscale" {
|
||||
return nil
|
||||
}
|
||||
@ -83,8 +84,3 @@ func ensureStateDirPerms(dir string) error {
|
||||
}
|
||||
return os.Chmod(dir, perm)
|
||||
}
|
||||
|
||||
// LegacyStateFilePath is not applicable to UNIX; it is just stubbed out.
|
||||
func LegacyStateFilePath() string {
|
||||
return ""
|
||||
}
|
||||
|
@ -1,10 +0,0 @@
|
||||
// Copyright (c) Tailscale Inc & AUTHORS
|
||||
// SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
package paths
|
||||
|
||||
func ensureStateDirPerms(dirPath string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func LegacyStateFilePath() string { return "" }
|
@ -12,7 +12,11 @@
|
||||
"tailscale.com/util/winutil"
|
||||
)
|
||||
|
||||
// ensureStateDirPerms applies a restrictive ACL to the directory specified by dirPath.
|
||||
func init() {
|
||||
ensureStateDirPerms = ensureStateDirPermsWindows
|
||||
}
|
||||
|
||||
// ensureStateDirPermsWindows applies a restrictive ACL to the directory specified by dirPath.
|
||||
// It sets the following security attributes on the directory:
|
||||
// Owner: The user for the current process;
|
||||
// Primary Group: The primary group for the current process;
|
||||
@ -26,7 +30,7 @@
|
||||
//
|
||||
// However, any directories and/or files created within this
|
||||
// directory *do* inherit the ACL that we are setting.
|
||||
func ensureStateDirPerms(dirPath string) error {
|
||||
func ensureStateDirPermsWindows(dirPath string) error {
|
||||
fi, err := os.Stat(dirPath)
|
||||
if err != nil {
|
||||
return err
|
||||
@ -94,9 +98,3 @@ func ensureStateDirPerms(dirPath string) error {
|
||||
return windows.SetNamedSecurityInfo(dirPath, windows.SE_FILE_OBJECT, flags,
|
||||
sids.User, sids.PrimaryGroup, dacl, nil)
|
||||
}
|
||||
|
||||
// LegacyStateFilePath returns the legacy path to the state file when it was stored under the
|
||||
// current user's %LocalAppData%.
|
||||
func LegacyStateFilePath() string {
|
||||
return filepath.Join(os.Getenv("LocalAppData"), "Tailscale", "server-state.conf")
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user