mirror of
https://github.com/tailscale/tailscale.git
synced 2025-02-18 02:48:40 +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"
|
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
|
// DefaultTailscaledStateFile returns the default path to the
|
||||||
// tailscaled state file, or the empty string if there's no reasonable
|
// 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 {
|
if err := os.MkdirAll(dirPath, 0700); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
return ensureStateDirPerms(dirPath)
|
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
|
// Copyright (c) Tailscale Inc & AUTHORS
|
||||||
// SPDX-License-Identifier: BSD-3-Clause
|
// SPDX-License-Identifier: BSD-3-Clause
|
||||||
|
|
||||||
//go:build !windows && !js && !wasip1
|
//go:build !windows && !wasm && !plan9
|
||||||
|
|
||||||
package paths
|
package paths
|
||||||
|
|
||||||
@ -17,6 +17,7 @@ import (
|
|||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
stateFileFunc = stateFileUnix
|
stateFileFunc = stateFileUnix
|
||||||
|
ensureStateDirPerms = ensureStateDirPermsUnix
|
||||||
}
|
}
|
||||||
|
|
||||||
func statePath() string {
|
func statePath() string {
|
||||||
@ -65,7 +66,7 @@ func xdgDataHome() string {
|
|||||||
return filepath.Join(os.Getenv("HOME"), ".local/share")
|
return filepath.Join(os.Getenv("HOME"), ".local/share")
|
||||||
}
|
}
|
||||||
|
|
||||||
func ensureStateDirPerms(dir string) error {
|
func ensureStateDirPermsUnix(dir string) error {
|
||||||
if filepath.Base(dir) != "tailscale" {
|
if filepath.Base(dir) != "tailscale" {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@ -83,8 +84,3 @@ func ensureStateDirPerms(dir string) error {
|
|||||||
}
|
}
|
||||||
return os.Chmod(dir, perm)
|
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 @@ import (
|
|||||||
"tailscale.com/util/winutil"
|
"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:
|
// It sets the following security attributes on the directory:
|
||||||
// Owner: The user for the current process;
|
// Owner: The user for the current process;
|
||||||
// Primary Group: The primary group for the current process;
|
// Primary Group: The primary group for the current process;
|
||||||
@ -26,7 +30,7 @@ import (
|
|||||||
//
|
//
|
||||||
// However, any directories and/or files created within this
|
// However, any directories and/or files created within this
|
||||||
// directory *do* inherit the ACL that we are setting.
|
// directory *do* inherit the ACL that we are setting.
|
||||||
func ensureStateDirPerms(dirPath string) error {
|
func ensureStateDirPermsWindows(dirPath string) error {
|
||||||
fi, err := os.Stat(dirPath)
|
fi, err := os.Stat(dirPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@ -94,9 +98,3 @@ func ensureStateDirPerms(dirPath string) error {
|
|||||||
return windows.SetNamedSecurityInfo(dirPath, windows.SE_FILE_OBJECT, flags,
|
return windows.SetNamedSecurityInfo(dirPath, windows.SE_FILE_OBJECT, flags,
|
||||||
sids.User, sids.PrimaryGroup, dacl, nil)
|
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…
x
Reference in New Issue
Block a user