diff options
author | Ted Trask <ttrask01@yahoo.com> | 2008-10-13 20:51:39 +0000 |
---|---|---|
committer | Ted Trask <ttrask01@yahoo.com> | 2008-10-13 20:51:39 +0000 |
commit | 4329b7b6da85440f537da8e4c1b9da1150912df3 (patch) | |
tree | 7733780e543cd6e738405f72114f94ffc8ecee6a /password-model.lua | |
parent | 303266d5fc5c1463a2aeecb2b4cc801b81ddfb06 (diff) | |
download | acf-alpine-baselayout-4329b7b6da85440f537da8e4c1b9da1150912df3.tar.bz2 acf-alpine-baselayout-4329b7b6da85440f537da8e4c1b9da1150912df3.tar.xz |
Added alpine-baselayout hostname and password edit.
git-svn-id: svn://svn.alpinelinux.org/acf/alpine-baselayout/trunk@1556 ab2d0c66-481e-0410-8bed-d214d4d58bed
Diffstat (limited to 'password-model.lua')
-rw-r--r-- | password-model.lua | 46 |
1 files changed, 30 insertions, 16 deletions
diff --git a/password-model.lua b/password-model.lua index 376c0e2..ba74e45 100644 --- a/password-model.lua +++ b/password-model.lua @@ -1,24 +1,38 @@ -- password model methods module (..., package.seeall) -require "format" --- no initializer in model - use controller.init for that +require ("fs") + +read_password = function() + pw = {} + pw.user = cfe({ label="User Name" }) + pw.password = cfe({ label="Password" }) + pw.password_confirm = cfe({ label="Password (confirm)" }) + return cfe({ type="group", value=pw, label="System Password" }) +end --setup so that it will compare password input -set = function (self, userid, cmd1, cmd2) - if cmd1 ~= cmd2 then report = "Invalid or non matching password. Try again" - else - command = "/usr/bin/cryptpw" .. " " .. cmd1 - f = io.popen(command) - c = f:read("*l") - f:close() - --this is hardcoded for root should be easy to change - newpass = "root:" .. c - t = fs.search_replace("/etc/shadow", "root:[!%w%$%/%.]+", newpass) - fs.write_file("/etc/shadow", fs.ipairs_string(t)) - report = "Success. New password set." +update_password = function (pw) + local success = true + if pw.value.password.value == "" or pw.value.password.value ~= pw.value.password_confirm.value then + pw.value.password.errtxt = "Invalid or non matching password" + success = false + end + local filecontent = "\n"..fs.read_file("/etc/shadow") + if pw.value.user.value == "" or not string.find(filecontent, "\n"..pw.value.user.value..":") then + pw.value.user.errtxt = "Unknown user" + success = false end - return( cfe{value=report, name="report"}) -end + if success then + local f = io.popen("/usr/bin/cryptpw " .. pw.value.password.value) + local newpass = f:read("*l") + f:close() + local new = string.gsub(filecontent, "(\n"..pw.value.user.value..":)[^:]*", "%1"..newpass) + fs.write_file("/etc/shadow", string.sub(new, 2)) + else + pw.errtxt = "Failed to set password" + end + return pw +end |