From 4d6ef97722446157e5b36facaed7e6db20a2c57a Mon Sep 17 00:00:00 2001 From: Itxaka Date: Mon, 12 Feb 2024 21:04:54 +0100 Subject: [PATCH] Do not write files in user system This stops sysinfo from writing files in the running system without telling the user about it. A system with no machine-id is a completely valid system and can be like that at different times, like inside a container, on a first boot, in immutable systems, etc... We should not write files in teh user system without informing them and not having a machine-id is a valid state. Signed-off-by: Itxaka --- node.go | 16 ---------------- 1 file changed, 16 deletions(-) diff --git a/node.go b/node.go index 480ac0d..216ee3a 100644 --- a/node.go +++ b/node.go @@ -6,11 +6,8 @@ package sysinfo import ( "bufio" - "crypto/rand" - "fmt" "os" "strings" - "time" ) // Node information. @@ -58,19 +55,6 @@ func (si *SysInfo) getSetMachineID() { si.Node.MachineID = systemdMachineID return } - - // Generate and write fresh new machine ID to both locations, conforming to the DBUS specification: - // https://dbus.freedesktop.org/doc/dbus-specification.html#uuids - - random := make([]byte, 12) - if _, err := rand.Read(random); err != nil { - return - } - newMachineID := fmt.Sprintf("%x%x", random, time.Now().Unix()) - - spewFile(pathSystemdMachineID, newMachineID, 0444) - spewFile(pathDbusMachineID, newMachineID, 0444) - si.Node.MachineID = newMachineID } func (si *SysInfo) getTimezone() {