Skip to content

Commit

Permalink
Shred a file instead of directory
Browse files Browse the repository at this point in the history
As with shred we can remove a file not a directory

Signed-off-by: GLVS Kiriti <[email protected]>
  • Loading branch information
GLVSKiriti committed Mar 25, 2024
1 parent da107c6 commit dc6cac1
Showing 1 changed file with 5 additions and 12 deletions.
17 changes: 5 additions & 12 deletions events/syscall/remove_bulk_data_from_disk.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ package syscall
import (
"os"
"os/exec"
"path/filepath"

"github.com/falcosecurity/event-generator/events"
)
Expand All @@ -26,20 +25,14 @@ var _ = events.Register(RemoveBulkDataFromDisk)

func RemoveBulkDataFromDisk(h events.Helper) error {
// Creates temporary data for testing, avoiding critical file deletion.
tmpDir, err := os.MkdirTemp(os.TempDir(), "created-by-falco-event-generator")
if err != nil {
return err
}

filename := filepath.Join(tmpDir, "file.txt")
filename := "/created-by-falco-event-generator"
defer os.RemoveAll(filename) // clean up
if err := os.WriteFile(filename, []byte("bulk data content"), os.FileMode(0755)); err != nil {
return err
}

// Generating the event
const command = "shred"
h.Log().Infof("attempting to run %s command to remove bulk data from disk", command)
cmd := exec.Command("shred", "-u", tmpDir)
err = cmd.Run()
h.Log().Infof("attempting to run shred command to remove bulk data from disk")
cmd := exec.Command("shred", "-u", filename)
err := cmd.Run()
return err
}

0 comments on commit dc6cac1

Please sign in to comment.