mirror of
https://github.com/ansible/ansible.git
synced 2026-05-28 04:32:20 -04:00
Merge 1d80283efa into ba21909655
This commit is contained in:
commit
397bcbac6f
2 changed files with 24 additions and 0 deletions
2
changelogs/fragments/86243-user-busybox-shell-warn.yml
Normal file
2
changelogs/fragments/86243-user-busybox-shell-warn.yml
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
bugfixes:
|
||||
- user - On BusyBox systems, warn when an invalid shell is specified (https://github.com/ansible/ansible/pull/86342)
|
||||
|
|
@ -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()
|
||||
|
|
|
|||
Loading…
Reference in a new issue