From 50ab27c6749d13fc6842d92259f8e0fd8fa5340c Mon Sep 17 00:00:00 2001 From: Randall Winkhart Date: Thu, 29 May 2025 16:52:15 +0000 Subject: [PATCH] Ensure libmutton.ini is created with 0600 permissions (on *nix) --- core/configParser.go | 1 + core/utilitiesUNIX.go | 12 ++++++++++++ core/utilitiesWIN.go | 8 ++++++++ 3 files changed, 21 insertions(+) create mode 100644 core/utilitiesUNIX.go create mode 100644 core/utilitiesWIN.go diff --git a/core/configParser.go b/core/configParser.go index a041215..8a62b78 100644 --- a/core/configParser.go +++ b/core/configParser.go @@ -92,6 +92,7 @@ func WriteConfig(valuesToWrite [][3]string, keysToPrune [][2]string, append bool } // save to libmutton.ini + setUmask(0077) // only give permissions to owner err := cfg.SaveTo(global.ConfigPath) if err != nil { back.PrintError("Failed to save libmutton.ini: "+err.Error(), back.ErrorWrite, true) diff --git a/core/utilitiesUNIX.go b/core/utilitiesUNIX.go new file mode 100644 index 0000000..6bb17d7 --- /dev/null +++ b/core/utilitiesUNIX.go @@ -0,0 +1,12 @@ +//go:build !windows + +package core + +import "syscall" + +// setUmask sets the file mode creation mask (umask) for the current process. +// The call to syscall.Umask needs to be embedded in another function to allow +// compilation on Windows. +func setUmask(umask int) { + syscall.Umask(umask) +} diff --git a/core/utilitiesWIN.go b/core/utilitiesWIN.go new file mode 100644 index 0000000..f79f771 --- /dev/null +++ b/core/utilitiesWIN.go @@ -0,0 +1,8 @@ +//go:build windows + +package core + +// setUmask is a dummy function on Windows. +func setUmask(umask int) { + return +}