mirror of
https://blitiri.com.ar/repos/chasquid
synced 2025-12-17 14:37:02 +00:00
chasquid-util: Fix creating the directory on user-add
`chasquid-util user-add` is meant to create the domain directory if it doesn't exist; however there's a bug that makes this not happen, and instead the command fails with: Error writing database: open <path>: no such file or directory This patch fixes the issue and adds a test to ensure we don't have any regressions on this behaviour. Thanks to raspbeguy (https://github.com/raspbeguy) for reporting this issue (on IRC).
This commit is contained in:
@@ -4,7 +4,9 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"io/fs"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"sort"
|
"sort"
|
||||||
@@ -126,19 +128,22 @@ func userDBFromArgs(create bool) (string, string, *userdb.DB) {
|
|||||||
Fatalf("Domain missing, username should be of the form 'user@domain'")
|
Fatalf("Domain missing, username should be of the form 'user@domain'")
|
||||||
}
|
}
|
||||||
|
|
||||||
db, err := userdb.Load(userDBForDomain(domain))
|
if create {
|
||||||
if err != nil {
|
dbDir := filepath.Dir(userDBForDomain(domain))
|
||||||
if create && os.IsNotExist(err) {
|
if _, err := os.Stat(dbDir); errors.Is(err, fs.ErrNotExist) {
|
||||||
fmt.Println("Creating database")
|
fmt.Println("Creating database")
|
||||||
err = os.MkdirAll(filepath.Dir(userDBForDomain(domain)), 0755)
|
err = os.MkdirAll(dbDir, 0755)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
Fatalf("Error creating database dir: %v", err)
|
Fatalf("Error creating database dir: %v", err)
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
Fatalf("Error loading database: %v", err)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
db, err := userdb.Load(userDBForDomain(domain))
|
||||||
|
if err != nil {
|
||||||
|
Fatalf("Error loading database: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
user, err = normalize.User(user)
|
user, err = normalize.User(user)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
Fatalf("Error normalizing user: %v", err)
|
Fatalf("Error normalizing user: %v", err)
|
||||||
|
|||||||
@@ -25,13 +25,15 @@ function check_userdb() {
|
|||||||
|
|
||||||
|
|
||||||
rm -rf .config/
|
rm -rf .config/
|
||||||
mkdir -p .config/domains/domain/ .data/domaininfo
|
mkdir -p .config/ .data/domaininfo
|
||||||
echo 'data_dir: ".data"' >> .config/chasquid.conf
|
echo 'data_dir: ".data"' >> .config/chasquid.conf
|
||||||
|
|
||||||
if ! r print-config > /dev/null; then
|
if ! r print-config > /dev/null; then
|
||||||
fail print-config
|
fail print-config
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# We intentionally run this when the domain directory doesn't exist, as we
|
||||||
|
# want to confirm it creates it.
|
||||||
if ! r user-add interactive@domain --password=passwd > /dev/null; then
|
if ! r user-add interactive@domain --password=passwd > /dev/null; then
|
||||||
fail user-add
|
fail user-add
|
||||||
fi
|
fi
|
||||||
|
|||||||
Reference in New Issue
Block a user