Skip to content

Commit

Permalink
set default rules directory if empty
Browse files Browse the repository at this point in the history
Use /etc/opensnitchd/rules as the default directory if it has not been
provided via configuration.
  • Loading branch information
gustavo-iniguez-goya committed May 29, 2024
1 parent 5234df7 commit 41690b2
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 1 deletion.
3 changes: 3 additions & 0 deletions daemon/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -580,6 +580,9 @@ func main() {
log.Fatal("%s", err)
}

if cfg.Rules.Path == "" {
cfg.Rules.Path = rule.DefaultPath
}
log.Info("Loading rules from %s ...", cfg.Rules.Path)
rules, err = rule.NewLoader(!noLiveReload)
if err != nil {
Expand Down
3 changes: 3 additions & 0 deletions daemon/rule/loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,9 @@ func (l *Loader) HasChecksums(op Operand) {
// Reload loads rules from the specified path, deleting existing loaded
// rules from memory.
func (l *Loader) Reload(path string) error {
if path == "" {
path = DefaultPath
}
log.Info("rules.Loader.Reload(): %s", path)

// check that the new path exists before reloading
Expand Down
5 changes: 5 additions & 0 deletions daemon/rule/rule.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ import (
"github.com/evilsocket/opensnitch/daemon/ui/protocol"
)

// DefaultPath directory
const (
DefaultPath = "/etc/opensnitchd/rules"
)

// Action of a rule
type Action string

Expand Down
2 changes: 1 addition & 1 deletion daemon/ui/config_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ func (c *Client) reloadConfiguration(reload bool, newConfig config.Config) *moni

// 1. load rules
c.rules.EnableChecksums(newConfig.Rules.EnableChecksums)
if c.config.Rules.Path != newConfig.Rules.Path {
if newConfig.Rules.Path == "" || c.config.Rules.Path != newConfig.Rules.Path {
c.rules.Reload(newConfig.Rules.Path)
log.Debug("[config] reloading config.rules.path, old: <%s> new: <%s>", c.config.Rules.Path, newConfig.Rules.Path)
} else {
Expand Down

0 comments on commit 41690b2

Please sign in to comment.