-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.go
More file actions
106 lines (84 loc) · 2.39 KB
/
main.go
File metadata and controls
106 lines (84 loc) · 2.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
package main
import (
"fmt"
"os"
"strings"
"time"
"github.com/markdingo/autoreverse/log"
)
func reportError(severity string, err error, messages ...string) {
msg := severity
if len(messages) > 0 {
msg += ": " + strings.Join(messages, " ")
}
if err != nil {
msg += ": " + err.Error()
}
fmt.Fprintln(log.Out(), msg)
}
func fatal(err error, messages ...string) {
reportError("Fatal", err, messages...)
os.Exit(1)
}
func warning(err error, messages ...string) {
reportError("Warning", err, messages...)
}
//////////////////////////////////////////////////////////////////////
func main() {
ar := newAutoReverse(nil, nil)
switch ar.parseOptions(os.Args) {
case parseStop:
return
case parseFailed:
os.Exit(1)
case parseContinue:
}
// Transfer logging options to the log package
if ar.cfg.logMajorFlag {
log.SetLevel(log.MajorLevel)
}
if ar.cfg.logMinorFlag {
log.SetLevel(log.MinorLevel)
}
if ar.cfg.logDebugFlag {
log.SetLevel(log.DebugLevel)
}
fmt.Fprintln(log.Out(),
programName, Version, "Starting with Log Level:", log.Level())
// Validate everything that is likely a typo or usage error
err := ar.ValidateCommandLineOptions()
if err != nil {
fatal(err)
}
// RRL is conditionally activated if any --rrl-*psec options have been set
if ar.activateRRL() {
fmt.Fprintln(log.Out(), "RRL Active", ar.cfg.rrlConfig.String())
}
// Zone of Authority phase
if len(ar.cfg.localForward) > 0 {
ar.generateLocalForward(ar.cfg.localForward) // Synthesize local forward zone
}
ar.startServers() // Only returns if listens succeed
err = ar.discover() // Discover all delegated zones
if err != nil {
fatal(err)
}
if len(ar.localReverses) > 0 { // Generate locals once forward is assured
err = ar.generateLocalReverses()
if err != nil {
fatal(err)
}
}
// Zones of Authority are set - ensure correct search order. This should rarely if
// ever matter, but it's possible that one authority might legitimately be a
// superset of another. The sort ensures that more specific zone comes first.
ar.authorities.sort()
ar.Constrain() // setuid/setgid/chroot
if !ar.loadAllZones(ar.cfg.PTRZones, "Initial load") {
fatal(nil, "Cannot continue due to failed -PTRZone load")
}
ar.Run()
ar.statsReport(false) // Final stats - depending on log level
fmt.Fprintln(log.Out(), programName, Version, "Exiting after",
time.Now().Sub(ar.startTime).Round(time.Second))
}