summaryrefslogtreecommitdiff
path: root/cloudinit/distros
diff options
context:
space:
mode:
authorIgor Galić <me+github@igalic.co>2019-11-26 17:44:21 +0100
committerChad Smith <chad.smith@canonical.com>2019-11-26 09:44:21 -0700
commitb6055c40189afba323986059434b8d8adc85bba3 (patch)
tree8dcfe0b90986f11a056fcd03403e8f3495dd679d /cloudinit/distros
parent250a3f92473feeb2689f3a214e8f1b79fa419334 (diff)
downloadvyos-cloud-init-b6055c40189afba323986059434b8d8adc85bba3.tar.gz
vyos-cloud-init-b6055c40189afba323986059434b8d8adc85bba3.zip
set_passwords: support for FreeBSD (#46)
Allow setting of user passwords on FreeBSD The www/chpasswd utility which we depended on for FreeBSD installations does *not* do the same thing as the equally named Linux utility. For FreeBSD, we now use the pw(8) utility (which can only process one user at a time) Additionally, we abstract expire passwd into a function, and override it in the FreeBSD distro class. Co-Authored-By: Chad Smith <chad.smith@canonical.com>
Diffstat (limited to 'cloudinit/distros')
-rw-r--r--cloudinit/distros/__init__.py7
-rw-r--r--cloudinit/distros/freebsd.py7
2 files changed, 14 insertions, 0 deletions
diff --git a/cloudinit/distros/__init__.py b/cloudinit/distros/__init__.py
index 00bdee3d..2ec79577 100644
--- a/cloudinit/distros/__init__.py
+++ b/cloudinit/distros/__init__.py
@@ -591,6 +591,13 @@ class Distro(object):
util.logexc(LOG, 'Failed to disable password for user %s', name)
raise e
+ def expire_passwd(self, user):
+ try:
+ util.subp(['passwd', '--expire', user])
+ except Exception as e:
+ util.logexc(LOG, "Failed to set 'expire' for %s", user)
+ raise e
+
def set_passwd(self, user, passwd, hashed=False):
pass_string = '%s:%s' % (user, passwd)
cmd = ['chpasswd']
diff --git a/cloudinit/distros/freebsd.py b/cloudinit/distros/freebsd.py
index c55f8990..8e5ae96c 100644
--- a/cloudinit/distros/freebsd.py
+++ b/cloudinit/distros/freebsd.py
@@ -234,6 +234,13 @@ class Distro(distros.Distro):
if passwd_val is not None:
self.set_passwd(name, passwd_val, hashed=True)
+ def expire_passwd(self, user):
+ try:
+ util.subp(['pw', 'usermod', user, '-p', '01-Jan-1970'])
+ except Exception as e:
+ util.logexc(LOG, "Failed to set pw expiration for %s", user)
+ raise e
+
def set_passwd(self, user, passwd, hashed=False):
if hashed:
hash_opt = "-H"