def testDeleteLegacyConfigOptions(self): key = winreg.OpenKeyEx(winreg.HKEY_LOCAL_MACHINE, _TEST_KEY_PATH, 0, winreg.KEY_ALL_ACCESS) winreg.SetValueEx(key, "foo", 0, winreg.REG_SZ, "foo-value") winreg.SetValueEx(key, "bar", 0, winreg.REG_SZ, "bar-value") installers._DeleteLegacyConfigOptions( "reg://HKEY_LOCAL_MACHINE/{}".format(_TEST_KEY_PATH)) remaining_values = _GetAllRegistryKeyValues(key) self.assertDictEqual(remaining_values, {"foo": "foo-value"})
def Run(): """Installs the windows client binary.""" _CheckForWow64() _StopPreviousService() _CopyToSystemDir() if not config.CONFIG["Client.fleetspeak_enabled"]: _InstallNanny() return # Remove the Nanny service for the legacy GRR since it will # not be needed any more. _RemoveService(config.CONFIG["Nanny.service_name"]) _DeleteLegacyConfigOptions(config.CONFIG["Config.writeback"]) # Write the Fleetspeak config to the registry. key_path = config.CONFIG["Client.fleetspeak_unsigned_services_regkey"] regkey = _OpenRegkey(key_path) fleetspeak_unsigned_config_path = os.path.join( config.CONFIG["Client.install_path"], config.CONFIG["Client.fleetspeak_unsigned_config_fname"]) winreg.SetValueEx(regkey, config.CONFIG["Client.name"], 0, winreg.REG_SZ, fleetspeak_unsigned_config_path) fs_service = config.CONFIG["Client.fleetspeak_service_name"] _StopService(service_name=fs_service) _StartService(service_name=fs_service)
def Heartbeat(self): """Writes a heartbeat to the registry.""" service_key = _GetServiceKey() try: winreg.SetValueEx(service_key, "Nanny.heartbeat", 0, winreg.REG_DWORD, int(time.time())) except OSError as e: logging.debug("Failed to heartbeat nanny at %s: %s", service_key, e)
def SaveData(self, raw_data): logging.info("Writing back configuration to key %s.", self._key_spec) # Ensure intermediate directories exist. try: for key, value in iteritems(raw_data): winreg.SetValueEx(self._AccessRootKey(), key, 0, winreg.REG_SZ, utils.SmartStr(value)) finally: # Make sure changes hit the disk. winreg.FlushKey(self._AccessRootKey())
def Write(self, grr_message): """Write the message into the transaction log. Args: grr_message: A GrrMessage instance. """ grr_message = grr_message.SerializeToBytes() try: winreg.SetValueEx(_GetServiceKey(), "Transaction", 0, winreg.REG_BINARY, grr_message) self._synced = False except OSError: pass
def Run(self): if not config.CONFIG["Client.fleetspeak_enabled"]: self.InstallNanny() return # Remove the Nanny service for the legacy GRR since it will # not be needed any more. RemoveService(config.CONFIG["Nanny.service_name"]) # Write the Fleetspeak config to the registry. key_path = config.CONFIG["Client.fleetspeak_unsigned_services_regkey"] regkey = OpenRegkey(key_path) fleetspeak_unsigned_config_path = os.path.join( config.CONFIG["Client.install_path"], config.CONFIG["Client.fleetspeak_unsigned_config_fname"]) winreg.SetValueEx(regkey, config.CONFIG["Client.name"], 0, winreg.REG_SZ, fleetspeak_unsigned_config_path) fs_service = config.CONFIG["Client.fleetspeak_service_name"] StopService(service_name=fs_service) StartService(service_name=fs_service)
def SaveData(self, raw_data): logging.info("Writing back configuration to key %s.", self._key_spec) # Ensure intermediate directories exist. try: for key, value in iteritems(raw_data): # TODO(user): refactor regconfig. At the moment it has no idea # what kind of data it's serializing and simply stringifies, them # assuming that bytes are simply ascii-encoded strings. Note that # lists (Client.tempdir_roots) also get stringified and can't # really be deserialized, since RegistryConfigParser doesn't # support deserializing anything but strings. if isinstance(value, bytes): str_value = value.decode("ascii") else: str_value = str(value) winreg.SetValueEx(self._AccessRootKey(), key, 0, winreg.REG_SZ, str_value) finally: # Make sure changes hit the disk. winreg.FlushKey(self._AccessRootKey())