summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Matthias Jaros <jarlucmat@mailbox.org>2026-08-12 21:59:54 +0200
committerGravatar Matthias Jaros <jarlucmat@mailbox.org>2026-08-12 21:59:54 +0200
commit039a1424ef228b062c018bff1bc132800c8c2cfb (patch)
tree031ed5e29b13884dd783dbdc6d5e0a3a86401a24
parentdf5b3c3496b459737e98c7061f30324872ae9b00 (diff)
Moved user check into function and also verify in repo setup proper username
-rw-r--r--src/env2
-rwxr-xr-xsrc/init22
2 files changed, 18 insertions, 6 deletions
diff --git a/src/env b/src/env
index 42cb089..c32fa12 100644
--- a/src/env
+++ b/src/env
@@ -10,4 +10,4 @@ set _PERMISSIONS r w
set _REPO_PERMISSIONS_FILE /etc/repo-permissions
set _REPO_VALIDATION_REGEX "((?:\/[a-zA-Z0-9_\-\.]+)+.git)"
set _GIT_VALIDATION_REGEX "^(git-(?:upload-pack|receive-pack|upload-archive)) '$_REPO_VALIDATION_REGEX'\$"
-set _USER_VALIDATION_REGEX "^[a-z0-9]([a-z0-9_-]{0,30}[a-z0-9])?\$"
+set _USER_VALIDATION_REGEX "[a-z0-9]([a-z0-9_-]{0,30}[a-z0-9])?"
diff --git a/src/init b/src/init
index 383d1c1..01d5f11 100755
--- a/src/init
+++ b/src/init
@@ -28,10 +28,7 @@ function setupUser
set -l key $userConfig[2]
# validate username
- if not string match -q -r -- $_USER_VALIDATION_REGEX "$user"
- echo "Error: User '$user' does not match validation regex"
- return 1
- end
+ checkUsername "$user"; or return $status
echo "Setting up user: $user"
if [ "$user" = git ]
@@ -59,6 +56,17 @@ function setupUser
chmod -R 700 "$HOME"
end
+function checkUsername
+ set -l user "$argv[1]"
+ # validate username
+ if not string match -q -r -- "^$_USER_VALIDATION_REGEX\$" "$user"
+ echo "Error: User '$user' does not match validation regex"
+ return 1
+ end
+
+ return 0
+end
+
function setupGitUser
doesUserExist "git"; and return 0
echo "Setting up git user"
@@ -92,7 +100,11 @@ function setupRepo
set -l parsedConfig (string split ':' -- $userConfig)
set -l user $parsedConfig[1]
set -l permission $parsedConfig[2]
-
+
+ if not checkUsername "$user"
+ continue
+ end
+
# check for valid permission
if not contains $permission $_PERMISSIONS
set permission "r"