Made the socket configuration optionnal
This commit is contained in:
parent
be6198dbed
commit
1976f7b2a8
3 changed files with 18 additions and 8 deletions
|
@ -13,6 +13,9 @@ type TClient struct {
|
||||||
|
|
||||||
// Initialize the client's state.
|
// Initialize the client's state.
|
||||||
func InitClient(config tConfiguration) TClient {
|
func InitClient(config tConfiguration) TClient {
|
||||||
|
if config.Socket == nil {
|
||||||
|
log.Fatal("Cannot run in client mode without a socket configuration")
|
||||||
|
}
|
||||||
return TClient{
|
return TClient{
|
||||||
config: config,
|
config: config,
|
||||||
}
|
}
|
||||||
|
|
10
config.go
10
config.go
|
@ -86,7 +86,7 @@ type (
|
||||||
|
|
||||||
// Main configuration.
|
// Main configuration.
|
||||||
tConfiguration struct {
|
tConfiguration struct {
|
||||||
Socket tSocketConfig `yaml:"socket"`
|
Socket *tSocketConfig `yaml:"socket"`
|
||||||
LdapConfig tLdapConfig `yaml:"ldap"`
|
LdapConfig tLdapConfig `yaml:"ldap"`
|
||||||
Handlers tHandlers `yaml:"handlers"`
|
Handlers tHandlers `yaml:"handlers"`
|
||||||
Certificates []tCertificateFileConfig `yaml:"certificates"`
|
Certificates []tCertificateFileConfig `yaml:"certificates"`
|
||||||
|
@ -124,6 +124,9 @@ func (c *tSocketConfig) Validate() error {
|
||||||
if c.Group != "" && !isValidGroup(c.Group) {
|
if c.Group != "" && !isValidGroup(c.Group) {
|
||||||
return fmt.Errorf("Invalid group '%s'", c.Group)
|
return fmt.Errorf("Invalid group '%s'", c.Group)
|
||||||
}
|
}
|
||||||
|
if c.Mode == 0 {
|
||||||
|
c.Mode = 0640
|
||||||
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -284,11 +287,13 @@ func (c *tCertificateFileConfig) Validate(handlers *tHandlers) error {
|
||||||
|
|
||||||
// Validate the configuration
|
// Validate the configuration
|
||||||
func (c *tConfiguration) Validate() error {
|
func (c *tConfiguration) Validate() error {
|
||||||
|
if c.Socket != nil {
|
||||||
err := c.Socket.Validate()
|
err := c.Socket.Validate()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
err = c.LdapConfig.Validate()
|
}
|
||||||
|
err := c.LdapConfig.Validate()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -307,7 +312,6 @@ func (c *tConfiguration) Validate() error {
|
||||||
// Create a configuration data structure containing default values.
|
// Create a configuration data structure containing default values.
|
||||||
func defaultConfiguration() tConfiguration {
|
func defaultConfiguration() tConfiguration {
|
||||||
cfg := tConfiguration{}
|
cfg := tConfiguration{}
|
||||||
cfg.Socket.Mode = 0640
|
|
||||||
cfg.LdapConfig.Defaults.TLS = "no"
|
cfg.LdapConfig.Defaults.TLS = "no"
|
||||||
cfg.LdapConfig.Structure.CAChaining = "seeAlso"
|
cfg.LdapConfig.Structure.CAChaining = "seeAlso"
|
||||||
return cfg
|
return cfg
|
||||||
|
|
|
@ -39,7 +39,7 @@ type (
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
func configureSocket(cfg tSocketConfig) error {
|
func configureSocket(cfg *tSocketConfig) error {
|
||||||
if cfg.Group != "" {
|
if cfg.Group != "" {
|
||||||
group, err := user.LookupGroup(cfg.Group)
|
group, err := user.LookupGroup(cfg.Group)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -65,7 +65,7 @@ func configureSocket(cfg tSocketConfig) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func initSocket(cfg tSocketConfig) (net.Listener, error) {
|
func initSocket(cfg *tSocketConfig) (net.Listener, error) {
|
||||||
listener, err := net.Listen("unix", cfg.Path)
|
listener, err := net.Listen("unix", cfg.Path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("Cannot listen on UNIX socket at %s: %w", cfg.Path, err)
|
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
|
// Initialize server state
|
||||||
func InitServer(cfgFile string, config tConfiguration) TServerState {
|
func InitServer(cfgFile string, config tConfiguration) TServerState {
|
||||||
|
if config.Socket == nil {
|
||||||
|
log.Fatal("Cannot run in server mode without a socket configuration")
|
||||||
|
}
|
||||||
ss := TServerState{
|
ss := TServerState{
|
||||||
cfgFile: cfgFile,
|
cfgFile: cfgFile,
|
||||||
config: config,
|
config: config,
|
||||||
|
|
Loading…
Reference in a new issue