-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathdbgen.go
84 lines (70 loc) · 1.82 KB
/
dbgen.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
package main
import (
"flag"
"fmt"
"os"
"os/signal"
"strconv"
"syscall"
log "github.com/sirupsen/logrus"
"github.com/vul-dbgen/common"
utils "github.com/vul-dbgen/share"
"github.com/vul-dbgen/updater"
_ "github.com/vul-dbgen/updater/fetchers/alpine"
_ "github.com/vul-dbgen/updater/fetchers/amazon"
_ "github.com/vul-dbgen/updater/fetchers/apps"
_ "github.com/vul-dbgen/updater/fetchers/debian"
_ "github.com/vul-dbgen/updater/fetchers/mariner"
_ "github.com/vul-dbgen/updater/fetchers/oracle"
_ "github.com/vul-dbgen/updater/fetchers/photon"
_ "github.com/vul-dbgen/updater/fetchers/rhel2"
_ "github.com/vul-dbgen/updater/fetchers/rocky"
_ "github.com/vul-dbgen/updater/fetchers/suse"
_ "github.com/vul-dbgen/updater/fetchers/ubuntu"
)
func usage() {
fmt.Fprintf(os.Stderr, "usage: dbgen [OPTIONS]\n")
flag.PrintDefaults()
os.Exit(2)
}
func main() {
log.SetOutput(os.Stdout)
log.SetLevel(log.DebugLevel)
log.SetFormatter(&utils.LogFormatter{Module: "DBG"})
version := flag.String("v", "0.90", "cve database version")
dbPath := flag.String("d", "", "cve database path")
debug := flag.String("debug", "", "debug filters. -debug v=CVE-2023-1000")
flag.Usage = usage
flag.Parse()
_, err := strconv.ParseFloat(*version, 64)
if err != nil {
log.WithFields(log.Fields{"error": err}).Error("Parse version fail")
os.Exit(2)
}
if *debug != "" {
common.ParseDebugFilters(*debug)
}
done := make(chan bool, 1)
c_sig := make(chan os.Signal, 1)
signal.Notify(c_sig, os.Interrupt, syscall.SIGTERM)
db, err := memdbOpen(*dbPath)
if err != nil {
os.Exit(2)
}
go func() {
if updater.Update(db) == false {
os.Exit(2)
}
if db.UpdateDb(*version) == false {
os.Exit(2)
}
db.Close()
done <- true
}()
go func() {
<-c_sig
done <- true
}()
<-done
log.Info("Update CVE database successfully")
}