Created
January 28, 2015 20:15
-
-
Save arunk-s/ce6e80467366877b1de9 to your computer and use it in GitHub Desktop.
Update main.go to print the errors
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"./netlinkAudit" | |
"log" | |
"os" | |
"syscall" | |
"time" | |
) | |
var done chan bool | |
var debug bool | |
func main() { | |
debug = true | |
s, err := netlinkAudit.GetNetlinkSocket() | |
if err != nil { | |
log.Println(err) | |
log.Fatalln("Error while availing socket! Exiting!") | |
} | |
defer s.Close() | |
debug = false | |
if os.Getuid() != 0 { | |
log.Fatalln("Not Root User! Exiting!") | |
} | |
err = netlinkAudit.AuditSetEnabled(s) | |
if err != nil { | |
log.Fatal("Error while enabling Audit !", err) | |
} | |
err = netlinkAudit.AuditIsEnabled(s) | |
if debug == true { | |
log.Println(netlinkAudit.ParsedResult) | |
} | |
if err == nil && netlinkAudit.ParsedResult.Enabled == 1 { | |
log.Println("Enabled Audit!!") | |
} else { | |
log.Fatalln("Audit Not Enabled! Exiting",err) | |
} | |
err = netlinkAudit.AuditSetRateLimit(s, 600) | |
if err != nil { | |
log.Fatalln("Error Setting Rate Limit!!", err) | |
} | |
err = netlinkAudit.AuditSetBacklogLimit(s, 420) | |
if err != nil { | |
log.Fatalln("Error Setting Backlog Limit!!", err) | |
} | |
err = netlinkAudit.AuditSetPid(s, uint32(syscall.Getpid())) | |
if err == nil { | |
log.Println("Set pid successful!!") | |
} | |
err = netlinkAudit.SetRules(s) | |
// err = netlinkAudit.DeleteAllRules(s) | |
if err != nil { | |
log.Fatalln("Setting Rules Unsuccessful! Exiting") | |
} | |
done := make(chan bool, 1) | |
msg := make(chan string) | |
errchan := make(chan error) | |
f, err := os.OpenFile("/tmp/log", os.O_CREATE|os.O_RDWR|os.O_APPEND, 0660) | |
if err != nil { | |
log.Fatalln("Error Creating File!!") | |
} | |
defer f.Close() | |
go func() { | |
for { | |
select { | |
case ev := <-msg: | |
log.Println(ev + "\n") | |
_, err := f.WriteString(ev + "\n") | |
if err != nil { | |
log.Println("Writing Error!!") | |
} | |
case ev := <-errchan: | |
log.Println(ev) | |
} | |
} | |
}() | |
go netlinkAudit.Getreply(s, done, msg, errchan) | |
time.Sleep(time.Second * 10) | |
done <- true | |
close(done) | |
//Important point is that NLMSG_ERROR is also an acknowledgement from Kernel. | |
//If the first 4 bytes of Data part are zero then it means the message is acknowledged | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment