diff --git a/system_setup/server/controllers/configure.py b/system_setup/server/controllers/configure.py index 7d6cb303..9a2b7dab 100644 --- a/system_setup/server/controllers/configure.py +++ b/system_setup/server/controllers/configure.py @@ -266,9 +266,8 @@ class ConfigureController(SubiquityController): shutil.copy(localeGenPath, "{}.test".format(testLocGenPath)) return testLocGenPath - async def apply_locale(self, lang): + async def apply_locale(self, lang, env): """ Effectively apply the locale setup to the new system.""" - env = os.environ.copy() localeGenPath = self._locale_gen_file_path() if self._update_locale_gen_file(localeGenPath, lang) is False: log.error("Failed to update locale.gen") @@ -299,7 +298,7 @@ class ConfigureController(SubiquityController): return uid - async def _create_user(self, root_dir): + async def create_user(self, root_dir, env): """ Helper method to create the user from the identity model and store it's UID. """ wsl_id = self.model.identity.user @@ -339,13 +338,14 @@ class ConfigureController(SubiquityController): create_user_base = ["-P", root_dir] assign_grp_base = ["-P", root_dir] - create_user_cmd = ["useradd"] + create_user_base + \ + # TODO: Figure out if Hardcoded paths here cause trouble for runtests. + create_user_cmd = ["/usr/sbin/useradd"] + create_user_base + \ ["-m", "-s", "/bin/bash", "-c", wsl_id.realname, "-p", wsl_id.password, username] - assign_grp_cmd = ["usermod"] + assign_grp_base + \ + assign_grp_cmd = ["/usr/sbin/usermod"] + assign_grp_base + \ ["-a", "-G", ",".join(usergroups_list), username] - create_user_proc = await arun_command(create_user_cmd) + create_user_proc = await arun_command(create_user_cmd, env=env) if create_user_proc.returncode != 0: raise Exception("Failed to create user %s: %s" % (username, create_user_proc.stderr)) @@ -355,7 +355,7 @@ class ConfigureController(SubiquityController): if self.default_uid is None: log.error("Could not retrieve %s UID", username) - assign_grp_proc = await arun_command(assign_grp_cmd) + assign_grp_proc = await arun_command(assign_grp_cmd, env=env) if assign_grp_proc.returncode != 0: raise Exception(("Failed to assign group to user %s: %s") % (username, assign_grp_proc.stderr)) @@ -386,9 +386,14 @@ class ConfigureController(SubiquityController): root_dir = self.model.root if variant == "wsl_setup": - await self._create_user(root_dir) lang = self.model.locale.selected_language - await self.apply_locale(lang) + envcp = os.environ.copy() + # Ensures a safe escape out of the snap environment for WSL. + if not self.app.opts.dry_run: + envcp['LD_LIBRARY_PATH']='' + envcp['LD_PRELOAD']='' + await self.create_user(root_dir, envcp) + await self.apply_locale(lang, envcp) else: wsl_config_update(self.model.wslconfadvanced.wslconfadvanced,