Made the socket configuration optionnal

This commit is contained in:
Emmanuel BENOîT 2021-12-05 09:49:57 +01:00
parent be6198dbed
commit 1976f7b2a8
3 changed files with 18 additions and 8 deletions

View file

@ -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,
}

View file

@ -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 {
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

View file

@ -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,