summaryrefslogtreecommitdiffstats
path: root/core/includes
diff options
context:
space:
mode:
authorSimon Rettberg2024-02-01 15:18:05 +0100
committerSimon Rettberg2024-02-01 15:18:05 +0100
commit63bf839ea0b5e4cc9643b70d22e4ac856939d027 (patch)
tree0611189195c66f58a4bd7b0ab717b478a1059b70 /core/includes
parent[disk-partitions] Refactor gettmp (diff)
downloadmltk-63bf839ea0b5e4cc9643b70d22e4ac856939d027.tar.gz
mltk-63bf839ea0b5e4cc9643b70d22e4ac856939d027.tar.xz
mltk-63bf839ea0b5e4cc9643b70d22e4ac856939d027.zip
[vbox-src] Add vboxusers at build time, add demo to group
Diffstat (limited to 'core/includes')
-rw-r--r--core/includes/useradd.inc13
1 files changed, 13 insertions, 0 deletions
diff --git a/core/includes/useradd.inc b/core/includes/useradd.inc
index 359a859f..d47b43b9 100644
--- a/core/includes/useradd.inc
+++ b/core/includes/useradd.inc
@@ -138,18 +138,31 @@ groupadd () {
command groupadd "${_USER_EXTRA_OPTS[@]}" "${opts[@]}" || perror "groupadd failed"
}
+# Add user to given group. Not entirely safe as we don't wait for a lock,
+# but should not be an issue during build time as system is usually offline.
+# $1=user $2=group
+add_to_group () {
+ ua_set_vars
+ grep -qP "^${2}:.*:.*[:,]${1}(,|$)" "$_GROUP" && return 0
+ grep -q "^${2}:" "$_GROUP" || return 1
+ sed -i -r "s/^${2}:[^:]*:[^:]*:.+$/&,$1/;s/^${2}:[^:]*:[^:]*:$/&$1/" "$_GROUP"
+}
+
# Get numeric ID of given user (name or ID)
getuid () {
+ ua_set_vars
awk -F ':' -v p="$1" -v n= '{if ($1 == p) n = $3; if (n == "" && $3 == p) n = $3;}END{if (length(n)) print n}' "$_PASSWD"
}
# Get numeric ID of given group (name or ID)
getgid () {
+ ua_set_vars
awk -F ':' -v p="$1" -v n= '{if ($1 == p) n = $3; if (n == "" && $3 == p) n = $3;}END{if (length(n)) print n}' "$_GROUP"
}
# Get numeric ID of primary group of given user (name or ID)
getusergroup () {
+ ua_set_vars
awk -F ':' -v p="$1" -v n= '{if ($1 == p) n = $4; if (n == "" && $4 == p) n = $3;}END{if (length(n)) print n}' "$_PASSWD"
}