summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobin Jarry <robin@jarry.cc>2023-03-09 22:05:38 +0100
committerRobin Jarry <robin@jarry.cc>2023-03-26 21:05:48 +0200
commit86441411f46ba067cb445e6590b8d12cd20c4490 (patch)
treeff8cd38569bf4b2674c14bec8c189277bdbb8428
parent65b1524bc63ddb926c4b83b1a34b89599fd8d156 (diff)
downloadaerc-86441411f46ba067cb445e6590b8d12cd20c4490.tar.gz
aerc-86441411f46ba067cb445e6590b8d12cd20c4490.zip
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 <jon@fineman.me> Signed-off-by: Robin Jarry <robin@jarry.cc> Tested-by: Bence Ferdinandy <bence@ferdinandy.com>
-rw-r--r--config/accounts.go24
-rw-r--r--config/binds.go4
2 files changed, 15 insertions, 13 deletions
diff --git a/config/accounts.go b/config/accounts.go
index bacd7e39..656abf29 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() {
@@ -241,16 +244,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
}