Update to new logging library API, Warning() -> Warningf() etc...

socks-filter
Bruce Leidl 9 years ago
parent 9259438ae5
commit 9eeeb59957

@ -90,7 +90,7 @@ func newDbusServer() (*dbusServer, error) {
} }
func (ds *dbusServer) SetEnabled(flag bool) *dbus.Error { func (ds *dbusServer) SetEnabled(flag bool) *dbus.Error {
log.Debug("SetEnabled(%v) called", flag) log.Debugf("SetEnabled(%v) called", flag)
ds.fw.setEnabled(flag) ds.fw.setEnabled(flag)
return nil return nil
} }
@ -136,7 +136,7 @@ func (ds *dbusServer) DeleteRule(id uint32) *dbus.Error {
} }
func (ds *dbusServer) UpdateRule(rule DbusRule) *dbus.Error { func (ds *dbusServer) UpdateRule(rule DbusRule) *dbus.Error {
log.Debug("UpdateRule %v", rule) log.Debugf("UpdateRule %v", rule)
ds.fw.lock.Lock() ds.fw.lock.Lock()
r := ds.fw.rulesById[uint(rule.Id)] r := ds.fw.rulesById[uint(rule.Id)]
ds.fw.lock.Unlock() ds.fw.lock.Unlock()
@ -144,7 +144,7 @@ func (ds *dbusServer) UpdateRule(rule DbusRule) *dbus.Error {
tmp := new(Rule) tmp := new(Rule)
tmp.addr = noAddress tmp.addr = noAddress
if !tmp.parseTarget(rule.Target) { if !tmp.parseTarget(rule.Target) {
log.Warning("Unable to parse target: %s", rule.Target) log.Warningf("Unable to parse target: %s", rule.Target)
return nil return nil
} }
r.policy.lock.Lock() r.policy.lock.Lock()

@ -31,7 +31,7 @@ func (dc *dnsCache) processDNS(pkt *nfqueue.Packet) {
return return
} }
if len(dns.question) != 1 { if len(dns.question) != 1 {
log.Warning("Length of DNS Question section is not 1 as expected: %d", len(dns.question)) log.Warningf("Length of DNS Question section is not 1 as expected: %d", len(dns.question))
return return
} }
q := dns.question[0] q := dns.question[0]
@ -39,7 +39,7 @@ func (dc *dnsCache) processDNS(pkt *nfqueue.Packet) {
dc.processRecordA(q.Name, dns.answer) dc.processRecordA(q.Name, dns.answer)
return return
} }
log.Info("Unhandled DNS message: %v", dns) log.Infof("Unhandled DNS message: %v", dns)
} }
@ -55,10 +55,10 @@ func (dc *dnsCache) processRecordA(name string, answers []dnsRR) {
} }
dc.ipMap[ip] = name dc.ipMap[ip] = name
if !logRedact { if !logRedact {
log.Info("Adding %s: %s", name, ip) log.Infof("Adding %s: %s", name, ip)
} }
default: default:
log.Warning("Unexpected RR type in answer section of A response: %v", rec) log.Warningf("Unexpected RR type in answer section of A response: %v", rec)
} }
} }
} }

