From 11f380924f70eb6469bb2fb18de1fb70d6dc0477 Mon Sep 17 00:00:00 2001 From: Conrad Hoffmann Date: Mon, 15 Apr 2019 11:01:59 +0200 Subject: [PATCH] Escape hashes in password for config file The hash is the comment character in the config file, even if it occurs in the middle of the password. This can be worked around however by escaping it. This fixes #16. --- collector.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/collector.go b/collector.go index 72d197c..fe09115 100644 --- a/collector.go +++ b/collector.go @@ -185,7 +185,7 @@ func freeipmiConfig(config IPMIConfig) string { fmt.Fprintf(&b, "username %s\n", config.User) } if config.Password != "" { - fmt.Fprintf(&b, "password %s\n", config.Password) + fmt.Fprintf(&b, "password %s\n", escapePassword(config.Password)) } if config.Timeout != 0 { fmt.Fprintf(&b, "session-timeout %d\n", config.Timeout) @@ -515,6 +515,10 @@ func contains(s []int64, elm int64) bool { return false } +func escapePassword(password string) string { + return strings.Replace(password, "#", "\\#", -1) +} + func targetName(target string) string { if targetIsLocal(target) { return "[local]"