diff --git a/client.go b/client.go index 705ad56..3b88439 100644 --- a/client.go +++ b/client.go @@ -13,6 +13,9 @@ type TClient struct { // Initialize the client's state. func InitClient(config tConfiguration) TClient { + if config.Socket == nil { + log.Fatal("Cannot run in client mode without a socket configuration") + } return TClient{ config: config, } diff --git a/config.go b/config.go index 805daf8..bac8fe5 100644 --- a/config.go +++ b/config.go @@ -86,7 +86,7 @@ type ( // Main configuration. tConfiguration struct { - Socket tSocketConfig `yaml:"socket"` + Socket *tSocketConfig `yaml:"socket"` LdapConfig tLdapConfig `yaml:"ldap"` Handlers tHandlers `yaml:"handlers"` Certificates []tCertificateFileConfig `yaml:"certificates"` @@ -124,6 +124,9 @@ func (c *tSocketConfig) Validate() error { if c.Group != "" && !isValidGroup(c.Group) { return fmt.Errorf("Invalid group '%s'", c.Group) } + if c.Mode == 0 { + c.Mode = 0640 + } return nil } @@ -284,11 +287,13 @@ func (c *tCertificateFileConfig) Validate(handlers *tHandlers) error { // Validate the configuration func (c *tConfiguration) Validate() error { - err := c.Socket.Validate() - if err != nil { - return err + if c.Socket != nil { + err := c.Socket.Validate() + if err != nil { + return err + } } - err = c.LdapConfig.Validate() + err := c.LdapConfig.Validate() if err != nil { return err } @@ -307,7 +312,6 @@ func (c *tConfiguration) Validate() error { // Create a configuration data structure containing default values. func defaultConfiguration() tConfiguration { cfg := tConfiguration{} - cfg.Socket.Mode = 0640 cfg.LdapConfig.Defaults.TLS = "no" cfg.LdapConfig.Structure.CAChaining = "seeAlso" return cfg diff --git a/server.go b/server.go index bec4d69..21bc6d1 100644 --- a/server.go +++ b/server.go @@ -39,7 +39,7 @@ type ( } ) -func configureSocket(cfg tSocketConfig) error { +func configureSocket(cfg *tSocketConfig) error { if cfg.Group != "" { group, err := user.LookupGroup(cfg.Group) if err != nil { @@ -65,7 +65,7 @@ func configureSocket(cfg tSocketConfig) error { return nil } -func initSocket(cfg tSocketConfig) (net.Listener, error) { +func initSocket(cfg *tSocketConfig) (net.Listener, error) { listener, err := net.Listen("unix", cfg.Path) if err != nil { return nil, fmt.Errorf("Cannot listen on UNIX socket at %s: %w", cfg.Path, err) @@ -157,6 +157,9 @@ func parseCommand(n int, buf []byte) *tCommand { // Initialize server state func InitServer(cfgFile string, config tConfiguration) TServerState { + if config.Socket == nil { + log.Fatal("Cannot run in server mode without a socket configuration") + } ss := TServerState{ cfgFile: cfgFile, config: config,