Permissions of unix socket

This commit is contained in:
Philipp Heckel 2022-07-03 19:33:01 -04:00
parent 8532b5b7ea
commit bf8077626e
4 changed files with 13 additions and 9 deletions

View file

@ -8,7 +8,6 @@ import (
// Defines default config settings (excluding limits, see below)
const (
DefaultListenHTTP = ":80"
DefaultListenUnixMode = 0777
DefaultCacheDuration = 12 * time.Hour
DefaultKeepaliveInterval = 45 * time.Second // Not too frequently to save battery (Android read timeout used to be 77s!)
DefaultManagerInterval = time.Minute
@ -108,7 +107,7 @@ func NewConfig() *Config {
ListenHTTP: DefaultListenHTTP,
ListenHTTPS: "",
ListenUnix: "",
ListenUnixMode: DefaultListenUnixMode,
ListenUnixMode: 0,
KeyFile: "",
CertFile: "",
FirebaseKeyFile: "",

View file

@ -174,7 +174,7 @@ func (s *Server) Run() error {
listenStr += fmt.Sprintf(" %s[https]", s.config.ListenHTTPS)
}
if s.config.ListenUnix != "" {
listenStr += fmt.Sprintf(" %s[unix/%04o]", s.config.ListenUnix, s.config.ListenUnixMode)
listenStr += fmt.Sprintf(" %s[unix]", s.config.ListenUnix)
}
if s.config.SMTPServerListen != "" {
listenStr += fmt.Sprintf(" %s[smtp]", s.config.SMTPServerListen)
@ -204,13 +204,17 @@ func (s *Server) Run() error {
os.Remove(s.config.ListenUnix)
s.unixListener, err = net.Listen("unix", s.config.ListenUnix)
if err != nil {
s.mu.Unlock()
errChan <- err
return
}
if err := os.Chmod(s.config.ListenUnix, s.config.ListenUnixMode); err != nil {
s.unixListener.Close()
errChan <- err
return
defer s.unixListener.Close()
if s.config.ListenUnixMode > 0 {
if err := os.Chmod(s.config.ListenUnix, s.config.ListenUnixMode); err != nil {
s.mu.Unlock()
errChan <- err
return
}
}
s.mu.Unlock()
httpServer := &http.Server{Handler: mux}