diff options
author | Pierre Schmitz <pierre@archlinux.de> | 2010-08-13 08:20:27 +0200 |
---|---|---|
committer | Pierre Schmitz <pierre@archlinux.de> | 2010-08-13 08:20:27 +0200 |
commit | e2c005b490df6762e23da3223944151c17d1de80 (patch) | |
tree | bb9619cb292a76a09eb0d6604d9871e35ebbb8ba /db-functions | |
parent | af4f86808e8cd45cc171f55a1ec15bf30d858a0d (diff) |
Check permission before any action
Added a function to check if user has permission to alter the repos
and db files.
Diffstat (limited to 'db-functions')
-rw-r--r-- | db-functions | 29 |
1 files changed, 28 insertions, 1 deletions
diff --git a/db-functions b/db-functions index c4fc8f3..f22567b 100644 --- a/db-functions +++ b/db-functions @@ -73,7 +73,7 @@ die() { cleanup 1 } -trap abort INT QUIT TERM +trap abort INT QUIT TERM HUP trap cleanup EXIT @@ -274,3 +274,30 @@ pkgver_from_src() { tmp=${tmp%-any} echo $tmp | sed 's|.*-\(.*-.*\)$|\1|g' } + +check_repo_permission() { + local repo=$1 + + local repos="$(get_repos_for_host)" + local found=false + local r + for r in $repos; do + if [ "$r" = "$repo" ]; then + found=true + fi + done + [ $found ] || return 1 + + [ -w "$FTP_BASE/$(get_pkgpool_for_host)" ] || return 1 + + local arch + for arch in ${ARCHES} any; do + local w + local ws=("${FTP_BASE}/${repo}/os/${arch}/"{,${repo}${DBEXT}}) + for w in ws; do + [ -w ] || return 1 + done + done + + return 0 +} |