summaryrefslogtreecommitdiff
path: root/src/init
diff options
context:
space:
mode:
authorGravatar Matthias Jaros <jarlucmat@mailbox.org>2026-08-12 21:44:39 +0200
committerGravatar Matthias Jaros <jarlucmat@mailbox.org>2026-08-12 21:44:39 +0200
commitf45fbe8fbe18204e24aa3e42f338d486f3ac64a8 (patch)
treec03bc9aa77efd2edb8f46eeafb0807bd64a5b4db /src/init
parentfd4e96515a7e0d91a00d99749c634b97ffcc6352 (diff)
Added user validation regex
Diffstat (limited to 'src/init')
-rwxr-xr-xsrc/init18
1 files changed, 12 insertions, 6 deletions
diff --git a/src/init b/src/init
index d82f7a3..383d1c1 100755
--- a/src/init
+++ b/src/init
@@ -16,9 +16,9 @@ function fail
return 1
end
-function checkUser
+function doesUserExist
set -l user $argv[1]
- grep -q -E "^$user:" < /etc/passwd
+ string match -q -r -- "^$user:" < /etc/passwd
return $status
end
@@ -26,16 +26,22 @@ function setupUser
set -l userConfig (string split ':' $argv[1])
set -l user $userConfig[1]
set -l key $userConfig[2]
- set -l HOME "/home/$user"
+
+ # validate username
+ if not string match -q -r -- $_USER_VALIDATION_REGEX "$user"
+ echo "Error: User '$user' does not match validation regex"
+ return 1
+ end
echo "Setting up user: $user"
if [ "$user" = git ]
echo "Error: User git is reserved"
- return 1
+ return 2
end
+ set -l HOME "/home/$user"
# setup user exist if necessary
- if not checkUser "$user"
+ if not doesUserExist "$user"
# user is not restricted, this is done in ssh config with forceCommand
# we need to be able to run a fish script to check for permissions
adduser --home $HOME -D "$user"; or fail "Failed to create user $user"
@@ -54,7 +60,7 @@ function setupUser
end
function setupGitUser
- checkUser "git"; and return 0
+ doesUserExist "git"; and return 0
echo "Setting up git user"
# git user has read/write access to all repos, set git-shell
# and no password login allowed -> no ssh login possible