Beispiel #1
0
def main(unused_argv):
    """Main."""
    token = GetToken()
    grr_config.CONFIG.AddContext(contexts.COMMAND_LINE_CONTEXT)
    grr_config.CONFIG.AddContext(contexts.CONFIG_UPDATER_CONTEXT)

    if flags.FLAGS.subparser_name == "initialize":
        config_lib.ParseConfigCommandLine()
        if flags.FLAGS.noprompt:
            InitializeNoPrompt(grr_config.CONFIG, token=token)
        else:
            Initialize(grr_config.CONFIG, token=token)
        return

    server_startup.Init()

    try:
        print "Using configuration %s" % grr_config.CONFIG
    except AttributeError:
        raise RuntimeError("No valid config specified.")

    if flags.FLAGS.subparser_name == "generate_keys":
        try:
            GenerateKeys(grr_config.CONFIG,
                         overwrite_keys=flags.FLAGS.overwrite_keys)
        except RuntimeError, e:
            # GenerateKeys will raise if keys exist and overwrite_keys is not set.
            print "ERROR: %s" % e
            sys.exit(1)
        grr_config.CONFIG.Write()
Beispiel #2
0
def main(unused_argv):
  """Main."""
  # Change the startup sequence in order to set the database path, if needed.
  config_lib.SetPlatformArchContext()
  config_lib.CONFIG.AddContext(contexts.DATA_SERVER_CONTEXT,
                               "Context applied when running a data server.")
  config_lib.ParseConfigCommandLine()

  if flags.FLAGS.path:
    config_lib.CONFIG.Set("Datastore.location", flags.FLAGS.path)

  log.ServerLoggingStartupInit()
  stats.STATS = stats.StatsCollector()

  # We avoid starting some hooks because they add unneeded things
  # to the data store.
  do_not_start = set(
      ["ConfigurationViewInitHook", "FileStoreInit", "GRRAFF4Init"])
  registry.Init(skip_set=do_not_start)

  if flags.FLAGS.ipv6:
    af = socket.AF_INET6
  else:
    af = socket.AF_INET

  Start(
      data_store.DB,
      port=flags.FLAGS.port,
      address_family=af,
      is_master=flags.FLAGS.master)
Beispiel #3
0
def ConfigInit():
  """Initialize the configuration manager from the command line arg."""
  # Initialize the config system from the command line options.
  config_lib.ParseConfigCommandLine()

  if config_lib.CONFIG["Config.writeback"]:
    config_lib.CONFIG.SetWriteBack(config_lib.CONFIG["Config.writeback"])
Beispiel #4
0
def ClientInit():
    """Run all startup routines for the client."""
    if stats.STATS is None:
        stats.STATS = stats.StatsCollector()

    config_lib.SetPlatformArchContext()
    config_lib.ParseConfigCommandLine()

    client_logging.LogInit()
    registry.Init()
Beispiel #5
0
def TestInit():
    """Only used in tests and will rerun all the hooks to create a clean state."""
    global INIT_RAN

    if stats.STATS is None:
        stats.STATS = stats.StatsCollector()

    # Tests use both the server template grr_server.yaml as a primary config file
    # (this file does not contain all required options, e.g. private keys), and
    # additional configuration in test_data/grr_test.yaml which contains typical
    # values for a complete installation.
    flags.FLAGS.config = config_lib.Resource().Filter(
        "install_data/etc/grr-server.yaml")

    flags.FLAGS.secondary_configs.append(config_lib.Resource().Filter(
        "test_data/grr_test.yaml@grr-response-test"))

    # This config contains non-public settings that should be applied during
    # tests.
    extra_test_config = config.CONFIG["Test.additional_test_config"]
    if os.path.exists(extra_test_config):
        flags.FLAGS.secondary_configs.append(extra_test_config)

    # Tests additionally add a test configuration file.
    config_lib.SetPlatformArchContext()
    config_lib.ParseConfigCommandLine()

    # We are running a test so let the config system know that.
    config.CONFIG.AddContext(contexts.TEST_CONTEXT,
                             "Context applied when we run tests.")

    test_ds = flags.FLAGS.test_data_store
    if test_ds is None:
        test_ds = fake_data_store.FakeDataStore.__name__

    if not INIT_RAN:
        config.CONFIG.Set("Datastore.implementation", test_ds)
        config.CONFIG.Set("Blobstore.implementation",
                          memory_stream_bs.MemoryStreamBlobstore.__name__)

        server_logging.ServerLoggingStartupInit()
        server_logging.SetTestVerbosity()

    registry.TestInit()

    db = data_store.DB.SetupTestDB()
    if db:
        data_store.DB = db
    data_store.DB.Initialize()
    aff4.AFF4InitHook().Run()

    INIT_RAN = True
