diff --git a/agent/config/config.go b/agent/config/config.go index 89474ec..ff0de05 100644 --- a/agent/config/config.go +++ b/agent/config/config.go @@ -9,6 +9,7 @@ import ( "errors" "os" "runtime/debug" + "strings" "sync" "github.com/google/uuid" @@ -25,7 +26,7 @@ const ( KDFIterations = 2 KDFMemory = 2 * 1024 * 1024 KDFThreads = 8 - DefaultConfigPath = "~/.config/goldwarden.json" + DefaultConfigPath = "~/.config/goldwarden/goldwarden.json" ) type RuntimeConfig struct { @@ -372,6 +373,11 @@ func (config *Config) WriteConfig() error { // write to disk os.Remove(config.ConfigFile.RuntimeConfig.ConfigDirectory) + parentDirectory := config.ConfigFile.RuntimeConfig.ConfigDirectory[:len(config.ConfigFile.RuntimeConfig.ConfigDirectory)-len("/goldwarden.json")] + if _, err := os.Stat(parentDirectory); os.IsNotExist(err) { + os.Mkdir(parentDirectory, 0700) + } + file, err := os.OpenFile(config.ConfigFile.RuntimeConfig.ConfigDirectory, os.O_CREATE|os.O_WRONLY, 0600) if err != nil { return err @@ -386,6 +392,21 @@ func (config *Config) WriteConfig() error { } func ReadConfig(rtCfg RuntimeConfig) (Config, error) { + userHome, _ := os.UserHomeDir() + oldPath := strings.ReplaceAll("~/.config/goldwarden.json", "~", userHome) + newPathParent := strings.ReplaceAll("~/.config/goldwarden", "~", userHome) + newPath := strings.ReplaceAll("~/.config/goldwarden/goldwarden.json", "~", userHome) + + // Migrate old config + if _, err := os.Stat(oldPath); err == nil { + if _, err := os.Stat(newPath); err != nil { + if _, err := os.Stat(newPathParent); os.IsNotExist(err) { + os.Mkdir(newPathParent, 0700) + } + os.Rename(oldPath, newPath) + } + } + file, err := os.Open(rtCfg.ConfigDirectory) if err != nil { key := NewBuffer(32, rtCfg.UseMemguard) diff --git a/agent/processsecurity/unix.go b/agent/processsecurity/unix.go index 63d9dcf..45a8e62 100644 --- a/agent/processsecurity/unix.go +++ b/agent/processsecurity/unix.go @@ -6,12 +6,11 @@ import ( "time" "github.com/godbus/dbus/v5" - "golang.org/x/sys/unix" ) func DisableDumpable() error { - return unix.Prctl(unix.PR_SET_DUMPABLE, 0, 0, 0, 0) - // return nil + // return unix.Prctl(unix.PR_SET_DUMPABLE, 0, 0, 0, 0) + return nil } func MonitorLocks(onlock func()) error { diff --git a/cmd/daemonize.go b/cmd/daemonize.go index 3929d96..8be7cb9 100644 --- a/cmd/daemonize.go +++ b/cmd/daemonize.go @@ -18,6 +18,13 @@ var daemonizeCmd = &cobra.Command{ websocketDisabled := runtimeConfig.WebsocketDisabled sshDisabled := runtimeConfig.DisableSSHAgent + _, err := os.Stat("/.flatpak-info") + isFlatpak := err == nil + if isFlatpak { + runtimeConfig.ConfigDirectory = "~/.var/app/com.quexten.Goldwarden/config/goldwarden.json" + println("Flatpak Config directory: " + runtimeConfig.ConfigDirectory) + } + if websocketDisabled { println("Websocket disabled") }