fix setting of password for a user on azure.

If azure ovf data specified a password, then get that password passed
through to useradd.  Also updates the test case to verify that the
value was encrypted correctly.
This commit is contained in:
Scott Moser 2013-08-15 13:32:14 -04:00
commit d56c83eb8e
2 changed files with 14 additions and 4 deletions

View File

@ -17,6 +17,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import base64
import crypt
import os
import os.path
import time
@ -424,7 +425,7 @@ def read_azure_ovf(contents):
if username:
defuser['name'] = username
if password:
defuser['password'] = password
defuser['passwd'] = encrypt_pass(password)
defuser['lock_passwd'] = False
if defuser:
@ -436,6 +437,10 @@ def read_azure_ovf(contents):
return (md, ud, cfg)
def encrypt_pass(password, salt_id="$6$"):
return crypt.crypt(password, salt_id + util.rand_str(strlen=16))
def list_possible_azure_ds_devs():
# return a sorted list of devices that might have a azure datasource
devlist = []

View File

@ -2,6 +2,7 @@ from cloudinit import helpers
from cloudinit.sources import DataSourceAzure
from tests.unittests.helpers import populate_dir
import crypt
import base64
from mocker import MockerTestCase
import os
@ -207,11 +208,15 @@ class TestAzureDataSource(MockerTestCase):
self.assertTrue('default_user' in dsrc.cfg['system_info'])
defuser = dsrc.cfg['system_info']['default_user']
# default user shoudl be updated for password and username
# and should not be locked.
# default user should be updated username and should not be locked.
self.assertEqual(defuser['name'], odata['UserName'])
self.assertEqual(defuser['password'], odata['UserPassword'])
self.assertFalse(defuser['lock_passwd'])
# passwd is crypt formated string $id$salt$encrypted
# encrypting plaintext with salt value of everything up to final '$'
# should equal that after the '$'
pos = defuser['passwd'].rfind("$") + 1
self.assertEqual(defuser['passwd'],
crypt.crypt(odata['UserPassword'], defuser['passwd'][0:pos]))
def test_userdata_found(self):
mydata = "FOOBAR"