diff options
author | Michael Raskin <7c6f434c@mail.ru> | 2015-01-03 16:55:56 +0300 |
---|---|---|
committer | Michael Raskin <7c6f434c@mail.ru> | 2015-01-03 16:56:05 +0300 |
commit | 187646f0711b0c7f5cbbd9a759f831ffe18cd703 (patch) | |
tree | 294a2fec315713840c081f1213adf65e81e6fcf6 /pkgs/servers/http | |
parent | 60d0005a0c02b233653f8089456270a0ba13b59d (diff) | |
download | nixlib-187646f0711b0c7f5cbbd9a759f831ffe18cd703.tar nixlib-187646f0711b0c7f5cbbd9a759f831ffe18cd703.tar.gz nixlib-187646f0711b0c7f5cbbd9a759f831ffe18cd703.tar.bz2 nixlib-187646f0711b0c7f5cbbd9a759f831ffe18cd703.tar.lz nixlib-187646f0711b0c7f5cbbd9a759f831ffe18cd703.tar.xz nixlib-187646f0711b0c7f5cbbd9a759f831ffe18cd703.tar.zst nixlib-187646f0711b0c7f5cbbd9a759f831ffe18cd703.zip |
Return proper 404 when path is missing
Diffstat (limited to 'pkgs/servers/http')
-rw-r--r-- | pkgs/servers/http/nix-binary-cache/nix-binary-cache.cgi.in | 22 |
1 files changed, 15 insertions, 7 deletions
diff --git a/pkgs/servers/http/nix-binary-cache/nix-binary-cache.cgi.in b/pkgs/servers/http/nix-binary-cache/nix-binary-cache.cgi.in index 1afe8854fed1..890e68765b40 100644 --- a/pkgs/servers/http/nix-binary-cache/nix-binary-cache.cgi.in +++ b/pkgs/servers/http/nix-binary-cache/nix-binary-cache.cgi.in @@ -10,13 +10,18 @@ KEYNAME=na export NIX_REMOTE=daemon config="${NIX_BINARY_CACHE_CONFIG:-${HTTP_NIX_BINARY_CACHE_CONFIG:-/etc/nix/nix-binary-cache.cgi.conf}}" -config="$(cd "$(@coreutils@/dirname "$config")"; +config="$(cd "$(@coreutils@/dirname "$config")"; @coreutils@/pwd)/$(@coreutils@/basename "$config")" @coreutils@/test -e "$config" && . "$config" header(){ echo "Content-Type: text/plain; charset=utf-8" - echo + echo +} + +header404(){ + echo "Status: 404 Not Found" + echo } clean_path() { @@ -28,12 +33,12 @@ storeq(){ } sign(){ - test -n "$1" && - @coreutils@/sha256sum | @gnused@/sed -e 's/ .*//' | + test -n "$1" && + @coreutils@/sha256sum | @gnused@/sed -e 's/ .*//' | @openssl@/openssl rsautl -sign -inkey "$@" | @coreutils@/base64 -w 0 } -case "$QUERY_STRING" in +case "$QUERY_STRING" in "") header echo "Hello, this is a dynamically-generated Nix binary cache" @@ -61,9 +66,9 @@ case "$QUERY_STRING" in echo "Compression: $COMPRESSION" echo "NarHash: $(storeq --hash "$path")" echo "NarSize: $(storeq --size "$path")" - echo "References: $(storeq --references "$path" | + echo "References: $(storeq --references "$path" | @coreutils@/tac | clean_path )" - echo "Deriver: $(storeq --deriver "$path" | + echo "Deriver: $(storeq --deriver "$path" | clean_path )" )" signature="$(echo "$info" | sign "$KEY")" @@ -72,6 +77,7 @@ case "$QUERY_STRING" in echo "Signature: 1;$KEYNAME;$signature" else + header404 exit 1 fi ;; @@ -81,6 +87,7 @@ case "$QUERY_STRING" in header @nix@/nix-store --dump "$path" | @xz@/xz else + header404 exit 1 fi ;; @@ -91,6 +98,7 @@ case "$QUERY_STRING" in header @nix@/nix-store --dump "$path" | @bzip2@/bzip2 else + header404 exit 1 fi ;; |