def Run(self, arg):
    """Does the actual work."""
    try:
      if self.grr_worker.client.FleetspeakEnabled():
        raise ValueError("Not supported on Fleetspeak enabled clients.")
    except AttributeError:
      pass

    smart_arg = {str(field): value for field, value in iteritems(arg)}

    disallowed_fields = [
        field for field in smart_arg
        if field not in UpdateConfiguration.UPDATABLE_FIELDS
    ]

    if disallowed_fields:
      raise ValueError("Received an update request for restricted field(s) %s."
                       % ",".join(disallowed_fields))

    if platform.system() != "Windows":
      # Check config validity before really applying the changes. This isn't
      # implemented for our Windows clients though, whose configs are stored in
      # the registry, as opposed to in the filesystem.

      canary_config = config.CONFIG.CopyConfig()

      # Prepare a temporary file we'll write changes to.
      with tempfiles.CreateGRRTempFile(mode="w+") as temp_fd:
        temp_filename = temp_fd.name

      # Write canary_config changes to temp_filename.
      canary_config.SetWriteBack(temp_filename)
      self._UpdateConfig(smart_arg, canary_config)

      try:
        # Assert temp_filename is usable by loading it.
        canary_config.SetWriteBack(temp_filename)
      # Wide exception handling passed here from config_lib.py...
      except Exception:  # pylint: disable=broad-except
        logging.warning("Updated config file %s is not usable.", temp_filename)
        raise

      # If temp_filename works, remove it (if not, it's useful for debugging).
      os.unlink(temp_filename)

    # The changes seem to work, so push them to the real config.
    self._UpdateConfig(smart_arg, config.CONFIG)
def Run ( self , arg ) : try : if self . grr_worker . client . FleetspeakEnabled ( ) : raise ValueError ( "Not supported on Fleetspeak enabled clients." ) except AttributeError : pass smart_arg = { str ( field ) : value for field , value in iteritems ( arg ) } disallowed_fields = [ field for field in smart_arg if field not in UpdateConfiguration . UPDATABLE_FIELDS ] if disallowed_fields : raise ValueError ( "Received an update request for restricted field(s) %s." % "," . join ( disallowed_fields ) ) if platform . system ( ) != "Windows" : canary_config = config . CONFIG . CopyConfig ( ) with tempfiles . CreateGRRTempFile ( mode = "w+" ) as temp_fd : temp_filename = temp_fd . name canary_config . SetWriteBack ( temp_filename ) self . _UpdateConfig ( smart_arg , canary_config ) try : canary_config . SetWriteBack ( temp_filename ) except Exception : logging . warning ( "Updated config file %s is not usable." , temp_filename ) raise os . unlink ( temp_filename ) self . _UpdateConfig ( smart_arg , config . CONFIG )
Does the actual work.