Page MenuHomeFreeBSD

D61174.1794497900.diff
No OneTemporary

Authored By
Unknown
Size
3 KB
Referenced Files
None
Subscribers
None

D61174.1794497900.diff

diff --git a/libexec/nuageinit/nuage.lua b/libexec/nuageinit/nuage.lua
--- a/libexec/nuageinit/nuage.lua
+++ b/libexec/nuageinit/nuage.lua
@@ -355,6 +355,17 @@
if pwd.primary_group and pwd.primary_group ~= pwd.name then
extraargs = extraargs .. " -g " .. shell_escape(pwd.primary_group)
end
+
+ -- explicitly specify an uid
+ if pwd.uid ~= nil then
+ local uid = math.tointeger(pwd.uid)
+ if not uid or uid < 0 then
+ warnmsg("invalid uid for user " .. pwd.name)
+ return nil
+ end
+ extraargs = extraargs .. " -u " .. tostring(uid)
+ end
+
if not pwd.no_create_home then
extraargs = extraargs .. " -m "
end
diff --git a/libexec/nuageinit/nuageinit.7 b/libexec/nuageinit/nuageinit.7
--- a/libexec/nuageinit/nuageinit.7
+++ b/libexec/nuageinit/nuageinit.7
@@ -3,7 +3,7 @@
.\" Copyright (c) 2025 Baptiste Daroussin <bapt@FreeBSD.org>
.\" Copyright (c) 2025 Jesús Daniel Colmenares Oviedo <dtxdf@FreeBSD.org>
.\"
-.Dd June 8, 2026
+.Dd November 11, 2026
.Dt NUAGEINIT 7
.Os
.Sh NAME
@@ -546,6 +546,8 @@
.Bl -tag -width "ssh_authorized_keys"
.It Ic name
Name of the user.
+.It Ic uid
+The numeric user ID to assign to the user.
.It Ic gecos
GECOS for the user.
.It Ic homedir
diff --git a/libexec/nuageinit/tests/Makefile b/libexec/nuageinit/tests/Makefile
--- a/libexec/nuageinit/tests/Makefile
+++ b/libexec/nuageinit/tests/Makefile
@@ -12,6 +12,7 @@
${PACKAGE}FILES+= addsshkey.lua
${PACKAGE}FILES+= adduser.lua
${PACKAGE}FILES+= adduser_passwd.lua
+${PACKAGE}FILES+= adduser_uid.lua
${PACKAGE}FILES+= dirname.lua
${PACKAGE}FILES+= err.lua
${PACKAGE}FILES+= sethostname.lua
diff --git a/libexec/nuageinit/tests/adduser_uid.lua b/libexec/nuageinit/tests/adduser_uid.lua
new file mode 100644
--- /dev/null
+++ b/libexec/nuageinit/tests/adduser_uid.lua
@@ -0,0 +1,27 @@
+#!/usr/libexec/flua
+
+local n = require("nuage")
+
+local pw1 = {}
+pw1.name = "numericuser"
+pw1.uid = 1600
+local res = n.adduser(pw1)
+if not res then
+ n.err("adduser with numeric uid should return a path")
+end
+
+local pw2 = {}
+pw2.name = "stringuser"
+pw2.uid = "1601"
+res = n.adduser(pw2)
+if not res then
+ n.err("adduser with string uid should return a path")
+end
+
+local pw3 = {}
+pw3.name = "baduser"
+pw3.uid = -1
+res = n.adduser(pw3)
+if res then
+ n.err("adduser should reject negative uid")
+end
diff --git a/libexec/nuageinit/tests/nuage.sh b/libexec/nuageinit/tests/nuage.sh
--- a/libexec/nuageinit/tests/nuage.sh
+++ b/libexec/nuageinit/tests/nuage.sh
@@ -12,6 +12,7 @@
atf_test_case addsshkey
atf_test_case adduser
atf_test_case adduser_passwd
+atf_test_case adduser_uid
atf_test_case addgroup
atf_test_case addfile
atf_test_case decode_base64
@@ -80,6 +81,23 @@
$(atf_get_srcdir)/crypt $passhash "barcrypted"
}
+adduser_uid_head()
+{
+ atf_set "require.user" root
+}
+
+adduser_uid_body()
+{
+ mkdir etc
+ printf "root:*:0:0::0:0:Charlie &:/root:/bin/sh\n" > etc/master.passwd
+ pwd_mkdb -d etc etc/master.passwd
+ printf "wheel:*:0:root\n" > etc/group
+ atf_check -e inline:"nuageinit: invalid uid for user baduser\n" /usr/libexec/flua $(atf_get_srcdir)/adduser_uid.lua
+ atf_check -s exit:1 grep '^baduser:' etc/master.passwd
+ atf_check -o inline:"1600\n" awk -F ':' '/^numericuser:/ {print $3}' etc/master.passwd
+ atf_check -o inline:"1601\n" awk -F ':' '/^stringuser:/ {print $3}' etc/master.passwd
+}
+
addgroup_body()
{
mkdir etc
@@ -122,6 +140,7 @@
atf_add_test_case addsshkey
atf_add_test_case adduser
atf_add_test_case adduser_passwd
+ atf_add_test_case adduser_uid
atf_add_test_case addgroup
atf_add_test_case addfile
atf_add_test_case decode_base64

File Metadata

Mime Type
text/plain
Expires
Thu, Nov 12, 3:38 PM (3 h, 33 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
41678456
Default Alt Text
D61174.1794497900.diff (3 KB)

Event Timeline