예제 #1
0
    def InterpolateFiles(self):
        if self.fleetspeak_enabled:
            shutil.copy(flags.FLAGS.fleetspeak_service_config,
                        self.pkg_fleetspeak_service_dir)
            build_files_dir = config_lib.Resource().Filter(
                "install_data/macosx/client/fleetspeak")
        else:
            build_files_dir = config_lib.Resource().Filter(
                "install_data/macosx/client")
            self.GenerateFile(
                input_filename=os.path.join(build_files_dir, "grr.plist.in"),
                output_filename=os.path.join(self.pkg_root,
                                             "Library/LaunchDaemons",
                                             self.plist_name))
        # We pass in scripts separately with --scripts so they don't go in pkg_root
        self.GenerateFile(input_filename=os.path.join(build_files_dir,
                                                      "preinstall.sh.in"),
                          output_filename=os.path.join(self.script_dir,
                                                       "preinstall"))

        self.GenerateFile(input_filename=os.path.join(build_files_dir,
                                                      "postinstall.sh.in"),
                          output_filename=os.path.join(self.script_dir,
                                                       "postinstall"))
        self.GenerateFile(input_filename=os.path.join(build_files_dir,
                                                      "Distribution.xml.in"),
                          output_filename=os.path.join(self.build_dir,
                                                       "Distribution.xml"))
예제 #2
0
    def CopyFiles(self):
        """This sets up the template directory."""

        build_dir = config.CONFIG.Get("PyInstaller.dpkg_root",
                                      context=self.context)
        # Copy files needed for rpmbuild.
        shutil.move(os.path.join(build_dir, "debian"),
                    os.path.join(build_dir, "rpmbuild"))
        shutil.copy(
            config_lib.Resource().Filter("install_data/centos/grr.spec.in"),
            os.path.join(build_dir, "rpmbuild/grr.spec.in"))
        shutil.copy(
            config_lib.Resource().Filter(
                "install_data/centos/grr-client.initd.in"),
            os.path.join(build_dir, "rpmbuild/grr-client.initd.in"))

        # Copy systemd unit file
        shutil.copy(
            config_lib.Resource().Filter(
                "install_data/systemd/client/grr-client.service"),
            os.path.join(build_dir, "rpmbuild/grr-client.service.in"))

        # Copy prelink blacklist file
        shutil.copy(
            config_lib.Resource().Filter(
                "install_data/centos/prelink_blacklist.conf.in"),
            os.path.join(build_dir, "rpmbuild/prelink_blacklist.conf.in"))
