mirror of
https://github.com/netbirdio/netbird.git
synced 2025-06-19 08:17:01 +02:00
Add platform-specific profile handling and sanitize usernames
This commit is contained in:
parent
ee8957b052
commit
bccf672dc0
@ -1,3 +1,6 @@
|
||||
//go:build windows
|
||||
// +build windows
|
||||
|
||||
package server
|
||||
|
||||
import (
|
||||
|
@ -2,6 +2,7 @@ package server
|
||||
|
||||
import (
|
||||
"context"
|
||||
"strings"
|
||||
|
||||
"github.com/netbirdio/netbird/client/proto"
|
||||
)
|
||||
@ -63,3 +64,14 @@ func (s *Server) RemoveProfile(ctx context.Context, req *proto.RemoveProfileRequ
|
||||
Error: "",
|
||||
}, nil
|
||||
}
|
||||
|
||||
// sanitazeUsername sanitizes the username by removing any invalid characters
|
||||
func sanitazeUsername(username string) string {
|
||||
// Remove invalid characters for a username in a file path
|
||||
return strings.Map(func(r rune) rune {
|
||||
if r == '/' || r == '\\' || r == ':' || r == '*' || r == '?' || r == '"' || r == '<' || r == '>' || r == '|' {
|
||||
return -1 // remove this character
|
||||
}
|
||||
return r
|
||||
}, username)
|
||||
}
|
||||
|
14
client/server/profile_darwin.go
Normal file
14
client/server/profile_darwin.go
Normal file
@ -0,0 +1,14 @@
|
||||
//go:build darwin
|
||||
// +build darwin
|
||||
|
||||
package server
|
||||
|
||||
import "path/filepath"
|
||||
|
||||
func getSystemProfilesDir() string {
|
||||
return "/Library/Application Support/Netbird/Profiles"
|
||||
}
|
||||
|
||||
func getUserProfilesDir(username string) string {
|
||||
return filepath.Join("/Users", sanitazeUsername(username), "Library", "Application Support", "Netbird", "Profiles")
|
||||
}
|
15
client/server/profile_unix.go
Normal file
15
client/server/profile_unix.go
Normal file
@ -0,0 +1,15 @@
|
||||
//go:build linux || dragonfly || freebsd || netbsd || openbsd
|
||||
// +build linux dragonfly freebsd netbsd openbsd
|
||||
|
||||
package server
|
||||
|
||||
import "path/filepath"
|
||||
|
||||
func getSystemProfilesDir() string {
|
||||
return "/var/lib/netbird/profiles"
|
||||
}
|
||||
|
||||
func getUserProfilesDir(username string) string {
|
||||
// ~/.config/netbird/profiles
|
||||
return filepath.Join("/home", sanitazeUsername(username), ".config", "netbird", "profiles")
|
||||
}
|
17
client/server/profile_windows.go
Normal file
17
client/server/profile_windows.go
Normal file
@ -0,0 +1,17 @@
|
||||
//go:build windows
|
||||
// +build windows
|
||||
|
||||
package server
|
||||
|
||||
import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
)
|
||||
|
||||
func getSystemProfilesDir() string {
|
||||
return filepath.Join(os.Getenv("PROGRAMDATA"), "Netbird", "Profiles")
|
||||
}
|
||||
|
||||
func getUserProfilesDir(username string) string {
|
||||
return filepath.Join(os.Getenv("LOCALAPPDATA"), "Netbird", "Profiles")
|
||||
}
|
@ -434,6 +434,7 @@ func (s *Server) Login(callerCtx context.Context, msg *proto.LoginRequest) (*pro
|
||||
inputConfig.PreSharedKey = msg.OptionalPreSharedKey
|
||||
}
|
||||
|
||||
fmt.Printf("LOGGED IN!!!!!!: %s\n", inputConfig.ConfigPath)
|
||||
config, err := internal.UpdateOrCreateConfig(inputConfig)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
Loading…
x
Reference in New Issue
Block a user