From 96d85a905f33c5b85b558c1059284db719292096 Mon Sep 17 00:00:00 2001 From: Robin Jarry Date: Thu, 9 Mar 2023 22:05:38 +0100 Subject: config: report accounts.conf format errors When accounts.conf cannot be parsed, return an error instead of assuming that the file is non existent and wrongfully opening the new account wizard. Use the same ini delimiters for all configuration files. Fixes: https://todo.sr.ht/~rjarry/aerc/151 Reported-by: Jon Fineman Signed-off-by: Robin Jarry --- config/accounts.go | 24 ++++++++++++------------ config/binds.go | 4 +++- 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/config/accounts.go b/config/accounts.go index 8aadb329..f9b90ef8 100644 --- a/config/accounts.go +++ b/config/accounts.go @@ -118,18 +118,21 @@ var Accounts []*AccountConfig func parseAccounts(root string, accts []string) error { filename := path.Join(root, "accounts.conf") - if !General.UnsafeAccountsConf { - if err := checkConfigPerms(filename); err != nil { - return err - } + err := checkConfigPerms(filename) + if errors.Is(err, os.ErrNotExist) { + // No config triggers account configuration wizard + return nil + } else if err != nil { + return err } log.Debugf("Parsing accounts configuration from %s", filename) - file, err := ini.Load(filename) + file, err := ini.LoadSources(ini.LoadOptions{ + KeyValueDelimiters: "=", + }, filename) if err != nil { - // No config triggers account configuration wizard - return nil + return err } for _, _sec := range file.SectionStrings() { @@ -231,16 +234,13 @@ func (a *AccountConfig) ParsePgpErrorLevel(sec *ini.Section, key *ini.Key) (int, // printing the fix on stdout and returning an error func checkConfigPerms(filename string) error { info, err := os.Stat(filename) - if errors.Is(err, os.ErrNotExist) { - return nil // disregard absent files - } if err != nil { return err } perms := info.Mode().Perm() - // group or others have read access - if perms&0o44 != 0 { + if perms&0o44 != 0 && !General.UnsafeAccountsConf { + // group or others have read access fmt.Fprintf(os.Stderr, "The file %v has too open permissions.\n", filename) fmt.Fprintln(os.Stderr, "This is a security issue (it contains passwords).") fmt.Fprintf(os.Stderr, "To fix it, run `chmod 600 %v`\n", filename) diff --git a/config/binds.go b/config/binds.go index 5271e0b0..79369247 100644 --- a/config/binds.go +++ b/config/binds.go @@ -107,7 +107,9 @@ func parseBinds(root string) error { } } log.Debugf("Parsing key bindings configuration from %s", filename) - binds, err := ini.Load(filename) + binds, err := ini.LoadSources(ini.LoadOptions{ + KeyValueDelimiters: "=", + }, filename) if err != nil { return err } -- cgit v1.2.3-54-g00ecf