install.sh: update XDL_FAST_HASH warning URL again
[girocco.git] / bin / git-daemon-verify
blob95b1c9d0bdd9c083278722461388d55fdd0e5023
1 #!/bin/sh
3 # Abort any fetch early if the fetch is invalid or times out.
4 # This avoids unnecessary traffic and unpacked object pollution.
6 # This script is called for fetch, archive and push.
7 # Push requests are outright rejected and so are paths starting with ~.
9 set -e
11 . @basedir@/shlib.sh
13 unset GIT_USER_AGENT
14 unset GIT_HTTP_USER_AGENT
15 if [ -n "$defined_cfg_git_server_ua" ]; then
16 GIT_USER_AGENT="$cfg_git_server_ua"
17 export GIT_USER_AGENT
20 [ -z "$GIT_DAEMON_BIN" ] || cfg_git_daemon_bin="$GIT_DAEMON_BIN"
21 [ -n "$cfg_git_daemon_bin" ] ||
22 cfg_git_daemon_bin="$var_git_exec_path/git-daemon"
24 errormsg()
26 _l="$*"
27 printf '%04xERR %s' $(( 8 + ${#_l} )) "$_l"
30 invalbaderr()
32 errormsg "invalid or incomplete request"
35 invalerr()
37 errormsg "invalid or unsupported request"
40 denied()
42 errormsg "access denied or no such repository"
45 internalerr()
47 printf '%s\n' "git-daemon-verify: $*" >&2
48 errormsg "internal server error"
51 # A quick sanity check
52 if [ -z "$cfg_git_daemon_bin" ] || ! [ -x "$cfg_git_daemon_bin" ]; then
53 internalerr "bad cfg_git_daemon_bin: $cfg_git_daemon_bin"
54 exit 1
56 case "$cfg_reporoot" in /?*) :;; *)
57 internalerr "bad reporoot: $cfg_reporoot"
58 exit 1
59 esac
61 PATH="$(dirname "$cfg_git_daemon_bin"):$PATH"
62 export PATH
64 if ! request="$("$cfg_basedir/bin/peek_packet")"; then
65 invalbaderr
66 exit 1
69 # The request should look like one of the following
71 # git-upload-pack /dir
72 # git-upload-pack ~name/dir
73 # git-upload-archive /dir
74 # git-upload-archive ~name/dir
75 # git-receive-pack /dir
76 # git-receive-pack ~name/dir
78 # Where the '~' forms are relative to a user's home directory.
79 # A trailing '/' is optional as well as a final '.git'.
80 # git-receive-pack and paths starting with '~' are rejected outright.
82 type=
83 dir=
84 case "$request" in
85 "git-upload-pack "*) type='upload-pack'; dir="${request#git-upload-pack }";;
86 "git-upload-archive "*) type='upload-archive'; dir="${request#git-upload-archive }";;
87 "git-receive-pack "*) type='receive-pack'; dir="${request#git-receive-pack }";;
89 invalerr
90 exit 1
91 esac
92 if [ "$type" = 'receive-pack' ]; then
93 invalerr
94 exit 1
96 case "$dir" in /*) :;; *)
97 invalerr
98 exit 1
99 esac
101 # remove extraneous '/' chars
102 proj="${dir#/}"
103 proj="${proj%/}"
104 # add a missing .git
105 case "$proj" in
106 *.git) :;;
108 proj="$proj.git"
109 esac
111 # Reject any project names that start with _ or contain ..
112 case "$proj" in _*|*..*)
113 denied
114 exit 1
115 esac
117 reporoot="$cfg_reporoot"
118 dir="$reporoot/$proj"
120 # Valid project names never end in .git (we add that automagically), so a valid
121 # fork can never have .git at the end of any path component except the last.
122 # We check this to avoid a situation where a certain collection of pushed refs
123 # could be mistaken for a GIT_DIR. Git would ultimately complain, but some
124 # undesirable things could happen along the way.
126 # Remove the leading $reporoot and trailing .git to get a test string
127 testpath="${dir#$reporoot/}"
128 testpath="${testpath%.git}"
129 case "$testpath/" in *.[Gg][Ii][Tt]/*|_*)
130 denied
131 exit 1
132 esac
134 if ! [ -d "$dir" ] || ! [ -f "$dir/HEAD" ] || ! [ -d "$dir/objects" ]; then
135 denied
136 exit 1
139 [ -z "$var_upload_window" ] || [ "$type" != "upload-pack" ] ||
140 git_add_config "pack.window=$var_upload_window"
142 if [ "${cfg_fetch_stash_refs:-0}" = "0" ]; then
143 git_add_config "uploadpack.hiderefs=refs/stash"
144 git_add_config "uploadpack.hiderefs=refs/tgstash"
147 exec "$cfg_git_daemon_bin" --inetd --verbose --export-all --enable=upload-archive --base-path="$cfg_reporoot"
148 internalerr "exec failed: $cfg_git_daemon_bin"
149 exit 1