|
@@ -9,6 +9,16 @@ import (
|
9
|
9
|
"github.com/oragono/oragono/irc/sno"
|
10
|
10
|
)
|
11
|
11
|
|
|
12
|
+// Constants
|
|
13
|
+const (
|
|
14
|
+ DnsblRequireSaslReply uint = iota
|
|
15
|
+ DnsblAllowReply
|
|
16
|
+ DnsblBlockReply
|
|
17
|
+ DnsblNotifyReply
|
|
18
|
+ DnsblUnknownReply
|
|
19
|
+)
|
|
20
|
+
|
|
21
|
+// ReverseAddress returns IPv4 addresses reversed
|
12
|
22
|
func ReverseAddress(ip net.IP) string {
|
13
|
23
|
// This is a IPv4 address
|
14
|
24
|
if ip.To4() != nil {
|
|
@@ -25,12 +35,7 @@ func ReverseAddress(ip net.IP) string {
|
25
|
35
|
return ip.String()
|
26
|
36
|
}
|
27
|
37
|
|
28
|
|
-func LastIpOctet(addr string) string {
|
29
|
|
- address := strings.Split(addr, ".")
|
30
|
|
-
|
31
|
|
- return address[len(address)-1]
|
32
|
|
-}
|
33
|
|
-
|
|
38
|
+// LookupBlacklistEntry performs a lookup on the dnsbl on the client IP
|
34
|
39
|
func (server *Server) LookupBlacklistEntry(list *DnsblListEntry, client *Client) []string {
|
35
|
40
|
res, err := net.LookupHost(fmt.Sprintf("%s.%s", ReverseAddress(client.IP()), list.Host))
|
36
|
41
|
|
|
@@ -42,23 +47,16 @@ func (server *Server) LookupBlacklistEntry(list *DnsblListEntry, client *Client)
|
42
|
47
|
|
43
|
48
|
if len(res) > 0 {
|
44
|
49
|
for _, addr := range res {
|
45
|
|
- entries = append(entries, LastIpOctet(addr))
|
|
50
|
+ octet := strings.Split(addr, ".")
|
|
51
|
+ if len(octet) > 0 {
|
|
52
|
+ entries = append(entries, octet[len(octet)-1])
|
|
53
|
+ }
|
46
|
54
|
}
|
47
|
55
|
}
|
48
|
56
|
|
49
|
57
|
return entries
|
50
|
58
|
}
|
51
|
59
|
|
52
|
|
-func sendDnsblMessage(client *Client, message string) {
|
53
|
|
- /*fmt.Printf(client.server.DnsblConfig().Channel)
|
54
|
|
- if channel := client.server.DnsblConfig().Channel; channel != "" {
|
55
|
|
- fmt.Printf(channel)
|
56
|
|
- client.Send(nil, client.server.name, "PRIVMSG", channel, message)
|
57
|
|
- }
|
58
|
|
- */
|
59
|
|
- client.server.snomasks.Send(sno.Dnsbl, message)
|
60
|
|
-}
|
61
|
|
-
|
62
|
60
|
// ProcessBlacklist does
|
63
|
61
|
func (server *Server) ProcessBlacklist(client *Client) {
|
64
|
62
|
|
|
@@ -67,56 +65,51 @@ func (server *Server) ProcessBlacklist(client *Client) {
|
67
|
65
|
return
|
68
|
66
|
}
|
69
|
67
|
|
|
68
|
+ channel := server.DnsblConfig().Channel
|
|
69
|
+ lists := server.DnsblConfig().Lists
|
|
70
|
+
|
70
|
71
|
type DnsblTypeResponse struct {
|
71
|
|
- Host string
|
72
|
|
- Action string
|
73
|
|
- Reason string
|
|
72
|
+ Host string
|
|
73
|
+ ActionType uint
|
|
74
|
+ Reason string
|
74
|
75
|
}
|
75
|
76
|
var items = []DnsblTypeResponse{}
|
76
|
|
- for _, list := range server.DnsblConfig().Lists {
|
|
77
|
+ for _, list := range lists {
|
77
|
78
|
response := DnsblTypeResponse{
|
78
|
|
- Host: list.Host,
|
79
|
|
- Action: list.Action,
|
80
|
|
- Reason: list.Reason,
|
|
79
|
+ Host: list.Host,
|
|
80
|
+ ActionType: list.ActionType,
|
|
81
|
+ Reason: list.Reason,
|
81
|
82
|
}
|
82
|
83
|
// update action/reason if matched with new ...
|
83
|
84
|
for _, entry := range server.LookupBlacklistEntry(&list, client) {
|
84
|
85
|
if reply, exists := list.Reply[entry]; exists {
|
85
|
|
- response.Action, response.Reason = reply.Action, reply.Reason
|
|
86
|
+ response.ActionType, response.Reason = list.ActionType, reply.Reason
|
86
|
87
|
}
|
87
|
88
|
items = append(items, response)
|
88
|
89
|
}
|
89
|
90
|
}
|
90
|
91
|
|
91
|
|
- // Sort responses so that require-sasl blocks come first. Otherwise A>B (allow>block, allow>notify, block>notify)
|
92
|
|
- // so that responses come in this order:
|
93
|
|
- // - require-sasl
|
94
|
|
- // - allow
|
95
|
|
- // - block
|
96
|
|
- // - notify
|
|
92
|
+ // Sorts in the following order: require-sasl, allow, block, notify
|
97
|
93
|
sort.Slice(items, func(i, j int) bool {
|
98
|
|
- if items[i].Action == "require-sasl" {
|
99
|
|
- return true
|
100
|
|
- }
|
101
|
|
- return items[i].Action > items[j].Action
|
|
94
|
+ return items[i].ActionType > items[j].ActionType
|
102
|
95
|
})
|
103
|
96
|
|
104
|
97
|
if len(items) > 0 {
|
105
|
98
|
item := items[0]
|
106
|
|
- switch item.Action {
|
107
|
|
- case "require-sasl":
|
108
|
|
- sendDnsblMessage(client, fmt.Sprintf("Connecting client %s matched %s, requiring SASL to proceed", client.IP(), item.Host))
|
|
99
|
+ switch item.ActionType {
|
|
100
|
+ case DnsblRequireSaslReply:
|
|
101
|
+ client.sendServerMessage("", channel, sno.Dnsbl, fmt.Sprintf("Connecting client %s matched %s, requiring SASL to proceed", client.IP(), item.Host))
|
109
|
102
|
client.SetRequireSasl(true, item.Reason)
|
110
|
103
|
|
111
|
|
- case "block":
|
112
|
|
- sendDnsblMessage(client, fmt.Sprintf("Connecting client %s matched %s - killing", client.IP(), item.Host))
|
|
104
|
+ case DnsblBlockReply:
|
|
105
|
+ client.sendServerMessage("", channel, sno.Dnsbl, fmt.Sprintf("Connecting client %s matched %s - killing", client.IP(), item.Host))
|
113
|
106
|
client.Quit(strings.Replace(item.Reason, "{ip}", client.IPString(), -1))
|
114
|
107
|
|
115
|
|
- case "notify":
|
116
|
|
- sendDnsblMessage(client, fmt.Sprintf("Connecting client %s matched %s", client.IP(), item.Host))
|
|
108
|
+ case DnsblNotifyReply:
|
|
109
|
+ client.sendServerMessage("", channel, sno.Dnsbl, fmt.Sprintf("Connecting client %s matched %s", client.IP(), item.Host))
|
117
|
110
|
|
118
|
|
- case "allow":
|
119
|
|
- sendDnsblMessage(client, fmt.Sprintf("Allowing host %s [%s]", client.IP(), item.Host))
|
|
111
|
+ case DnsblAllowReply:
|
|
112
|
+ client.sendServerMessage("", channel, sno.Dnsbl, fmt.Sprintf("Allowing host %s [%s]", client.IP(), item.Host))
|
120
|
113
|
}
|
121
|
114
|
}
|
122
|
115
|
|
|
@@ -130,13 +123,29 @@ func connectionRequiresSasl(client *Client) bool {
|
130
|
123
|
return false
|
131
|
124
|
}
|
132
|
125
|
|
|
126
|
+ channel := client.server.DnsblConfig().Channel
|
|
127
|
+
|
133
|
128
|
if client.Account() == "" {
|
134
|
|
- sendDnsblMessage(client, fmt.Sprintf("Connecting client %s and did not authenticate through SASL - blocking connection", client.IP()))
|
|
129
|
+ //client.sendServerMessage("", channel, sno.Dnsbl, fmt.Sprintf("Connecting client %s and did not authenticate through SASL - blocking connection", client.IP()))
|
135
|
130
|
client.Quit(strings.Replace(reason, "{ip}", client.IPString(), -1))
|
136
|
131
|
return true
|
137
|
132
|
}
|
138
|
133
|
|
139
|
|
- sendDnsblMessage(client, fmt.Sprintf("Connecting client %s authenticated through SASL - allowing", client.IP()))
|
|
134
|
+ client.sendServerMessage("", channel, sno.Dnsbl, fmt.Sprintf("Connecting client %s authenticated through SASL - allowing", client.IP()))
|
140
|
135
|
|
141
|
136
|
return false
|
142
|
137
|
}
|
|
138
|
+
|
|
139
|
+func (client *Client) sendServerMessage(pseudo string, channel string, mask sno.Mask, message string) {
|
|
140
|
+ /*
|
|
141
|
+ This causes an out of bounds error - possibly in client.Send() - investigate further
|
|
142
|
+ if pseudo == "" {
|
|
143
|
+ pseudo = client.server.name
|
|
144
|
+ }
|
|
145
|
+
|
|
146
|
+ if channel != "" {
|
|
147
|
+ client.Send(nil, pseudo, "PRIVMSG", channel, message)
|
|
148
|
+ }
|
|
149
|
+ */
|
|
150
|
+ client.server.snomasks.Send(mask, message)
|
|
151
|
+}
|