-
Notifications
You must be signed in to change notification settings - Fork 6
/
smb2_server.go
89 lines (76 loc) · 1.84 KB
/
smb2_server.go
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
package main
import (
"os"
"os/signal"
"github.com/macos-fuse-t/go-smb2/bonjour"
"github.com/macos-fuse-t/go-smb2/config"
smb2 "github.com/macos-fuse-t/go-smb2/server"
"github.com/macos-fuse-t/go-smb2/vfs"
log "github.com/sirupsen/logrus"
"gopkg.in/natefinch/lumberjack.v2"
)
var cfg config.AppConfig
func main() {
homeDir, _ := os.UserHomeDir()
cfg = config.NewConfig([]string{
"smb2.ini",
homeDir + "/.fuse-t/smb2.ini",
})
initLogs()
srv := smb2.NewServer(
&smb2.ServerConfig{
AllowGuest: cfg.AllowGuest,
MaxIOReads: cfg.MaxIOReads,
MaxIOWrites: cfg.MaxIOWrites,
Xatrrs: cfg.Xatrrs,
},
&smb2.NTLMAuthenticator{
TargetSPN: "",
NbDomain: cfg.Hostname,
NbName: cfg.Hostname,
DnsName: cfg.Hostname + ".local",
DnsDomain: ".local",
UserPassword: map[string]string{"a": "a"},
AllowGuest: cfg.AllowGuest,
},
map[string]vfs.VFSFileSystem{cfg.ShareName: NewPassthroughFS(cfg.MountDir)},
)
log.Infof("Starting server at %s", cfg.ListenAddr)
go srv.Serve(cfg.ListenAddr)
if cfg.Advertise {
go bonjour.Advertise(cfg.ListenAddr, cfg.Hostname, cfg.Hostname, cfg.ShareName, true)
}
//go stats.StatServer(":9092")
waitSignal()
}
func initLogs() {
log.Infof("debug level %v", cfg.Debug)
if cfg.Debug {
log.SetLevel(log.DebugLevel)
} else {
log.SetLevel(log.InfoLevel)
}
homeDir, _ := os.UserHomeDir()
if !cfg.Console {
log.SetOutput(&lumberjack.Logger{
Filename: homeDir + "smb2-go.log",
MaxSize: 100, // megabytes
MaxBackups: 3,
MaxAge: 28, //days
Compress: true, // disabled by default
})
} else {
log.SetOutput(os.Stdout)
}
}
func waitSignal() {
// Ctrl+C handling
handler := make(chan os.Signal, 1)
signal.Notify(handler, os.Interrupt)
for sig := range handler {
if sig == os.Interrupt {
bonjour.Shutdown()
break
}
}
}