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.
This commit is contained in:
Conrad Hoffmann 2019-04-15 11:01:59 +02:00
parent ab356b2890
commit 11f380924f
1 changed files with 5 additions and 1 deletions

View File

@ -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]"