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 {
log.Debug("SetEnabled(%v) called", flag)
log.Debugf("SetEnabled(%v) called", flag)
ds.fw.setEnabled(flag)
return nil
}
@ -136,7 +136,7 @@ func (ds *dbusServer) DeleteRule(id uint32) *dbus.Error {
}
func (ds *dbusServer) UpdateRule(rule DbusRule) *dbus.Error {
log.Debug("UpdateRule %v", rule)
log.Debugf("UpdateRule %v", rule)
ds.fw.lock.Lock()
r := ds.fw.rulesById[uint(rule.Id)]
ds.fw.lock.Unlock()
@ -144,7 +144,7 @@ func (ds *dbusServer) UpdateRule(rule DbusRule) *dbus.Error {
tmp := new(Rule)
tmp.addr = noAddress
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
}
r.policy.lock.Lock()

@ -31,7 +31,7 @@ func (dc *dnsCache) processDNS(pkt *nfqueue.Packet) {
return
}
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
}
q := dns.question[0]
@ -39,7 +39,7 @@ func (dc *dnsCache) processDNS(pkt *nfqueue.Packet) {
dc.processRecordA(q.Name, dns.answer)
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
if !logRedact {
log.Info("Adding %s: %s", name, ip)
log.Infof("Adding %s: %s", name, ip)
}
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"
dir, err := os.Open(path)
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
}
names, err := dir.Readdirnames(0)
if err != nil {
log.Warning("Could not read directory %s: %v", path, err)
log.Warningf("Could not read directory %s: %v", path, err)
return
}
for _, n := range names {
@ -53,7 +53,7 @@ func initIcons() {
func loadDesktopFile(path string) {
bs, err := ioutil.ReadFile(path)
if err != nil {
log.Warning("Error reading %s: %v", path, err)
log.Warningf("Error reading %s: %v", path, err)
return
}
exec := ""

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

@ -99,7 +99,7 @@ func (p *Policy) processPacket(pkt *nfqueue.Packet, pinfo *procsnitch.Info) {
defer p.lock.Unlock()
name := p.fw.dns.Lookup(pkt.Dst)
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)
switch result {
@ -111,7 +111,7 @@ func (p *Policy) processPacket(pkt *nfqueue.Packet, pinfo *procsnitch.Info) {
case FILTER_PROMPT:
p.processPromptResult(&pendingPkt{pol: p, name: name, pkt: pkt, pinfo: pinfo})
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{}
for _, pc := range p.pendingQueue {
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 {
pc.accept()
} else {
@ -249,11 +249,11 @@ func (fw *Firewall) filterPacket(pkt *nfqueue.Packet) {
}
pinfo := findProcessForPacket(pkt)
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()
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) {
pkt.Accept()
return
@ -269,7 +269,7 @@ func findProcessForPacket(pkt *nfqueue.Packet) *procsnitch.Info {
case nfqueue.UDP:
return procsnitch.LookupUDPSocketProcess(pkt.SrcPort)
default:
log.Warning("Packet has unknown protocol: %d", pkt.Protocol)
log.Warningf("Packet has unknown protocol: %d", pkt.Protocol)
return nil
}
}

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

@ -106,7 +106,7 @@ func (rl *RuleList) filter(dst net.IP, dstPort uint16, hostname string, pinfo *p
if logRedact {
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 {
return FILTER_DENY
} else if r.rtype == RULE_ALLOW {
@ -205,12 +205,12 @@ func (fw *Firewall) saveRules() {
p, err := rulesPath()
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
}
f, err := os.Create(p)
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
}
defer f.Close()
@ -242,7 +242,7 @@ func savePolicy(f *os.File, p *Policy) {
func writeLine(f *os.File, line string) bool {
_, err := f.WriteString(line + "\n")
if err != nil {
log.Warning("Error writing to rule file: %v", err)
log.Warningf("Error writing to rule file: %v", err)
return false
}
return true
@ -256,13 +256,13 @@ func (fw *Firewall) loadRules() {
p, err := rulesPath()
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
}
bs, err := ioutil.ReadFile(p)
if err != nil {
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
}
@ -287,12 +287,12 @@ func (fw *Firewall) processPathLine(line string) *Policy {
func processRuleLine(policy *Policy, line string) {
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
}
_, err := policy.parseRule(line, true)
if err != nil {
log.Warning("Error parsing rule (%s): %v", line, err)
log.Warningf("Error parsing rule (%s): %v", line, err)
return
}
}

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

Loading…
Cancel
Save