html/about.html: bring some of the URLs up-to-date
[girocco.git] / bin / git-daemon-verify
blob522b20555d05173d26c17a988d099869c6361fbd
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 logmsg()
26 [ "${cfg_suppress_git_ssh_logging:-0}" = "0" ] || return 0
27 _msg="$(LC_ALL=C tr -c '\040-\176' '[?*]' <<EOT
29 EOT
30 )" && _msg="${_msg%[?]}" &&
31 logger -t "${0##*/}[$$]" <<EOT
32 $_msg
33 EOT
36 errormsg()
38 _l="$*"
39 printf '%04xERR %s' $(( 8 + ${#_l} )) "$_l"
42 invalbaderr()
44 errormsg "invalid or incomplete request"
47 invalerr()
49 errormsg "invalid or unsupported request"
52 denied()
54 errormsg "access denied or no such repository"
57 internalerr()
59 printf '%s\n' "git-daemon-verify: $*" >&2
60 errormsg "internal server error"
63 # A quick sanity check
64 if [ -z "$cfg_git_daemon_bin" ] || ! [ -x "$cfg_git_daemon_bin" ]; then
65 internalerr "bad cfg_git_daemon_bin: $cfg_git_daemon_bin"
66 exit 1
68 case "$cfg_reporoot" in /?*) :;; *)
69 internalerr "bad reporoot: $cfg_reporoot"
70 exit 1
71 esac
73 PATH="$(dirname "$cfg_git_daemon_bin"):$PATH"
74 export PATH
76 if ! request="$("$cfg_basedir/bin/peek_packet")"; then
77 invalbaderr
78 exit 1
81 # The request should look like one of the following
83 # git-upload-pack /dir
84 # git-upload-pack ~name/dir
85 # git-upload-archive /dir
86 # git-upload-archive ~name/dir
87 # git-receive-pack /dir
88 # git-receive-pack ~name/dir
90 # Where the '~' forms are relative to a user's home directory.
91 # A trailing '/' is optional as well as a final '.git'.
92 # git-receive-pack and paths starting with '~' are rejected outright.
94 type=
95 dir=
96 case "$request" in
97 "git-upload-pack "*) type='upload-pack'; dir="${request#git-upload-pack }";;
98 "git-upload-archive "*) type='upload-archive'; dir="${request#git-upload-archive }";;
99 "git-receive-pack "*) type='receive-pack'; dir="${request#git-receive-pack }";;
101 invalerr
102 exit 1
103 esac
104 if [ "$type" = 'receive-pack' ]; then
105 logmsg "denied $type $dir"
106 invalerr
107 exit 1
109 case "$dir" in /*) :;; *)
110 logmsg "denied $type $dir"
111 invalerr
112 exit 1
113 esac
115 # remove extraneous '/' chars
116 proj="${dir#/}"
117 proj="${proj%/}"
118 # add a missing .git
119 case "$proj" in
120 *.git) :;;
122 proj="$proj.git"
123 esac
125 # Reject any project names that start with _ or contain ..
126 case "$proj" in _*|*..*)
127 logmsg "denied $type $dir"
128 denied
129 exit 1
130 esac
132 odir="$dir"
133 reporoot="$cfg_reporoot"
134 dir="$reporoot/$proj"
136 # Valid project names never end in .git (we add that automagically), so a valid
137 # fork can never have .git at the end of any path component except the last.
138 # We check this to avoid a situation where a certain collection of pushed refs
139 # could be mistaken for a GIT_DIR. Git would ultimately complain, but some
140 # undesirable things could happen along the way.
142 # Remove the leading $reporoot and trailing .git to get a test string
143 testpath="${dir#$reporoot/}"
144 testpath="${testpath%.git}"
145 case "$testpath/" in *.[Gg][Ii][Tt]/*|_*)
146 logmsg "denied $type $odir"
147 denied
148 exit 1
149 esac
151 if ! [ -d "$dir" ] || ! [ -f "$dir/HEAD" ] || ! [ -d "$dir/objects" ]; then
152 logmsg "denied $type $odir"
153 denied
154 exit 1
157 [ -z "$var_upload_window" ] || [ "$type" != "upload-pack" ] ||
158 git_add_config "pack.window=$var_upload_window"
160 if [ "${cfg_fetch_stash_refs:-0}" = "0" ]; then
161 git_add_config "uploadpack.hiderefs=refs/stash"
162 git_add_config "uploadpack.hiderefs=refs/tgstash"
165 logmsg "accepted $type $odir"
166 exec "$cfg_git_daemon_bin" --inetd --verbose --export-all --enable=upload-archive --base-path="$cfg_reporoot"
167 internalerr "exec failed: $cfg_git_daemon_bin"
168 exit 1