mirror of
https://github.com/netbirdio/netbird.git
synced 2025-08-15 17:52:47 +02:00
Add platform-specific profile handling and sanitize usernames
This commit is contained in:
@ -1,3 +1,6 @@
|
|||||||
|
//go:build windows
|
||||||
|
// +build windows
|
||||||
|
|
||||||
package server
|
package server
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
@ -2,6 +2,7 @@ package server
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/netbirdio/netbird/client/proto"
|
"github.com/netbirdio/netbird/client/proto"
|
||||||
)
|
)
|
||||||
@ -63,3 +64,14 @@ func (s *Server) RemoveProfile(ctx context.Context, req *proto.RemoveProfileRequ
|
|||||||
Error: "",
|
Error: "",
|
||||||
}, nil
|
}, 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
|
inputConfig.PreSharedKey = msg.OptionalPreSharedKey
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fmt.Printf("LOGGED IN!!!!!!: %s\n", inputConfig.ConfigPath)
|
||||||
config, err := internal.UpdateOrCreateConfig(inputConfig)
|
config, err := internal.UpdateOrCreateConfig(inputConfig)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
Reference in New Issue
Block a user