From 75f393d8bdfb973a9241cec0f074302de42d833e Mon Sep 17 00:00:00 2001 From: Justin Reichardt Date: Tue, 1 Mar 2022 21:59:49 -0600 Subject: [PATCH] Checks for rhosts.cfg and parent directory If the directory doesn't exist it tries to create it. If the config doesn't exist it fails with a log error explaining. --- src/rhosts.go | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/src/rhosts.go b/src/rhosts.go index 198ae5c..cc8c107 100644 --- a/src/rhosts.go +++ b/src/rhosts.go @@ -112,11 +112,11 @@ func sysdetect (tmpdir, hostsloc, cfgloc *string) { //log.Fatal("Windows is not supported") *tmpdir = "/tmp" *hostsloc = "/Windows/System32/drivers/etc/hosts" - *cfgloc = "/rhosts.cfg" + *cfgloc = "/ProgramData/rhosts/" case "linux": *tmpdir = "/tmp/" *hostsloc = "/etc/hosts" - *cfgloc ="/etc/rhosts/rhosts.cfg" + *cfgloc ="/etc/rhosts/" case "ios": log.Fatal("IOS is not supported") default: @@ -126,9 +126,20 @@ 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 (sites, downloads, whitelist *[]string, cfgloc string) (error){ + l := (cfgloc + "rhosts.cfg") var err error=nil - log.Print("Opening: ", cfgloc) - file, err := os.Open(cfgloc) + log.Print("Opening: ", l) + if _,err = os.Stat(cfgloc); os.IsNotExist(err) { + log.Print(cfgloc + " Does not exist, attempting to create it") + err = os.MkdirAll(cfgloc,731) + if err != nil { + log.Fatal("Could not create " + cfgloc) + } + } + if _,err = os.Stat(l); os.IsNotExist(err) { + log.Fatal(l + " does not exist, you need to create it") + } + file, err := os.Open(l) defer file.Close() if err != nil { log.Print(err)