summaryrefslogtreecommitdiffhomepage
path: root/libs/sys
diff options
context:
space:
mode:
authorJo-Philipp Wich <jow@openwrt.org>2011-01-25 12:51:41 +0000
committerJo-Philipp Wich <jow@openwrt.org>2011-01-25 12:51:41 +0000
commit9c03a76fc28dac4efe4714f0e61bb41bf2784ef7 (patch)
tree959faffc6f22e727f09c5ed73c3add1a3450abe1 /libs/sys
parentdc0688dbbcd46fac5a661bb0e5f5e8fbeb3ffbf4 (diff)
libs/sys: properly handle passwords with apostrophes
Diffstat (limited to 'libs/sys')
-rw-r--r--libs/sys/luasrc/sys.lua11
1 files changed, 6 insertions, 5 deletions
diff --git a/libs/sys/luasrc/sys.lua b/libs/sys/luasrc/sys.lua
index 1cf8b9f18..1333cd859 100644
--- a/libs/sys/luasrc/sys.lua
+++ b/libs/sys/luasrc/sys.lua
@@ -604,16 +604,17 @@ end
-- @return Number containing 0 on success and >= 1 on error
function user.setpasswd(username, password)
if password then
- password = password:gsub("'", "")
+ password = password:gsub("'", [['"'"']])
end
if username then
- username = username:gsub("'", "")
+ username = username:gsub("'", [['"'"']])
end
- local cmd = "(echo '"..password.."';sleep 1;echo '"..password.."')|"
- cmd = cmd .. "passwd '"..username.."' >/dev/null 2>&1"
- return os.execute(cmd)
+ return os.execute(
+ "(echo '" .. password .. "'; sleep 1; echo '" .. password .. "') | " ..
+ "passwd '" .. username .. "' >/dev/null 2>&1"
+ )
end