From 901f8c537e68a0d35ef01f795febb3f1e9c82b56 Mon Sep 17 00:00:00 2001 From: Justin Reichardt Date: Tue, 1 Mar 2022 10:44:46 -0600 Subject: [PATCH] Detects whitelist in the options Passes the addresses of the variables when parsing the config file Fills out the whitelist string array with config entries --- src/rhosts.go | 32 +++++++++++++++++++++++--------- 1 file changed, 23 insertions(+), 9 deletions(-) diff --git a/src/rhosts.go b/src/rhosts.go index aa2d7fc..e276960 100644 --- a/src/rhosts.go +++ b/src/rhosts.go @@ -60,8 +60,9 @@ func main() { sysdetect (&tmpdir, &hostsloc, &cfgloc) for true { + var sites, downloads, whitelist []string err := error(nil) - sites, downloads, err := cfgparse(cfgloc) + err = cfgparse(&sites, &downloads, &whitelist, cfgloc) if (err != nil){ log.Print("Failed to parse config file") continue @@ -124,16 +125,14 @@ func sysdetect (tmpdir, hostsloc, cfgloc *string) { } // cfgparse recieves the location of the config file and returns a list of sites to add and content to download -func cfgparse (cfgloc string) ([]string, []string, error){ +func cfgparse (sites, downloads, whitelist *[]string, cfgloc string) (error){ var err error=nil - var downloads []string - var sites []string log.Print("Opening: ", cfgloc) file, err := os.Open(cfgloc) defer file.Close() if err != nil { log.Print(err) - return nil, nil,err + return err } filebuf := bufio.NewScanner(file) filebuf.Split(bufio.ScanLines) @@ -141,17 +140,19 @@ func cfgparse (cfgloc string) ([]string, []string, error){ state, body := cfgparseline(filebuf.Text()) switch state { case 3: - sites =append(sites,body) + *sites =append(*sites,body) case 4: - downloads = append(downloads,body) + *downloads = append(*downloads,body) + case 5: + *whitelist = append(*whitelist,body) } } err = filebuf.Err() if err != nil { log.Print(err) - return nil, nil, err + return err } - return sites, downloads, err + return err } // cfgparseline reads a single line of the config and returns the type and content of the line @@ -162,6 +163,7 @@ func cfgparseline(buf string) (uint8, string){ // 2 - Comment // 3 - Site // 4 - Download + // 5 - Whitelist var state uint8= 0 body :=buf[:] for i:=0; i