Skip to content

Commit

Permalink
Support other.conf files in Ubuntu 2210 (#1635)
Browse files Browse the repository at this point in the history
* bug fix

* Update distroutils.py
  • Loading branch information
norakoiralamsft authored Dec 5, 2022
1 parent d1a36b8 commit cb79edd
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
13 changes: 13 additions & 0 deletions Utils/distroutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ def get_my_distro(config):
if re.search("sles", os_name, re.IGNORECASE):
# SuSE
return SuSEDistro(config)
if re.search("ubuntu", os_name, re.IGNORECASE):
return UbuntuDistro(config)
return GenericDistro(config)


Expand Down Expand Up @@ -247,6 +249,17 @@ def delete_account(self, user):
pass
return

class UbuntuDistro(GenericDistro):
def __init__(self, config):
"""
Generic Attributes go here. These are based on 'majority rules'.
This __init__() may be called or overriden by the child.
"""
super(UbuntuDistro, self).__init__(config)
self.selinux = False
self.ssh_service_name = 'sshd'
self.sudoers_dir_base = '/usr/local/etc'
self.distro_name = 'Ubuntu'

class FreeBSDDistro(GenericDistro):
"""
Expand Down
11 changes: 8 additions & 3 deletions VMAccess/vmaccess.py
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,13 @@ def _allow_password_auth():
_set_sshd_config(config, "PasswordAuthentication", "yes")
ext_utils.replace_file_with_contents_atomic(SshdConfigPath, "\n".join(config))

if isinstance(MyDistro, dist_utils.UbuntuDistro): #handle ubuntu 22.04 (sshd_config.d directory)
cloudInitConfigPath = "/etc/ssh/sshd_config.d/50-cloud-init.conf"
config = ext_utils.get_file_contents(cloudInitConfigPath)
if config is not None: #other versions of ubuntu don't contain this file
config = config.split("\n")
_set_sshd_config(config, "PasswordAuthentication", "yes")
ext_utils.replace_file_with_contents_atomic(cloudInitConfigPath, "\n".join(config))

def _set_sshd_config(config, name, val):
notfound = True
Expand All @@ -360,9 +367,7 @@ def _set_sshd_config(config, name, val):
# Match block must be put in the end of sshd config
break
if notfound:
if i is None:
i = 0
config.insert(i, "{0} {1}".format(name, val))
config = "{0} {1}".format(name, val) + config
return config


Expand Down

0 comments on commit cb79edd

Please sign in to comment.