libs/sys: properly handle passwords with apostrophes
authorJo-Philipp Wich <jow@openwrt.org>
Tue, 25 Jan 2011 12:51:41 +0000 (12:51 +0000)
committerJo-Philipp Wich <jow@openwrt.org>
Tue, 25 Jan 2011 12:51:41 +0000 (12:51 +0000)
libs/sys/luasrc/sys.lua

index 1cf8b9f1865e4f5e2a0575f2f324a9aaeac82f9e..1333cd8593e98e6facae5dbe8acaa50706479fee 100644 (file)
@@ -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