This commit is contained in:
Sam Doran 2026-05-27 22:06:28 -05:00 committed by GitHub
commit 397bcbac6f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 24 additions and 0 deletions

View file

@ -0,0 +1,2 @@
bugfixes:
- user - On BusyBox systems, warn when an invalid shell is specified (https://github.com/ansible/ansible/pull/86342)

View file

@ -3133,6 +3133,24 @@ class BusyBox(User):
- remove_user()
- modify_user()
"""
def _validate_shell(self):
if not self.shell:
return
try:
with open("/etc/shells", "r") as f:
shells = [
shell
for shell in (line.strip() for line in f)
if shell
and not shell.startswith("#")
]
except FileNotFoundError:
return
if self.shell not in shells:
self.module.warn(f"'{self.shell}' is not listed as a valid shell on the remote host.")
def _build_password_string(self, current_password=None):
"""
Build the appropriate password string based on the current password and
@ -3166,6 +3184,8 @@ class BusyBox(User):
def create_user(self):
cmd = [self.module.get_bin_path('adduser', True)]
self._validate_shell()
cmd.append('-D')
if self.uid is not None:
@ -3275,6 +3295,8 @@ class BusyBox(User):
add_cmd_bin = self.module.get_bin_path('adduser', True)
remove_cmd_bin = self.module.get_bin_path('delgroup', True)
self._validate_shell()
# Manage group membership
if self.groups:
groups = self.get_groups_set() or set()