The branch main has been updated by bapt:

URL: 
https://cgit.FreeBSD.org/src/commit/?id=83fcab792c9d7f13f7e8bd73cf1850ba74f49341

commit 83fcab792c9d7f13f7e8bd73cf1850ba74f49341
Author:     Baptiste Daroussin <b...@freebsd.org>
AuthorDate: 2024-06-05 08:34:25 +0000
Commit:     Baptiste Daroussin <b...@freebsd.org>
CommitDate: 2024-06-05 09:00:53 +0000

    nuageinit: use pw(8) instead of getent(1)
    
    pw(8) allows to seek for users in a custom rootdir, which makes it
    easier for a testsuite
    
    MFC After:      3 days
---
 libexec/nuageinit/nuage.lua | 20 ++++++++++++++------
 1 file changed, 14 insertions(+), 6 deletions(-)

diff --git a/libexec/nuageinit/nuage.lua b/libexec/nuageinit/nuage.lua
index 55486ae2b122..020b54b0776c 100644
--- a/libexec/nuageinit/nuage.lua
+++ b/libexec/nuageinit/nuage.lua
@@ -72,7 +72,12 @@ local function adduser(pwd)
                warnmsg("Argument should be a table")
                return nil
        end
-       local f = io.popen("getent passwd "..pwd.name)
+       local root = os.getenv("NUAGE_FAKE_ROOTDIR")
+       local cmd = "pw "
+       if root then
+               cmd = cmd .. "-R " .. root .. " "
+       end
+       local f = io.popen(cmd .. " usershow " ..pwd.name .. " -7 2>/dev/null")
        local pwdstr = f:read("*a")
        f:close()
        if pwdstr:len() ~= 0 then
@@ -109,8 +114,7 @@ local function adduser(pwd)
                precmd = "echo "..pwd.plain_text_passwd .. "| "
                postcmd = " -H 0 "
        end
-       local root = os.getenv("NUAGE_FAKE_ROOTDIR")
-       local cmd = precmd .. "pw "
+       cmd = precmd .. "pw "
        if root then
                cmd = cmd .. "-R " .. root .. " "
        end
@@ -140,7 +144,12 @@ local function addgroup(grp)
                warnmsg("Argument should be a table")
                return false
        end
-       local f = io.popen("getent group "..grp.name)
+       local root = os.getenv("NUAGE_FAKE_ROOTDIR")
+       local cmd = "pw "
+       if root then
+               cmd = cmd .. "-R " .. root .. " "
+       end
+       local f = io.popen(cmd .. " groupshow " ..grp.name .. " 2>/dev/null")
        local grpstr = f:read("*a")
        f:close()
        if grpstr:len() ~= 0 then
@@ -151,8 +160,7 @@ local function addgroup(grp)
                local list = splitlist(grp.members)
                extraargs = " -M " .. table.concat(list, ',')
        end
-       local root = os.getenv("NUAGE_FAKE_ROOTDIR")
-       local cmd = "pw "
+       cmd = "pw "
        if root then
                cmd = cmd .. "-R " .. root .. " "
        end

Reply via email to