nuageinit: Fix passwords

The hashed password usually contains a "$" sign, which, when used on a
shell, must be escaped.  Also, the plain text password may contain
special characters that require escaping.

Add a quick fix by enclosing it in single quotes.  Note that if the
plain text password contains a "'", it will still fail.  This will be
properly fixed in later commits.

Some here documents require the document to be a string literal,
especially when passing invalid characters.  Enclose it in single
quotes.

Signed-off-by: Jose Luis Duran <jlduran@gmail.com>
This commit is contained in:
Jose Luis Duran 2024-07-30 01:28:18 +00:00 committed by Baptiste Daroussin
parent 38bb6f79e3
commit b9ce743c54
2 changed files with 7 additions and 7 deletions

View file

@ -120,11 +120,11 @@ local function adduser(pwd)
local precmd = ""
local postcmd = ""
if pwd.passwd then
precmd = "echo " .. pwd.passwd .. "| "
postcmd = " -H 0 "
precmd = "echo '" .. pwd.passwd .. "' | "
postcmd = " -H 0"
elseif pwd.plain_text_passwd then
precmd = "echo " .. pwd.plain_text_passwd .. "| "
postcmd = " -h 0 "
precmd = "echo '" .. pwd.plain_text_passwd .. "' | "
postcmd = " -h 0"
end
cmd = precmd .. "pw "
if root then

View file

@ -81,7 +81,7 @@ EOF
wheel:*:0:root
users:*:1:
EOF
cat > media/nuageinit/user-data << EOF
cat > media/nuageinit/user-data << 'EOF'
#cloud-config
groups:
- admingroup: [root,sys]
@ -103,11 +103,11 @@ cloud-users:*:1002:
freebsd:*:1003:
foobar:*:1004:
EOF
cat > expectedpasswd << EOF
cat > expectedpasswd << 'EOF'
root:*:0:0::0:0:Charlie &:/root:/bin/csh
sys:*:1:0::0:0:Sys:/home/sys:/bin/csh
freebsd:freebsd:1001:1003::0:0:FreeBSD User:/home/freebsd:/bin/sh
foobar:H/1LT4f9/N3wpgNunhsIqtMj62OKiS3nyNwuizouQc3u7MbYCarYeAHWYPYb2FT.lbioDm2RrkJPb9BZMN1O/:1002:1004::0:0:Foo B. Bar:/home/foobar:/bin/sh
foobar:$6$j212wezy$7H/1LT4f9/N3wpgNunhsIqtMj62OKiS3nyNwuizouQc3u7MbYCarYeAHWYPYb2FT.lbioDm2RrkJPb9BZMN1O/:1002:1004::0:0:Foo B. Bar:/home/foobar:/bin/sh
EOF
sed -i "" "s/freebsd:.*:1001/freebsd:freebsd:1001/" ${here}/etc/master.passwd
atf_check -o file:expectedpasswd cat ${here}/etc/master.passwd