Beispiel #6
0
def GetClientConfig(filename):
  """Write client config to filename."""
  config_lib.SetPlatformArchContext()
  config_lib.ParseConfigCommandLine()
  context = list(grr_config.CONFIG.context)
  context.append("Client Context")
  deployer = build.ClientRepacker()
  # Disable timestamping so we can get a reproducible and cachable config file.
  config_data = deployer.GetClientConfig(
      context, validate=True, deploy_timestamp=False)
  builder = build.ClientBuilder()
  with open(filename, "w") as fd:
    fd.write(config_data)
    builder.WriteBuildYaml(fd, build_timestamp=False)
Beispiel #7
0
def ClientInit():
    """Run all startup routines for the client."""
    if stats.STATS is None:
        stats.STATS = stats.StatsCollector()

    config_lib.SetPlatformArchContext()
    config_lib.ParseConfigCommandLine()

    client_logging.LogInit()
    registry.Init()

    if not config.CONFIG.ContextApplied(contexts.CLIENT_BUILD_CONTEXT):
        config.CONFIG.Persist("Client.labels")
        config.CONFIG.Persist("Client.proxy_servers")
        config.CONFIG.Persist("Client.tempdir_roots")
Beispiel #8
0
def Init():
    """Run all required startup routines and initialization hooks."""
    global INIT_RAN
    if INIT_RAN:
        return

    # Set up a temporary syslog handler so we have somewhere to log problems
    # with ConfigInit() which needs to happen before we can start our create our
    # proper logging setup.
    syslog_logger = logging.getLogger("TempLogger")
    if os.path.exists("/dev/log"):
        handler = logging.handlers.SysLogHandler(address="/dev/log")
    else:
        handler = logging.handlers.SysLogHandler()
    syslog_logger.addHandler(handler)

    try:
        config_lib.SetPlatformArchContext()
        config_lib.ParseConfigCommandLine()
    except config_lib.Error:
        syslog_logger.exception("Died during config initialization")
        raise

    if hasattr(registry_init, "stats"):
        logging.debug("Using local stats collector.")
        stats.STATS = registry_init.stats.StatsCollector()
    else:
        logging.debug("Using default stats collector.")
        stats.STATS = stats.StatsCollector()

    server_logging.ServerLoggingStartupInit()

    registry.Init()

    # Exempt config updater from this check because it is the one responsible for
    # setting the variable.
    if not config.CONFIG.ContextApplied("ConfigUpdater Context"):
        if not config.CONFIG.Get("Server.initialized"):
            raise RuntimeError(
                "Config not initialized, run \"grr_config_updater"
                " initialize\". If the server is already configured,"
                " add \"Server.initialized: True\" to your config.")

    INIT_RAN = True
Beispiel #9
0
def TestInit():
  """Only used in tests and will rerun all the hooks to create a clean state."""
  global INIT_RAN

  if stats.STATS is None:
    stats.STATS = stats.StatsCollector()

  # Tests use both the server template grr_server.yaml as a primary config file
  # (this file does not contain all required options, e.g. private keys), and
  # additional configuration in test_data/grr_test.yaml which contains typical
  # values for a complete installation.
  flags.FLAGS.config = config_lib.Resource().Filter(
      "install_data/etc/grr-server.yaml")

  flags.FLAGS.secondary_configs = [
      config_lib.Resource().Filter("test_data/grr_test.yaml@grr-response-test")
  ]

  # This config contains non-public settings that should be applied during
  # tests.
  extra_test_config = config_lib.CONFIG["Test.additional_test_config"]
  if os.path.exists(extra_test_config):
    flags.FLAGS.secondary_configs.append(extra_test_config)

  # We are running a test so let the config system know that.
  config_lib.CONFIG.AddContext("Test Context",
                               "Context applied when we run tests.")

  # Tests additionally add a test configuration file.
  config_lib.SetPlatformArchContext()
  config_lib.ParseConfigCommandLine()

  if not INIT_RAN:
    log.ServerLoggingStartupInit()

  registry.TestInit()

  INIT_RAN = True
Beispiel #10
0
def ConfigInit():
    """Initialize the configuration manager from the command line arg."""
    # Initialize the config system from the command line options.
    config_lib.ParseConfigCommandLine()