aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBaptiste Daroussin <bapt@FreeBSD.org>2026-06-04 20:02:58 +0000
committerBaptiste Daroussin <bapt@FreeBSD.org>2026-06-04 20:02:58 +0000
commitea0932d71aa7a2d25b178f1593bfad194d8c7929 (patch)
tree3a536f5d7d78656193fc0be45991de4315fa117f
parent0ba9b7b7f815b57f1c121b0f78eaee02d2cdd414 (diff)
nuageinit: refactor goto abuse in chpasswd()
Replace goto next/list pattern with proper elseif/else control structure. The goto-based flow was fragile and hard to follow; the elseif chain makes the validation logic explicit and linear.
-rw-r--r--libexec/nuageinit/nuage.lua28
1 files changed, 11 insertions, 17 deletions
diff --git a/libexec/nuageinit/nuage.lua b/libexec/nuageinit/nuage.lua
index bdd4bf60007e..e2db27bc7e85 100644
--- a/libexec/nuageinit/nuage.lua
+++ b/libexec/nuageinit/nuage.lua
@@ -605,26 +605,20 @@ local function chpasswd(obj)
if obj.users ~= nil then
if type(obj.users) ~= "table" then
warnmsg("Invalid type for chpasswd.users, expecting a list, got a ".. type(obj.users))
- goto list
- end
- for _, u in ipairs(obj.users) do
- if type(u) ~= "table" then
- warnmsg("Invalid chpasswd.users entry, expecting an object, got a " .. type(u))
- goto next
- end
- if not u.name then
- warnmsg("Invalid entry for chpasswd.users: missing 'name'")
- goto next
- end
- if not u.password then
- warnmsg("Invalid entry for chpasswd.users: missing 'password'")
- goto next
+ else
+ for _, u in ipairs(obj.users) do
+ if type(u) ~= "table" then
+ warnmsg("Invalid chpasswd.users entry, expecting an object, got a " .. type(u))
+ elseif not u.name then
+ warnmsg("Invalid entry for chpasswd.users: missing 'name'")
+ elseif not u.password then
+ warnmsg("Invalid entry for chpasswd.users: missing 'password'")
+ else
+ exec_change_password(u.name, u.password, u.type, expire)
+ end
end
- exec_change_password(u.name, u.password, u.type, expire)
- ::next::
end
end
- ::list::
if obj.list ~= nil then
warnmsg("chpasswd.list is deprecated consider using chpasswd.users")
if type(obj.list) == "string" then