Skip to content

Commit

Permalink
Allow for empty string syscall filters
Browse files Browse the repository at this point in the history
  • Loading branch information
nbrownus committed Dec 19, 2016
1 parent 2cd7fc8 commit cb7943e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
6 changes: 3 additions & 3 deletions audit.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ import (
var l = log.New(os.Stdout, "", 0)
var el = log.New(os.Stderr, "", 0)

type executor func (string, ...string) error
type executor func(string, ...string) error

func lExec (s string, a ...string) error {
func lExec(s string, a ...string) error {
return exec.Command(s, a...).Run()
}

Expand Down Expand Up @@ -262,7 +262,7 @@ func createFilters(config *viper.Viper) []AuditFilter {

case "syscall":
if af.syscall, ok = v.(string); ok {
el.Fatal("`syscall` in filter ", i+1, " could not be parsed ", v)
// All is good
} else if ev, ok := v.(int); ok {
af.syscall = strconv.Itoa(ev)
} else {
Expand Down
10 changes: 5 additions & 5 deletions audit_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package main

import (
"errors"
"github.com/spf13/viper"
"github.com/stretchr/testify/assert"
"io/ioutil"
Expand All @@ -12,7 +13,6 @@ import (
"strconv"
"syscall"
"testing"
"errors"
)

func Test_loadConfig(t *testing.T) {
Expand Down Expand Up @@ -46,7 +46,7 @@ func Test_setRules(t *testing.T) {
// fail to flush rules
config := viper.New()

err := setRules(config, func (s string, a ...string) error {
err := setRules(config, func(s string, a ...string) error {
if s == "auditctl" && a[0] == "-D" {
return errors.New("testing")
}
Expand All @@ -57,13 +57,13 @@ func Test_setRules(t *testing.T) {
assert.EqualError(t, err, "Failed to flush existing audit rules. Error: testing")

// fail on 0 rules
err = setRules(config, func (s string, a ...string) error { return nil })
err = setRules(config, func(s string, a ...string) error { return nil })
assert.EqualError(t, err, "No audit rules found.")

// failure to set rule
r := 0
config.Set("rules", []string{"-a -1 -2", "", "-a -3 -4"})
err = setRules(config, func (s string, a ...string) error {
err = setRules(config, func(s string, a ...string) error {
if a[0] != "-D" {
return errors.New("testing rule")
}
Expand All @@ -78,7 +78,7 @@ func Test_setRules(t *testing.T) {

// properly set rules
r = 0
err = setRules(config, func (s string, a ...string) error {
err = setRules(config, func(s string, a ...string) error {
// Skip the flush rules
if a[0] != "-a" {
return nil
Expand Down

0 comments on commit cb7943e

Please sign in to comment.