コード例 #1
0
func (s *windowsNanoSeriesSuite) SetUpTest(c *gc.C) {
	s.windowsSeriesSuite.SetUpTest(c)
	s.createRegKey(c, series.IsNanoKey)

	k, err := registry.OpenKey(registry.LOCAL_MACHINE, *series.IsNanoKey, registry.ALL_ACCESS)
	c.Assert(err, jc.ErrorIsNil)

	err = k.SetDWordValue("NanoServer", 1)
	c.Assert(err, jc.ErrorIsNil)

	err = k.Close()
	c.Assert(err, jc.ErrorIsNil)
}
コード例 #2
0
func getVersionFromRegistry() (string, error) {
	k, err := registry.OpenKey(registry.LOCAL_MACHINE, currentVersionKey, registry.QUERY_VALUE)
	if err != nil {
		return "", err
	}
	defer k.Close()
	s, _, err := k.GetStringValue("ProductName")
	if err != nil {
		return "", err
	}

	return s, nil
}
コード例 #3
0
ファイル: series_windows.go プロジェクト: kat-co/utils
func isWindowsNano() (bool, error) {
	k, err := registry.OpenKey(registry.LOCAL_MACHINE, isNanoKey, registry.QUERY_VALUE)
	if err != nil {
		return false, errors.Trace(err)
	}
	defer k.Close()

	s, _, err := k.GetIntegerValue("NanoServer")
	if err != nil {
		return false, errors.Trace(err)
	}
	return s == 1, nil
}
コード例 #4
0
func (s *windowsNanoSeriesSuite) TestReadSeries(c *gc.C) {
	for _, value := range nanoVersionTests {
		k, err := registry.OpenKey(registry.LOCAL_MACHINE, *series.CurrentVersionKey, registry.ALL_ACCESS)
		c.Assert(err, jc.ErrorIsNil)

		err = k.SetStringValue("ProductName", value.version)
		c.Assert(err, jc.ErrorIsNil)

		err = k.Close()
		c.Assert(err, jc.ErrorIsNil)

		ver, err := series.ReadSeries()
		c.Assert(err, jc.ErrorIsNil)
		c.Assert(ver, gc.Equals, value.want)
	}
}
コード例 #5
0
func (s *windowsVersionSuite) TestOSVersion(c *gc.C) {
	for _, value := range versionTests {
		k, err := registry.OpenKey(registry.LOCAL_MACHINE, *version.CurrentVersionKey, registry.ALL_ACCESS)
		c.Assert(err, jc.ErrorIsNil)

		err = k.SetStringValue("ProductName", value.version)
		c.Assert(err, jc.ErrorIsNil)

		err = k.Close()
		c.Assert(err, jc.ErrorIsNil)

		ver, err := version.OSVersion()
		c.Assert(err, jc.ErrorIsNil)
		c.Assert(ver, gc.Equals, value.want)
	}
}
コード例 #6
0
ファイル: base_windows.go プロジェクト: Pankov404/juju
// tearDownFeatureFlags restores the old registry values
func (s *JujuOSEnvSuite) tearDownFeatureFlags(c *gc.C) {
	regKey := osenv.JujuRegistryKey[len(`HKLM:\`):]
	if s.regKeyExisted {
		k, err := registry.OpenKey(registry.LOCAL_MACHINE, regKey, registry.ALL_ACCESS)
		if s.regEntryExisted {
			err := k.SetStringValue(osenv.JujuFeatureFlagEnvKey, s.oldRegEntryValue)
			c.Assert(err, jc.ErrorIsNil)
		} else {
			err := k.DeleteValue(osenv.JujuFeatureFlagEnvKey)
			c.Assert(err, jc.ErrorIsNil)
		}
		err = k.Close()
		c.Assert(err, jc.ErrorIsNil)
	} else {
		err := registry.DeleteKey(registry.LOCAL_MACHINE, regKey)
		c.Assert(err, jc.ErrorIsNil)
	}

}
コード例 #7
0
ファイル: flags_windows.go プロジェクト: juju/utils
// getFlagsFromRegistry returns the string value from a registry key
func getFlagsFromRegistry(regVarKey, regVarName string) string {
	regKeyPath := regVarKey[len(`HKLM:\`):]
	k, err := registry.OpenKey(registry.LOCAL_MACHINE, regKeyPath, registry.QUERY_VALUE)
	if err != nil {
		// Since this is called during init, we can't fail here. We just log
		// the failure and move on.
		logger.Warningf("Failed to open juju registry key %s; feature flags not enabled", regVarKey)
		return ""
	}
	defer k.Close()

	f, _, err := k.GetStringValue(regVarName)
	if err != nil {
		// Since this is called during init, we can't fail here. We just log
		// the failure and move on.
		logger.Warningf("Failed to read juju registry value %s; feature flags not enabled", regVarName)
		return ""
	}

	return f
}
コード例 #8
0
}

// CloseHandle wraps the windows.CloseServiceHandle method.
// This allows us to stub out this module for testing.
func (m *manager) CloseHandle(handle windows.Handle) error {
	return windows.CloseServiceHandle(handle)
}

var newManager = func() (windowsManager, error) {
	return &manager{}, nil
}

// getPassword attempts to read the password for the jujud user. We define it as
// a variable to allow us to mock it out for testing
var getPassword = func() (string, error) {
	k, err := registry.OpenKey(registry.LOCAL_MACHINE, osenv.JujuRegistryKey[6:], registry.QUERY_VALUE)
	if err != nil {
		return "", errors.Annotate(err, "Failed to open juju registry key")
	}
	defer k.Close()

	f, _, err := k.GetBinaryValue(osenv.JujuRegistryPasswordKey)
	if err != nil {
		return "", errors.Annotate(err, "Failed to read password registry entry")
	}
	encryptedPasswd := strings.TrimSpace(string(f))
	passwd, err := securestring.Decrypt(encryptedPasswd)
	if err != nil {
		return "", errors.Annotate(err, "Failed to decrypt password")
	}
	return passwd, nil