def Initialize(config=None, token=None): """Initialize or update a GRR configuration.""" print "Checking write access on config %s" % config.parser if not os.access(config.parser.filename, os.W_OK): raise IOError("Config not writeable (need sudo?)") print "\nStep 0: Importing Configuration from previous installation." options_imported = 0 prev_config_file = config.Get("ConfigUpdater.old_config", default=None) if prev_config_file and os.access(prev_config_file, os.R_OK): print "Found config file %s." % prev_config_file if raw_input("Do you want to import this configuration?" " [yN]: ").upper() == "Y": options_imported = ImportConfig(prev_config_file, config) else: print "No old config file found." print "\nStep 1: Key Generation" if config.Get("PrivateKeys.server_key", default=None): if options_imported > 0: print ("Since you have imported keys from another installation in the " "last step,\nyou probably do not want to generate new keys now.") if ((raw_input("You already have keys in your config, do you want to" " overwrite them? [yN]: ").upper() or "N") == "Y"): flags.FLAGS.overwrite = True GenerateKeys(config) else: GenerateKeys(config) print "\nStep 2: Setting Basic Configuration Parameters" ConfigureBaseOptions(config) # Now load our modified config. startup.ConfigInit() print "\nStep 3: Adding Admin User" try: AddUser("admin", labels=["admin"], token=token) except UserError: if ((raw_input("User 'admin' already exists, do you want to" "reset the password? [yN]: ").upper() or "N") == "Y"): UpdateUser("admin", password=True, add_labels=["admin"], token=token) print "\nStep 4: Uploading Memory Drivers to the Database" LoadMemoryDrivers(flags.FLAGS.share_dir, token=token) print "\nStep 5: Repackaging clients with new configuration." # We need to update the config to point to the installed templates now. config.Set("ClientBuilder.executables_path", os.path.join( flags.FLAGS.share_dir, "executables")) # Build debug binaries, then build release binaries. maintenance_utils.RepackAllBinaries(upload=True, debug_build=True, token=token) maintenance_utils.RepackAllBinaries(upload=True, token=token) print "\nInitialization complete, writing configuration." config.Write() print "Please restart the service for it to take effect.\n\n"
def testRepackAll(self): """Test repacking all binaries.""" 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}): with test_lib.ConfigOverrider( {"ClientBuilder.unzipsfx_stub_dir": new_dir}): maintenance_utils.RepackAllBinaries() self.assertEqual(len(glob.glob( os.path.join(new_dir, "linux/installers/*.deb"))), 2) self.assertEqual(len(glob.glob(os.path.join( new_dir, "linux/installers/*.rpm"))), 2) self.assertEqual(len(glob.glob(os.path.join( new_dir, "windows/installers/*.exe"))), 2) self.assertEqual(len(glob.glob(os.path.join( new_dir, "darwin/installers/*.pkg"))), 1)
def ManageBinaries(config=None, token=None): """Load memory drivers and repack templates into installers.""" print "\nStep 4: Uploading Memory Drivers to the Database" LoadMemoryDrivers(flags.FLAGS.share_dir, token=token) print "\nStep 5: Repackaging clients with new configuration." # We need to update the config to point to the installed templates now. config.Set("ClientBuilder.executables_path", os.path.join( flags.FLAGS.share_dir, "executables")) # Build debug binaries, then build release binaries. maintenance_utils.RepackAllBinaries(upload=True, debug_build=True, token=token) maintenance_utils.RepackAllBinaries(upload=True, token=token) print "\nInitialization complete, writing configuration." config.Write() print "Please restart the service for it to take effect.\n\n"
def ManageBinaries(config=None, token=None): """Repack templates into installers.""" print ("\nStep 4: Installing template package and repackaging clients with" " new configuration.") if flags.FLAGS.noprompt or ((raw_input( "Download and upgrade client templates? You can skip this if " "templates are already installed. [Yn]: ").upper() or "Y") == "Y"): InstallTemplatePackage() # Build debug binaries, then build release binaries. maintenance_utils.RepackAllBinaries(upload=True, debug_build=True, token=token) maintenance_utils.RepackAllBinaries(upload=True, token=token) print "\nStep 5: Signing and uploading client components." maintenance_utils.SignAllComponents(token=token) print "\nInitialization complete, writing configuration." config.Write() print "Please restart the service for it to take effect.\n\n"
def testRepackAll(self): """Testing repacking all binaries.""" with utils.TempDirectory() as tmp_dir: new_dir = os.path.join(tmp_dir, "grr", "executables") # Copy templates and ensure our resulting directory is writeable. shutil.copytree(self.executables_dir, new_dir) for root, dirs, _ in os.walk(new_dir): for this_dir in dirs: os.chmod(os.path.join(root, this_dir), stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR) with test_lib.ConfigOverrider({"ClientBuilder.source": tmp_dir}): # If this doesn't raise, it means that there were either no templates, # or all of them were repacked successfully. maintenance_utils.RepackAllBinaries()
def testRepackAll(self): """Test repacking all binaries.""" 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) # Since we want to be able to increase the client version in the repo # without immediately making a client template release, just check we can # repack whatever templates we have installed. version = pkg_resources.get_distribution( "grr-response-templates").version.replace("post", "") major, minor, revision, release = version.split(".") with test_lib.ConfigOverrider({ "ClientBuilder.executables_dir": new_dir, "ClientBuilder.unzipsfx_stub_dir": new_dir, "Client.version_major": major, "Client.version_minor": minor, "Client.version_revision": revision, "Client.version_release": release, }): maintenance_utils.RepackAllBinaries() self.assertEqual( len(glob.glob(os.path.join(new_dir, "linux/installers/*.deb"))), 2) self.assertEqual( len(glob.glob(os.path.join(new_dir, "linux/installers/*.rpm"))), 2) self.assertEqual( len( glob.glob(os.path.join(new_dir, "windows/installers/*.exe"))), 2) self.assertEqual( len(glob.glob(os.path.join(new_dir, "darwin/installers/*.pkg"))), 1)
raise RuntimeError("No valid config specified.") if flags.FLAGS.subparser_name == "load_memory_drivers": LoadMemoryDrivers(flags.FLAGS.share_dir, token=token) elif flags.FLAGS.subparser_name == "generate_keys": try: GenerateKeys(config_lib.CONFIG) except RuntimeError, e: # GenerateKeys will raise if keys exist and --overwrite is not set. print "ERROR: %s" % e sys.exit(1) config_lib.CONFIG.Write() elif flags.FLAGS.subparser_name == "repack_clients": maintenance_utils.RepackAllBinaries(upload=flags.FLAGS.upload, token=token) maintenance_utils.RepackAllBinaries(upload=flags.FLAGS.upload, debug_build=True, token=token) elif flags.FLAGS.subparser_name == "initialize": Initialize(config_lib.CONFIG, token=token) elif flags.FLAGS.subparser_name == "show_user": ShowUser(flags.FLAGS.username, token=token) elif flags.FLAGS.subparser_name == "update_user": password = None if flags.FLAGS.password: password = getpass.getpass( prompt="Please enter new password for '%s': " %