예제 #3
0
파일: testing_startup.py 프로젝트: qsdj/grr
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(
        "grr_response_test/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
예제 #4
0
파일: distro_entry.py 프로젝트: qsdj/grr
def SetConfigOptions():
  """Set location of configuration flags.

  All GRR tools must use the same configuration files so they could all work
  together. This needs to happen even before the configuration subsystem is
  loaded so it must be bootstrapped by this code (all other options are
  tweakable via the configuration system).

  There are two main parts for the config system:

  1) The main config file is shipped with the package and controls general
     parameters. Note that this file is highly dependent on the exact version of
     the grr package which is using it because it might have options which are
     not understood by another version. We typically always use the config file
     from package resources because in most cases this is the right thing to do
     as this file matches exactly the running version. If you really have a good
     reason you can override with the --config flag.

  2) The writeback location. If any GRR component updates the configuration,
     changes will be written back to a different locally modified config
     file. This file specifies overrides of the main configuration file. The
     main reason is that typically the same locally written config file may be
     used with multiple versions of the GRR server because it specifies a very
     small and rarely changing set of options.

  """
  # The writeback config file is searched in the following order:

  # 1. Specified on the command line with the "--config XXXX" option.
  # 2. Use the default config file from the grr-response package.
  flags.PARSER.set_defaults(
      config=config_lib.Resource().Filter("install_data/etc/grr-server.yaml"))
예제 #5
0
파일: build.py 프로젝트: rainser/grr
    def BuildWithPyInstaller(self):
        """Use pyinstaller to build a client package."""
        self.CleanDirectory(
            config.CONFIG.Get("PyInstaller.distpath", context=self.context))

        logging.info("Copying pyinstaller support files")
        self.spec_file = os.path.join(self.build_dir, "grr.spec")

        with open(self.spec_file, "wb") as fd:
            fd.write(
                config.CONFIG.Get("PyInstaller.spec", context=self.context))

        with open(os.path.join(self.build_dir, "version.txt"), "wb") as fd:
            fd.write(
                config.CONFIG.Get("PyInstaller.version", context=self.context))

        with open(os.path.join(self.build_dir, "grr.ico"), "wb") as fd:
            fd.write(
                config.CONFIG.Get("PyInstaller.icon", context=self.context))

        # We expect the onedir output at this location.
        self.output_dir = os.path.join(
            config.CONFIG.Get("PyInstaller.distpath", context=self.context),
            "grr-client")

        # Pyinstaller doesn't handle unicode strings.
        args = [
            "--distpath",
            str(config.CONFIG.Get("PyInstaller.distpath",
                                  context=self.context)), "--workpath",
            str(
                config.CONFIG.Get("PyInstaller.workpath_dir",
                                  context=self.context)),
            str(self.spec_file)
        ]
        logging.info("Running pyinstaller: %s", args)
        PyInstallerMain.run(pyi_args=[utils.SmartStr(x) for x in args])

        # Clear out some crud that pyinstaller includes.
        for path in ["tcl", "tk", "pytz"]:
            dir_path = os.path.join(self.output_dir, path)
            try:
                shutil.rmtree(dir_path)
                os.mkdir(dir_path)
                # Create an empty file so the directories get put in the installers.
                with open(os.path.join(dir_path, path), "wb"):
                    pass
            except OSError:
                pass

        version_ini = config_lib.Resource().Filter("version.ini")
        if not os.path.exists(version_ini):
            raise RuntimeError(
                "Couldn't find version_ini in virtual env root: %s" %
                version_ini)
        shutil.copy(version_ini, os.path.join(self.output_dir, "version.ini"))

        with open(os.path.join(self.output_dir, "build.yaml"), "wb") as fd:
            self.WriteBuildYaml(fd)
예제 #6
0
파일: runner.py 프로젝트: qsdj/grr
 def _UploadBinary(self, bin_name, server_path):
     """Uploads a binary from the GRR installation dir to the datastore."""
     # TODO(user): Upload binaries via the GRR API.
     logging.info("Uploading %s binary to server.", server_path)
     package_dir = config_lib.Resource().Filter(
         "grr_response_test@grr-response-test")
     with open(os.path.join(package_dir, "test_data", bin_name), "rb") as f:
         maintenance_utils.UploadSignedConfigBlob(
             f.read(), "aff4:/config/executables/%s" % server_path)
예제 #7
0
파일: config_lib_test.py 프로젝트: qsdj/grr
    def testConfigOptionsDefined(self):
        """Test that all config options in use are defined."""
        # We need to use the actual config.CONFIG variable since that is where
        # all the variables are already defined.
        conf = config.CONFIG.MakeNewConfig()

        # Check our actual config validates
        configpath = config_lib.Resource().Filter(
            "install_data/etc/grr-server.yaml")
        conf.Initialize(filename=configpath)
예제 #8
0
파일: repacking_test.py 프로젝트: qsdj/grr
    def testRepackAll(self):
        """Test repacking all binaries."""
        self.executables_dir = config_lib.Resource().Filter("executables")
        with utils.TempDirectory() as tmp_dir:
            new_dir = os.path.join(tmp_dir, "grr", "executables")
            os.makedirs(new_dir)

            # Copy unzipsfx so it can be used in repacking/
            shutil.copy(
                os.path.join(self.executables_dir,
                             "windows/templates/unzipsfx/unzipsfx-i386.exe"),
                new_dir)
            shutil.copy(
                os.path.join(self.executables_dir,
                             "windows/templates/unzipsfx/unzipsfx-amd64.exe"),
                new_dir)

            with test_lib.ConfigOverrider({
                    "ClientBuilder.executables_dir":
                    new_dir,
                    "ClientBuilder.unzipsfx_stub_dir":
                    new_dir
            }):
                repacking.TemplateRepacker().RepackAllTemplates()

            self.assertEqual(
                len(glob.glob(os.path.join(new_dir, "installers/*.deb"))), 2)
            self.assertEqual(
                len(glob.glob(os.path.join(new_dir, "installers/*.rpm"))), 2)
            self.assertEqual(
                len(glob.glob(os.path.join(new_dir, "installers/*.exe"))), 4)
            self.assertEqual(
                len(glob.glob(os.path.join(new_dir, "installers/*.pkg"))), 1)

            # Validate the config appended to the OS X package.
            zf = zipfile.ZipFile(glob.glob(
                os.path.join(new_dir, "installers/*.pkg")).pop(),
                                 mode="r")
            fd = zf.open("config.yaml")

            # We can't load the included build.yaml because the package hasn't been
            # installed.
            loaded = yaml.safe_load(fd)
            loaded.pop("Config.includes")

            packaged_config = config.CONFIG.MakeNewConfig()
            packaged_config.Initialize(parser=config_lib.YamlParser,
                                       data=yaml.safe_dump(loaded))
            packaged_config.Validate(
                sections=build.ClientRepacker.CONFIG_SECTIONS)
            repacker = build.ClientRepacker()
            repacker.ValidateEndConfig(packaged_config)
예제 #9
0
    def CopyFiles(self):
        """This sets up the template directory."""
        # Copy the nanny binary.
        shutil.copy(
            config_lib.Resource().Filter(
                "install_data/debian/dpkg_client/nanny.sh.in"),
            self.output_dir)

        dpkg_dir = config.CONFIG.Get("PyInstaller.dpkg_root",
                                     context=self.context)

        # Copy files needed for dpkg-buildpackage.
        shutil.copytree(
            config_lib.Resource().Filter(
                "install_data/debian/dpkg_client/debian"),
            os.path.join(dpkg_dir, "debian/debian.in"))

        # Copy upstart files
        outdir = os.path.join(dpkg_dir, "debian/upstart.in")
        utils.EnsureDirExists(outdir)
        shutil.copy(
            config_lib.Resource().Filter(
                "install_data/debian/dpkg_client/upstart/grr-client.conf"),
            outdir)

        # Copy init files
        outdir = os.path.join(dpkg_dir, "debian/initd.in")
        utils.EnsureDirExists(outdir)
        shutil.copy(
            config_lib.Resource().Filter(
                "install_data/debian/dpkg_client/initd/grr-client"), outdir)

        # Copy systemd unit file
        outdir = os.path.join(dpkg_dir, "debian/systemd.in")
        utils.EnsureDirExists(outdir)
        shutil.copy(
            config_lib.Resource().Filter(
                "install_data/systemd/client/grr-client.service"), outdir)
예제 #10
0
파일: __init__.py 프로젝트: rainser/grr
def version():
  """Return a dict with GRR version information."""
  # Delay import until we have the config system to find the version.ini file.
  # pylint: disable=g-import-not-at-top
  from grr.core.grr_response_core.lib import config_lib

  version_ini = config_lib.Resource().Filter("version.ini")
  if not os.path.exists(version_ini):
    raise RuntimeError("Can't find version.ini at %s" % version_ini)

  config = ConfigParser.SafeConfigParser()
  config.read(version_ini)
  return dict(
      packageversion=config.get("Version", "packageversion"),
      major=config.getint("Version", "major"),
      minor=config.getint("Version", "minor"),
      revision=config.getint("Version", "revision"),
      release=config.getint("Version", "release"))
예제 #11
0
파일: distro_entry.py 프로젝트: rainser/grr
def SetConfigOptions():
  """Sets the default value for the config flag."""
  flags.PARSER.set_defaults(
      config=config_lib.Resource().Filter("install_data/etc/grr-server.yaml"))
예제 #12
0
파일: distro_entry.py 프로젝트: rainser/grr
def SetConfigOptions():
    """Set location of configuration flags."""
    flags.PARSER.set_defaults(config=config_lib.Resource().Filter(
        "install_data/etc/grr-server.yaml"))