mirror of
https://github.com/mjl-/mox.git
synced 2025-06-28 09:38:15 +03:00
unbreak the subcommands that talk to the mox instance of the ctl socket
broken on may 31st with the "open tls keys as root" change, 70d07c5459d8, so broken in v0.0.4, not in v0.0.3
This commit is contained in:
parent
f73125cbcd
commit
2eecf38842
@ -130,7 +130,7 @@ func TestDSN(t *testing.T) {
|
|||||||
// Test for valid DKIM signature.
|
// Test for valid DKIM signature.
|
||||||
mox.Context = context.Background()
|
mox.Context = context.Background()
|
||||||
mox.ConfigStaticPath = "../testdata/dsn/mox.conf"
|
mox.ConfigStaticPath = "../testdata/dsn/mox.conf"
|
||||||
mox.MustLoadConfig(false)
|
mox.MustLoadConfig(true, false)
|
||||||
msgbuf, err = m.Compose(log, false)
|
msgbuf, err = m.Compose(log, false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("composing utf-8 dsn with utf-8 support: %v", err)
|
t.Fatalf("composing utf-8 dsn with utf-8 support: %v", err)
|
||||||
|
@ -33,7 +33,7 @@ func TestAccount(t *testing.T) {
|
|||||||
os.RemoveAll("../testdata/httpaccount/data")
|
os.RemoveAll("../testdata/httpaccount/data")
|
||||||
mox.ConfigStaticPath = "../testdata/httpaccount/mox.conf"
|
mox.ConfigStaticPath = "../testdata/httpaccount/mox.conf"
|
||||||
mox.ConfigDynamicPath = filepath.Join(filepath.Dir(mox.ConfigStaticPath), "domains.conf")
|
mox.ConfigDynamicPath = filepath.Join(filepath.Dir(mox.ConfigStaticPath), "domains.conf")
|
||||||
mox.MustLoadConfig(false)
|
mox.MustLoadConfig(true, false)
|
||||||
acc, err := store.OpenAccount("mjl")
|
acc, err := store.OpenAccount("mjl")
|
||||||
tcheck(t, err, "open account")
|
tcheck(t, err, "open account")
|
||||||
defer acc.Close()
|
defer acc.Close()
|
||||||
|
@ -17,7 +17,7 @@ func TestServeHTTP(t *testing.T) {
|
|||||||
os.RemoveAll("../testdata/web/data")
|
os.RemoveAll("../testdata/web/data")
|
||||||
mox.ConfigStaticPath = "../testdata/web/mox.conf"
|
mox.ConfigStaticPath = "../testdata/web/mox.conf"
|
||||||
mox.ConfigDynamicPath = filepath.Join(filepath.Dir(mox.ConfigStaticPath), "domains.conf")
|
mox.ConfigDynamicPath = filepath.Join(filepath.Dir(mox.ConfigStaticPath), "domains.conf")
|
||||||
mox.MustLoadConfig(false)
|
mox.MustLoadConfig(true, false)
|
||||||
|
|
||||||
srv := &serve{
|
srv := &serve{
|
||||||
PathHandlers: []pathHandler{
|
PathHandlers: []pathHandler{
|
||||||
|
@ -22,7 +22,7 @@ func TestWebserver(t *testing.T) {
|
|||||||
os.RemoveAll("../testdata/webserver/data")
|
os.RemoveAll("../testdata/webserver/data")
|
||||||
mox.ConfigStaticPath = "../testdata/webserver/mox.conf"
|
mox.ConfigStaticPath = "../testdata/webserver/mox.conf"
|
||||||
mox.ConfigDynamicPath = filepath.Join(filepath.Dir(mox.ConfigStaticPath), "domains.conf")
|
mox.ConfigDynamicPath = filepath.Join(filepath.Dir(mox.ConfigStaticPath), "domains.conf")
|
||||||
mox.MustLoadConfig(false)
|
mox.MustLoadConfig(true, false)
|
||||||
|
|
||||||
srv := &serve{Webserver: true}
|
srv := &serve{Webserver: true}
|
||||||
|
|
||||||
@ -129,7 +129,7 @@ func TestWebsocket(t *testing.T) {
|
|||||||
os.RemoveAll("../testdata/websocket/data")
|
os.RemoveAll("../testdata/websocket/data")
|
||||||
mox.ConfigStaticPath = "../testdata/websocket/mox.conf"
|
mox.ConfigStaticPath = "../testdata/websocket/mox.conf"
|
||||||
mox.ConfigDynamicPath = filepath.Join(filepath.Dir(mox.ConfigStaticPath), "domains.conf")
|
mox.ConfigDynamicPath = filepath.Join(filepath.Dir(mox.ConfigStaticPath), "domains.conf")
|
||||||
mox.MustLoadConfig(false)
|
mox.MustLoadConfig(true, false)
|
||||||
|
|
||||||
srv := &serve{Webserver: true}
|
srv := &serve{Webserver: true}
|
||||||
|
|
||||||
|
@ -60,7 +60,7 @@ func FuzzServer(f *testing.F) {
|
|||||||
|
|
||||||
mox.Context = context.Background()
|
mox.Context = context.Background()
|
||||||
mox.ConfigStaticPath = "../testdata/imapserverfuzz/mox.conf"
|
mox.ConfigStaticPath = "../testdata/imapserverfuzz/mox.conf"
|
||||||
mox.MustLoadConfig(false)
|
mox.MustLoadConfig(true, false)
|
||||||
dataDir := mox.ConfigDirPath(mox.Conf.Static.DataDir)
|
dataDir := mox.ConfigDirPath(mox.Conf.Static.DataDir)
|
||||||
os.RemoveAll(dataDir)
|
os.RemoveAll(dataDir)
|
||||||
acc, err := store.OpenAccount("mjl")
|
acc, err := store.OpenAccount("mjl")
|
||||||
|
@ -311,7 +311,7 @@ func startArgs(t *testing.T, first, isTLS, allowLoginWithoutTLS bool) *testconn
|
|||||||
}
|
}
|
||||||
mox.Context = context.Background()
|
mox.Context = context.Background()
|
||||||
mox.ConfigStaticPath = "../testdata/imap/mox.conf"
|
mox.ConfigStaticPath = "../testdata/imap/mox.conf"
|
||||||
mox.MustLoadConfig(false)
|
mox.MustLoadConfig(true, false)
|
||||||
acc, err := store.OpenAccount("mjl")
|
acc, err := store.OpenAccount("mjl")
|
||||||
tcheck(t, err, "open account")
|
tcheck(t, err, "open account")
|
||||||
if first {
|
if first {
|
||||||
|
@ -53,7 +53,7 @@ func TestDeliver(t *testing.T) {
|
|||||||
// Load mox config.
|
// Load mox config.
|
||||||
mox.ConfigStaticPath = "testdata/integration/config/mox.conf"
|
mox.ConfigStaticPath = "testdata/integration/config/mox.conf"
|
||||||
filepath.Join(filepath.Dir(mox.ConfigStaticPath), "domains.conf")
|
filepath.Join(filepath.Dir(mox.ConfigStaticPath), "domains.conf")
|
||||||
if errs := mox.LoadConfig(ctxbg, false); len(errs) > 0 {
|
if errs := mox.LoadConfig(ctxbg, true, false); len(errs) > 0 {
|
||||||
t.Fatalf("loading mox config: %v", errs)
|
t.Fatalf("loading mox config: %v", errs)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -402,7 +402,7 @@ func writeLocalConfig(log *mlog.Log, dir string) (rerr error) {
|
|||||||
func localLoadConfig(log *mlog.Log, dir string) error {
|
func localLoadConfig(log *mlog.Log, dir string) error {
|
||||||
mox.ConfigStaticPath = filepath.Join(dir, "mox.conf")
|
mox.ConfigStaticPath = filepath.Join(dir, "mox.conf")
|
||||||
mox.ConfigDynamicPath = filepath.Join(dir, "domains.conf")
|
mox.ConfigDynamicPath = filepath.Join(dir, "domains.conf")
|
||||||
errs := mox.LoadConfig(context.Background(), false)
|
errs := mox.LoadConfig(context.Background(), true, false)
|
||||||
if len(errs) > 1 {
|
if len(errs) > 1 {
|
||||||
log.Error("loading config generated config file: multiple errors")
|
log.Error("loading config generated config file: multiple errors")
|
||||||
for _, err := range errs {
|
for _, err := range errs {
|
||||||
|
4
main.go
4
main.go
@ -356,9 +356,9 @@ var pedantic bool
|
|||||||
|
|
||||||
// subcommands that are not "serve" should use this function to load the config, it
|
// subcommands that are not "serve" should use this function to load the config, it
|
||||||
// restores any loglevel specified on the command-line, instead of using the
|
// restores any loglevel specified on the command-line, instead of using the
|
||||||
// loglevels from the config file.
|
// loglevels from the config file and it does not load files like TLS keys/certs.
|
||||||
func mustLoadConfig() {
|
func mustLoadConfig() {
|
||||||
mox.MustLoadConfig(false)
|
mox.MustLoadConfig(false, false)
|
||||||
if level, ok := mlog.Levels[loglevel]; loglevel != "" && ok {
|
if level, ok := mlog.Levels[loglevel]; loglevel != "" && ok {
|
||||||
mox.Conf.Log[""] = level
|
mox.Conf.Log[""] = level
|
||||||
mlog.SetConfig(mox.Conf.Log)
|
mlog.SetConfig(mox.Conf.Log)
|
||||||
|
@ -322,8 +322,8 @@ func writeDynamic(ctx context.Context, log *mlog.Log, c config.Dynamic) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// MustLoadConfig loads the config, quitting on errors.
|
// MustLoadConfig loads the config, quitting on errors.
|
||||||
func MustLoadConfig(checkACMEHosts bool) {
|
func MustLoadConfig(doLoadTLSKeyCerts, checkACMEHosts bool) {
|
||||||
errs := LoadConfig(context.Background(), checkACMEHosts)
|
errs := LoadConfig(context.Background(), doLoadTLSKeyCerts, checkACMEHosts)
|
||||||
if len(errs) > 1 {
|
if len(errs) > 1 {
|
||||||
xlog.Error("loading config file: multiple errors")
|
xlog.Error("loading config file: multiple errors")
|
||||||
for _, err := range errs {
|
for _, err := range errs {
|
||||||
@ -337,11 +337,11 @@ func MustLoadConfig(checkACMEHosts bool) {
|
|||||||
|
|
||||||
// LoadConfig attempts to parse and load a config, returning any errors
|
// LoadConfig attempts to parse and load a config, returning any errors
|
||||||
// encountered.
|
// encountered.
|
||||||
func LoadConfig(ctx context.Context, checkACMEHosts bool) []error {
|
func LoadConfig(ctx context.Context, doLoadTLSKeyCerts, checkACMEHosts bool) []error {
|
||||||
Shutdown, ShutdownCancel = context.WithCancel(context.Background())
|
Shutdown, ShutdownCancel = context.WithCancel(context.Background())
|
||||||
Context, ContextCancel = context.WithCancel(context.Background())
|
Context, ContextCancel = context.WithCancel(context.Background())
|
||||||
|
|
||||||
c, errs := ParseConfig(ctx, ConfigStaticPath, false, false, checkACMEHosts)
|
c, errs := ParseConfig(ctx, ConfigStaticPath, false, doLoadTLSKeyCerts, checkACMEHosts)
|
||||||
if len(errs) > 0 {
|
if len(errs) > 0 {
|
||||||
return errs
|
return errs
|
||||||
}
|
}
|
||||||
@ -367,12 +367,12 @@ func SetConfig(c *Config) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ParseConfig parses the static config at path p. If checkOnly is true, no changes
|
// ParseConfig parses the static config at path p. If checkOnly is true, no changes
|
||||||
// are made, such as registering ACME identities. If skipCheckTLSKeyCerts is true,
|
// are made, such as registering ACME identities. If doLoadTLSKeyCerts is true,
|
||||||
// the TLS KeyCerts configuration is not checked. This is used during the
|
// the TLS KeyCerts configuration is loaded and checked. This is used during the
|
||||||
// quickstart in the case the user is going to provide their own certificates.
|
// quickstart in the case the user is going to provide their own certificates.
|
||||||
// If checkACMEHosts is true, the hosts allowed for acme are compared with the
|
// If checkACMEHosts is true, the hosts allowed for acme are compared with the
|
||||||
// explicitly configured ips we are listening on.
|
// explicitly configured ips we are listening on.
|
||||||
func ParseConfig(ctx context.Context, p string, checkOnly, skipCheckTLSKeyCerts, checkACMEHosts bool) (c *Config, errs []error) {
|
func ParseConfig(ctx context.Context, p string, checkOnly, doLoadTLSKeyCerts, checkACMEHosts bool) (c *Config, errs []error) {
|
||||||
c = &Config{
|
c = &Config{
|
||||||
Static: config.Static{
|
Static: config.Static{
|
||||||
DataDir: ".",
|
DataDir: ".",
|
||||||
@ -391,7 +391,7 @@ func ParseConfig(ctx context.Context, p string, checkOnly, skipCheckTLSKeyCerts,
|
|||||||
return nil, []error{fmt.Errorf("parsing %s: %v", p, err)}
|
return nil, []error{fmt.Errorf("parsing %s: %v", p, err)}
|
||||||
}
|
}
|
||||||
|
|
||||||
if xerrs := PrepareStaticConfig(ctx, p, c, checkOnly, skipCheckTLSKeyCerts); len(xerrs) > 0 {
|
if xerrs := PrepareStaticConfig(ctx, p, c, checkOnly, doLoadTLSKeyCerts); len(xerrs) > 0 {
|
||||||
return nil, xerrs
|
return nil, xerrs
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -408,7 +408,7 @@ func ParseConfig(ctx context.Context, p string, checkOnly, skipCheckTLSKeyCerts,
|
|||||||
// PrepareStaticConfig parses the static config file and prepares data structures
|
// PrepareStaticConfig parses the static config file and prepares data structures
|
||||||
// for starting mox. If checkOnly is set no substantial changes are made, like
|
// for starting mox. If checkOnly is set no substantial changes are made, like
|
||||||
// creating an ACME registration.
|
// creating an ACME registration.
|
||||||
func PrepareStaticConfig(ctx context.Context, configFile string, config *Config, checkOnly, skipCheckTLSKeyCerts bool) (errs []error) {
|
func PrepareStaticConfig(ctx context.Context, configFile string, config *Config, checkOnly, doLoadTLSKeyCerts bool) (errs []error) {
|
||||||
addErrorf := func(format string, args ...any) {
|
addErrorf := func(format string, args ...any) {
|
||||||
errs = append(errs, fmt.Errorf(format, args...))
|
errs = append(errs, fmt.Errorf(format, args...))
|
||||||
}
|
}
|
||||||
@ -532,7 +532,7 @@ func PrepareStaticConfig(ctx context.Context, configFile string, config *Config,
|
|||||||
}
|
}
|
||||||
l.TLS.Config = tlsconfig
|
l.TLS.Config = tlsconfig
|
||||||
} else if len(l.TLS.KeyCerts) != 0 {
|
} else if len(l.TLS.KeyCerts) != 0 {
|
||||||
if !skipCheckTLSKeyCerts {
|
if doLoadTLSKeyCerts {
|
||||||
if err := loadTLSKeyCerts(configFile, "listener "+name, l.TLS); err != nil {
|
if err := loadTLSKeyCerts(configFile, "listener "+name, l.TLS); err != nil {
|
||||||
addErrorf("%w", err)
|
addErrorf("%w", err)
|
||||||
}
|
}
|
||||||
|
@ -35,7 +35,7 @@ func setup(t *testing.T) (*store.Account, func()) {
|
|||||||
os.RemoveAll("../testdata/queue/data")
|
os.RemoveAll("../testdata/queue/data")
|
||||||
mox.Context = ctxbg
|
mox.Context = ctxbg
|
||||||
mox.ConfigStaticPath = "../testdata/queue/mox.conf"
|
mox.ConfigStaticPath = "../testdata/queue/mox.conf"
|
||||||
mox.MustLoadConfig(false)
|
mox.MustLoadConfig(true, false)
|
||||||
acc, err := store.OpenAccount("mjl")
|
acc, err := store.OpenAccount("mjl")
|
||||||
tcheck(t, err, "open account")
|
tcheck(t, err, "open account")
|
||||||
err = acc.SetPassword("testtest")
|
err = acc.SetPassword("testtest")
|
||||||
|
4
serve.go
4
serve.go
@ -151,7 +151,7 @@ requested, other TLS certificates are requested on demand.
|
|||||||
log := mlog.New("serve")
|
log := mlog.New("serve")
|
||||||
|
|
||||||
if os.Getuid() == 0 {
|
if os.Getuid() == 0 {
|
||||||
mox.MustLoadConfig(checkACMEHosts)
|
mox.MustLoadConfig(true, checkACMEHosts)
|
||||||
|
|
||||||
// No need to potentially start and keep multiple processes. As root, we just need
|
// No need to potentially start and keep multiple processes. As root, we just need
|
||||||
// to start the child process.
|
// to start the child process.
|
||||||
@ -183,7 +183,7 @@ requested, other TLS certificates are requested on demand.
|
|||||||
} else {
|
} else {
|
||||||
log.Print("starting as unprivileged user", mlog.Field("user", mox.Conf.Static.User), mlog.Field("uid", mox.Conf.Static.UID), mlog.Field("gid", mox.Conf.Static.GID), mlog.Field("pid", os.Getpid()))
|
log.Print("starting as unprivileged user", mlog.Field("user", mox.Conf.Static.User), mlog.Field("uid", mox.Conf.Static.UID), mlog.Field("gid", mox.Conf.Static.GID), mlog.Field("pid", os.Getpid()))
|
||||||
mox.RestorePassedFiles()
|
mox.RestorePassedFiles()
|
||||||
mox.MustLoadConfig(checkACMEHosts)
|
mox.MustLoadConfig(true, checkACMEHosts)
|
||||||
}
|
}
|
||||||
|
|
||||||
syscall.Umask(syscall.Umask(007) | 007)
|
syscall.Umask(syscall.Umask(007) | 007)
|
||||||
|
@ -31,7 +31,7 @@ func FuzzServer(f *testing.F) {
|
|||||||
|
|
||||||
mox.Context = ctxbg
|
mox.Context = ctxbg
|
||||||
mox.ConfigStaticPath = "../testdata/smtpserverfuzz/mox.conf"
|
mox.ConfigStaticPath = "../testdata/smtpserverfuzz/mox.conf"
|
||||||
mox.MustLoadConfig(false)
|
mox.MustLoadConfig(true, false)
|
||||||
dataDir := mox.ConfigDirPath(mox.Conf.Static.DataDir)
|
dataDir := mox.ConfigDirPath(mox.Conf.Static.DataDir)
|
||||||
os.RemoveAll(dataDir)
|
os.RemoveAll(dataDir)
|
||||||
acc, err := store.OpenAccount("mjl")
|
acc, err := store.OpenAccount("mjl")
|
||||||
|
@ -92,7 +92,7 @@ func newTestServer(t *testing.T, configPath string, resolver dns.Resolver) *test
|
|||||||
|
|
||||||
mox.Context = ctxbg
|
mox.Context = ctxbg
|
||||||
mox.ConfigStaticPath = configPath
|
mox.ConfigStaticPath = configPath
|
||||||
mox.MustLoadConfig(false)
|
mox.MustLoadConfig(true, false)
|
||||||
dataDir := mox.ConfigDirPath(mox.Conf.Static.DataDir)
|
dataDir := mox.ConfigDirPath(mox.Conf.Static.DataDir)
|
||||||
os.RemoveAll(dataDir)
|
os.RemoveAll(dataDir)
|
||||||
var err error
|
var err error
|
||||||
|
@ -29,7 +29,7 @@ func tcheck(t *testing.T, err error, msg string) {
|
|||||||
func TestMailbox(t *testing.T) {
|
func TestMailbox(t *testing.T) {
|
||||||
os.RemoveAll("../testdata/store/data")
|
os.RemoveAll("../testdata/store/data")
|
||||||
mox.ConfigStaticPath = "../testdata/store/mox.conf"
|
mox.ConfigStaticPath = "../testdata/store/mox.conf"
|
||||||
mox.MustLoadConfig(false)
|
mox.MustLoadConfig(true, false)
|
||||||
acc, err := OpenAccount("mjl")
|
acc, err := OpenAccount("mjl")
|
||||||
tcheck(t, err, "open account")
|
tcheck(t, err, "open account")
|
||||||
defer acc.Close()
|
defer acc.Close()
|
||||||
|
@ -21,7 +21,7 @@ func TestExport(t *testing.T) {
|
|||||||
|
|
||||||
os.RemoveAll("../testdata/store/data")
|
os.RemoveAll("../testdata/store/data")
|
||||||
mox.ConfigStaticPath = "../testdata/store/mox.conf"
|
mox.ConfigStaticPath = "../testdata/store/mox.conf"
|
||||||
mox.MustLoadConfig(false)
|
mox.MustLoadConfig(true, false)
|
||||||
acc, err := OpenAccount("mjl")
|
acc, err := OpenAccount("mjl")
|
||||||
tcheck(t, err, "open account")
|
tcheck(t, err, "open account")
|
||||||
defer acc.Close()
|
defer acc.Close()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user