aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobin Jarry <robin@jarry.cc>2023-03-09 22:05:38 +0100
committerRobin Jarry <robin@jarry.cc>2023-03-09 22:08:58 +0100
commit96d85a905f33c5b85b558c1059284db719292096 (patch)
tree936d13c4f95d0008761c2bfada28f5b0034ccd29
parent04bfc81a1abe8865a036e941545be0c05fd4f3fd (diff)
downloadaerc-96d85a905f33c5b85b558c1059284db719292096.tar.gz
aerc-96d85a905f33c5b85b558c1059284db719292096.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>
-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 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
}