@ -34,12 +34,12 @@ func initIcons() {
path := "/usr/share/applications" path := "/usr/share/applications"
dir, err := os.Open(path) dir, err := os.Open(path)
if err != nil { if err != nil {
log.Warning("Failed to open %s for reading: %v", path, err) log.Warningf("Failed to open %s for reading: %v", path, err)
return return
} }
names, err := dir.Readdirnames(0) names, err := dir.Readdirnames(0)
if err != nil { if err != nil {
log.Warning("Could not read directory %s: %v", path, err) log.Warningf("Could not read directory %s: %v", path, err)
return return
} }
for _, n := range names { for _, n := range names {
@ -53,7 +53,7 @@ func initIcons() {
func loadDesktopFile(path string) { func loadDesktopFile(path string) {
bs, err := ioutil.ReadFile(path) bs, err := ioutil.ReadFile(path)
if err != nil { if err != nil {
log.Warning("Error reading %s: %v", path, err) log.Warningf("Error reading %s: %v", path, err)
return return
} }
exec := "" exec := ""

@ -18,9 +18,9 @@ func setupIPTables() {
func addIPTRules(rules ...string) { func addIPTRules(rules ...string) {
for _, r := range rules { for _, r := range rules {
if iptables('C', r) { if iptables('C', r) {
log.Info("IPTables rule already present: %s", r) log.Infof("IPTables rule already present: %s", r)
} else { } else {
log.Info("Installing IPTables rule: %s", r) log.Infof("Installing IPTables rule: %s", r)
iptables('I', r) iptables('I', r)
} }
} }
@ -38,7 +38,7 @@ func iptables(verb rune, rule string) bool {
_, err = cmd.CombinedOutput() _, err = cmd.CombinedOutput()
_, exitErr := err.(*exec.ExitError) _, exitErr := err.(*exec.ExitError)
if err != nil && !exitErr { if err != nil && !exitErr {
log.Warning("Error running iptables: %v", err) log.Warningf("Error running iptables: %v", err)
} }
return !exitErr return !exitErr
} }

@ -99,7 +99,7 @@ func (p *Policy) processPacket(pkt *nfqueue.Packet, pinfo *procsnitch.Info) {
defer p.lock.Unlock() defer p.lock.Unlock()
name := p.fw.dns.Lookup(pkt.Dst) name := p.fw.dns.Lookup(pkt.Dst)
if !logRedact { if !logRedact {
log.Info("Lookup(%s): %s", pkt.Dst.String(), name) log.Infof("Lookup(%s): %s", pkt.Dst.String(), name)
} }
result := p.rules.filterPacket(pkt, pinfo, name) result := p.rules.filterPacket(pkt, pinfo, name)
switch result { switch result {
@ -111,7 +111,7 @@ func (p *Policy) processPacket(pkt *nfqueue.Packet, pinfo *procsnitch.Info) {
case FILTER_PROMPT: case FILTER_PROMPT:
p.processPromptResult(&pendingPkt{pol: p, name: name, pkt: pkt, pinfo: pinfo}) p.processPromptResult(&pendingPkt{pol: p, name: name, pkt: pkt, pinfo: pinfo})
default: default:
log.Warning("Unexpected filter result: %d", result) log.Warningf("Unexpected filter result: %d", result)
} }
} }
@ -195,7 +195,7 @@ func (p *Policy) filterPending(rule *Rule) {
remaining := []pendingConnection{} remaining := []pendingConnection{}
for _, pc := range p.pendingQueue { for _, pc := range p.pendingQueue {
if rule.match(pc.dst(), pc.dstPort(), pc.hostname()) { if rule.match(pc.dst(), pc.dstPort(), pc.hostname()) {
log.Info("Also applying %s to %s", rule.getString(logRedact), pc.print()) log.Infof("Also applying %s to %s", rule.getString(logRedact), pc.print())
if rule.rtype == RULE_ALLOW { if rule.rtype == RULE_ALLOW {
pc.accept() pc.accept()
} else { } else {
@ -249,11 +249,11 @@ func (fw *Firewall) filterPacket(pkt *nfqueue.Packet) {
} }
pinfo := findProcessForPacket(pkt) pinfo := findProcessForPacket(pkt)
if pinfo == nil { if pinfo == nil {
log.Warning("No proc found for %s", printPacket(pkt, fw.dns.Lookup(pkt.Dst))) log.Warningf("No proc found for %s", printPacket(pkt, fw.dns.Lookup(pkt.Dst)))
pkt.Accept() pkt.Accept()
return return
} }
log.Debug("filterPacket [%s] %s", pinfo.ExePath, printPacket(pkt, fw.dns.Lookup(pkt.Dst))) log.Debugf("filterPacket [%s] %s", pinfo.ExePath, printPacket(pkt, fw.dns.Lookup(pkt.Dst)))
if basicAllowPacket(pkt) { if basicAllowPacket(pkt) {
pkt.Accept() pkt.Accept()
return return
@ -269,7 +269,7 @@ func findProcessForPacket(pkt *nfqueue.Packet) *procsnitch.Info {
case nfqueue.UDP: case nfqueue.UDP:
return procsnitch.LookupUDPSocketProcess(pkt.SrcPort) return procsnitch.LookupUDPSocketProcess(pkt.SrcPort)
default: default:
log.Warning("Packet has unknown protocol: %d", pkt.Protocol) log.Warningf("Packet has unknown protocol: %d", pkt.Protocol)
return nil return nil
} }
} }

@ -97,7 +97,7 @@ func (p *prompter) processConnection(pc pendingConnection) {
int32(pc.procInfo().Pid)) int32(pc.procInfo().Pid))
err := call.Store(&scope, &rule) err := call.Store(&scope, &rule)
if err != nil { if err != nil {
log.Warning("Error sending dbus RequestPrompt message: %v", err) log.Warningf("Error sending dbus RequestPrompt message: %v", err)
policy.removePending(pc) policy.removePending(pc)
pc.drop() pc.drop()
return return
@ -105,7 +105,7 @@ func (p *prompter) processConnection(pc pendingConnection) {
r, err := policy.parseRule(rule, false) r, err := policy.parseRule(rule, false)
if err != nil { if err != nil {
log.Warning("Error parsing rule string returned from dbus RequestPrompt: %v", err) log.Warningf("Error parsing rule string returned from dbus RequestPrompt: %v", err)
policy.removePending(pc) policy.removePending(pc)
pc.drop() pc.drop()
return return

@ -106,7 +106,7 @@ func (rl *RuleList) filter(dst net.IP, dstPort uint16, hostname string, pinfo *p
if logRedact { if logRedact {
dstStr = "[redacted]" dstStr = "[redacted]"
} }
log.Info("%s (%s -> %s:%d)", r.getString(logRedact), pinfo.ExePath, dstStr, dstPort) log.Infof("%s (%s -> %s:%d)", r.getString(logRedact), pinfo.ExePath, dstStr, dstPort)
if r.rtype == RULE_DENY { if r.rtype == RULE_DENY {
return FILTER_DENY return FILTER_DENY
} else if r.rtype == RULE_ALLOW { } else if r.rtype == RULE_ALLOW {
@ -205,12 +205,12 @@ func (fw *Firewall) saveRules() {
p, err := rulesPath() p, err := rulesPath()
if err != nil { if err != nil {
log.Warning("Failed to open %s for writing: %v", p, err) log.Warningf("Failed to open %s for writing: %v", p, err)
return return
} }
f, err := os.Create(p) f, err := os.Create(p)
if err != nil { if err != nil {
log.Warning("Failed to open %s for writing: %v", p, err) log.Warningf("Failed to open %s for writing: %v", p, err)
return return
} }
defer f.Close() defer f.Close()
@ -242,7 +242,7 @@ func savePolicy(f *os.File, p *Policy) {
func writeLine(f *os.File, line string) bool { func writeLine(f *os.File, line string) bool {
_, err := f.WriteString(line + "\n") _, err := f.WriteString(line + "\n")
if err != nil { if err != nil {
log.Warning("Error writing to rule file: %v", err) log.Warningf("Error writing to rule file: %v", err)
return false return false
} }
return true return true
@ -256,13 +256,13 @@ func (fw *Firewall) loadRules() {
p, err := rulesPath() p, err := rulesPath()
if err != nil { if err != nil {
log.Warning("Failed to open %s for reading: %v", p, err) log.Warningf("Failed to open %s for reading: %v", p, err)
return return
} }
bs, err := ioutil.ReadFile(p) bs, err := ioutil.ReadFile(p)
if err != nil { if err != nil {
if !os.IsNotExist(err) { if !os.IsNotExist(err) {
log.Warning("Failed to open %s for reading: %v", p, err) log.Warningf("Failed to open %s for reading: %v", p, err)
} }
return return
} }
@ -287,12 +287,12 @@ func (fw *Firewall) processPathLine(line string) *Policy {
func processRuleLine(policy *Policy, line string) { func processRuleLine(policy *Policy, line string) {
if policy == nil { if policy == nil {
log.Warning("Cannot process rule line without first seeing path line: %s", line) log.Warningf("Cannot process rule line without first seeing path line: %s", line)
return return
} }
_, err := policy.parseRule(line, true) _, err := policy.parseRule(line, true)
if err != nil { if err != nil {
log.Warning("Error parsing rule (%s): %v", line, err) log.Warningf("Error parsing rule (%s): %v", line, err)
return return
} }
} }

@ -43,7 +43,7 @@ func NewMortalService(network, address string, connectionCallback func(net.Conn)
// Stop will kill our listener and all it's connections // Stop will kill our listener and all it's connections
func (l *MortalService) Stop() { func (l *MortalService) Stop() {
log.Info("stopping listener service %s:%s", l.network, l.address) log.Infof("stopping listener service %s:%s", l.network, l.address)
close(l.quit) close(l.quit)
if l.listener != nil { if l.listener != nil {
l.listener.Close() l.listener.Close()
@ -54,10 +54,10 @@ func (l *MortalService) Stop() {
func (l *MortalService) acceptLoop() { func (l *MortalService) acceptLoop() {
defer l.waitGroup.Done() defer l.waitGroup.Done()
defer func() { defer func() {
log.Info("stoping listener service %s:%s", l.network, l.address) log.Infof("stoping listener service %s:%s", l.network, l.address)
for i, conn := range l.conns { for i, conn := range l.conns {
if conn != nil { if conn != nil {
log.Info("Closing connection #%d", i) log.Infof("Closing connection #%d", i)
conn.Close() conn.Close()
} }
} }
@ -70,7 +70,7 @@ func (l *MortalService) acceptLoop() {
if opErr, ok := err.(*net.OpError); ok && opErr.Timeout() { if opErr, ok := err.(*net.OpError); ok && opErr.Timeout() {
continue continue
} else { } else {
log.Info("MortalService connection accept failure: %s\n", err) log.Infof("MortalService connection accept failure: %s\n", err)
select { select {
case <-l.quit: case <-l.quit:
return return
@ -130,12 +130,12 @@ func (l *MortalService) Start() error {
func (l *MortalService) handleConnection(conn net.Conn, id int) error { func (l *MortalService) handleConnection(conn net.Conn, id int) error {
defer func() { defer func() {
log.Info("Closing connection #%d", id) log.Infof("Closing connection #%d", id)
conn.Close() conn.Close()
l.conns[id] = nil l.conns[id] = nil
}() }()
log.Info("Starting connection #%d", id) log.Infof("Starting connection #%d", id)
for { for {
if err := l.connectionCallback(conn); err != nil { if err := l.connectionCallback(conn); err != nil {

Loading…
Cancel
Save