func InitializeVariables()

in src/go/cmd/smbwalker/main.go [320:380]


func InitializeVariables() ([]string, int, string, bool) {
	if len(os.Args) <= 1 {
		fmt.Fprintf(os.Stderr, "ERROR: no base SMB PATH specified\n")
		usage()
		os.Exit(1)
	}
	baseSMBPath := os.Args[1]
	baseSMBPath = strings.ReplaceAll(baseSMBPath, "/", "\\")
	baseSMBPath = strings.TrimSuffix(baseSMBPath, "\\")

	walkersPerShare := DefaultWalkersPerShare
	if len(os.Args) > 2 {
		if i, err := strconv.Atoi(os.Args[2]); err == nil {
			walkersPerShare = i
		} else {
			fmt.Fprintf(os.Stderr, "ERROR: incorrect value specified for walker count %s\n", os.Args[2])
			usage()
			os.Exit(4)
		}
	}

	fileExtension := DefaultFileFilter
	if len(os.Args) > 3 {
		fileExtension = os.Args[3]
	}

	runForever := false
	if len(os.Args) > 4 {
		runForever = (os.Args[4] == "true")
	}

	// validate the smb path
	matches := matchSMB.FindAllStringSubmatch(baseSMBPath, -1)
	if len(matches) == 0 || len(matches[0]) < 3 {
		fmt.Fprintf(os.Stderr, "ERROR: invalid SMB format, must be specified as \\\\fileaddress\\path\n")
		usage()
		os.Exit(2)
	}
	filer := matches[0][1]
	path := matches[0][2]

	ip := net.ParseIP(filer)
	if ip != nil {
		return []string{baseSMBPath}, walkersPerShare, fileExtension, runForever
	}

	// perform a dns lookup on the name to resolve all IP addresses
	ipAddresses, err := net.LookupIP(filer)
	if err != nil {
		fmt.Fprintf(os.Stderr, "ERROR: invalid hostname, it doesn't resolve, and fails with error: %v\n", err)
		usage()
		os.Exit(3)
	}
	result := make([]string, 0, len(ipAddresses))
	for _, addr := range ipAddresses {
		fullPath := fmt.Sprintf("\\\\%s\\%s", addr.String(), path)
		Info.Printf("add path %s", fullPath)
		result = append(result, fullPath)
	}
	return result, walkersPerShare, fileExtension, runForever
}