Skip to content

Commit

Permalink
Merge pull request #1566 from criblio/feat/remove-proc-arg
Browse files Browse the repository at this point in the history
Support cmd line args when removing a proc from rules (#1158)
  • Loading branch information
iapaddler authored Jul 10, 2023
2 parents 9ac9162 + 411f38a commit 0d957a9
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 8 deletions.
2 changes: 1 addition & 1 deletion cli/cmd/rules.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ var rulesCmd = &cobra.Command{
util.ErrAndExit("Rules failure: %v", err)
}
} else if remProc != "" {
if err = rules.Remove(rulesFile, remProc, sourceid, rc.Rootdir, rc); err != nil {
if err = rules.Remove(rulesFile, remProc, procArg, sourceid, rc.Rootdir, rc); err != nil {
util.ErrAndExit("Rules failure: %v", err)
}
}
Expand Down
4 changes: 2 additions & 2 deletions cli/rules/rules.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ func Add(rulesFile libscope.Rules, addProc, procArg, sourceid, rootdir string, r

// Remove a process from the scope rules
// Note: No matching of the 'arg' field intended for removal.
func Remove(rulesFile libscope.Rules, remProc, sourceid, rootdir string, rc *run.Config) error {
func Remove(rulesFile libscope.Rules, remProc, procArg, sourceid, rootdir string, rc *run.Config) error {

// Create a history directory for logs
rc.CreateWorkDirBasic("rules")
Expand All @@ -206,7 +206,7 @@ func Remove(rulesFile libscope.Rules, remProc, sourceid, rootdir string, rc *run
// (only if there are changes)
remove := -1
for i, entry := range rulesFile.Allow {
if entry.ProcName == remProc && entry.SourceId == sourceid {
if entry.ProcName == remProc && entry.SourceId == sourceid && entry.ProcArg == procArg {
remove = i
}
}
Expand Down
13 changes: 8 additions & 5 deletions src/cfgutils.c
Original file line number Diff line number Diff line change
Expand Up @@ -3202,11 +3202,14 @@ processAllowProcCmdLineScalar(yaml_document_t *doc, yaml_node_t *node, void *ext

rules_cfg_t *fCfg = (rules_cfg_t *)extData;
const char *cmdline = (const char *)node->data.scalar.value;
if ((scope_strlen(cmdline) > 0) &&
(scope_strstr(fCfg->procCmdLine, cmdline)
|| !scope_strcmp(MATCH_ALL_VAL, cmdline))) {
fCfg->status = PROC_ALLOWED;
fCfg->rulesMatch = TRUE;
if (scope_strlen(cmdline) > 0) { // an arg is specified in the rules file
if (scope_strstr(fCfg->procCmdLine, cmdline) || !scope_strcmp(MATCH_ALL_VAL, cmdline)) {
fCfg->status = PROC_ALLOWED;
fCfg->rulesMatch = TRUE;
} else {
fCfg->status = PROC_DENIED;
fCfg->rulesMatch = FALSE;
}
}
}

Expand Down

0 comments on commit 0d957a9

Please sign in to comment.