func isMSOfficeInstalled() bool {
	k, err := registry.OpenKey(registry.CLASSES_ROOT, "Word.Application", registry.QUERY_VALUE)
	if err == registry.ErrNotExist {
		log.Print(err)
		return false
	} else {
		return true
	}
	defer k.Close()
	return false
}
Esempio n. 2
0
func (wnic windowsManager) getInterfaceRegKey() (registryKey string, err error) {
	//To do: Cleanup, add verbose output
	k, err := registry.OpenKey(registry.LOCAL_MACHINE, `SYSTEM\CurrentControlSet\Control\Class\{4D36E972-E325-11CE-BFC1-08002bE10318}`, registry.READ)
	if err != nil {
		return "", fmt.Errorf("Unable to open registry key: %s", err)
	}
	defer k.Close()

	subkeys, _ := k.ReadSubKeyNames(0) //0 -> read all

	for _, subkey := range subkeys {
		key, _ := registry.OpenKey(registry.LOCAL_MACHINE, fmt.Sprintf(`SYSTEM\CurrentControlSet\Control\Class\{4D36E972-E325-11CE-BFC1-08002bE10318}\%s`, subkey), registry.READ)

		netcfginstanceid, _, _ := key.GetStringValue("NetCfgInstanceId")

		if netcfginstanceid == wnic.interfaceID {
			key.Close()
			k.Close()
			return fmt.Sprintf(`SYSTEM\CurrentControlSet\Control\Class\{4D36E972-E325-11CE-BFC1-08002bE10318}\%s`, subkey), nil //Adapter key name is the interface ID
		}
		key.Close()
	}

	k.Close()
	return "", fmt.Errorf("Unable to find interface registry location for interfaceID '%s'", wnic.interfaceID)
}
func Location() (loc SetupLocation, err error) {
	var s string
	k, err := registry.OpenKey(registry.LOCAL_MACHINE, `SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\Hearthstone`, registry.QUERY_VALUE)
	if err != nil {
		defer k.Close()
		s, _, err = k.GetStringValue("DisplayIcon")
	}
	if err != nil {
		k, err = registry.OpenKey(registry.CURRENT_USER, `SOFTWARE\Microsoft\IntelliPoint\AppSpecific\Hearthstone.exe`, registry.QUERY_VALUE)
		if err != nil {
			defer k.Close()
			s, _, err = k.GetStringValue("Path")
			if err != nil {
				fmt.Printf("Could not determine location")
			}
		}
	}

	if err == nil {
		root := strings.TrimSuffix(s, "Hearthstone.exe")
		loc.LogFolder = filepath.Join(root, "Logs")
	} else {
		// finally try to stat a well known path
		fi, ierr := os.Stat(filepath.Join("C:", "Program Files (x86)", "Hearthstone", "Hearthstone.exe"))
		if ierr == nil {
			loc.LogFolder = filepath.Dir(fi.Name())
		} else {
			err = ierr
		}
	}
	loc.Config = filepath.Join(os.ExpandEnv("$LOCALAPPDATA"), "Blizzard", "Hearthstone", "log.config")
	return
}
Esempio n. 4
0
func (wnic windowsManager) getInterfaceID() (interfaceID string, err error) { //Fetch interface id from registry
	//To do: Cleanup, add verbose output
	k, err := registry.OpenKey(registry.LOCAL_MACHINE, `SYSTEM\CurrentControlSet\Control\Network\{4D36E972-E325-11CE-BFC1-08002BE10318}`, registry.READ)
	if err != nil {
		return "", fmt.Errorf("Unable to open registry: %s\n", err)
	}
	defer k.Close()

	adapterList, _ := k.ReadSubKeyNames(0) //0 -> read all

	for _, adapter := range adapterList {
		key := fmt.Sprintf(`SYSTEM\CurrentControlSet\Control\Network\{4D36E972-E325-11CE-BFC1-08002BE10318}\%s\Connection`, adapter)
		subkey, _ := registry.OpenKey(registry.LOCAL_MACHINE, key, registry.READ)

		value, _, _ := subkey.GetStringValue("Name")

		if value == wnic.InterfaceName {
			subkey.Close()
			k.Close()
			return adapter, nil //Adapter key name is the interface ID
		}
		subkey.Close()
	}
	k.Close()
	return "", fmt.Errorf("Unable to find interface id for interface '%s'", wnic.InterfaceName)
}
Esempio n. 5
0
func getTuntapComponentId() (string, error) {
	adapters, err := registry.OpenKey(registry.LOCAL_MACHINE, ADAPTER_KEY, registry.READ)
	if err != nil {
		return "", err
	}
	var i uint32
	for ; i < 1000; i++ {
		var name_length uint32 = TAPWIN32_MAX_REG_SIZE
		buf := make([]uint16, name_length)
		if err = syscall.RegEnumKeyEx(
			syscall.Handle(adapters),
			i,
			&buf[0],
			&name_length,
			nil,
			nil,
			nil,
			nil); err != nil {
			return "", err
		}
		key_name := syscall.UTF16ToString(buf[:])
		adapter, err := registry.OpenKey(adapters, key_name, registry.READ)
		if err != nil {
			return "", err
		}
		name := syscall.StringToUTF16("ComponentId")
		name2 := syscall.StringToUTF16("NetCfgInstanceId")
		var valtype uint32
		var component_id = make([]byte, TAPWIN32_MAX_REG_SIZE)
		var componentLen = uint32(len(component_id))
		if err = syscall.RegQueryValueEx(
			syscall.Handle(adapter),
			&name[0],
			nil,
			&valtype,
			&component_id[0],
			&componentLen); err != nil {
			return "", err
		}

		if unicodeTostring(component_id) == TUNTAP_COMPONENT_ID {
			var valtype uint32
			var netCfgInstanceId = make([]byte, TAPWIN32_MAX_REG_SIZE)
			var netCfgInstanceIdLen = uint32(len(netCfgInstanceId))
			if err = syscall.RegQueryValueEx(
				syscall.Handle(adapter),
				&name2[0],
				nil,
				&valtype,
				&netCfgInstanceId[0],
				&netCfgInstanceIdLen); err != nil {
				return "", err
			}
			fmt.Println("Device:", unicodeTostring(netCfgInstanceId))
			return unicodeTostring(netCfgInstanceId), nil
		}
	}
	return "", errors.New("not found component id")
}
Esempio n. 6
0
func TestCreateOpenDeleteKey(t *testing.T) {
	k, err := registry.OpenKey(registry.CURRENT_USER, "Software", registry.QUERY_VALUE)
	if err != nil {
		t.Fatal(err)
	}
	defer k.Close()

	testKName := randKeyName("TestCreateOpenDeleteKey_")

	testK, exist, err := registry.CreateKey(k, testKName, registry.CREATE_SUB_KEY)
	if err != nil {
		t.Fatal(err)
	}
	defer testK.Close()

	if exist {
		t.Fatalf("key %q already exists", testKName)
	}

	testKAgain, exist, err := registry.CreateKey(k, testKName, registry.CREATE_SUB_KEY)
	if err != nil {
		t.Fatal(err)
	}
	defer testKAgain.Close()

	if !exist {
		t.Fatalf("key %q should already exist", testKName)
	}

	testKOpened, err := registry.OpenKey(k, testKName, registry.ENUMERATE_SUB_KEYS)
	if err != nil {
		t.Fatal(err)
	}
	defer testKOpened.Close()

	err = registry.DeleteKey(k, testKName)
	if err != nil {
		t.Fatal(err)
	}

	testKOpenedAgain, err := registry.OpenKey(k, testKName, registry.ENUMERATE_SUB_KEYS)
	if err == nil {
		defer testKOpenedAgain.Close()
		t.Fatalf("key %q should already been deleted", testKName)
	}
	if err != registry.ErrNotExist {
		t.Fatalf(`unexpected error ("not exist" expected): %v`, err)
	}
}
Esempio n. 7
0
func main() {

	k, err := registry.OpenKey(registry.LOCAL_MACHINE, "SOFTWARE\\INT", registry.QUERY_VALUE)
	checkErr(err)
	defer k.Close()

	Path, _, err = k.GetStringValue("WorkingDirectory")
	checkErr(err)

	fmt.Printf("%s\n", Path)

	svcConfig := &service.Config{
		Name:        "SphinxMailer",
		DisplayName: "SphinxMailer",
		Description: "Отправляет письма при обнаружении событий в СКУД Сфинкс.",
	}

	prg := &program{}
	s, err := service.New(prg, svcConfig)
	if err != nil {
		log.Fatal(err)
	}
	logger, err = s.Logger(nil)
	if err != nil {
		log.Fatal(err)
	}
	err = s.Run()
	if err != nil {
		logger.Error(err)
	}
}
Esempio n. 8
0
func find(fontname string) (filename string, err error) {
	keyname := "Software\\Microsoft\\Windows NT\\CurrentVersion\\Fonts"
	key, err := registry.OpenKey(registry.LOCAL_MACHINE, keyname, registry.READ)
	if err != nil {
		return "", fmt.Errorf("cannot open fonts registry key: %s", err)
	}
	valuenames, err := key.ReadValueNames(0) // 0 means all
	if err != nil {
		return "", fmt.Errorf("cannot read font names from registry: %s", err)
	}
	for _, valuename := range valuenames {
		name := strings.TrimSpace(strings.TrimSuffix(valuename, "(TrueType)"))
		if name != fontname {
			continue
		}
		value, valuetype, err := key.GetStringValue(valuename)
		if err != nil {
			return "", fmt.Errorf("cannot read font key value (%s of type %d): %s", valuename, valuetype, err)
		}
		if !filepath.IsAbs(value) {
			value = filepath.Join(os.Getenv("windir"), "Fonts", value)
		}
		return value, nil
	}
	return "", fmt.Errorf("cannot find font name: %s", fontname)
}
Esempio n. 9
0
// Install modifies PC registry to allow logging with an event source src.
// It adds all required keys and values to the event log registry key.
// Install uses msgFile as the event message file. If useExpandKey is true,
// the event message file is installed as REG_EXPAND_SZ value,
// otherwise as REG_SZ. Use bitwise of log.Error, log.Warning and
// log.Info to specify events supported by the new event source.
func Install(src, msgFile string, useExpandKey bool, eventsSupported uint32) error {
	appkey, err := registry.OpenKey(registry.LOCAL_MACHINE, addKeyName, registry.CREATE_SUB_KEY)
	if err != nil {
		return err
	}
	defer appkey.Close()

	sk, alreadyExist, err := registry.CreateKey(appkey, src, registry.SET_VALUE)
	if err != nil {
		return err
	}
	defer sk.Close()
	if alreadyExist {
		return errors.New(addKeyName + `\` + src + " registry key already exists")
	}

	err = sk.SetDWordValue("CustomSource", 1)
	if err != nil {
		return err
	}
	if useExpandKey {
		err = sk.SetExpandStringValue("EventMessageFile", msgFile)
	} else {
		err = sk.SetStringValue("EventMessageFile", msgFile)
	}
	if err != nil {
		return err
	}
	err = sk.SetDWordValue("TypesSupported", eventsSupported)
	if err != nil {
		return err
	}
	return nil
}
Esempio n. 10
0
func TestValues(t *testing.T) {
	softwareK, err := registry.OpenKey(registry.CURRENT_USER, "Software", registry.QUERY_VALUE)
	if err != nil {
		t.Fatal(err)
	}
	defer softwareK.Close()

	testKName := randKeyName("TestValues_")

	k, exist, err := registry.CreateKey(softwareK, testKName, registry.CREATE_SUB_KEY|registry.QUERY_VALUE|registry.SET_VALUE)
	if err != nil {
		t.Fatal(err)
	}
	defer k.Close()

	if exist {
		t.Fatalf("key %q already exists", testKName)
	}

	defer registry.DeleteKey(softwareK, testKName)

	setValues(t, k)

	enumerateValues(t, k)

	testValues(t, k)

	testStat(t, k)

	deleteValues(t, k)
}
Esempio n. 11
0
// queryEventMessageFiles queries the registry to get the value of
// the EventMessageFile key that points to a DLL or EXE containing parameterized
// event log messages. If found, it loads the libraries as a datafiles and
// returns a slice of Handles to the libraries.
func queryEventMessageFiles(providerName, sourceName string) ([]Handle, error) {
	// Open key in registry:
	registryKeyName := fmt.Sprintf(
		"SYSTEM\\CurrentControlSet\\Services\\EventLog\\%s\\%s",
		providerName, sourceName)
	key, err := registry.OpenKey(registry.LOCAL_MACHINE, registryKeyName,
		registry.QUERY_VALUE)
	if err != nil {
		return nil, fmt.Errorf("Failed to open HKLM\\%s", registryKeyName)
	}
	defer func() {
		err := key.Close()
		if err != nil {
			logp.Warn("Failed to close registry key. key=%s err=%v",
				registryKeyName, err)
		}
	}()
	logp.Debug("eventlog", "RegOpenKey opened handle to HKLM\\%s, key=%v",
		registryKeyName, key)

	// Read value from registry:
	value, _, err := key.GetStringValue("EventMessageFile")
	if err != nil {
		return nil, fmt.Errorf("Failed querying EventMessageFile from "+
			"HKLM\\%s. %v", registryKeyName, err)
	}
	value, err = registry.ExpandString(value)
	if err != nil {
		return nil, err
	}

	// Split the value in case there is more than one file in the value.
	eventMessageFiles := strings.Split(value, ";")
	logp.Debug("eventlog", "RegQueryValueEx queried EventMessageFile from "+
		"HKLM\\%s and got [%s]", registryKeyName,
		strings.Join(eventMessageFiles, ","))

	// Load the libraries:
	var handles []Handle
	for _, eventMessageFile := range eventMessageFiles {
		sPtr, err := syscall.UTF16PtrFromString(eventMessageFile)
		if err != nil {
			logp.Debug("eventlog", "Failed to get UTF16Ptr for '%s'. "+
				"Skipping. %v", eventMessageFile, err)
			continue
		}
		handle, err := loadLibraryEx(sPtr, 0, LOAD_LIBRARY_AS_DATAFILE)
		if err != nil {
			logp.Debug("eventlog", "Failed to load library '%s' as data file. "+
				"Skipping. %v", eventMessageFile, err)
			continue
		}
		handles = append(handles, handle)
	}

	logp.Debug("eventlog", "Returning handles %v for sourceName %s", handles,
		sourceName)
	return handles, nil
}
Esempio n. 12
0
// Remove deletes all registry elements installed by the correspondent Install.
func Remove(src string) error {
	appkey, err := registry.OpenKey(registry.LOCAL_MACHINE, addKeyName, registry.SET_VALUE)
	if err != nil {
		return err
	}
	defer appkey.Close()
	return registry.DeleteKey(appkey, src)
}
func GetWindowsVersion() (string, error) {
	k, err := registry.OpenKey(registry.LOCAL_MACHINE, `SOFTWARE\Microsoft\Windows NT\CurrentVersion`, registry.QUERY_VALUE)
	if err != nil {
		log.Fatal(err)
	}
	defer k.Close()
	version, _, err := k.GetStringValue("SystemRoot")
	return version, err
}
Esempio n. 14
0
// Remove deletes all registry elements installed for an event logging source.
func RemoveSource(provider, src string) error {
	providerKeyName := fmt.Sprintf("%s\\%s", eventLogKeyName, provider)
	pk, err := registry.OpenKey(registry.LOCAL_MACHINE, providerKeyName, registry.SET_VALUE)
	if err != nil {
		return err
	}
	defer pk.Close()
	return registry.DeleteKey(pk, src)
}
Esempio n. 15
0
// queryEventMessageFiles queries the registry to get the value of
// the EventMessageFile key that points to a DLL or EXE containing templated
// event log messages. If found, it loads the libraries as a datafiles and
// returns a slice of Handles.
func queryEventMessageFiles(eventLogName, sourceName string) ([]Handle, error) {
	// Attempt to find the event message file in the registry and then store
	// a Handle to it in the cache, or store nil if an event message file does
	// not exist for the source name.

	// Open key in registry:
	registryKeyName := fmt.Sprintf(
		"SYSTEM\\CurrentControlSet\\Services\\EventLog\\%s\\%s",
		eventLogName, sourceName)
	key, err := registry.OpenKey(registry.LOCAL_MACHINE, registryKeyName,
		registry.QUERY_VALUE)
	if err != nil {
		logp.Debug("eventlog", "Failed to open HKLM\\%s", registryKeyName)
		return nil, err
	}
	defer key.Close()
	logp.Debug("eventlog", "RegOpenKey opened handle to HKLM\\%s, %v",
		registryKeyName, key)

	// Read value from registry:
	value, _, err := key.GetStringValue("EventMessageFile")
	if err != nil {
		logp.Debug("eventlog", "Failed querying EventMessageFile from HKLM\\%s", registryKeyName)
		return nil, err
	}
	value, err = registry.ExpandString(value)
	if err != nil {
		return nil, err
	}

	// Split the value in case there is more than one file specified.
	eventMessageFiles := strings.Split(value, ";")
	logp.Debug("eventlog", "RegQueryValueEx queried EventMessageFile from "+
		"HKLM\\%s and got %v", registryKeyName, eventMessageFiles)

	var handles []Handle
	for _, eventMessageFile := range eventMessageFiles {
		sPtr, err := syscall.UTF16PtrFromString(eventMessageFile)
		if err != nil {
			logp.Debug("Failed to get UTF16Ptr for '%s' (%v). Skipping",
				eventMessageFile, err)
			continue
		}
		handle, err := loadLibraryEx(sPtr, 0, LOAD_LIBRARY_AS_DATAFILE)
		if err != nil {
			logp.Debug("eventlog", "Failed to load library '%s' as data file:"+
				"%v", eventMessageFile, err)
			continue
		}
		handles = append(handles, handle)
	}

	logp.Debug("eventlog", "Returning handles %v for sourceName %s",
		handles, sourceName)
	return handles, nil
}
Esempio n. 16
0
func notifyRegChange(key registry.Key, path string, notifyCh chan error) (err error) {
	k, err := registry.OpenKey(key, path, syscall.KEY_NOTIFY)
	if err != nil {
		return
	}
	for {
		regNotifyChangeKeyValue.Call(uintptr(k), 0, 0x00000001|0x00000004, 0, 0)
		notifyCh <- nil
	}
}
func getNativeDriver(service string) (string, error) {
	k, err := registry.OpenKey(registry.LOCAL_MACHINE, `SYSTEM\CurrentControlSet\services\`+service, registry.QUERY_VALUE)
	if err != nil {
		return "", err
	}
	defer k.Close()

	v, _, err := k.GetStringValue("ImagePath")
	return v, err
}
Esempio n. 18
0
func updateSystemProxySetting() {
	k, err := registry.OpenKey(registry.CURRENT_USER, `Software\Microsoft\Windows\CurrentVersion\Internet Settings`, registry.ALL_ACCESS)
	if err != nil {
		log.Fatal(err)
	}
	defer k.Close()

	k.SetStringValue("ProxyServer", "127.0.0.1:720")
	if err != nil {
		log.Fatal(err)
	}
}
Esempio n. 19
0
func ProxyFromAutoConfig(req *http.Request) (proxyUrl *url.URL, err error) {

	// check if AutoConfigURL is definded in registry, otherwise no point in spending time to check it
	k, err := registry.OpenKey(registry.CURRENT_USER, PathInternetSettings, registry.READ)
	if err != nil {
		return
	}
	defer k.Close()

	autoConfigURL, _, err := k.GetStringValue("AutoConfigURL")
	if err != nil {
		// no auto proxy url
		return nil, nil
	}

	res, err := http.Get(autoConfigURL)
	if err != nil {
		return nil, err
	}

	vm := otto.New()
	vm.Run(res.Body)
	vm.Set("url", req.URL)
	vm.Set("host", req.URL.Host)
	vm.Run("proxy = FindProxyForURL(url, host);")
	val, err := vm.Get("proxy")
	if err != nil {
		return nil, err
	}

	proxyStr, err := val.ToString()
	if err != nil {
		return nil, err
	}
	// parse it
	// format reference: https://en.wikipedia.org/wiki/Proxy_auto-config
	for _, proxyMaybe := range strings.Split(proxyStr, ";") {
		proxyMaybe = strings.ToLower(proxyMaybe)
		if strings.Contains(proxyMaybe, "direct") {
			return nil, nil
		}

		proxyMaybe = strings.TrimSpace(strings.TrimPrefix(strings.TrimSpace(proxyMaybe), "proxy "))

		urlMaybe, err := safeParseUrl(proxyMaybe)
		if err == nil {
			return urlMaybe, err
		}
	}

	return
}
Esempio n. 20
0
// Remove deletes all registry elements installed for an event logging provider.
// Only use this method if you have installed a custom provider.
func RemoveProvider(provider string) error {
	// Protect against removing Application.
	if provider == Application {
		return fmt.Errorf("%s cannot be removed. Only custom providers can be removed.")
	}

	eventLogKey, err := registry.OpenKey(registry.LOCAL_MACHINE, eventLogKeyName, registry.SET_VALUE)
	if err != nil {
		return err
	}
	defer eventLogKey.Close()
	return registry.DeleteKey(eventLogKey, provider)
}
Esempio n. 21
0
func getToolsVerions() ([]string, error) {
	k, err := registry.OpenKey(registry.LOCAL_MACHINE, `SOFTWARE\Microsoft\MSBuild\ToolsVersions`, registry.READ)
	if err != nil {
		return nil, err
	}
	defer k.Close()

	sub, err := k.ReadSubKeyNames(-1)
	if err != nil {
		return nil, err
	}

	return sub, nil
}
Esempio n. 22
0
func main() {
	k, err := registry.OpenKey(registry.LOCAL_MACHINE, `SOFTWARE\Microsoft\Windows NT\CurrentVersion`, registry.QUERY_VALUE)
	if err != nil {
		log.Fatal(err)
	}
	defer k.Close()

	productId, _, err := k.GetBinaryValue("DigitalProductId")
	if err != nil {
		log.Fatal(err)
	}
	// fmt.Printf("DigitalProductId is [% x].\n", productId)
	DecodeKey(productId)

}
Esempio n. 23
0
// GetDeviceId finds out a TAP device from registry, it requires privileged right.
func getdeviceid() (string, error) {
	// TAP driver key location
	regkey := `SYSTEM\CurrentControlSet\Control\Class\{4D36E972-E325-11CE-BFC1-08002BE10318}`
	k, err := registry.OpenKey(registry.LOCAL_MACHINE, regkey, registry.ALL_ACCESS)
	if err != nil {
		return "", err
	}
	defer k.Close()
	// read all subkeys
	keys, err := k.ReadSubKeyNames(-1)
	if err != nil {
		return "", err
	}
	// find the one with ComponentId == "tap0901"
	for _, v := range keys {
		key, err := registry.OpenKey(registry.LOCAL_MACHINE, regkey+"\\"+v, registry.ALL_ACCESS)
		if err != nil {
			continue
		}
		val, _, err := key.GetStringValue("ComponentId")
		if err != nil {
			goto next
		}
		if val == "tap0901" {
			val, _, err = key.GetStringValue("NetCfgInstanceId")
			if err != nil {
				goto next
			}
			key.Close()
			return val, nil
		}
	next:
		key.Close()
	}
	return "", TapDeviceNotFound
}
Esempio n. 24
0
func readReg(key string) string {
	k, err := registry.OpenKey(registry.CURRENT_USER, `SOFTWARE\RA-MICRO\RA-MICRO\Global`, registry.QUERY_VALUE)
	defer k.Close()
	if err != nil {
		//log.Println("error during OpenKey, returning default")
		return ""
	}
	s, _, err := k.GetStringValue(key)

	if err != nil {
		log.Println("Fehler beim Lesen des Registry-Keys " + key)
		return ""
	}
	return strings.TrimSpace(s)
}
Esempio n. 25
0
func (wnic windowsManager) setInterfaceMACAddress(hwAddr string) error {
	var interfaceRegKey registry.Key
	var err error
	//open registry
	if interfaceRegKey, err = registry.OpenKey(registry.LOCAL_MACHINE, wnic.interfaceRegKey, registry.WRITE); err != nil {
		return fmt.Errorf("Unable to open registry key for writing: '%s'\n%s\n", wnic.interfaceRegKey, err)
	}
	defer interfaceRegKey.Close()

	//write spoofed mac to registry
	hwAddr = wnic.formatMacAddress(hwAddr)
	if err = interfaceRegKey.SetStringValue("NetworkAddress", hwAddr); err != nil {
		return fmt.Errorf("Unable to write MAC to registry: '%s'\n%s\n", wnic.interfaceRegKey, err)
	}
	return nil
}
Esempio n. 26
0
func ProxyFromRegistry(req *http.Request) (proxyUrl *url.URL, err error) {
	k, err := registry.OpenKey(registry.CURRENT_USER, PathInternetSettings, registry.READ)
	if err != nil {
		return
	}
	defer k.Close()

	proxyEnable, _, err := k.GetIntegerValue("ProxyEnable")
	if err != nil {
		return
	}

	if proxyEnable != 1 {
		return nil, nil
	}

	proxyServerStr, _, err := k.GetStringValue("ProxyServer")
	if err != nil {
		return
	}

	proxyOverrideStr, _, err := k.GetStringValue("ProxyOverride")
	if err == nil {
		_, localOverride := parseProxyOverride(proxyOverrideStr)

		host, _, err := net.SplitHostPort(canonicalAddr(req.URL))
		if err != nil {
			return nil, err
		}

		// if proxy is disabled for local addreses
		if localOverride {
			if host == "localhost" {
				return nil, nil
			}
			if ip := net.ParseIP(host); ip != nil && ip.IsLoopback() {
				return nil, nil
			}
		}

		// TODO check for custom overrides
	}

	proxyUrl, err = safeParseUrl(proxyServerStr)
	return
}
Esempio n. 27
0
// Validate() is a method implemented by the Config struct that attempts to
// retrieve the value of each property for each key in a Config. Each Property's
// PrevValue field is updated to its current value. This should be called before
// Set() but not after Write() is implemented.
func (c *Config) Validate() (err error) {
	con := *c
	for i, v := range con {
		k, err := registry.OpenKey(v.GetScope(), v.Path, registry.ALL_ACCESS)
		if err != nil {
			return err
		}
		defer k.Close()
		for n, p := range v.Properties {
			val := &con[i].Properties[n].PrevValue
			switch p.Type {
			case "DWord", "QWord":
				if s, _, err := k.GetIntegerValue(p.Name); err == nil {
					*val = s
				} else {
					return err
				}
			case "String":
				if s, _, err := k.GetStringValue(p.Name); err == nil {
					*val = s
				} else {
					return err
				}
			case "Strings":
				if s, _, err := k.GetStringsValue(p.Name); err == nil {
					*val = s
				} else {
					return err
				}
			case "Binary":
				if s, _, err := k.GetBinaryValue(p.Name); err == nil {
					*val = s
				} else {
					return err
				}
			default:
				var buf []byte
				if _, _, err := k.GetValue(p.Name, buf); err != nil {
					return err
				}
				return fmt.Errorf("%s of %s path in %s scope returned code %d.") // TODO: Convert const int representation of value types to explicitly match what the user should type into their JSON config.
			}
		}
	}
	return nil
}
func get_vboxmanage() (string, error) {
	vboxmanage, err := exec.LookPath("VBoxManage.exe")
	if err != nil {
		VboxKey, err := registry.OpenKey(registry.LOCAL_MACHINE, `SOFTWARE\Oracle\VirtualBox\`, registry.QUERY_VALUE)
		if err == nil {
			VboxInstallDir, _, err := VboxKey.GetStringValue("InstallDir")
			if err == nil {
				fmt.Printf("set PATH=%s;%s\n", `%PATH%`, VboxInstallDir)
			}
		}
	}
	if err != nil {
		fmt.Println("VBoxManage tool is required to create vdi.")
		os.Exit(1)
	}
	return vboxmanage, err
}
Esempio n. 29
0
// readCredentialSpecRegistry is a helper function to read a credential spec from
// the registry. If not found, we return an empty string and warn in the log.
// This allows for staging on machines which do not have the necessary components.
func readCredentialSpecRegistry(id, name string) (string, error) {
	var (
		k   registry.Key
		err error
		val string
	)
	if k, err = registry.OpenKey(registry.LOCAL_MACHINE, credentialSpecRegistryLocation, registry.QUERY_VALUE); err != nil {
		return "", fmt.Errorf("failed handling spec %q for container %s - %s could not be opened", name, id, credentialSpecRegistryLocation)
	}
	if val, _, err = k.GetStringValue(name); err != nil {
		if err == registry.ErrNotExist {
			return "", fmt.Errorf("credential spec %q for container %s as it was not found", name, id)
		}
		return "", fmt.Errorf("error %v reading credential spec %q from registry for container %s", err, name, id)
	}
	return val, nil
}
Esempio n. 30
0
// getStopTimeout fetches the time before windows will kill the service.
func getStopTimeout() time.Duration {
	// For default and paths see https://support.microsoft.com/en-us/kb/146092
	defaultTimeout := time.Millisecond * 20000
	key, err := registry.OpenKey(registry.LOCAL_MACHINE, `SYSTEM\CurrentControlSet\Control`, registry.READ)
	if err != nil {
		return defaultTimeout
	}
	sv, _, err := key.GetStringValue("WaitToKillServiceTimeout")
	if err != nil {
		return defaultTimeout
	}
	v, err := strconv.Atoi(sv)
	if err != nil {
		return defaultTimeout
	}
	return time.Millisecond * time.Duration(v)
}