This file is indexed.

/usr/sbin/vztmpl-dl is in vzctl 4.9.4-5.

This file is owned by root:root, with mode 0o755.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
#!/bin/sh
#  Copyright (C) 2011-2013, Parallels, Inc. All rights reserved.
#
#  This program is free software; you can redistribute it and/or modify
#  it under the terms of the GNU General Public License as published by
#  the Free Software Foundation; either version 2 of the License, or
#  (at your option) any later version.
#
#  This program is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#  GNU General Public License for more details.
#
#  You should have received a copy of the GNU General Public License
#  along with this program; if not, write to the Free Software
#  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
#
#
# Download a precreated container tarball (a template cache).
# Usage: please see usage() below.
# There are some built-in defaults in this script, those can be changed
# by editing /etc/vz/download.conf
#
# Exit codes:
#  0 -- template downloaded successfully
#  1 -- download error
#  2 -- local template file already present, not updating
#  3 -- error in usage (no argument provided)
#  4 -- wget binary not found
#  5 -- GPG signature check failed
#
# If you want this script to do automatic GPG signature checking, you need
# to have gpg binary installed, and OpenVZ public key to be in your keyring.
# The latter can be achieved by running the following command as root:
#   gpg --search-keys security@openvz.org
# For more details, see gpg(1) man page and the following link:
#   http://wiki.openvz.org/Package_signatures#Importing_the_public_key


# Wget is required for this script to function
wget -V >/dev/null || exit 4

. /usr/lib/vzctl/vzctl/scripts/vps-functions
. /etc/vz/vz.conf
test -r /etc/vz/download.conf && . /etc/vz/download.conf

# Prefix to template cache repository URL
: ${TMPL_REPO_PREFIX="http://download.openvz.org/template/precreated"}
# What directories to use
: ${TEMPLATE_REPOS="${TMPL_REPO_PREFIX}"}
# Uncomment this to enable 'beta' (new) templates
#TEMPLATE_REPOS="${TEMPLATE_REPOS} ${TMPL_REPO_PREFIX}/beta/"
# Uncomment this to enable 'unsupported' (old) templates
#TEMPLATE_REPOS="${TEMPLATE_REPOS} ${TMPL_REPO_PREFIX}/unsupported"

: ${TMPL_SUFFIXES="tar.gz"}
: ${GPG_KEY="security@openvz.org"}
: ${CHECK_TEMPLATE_SIG="no"}
: ${UPDATE_TEMPLATE="yes"}
: ${IGNORE_ERRORS="no"}
: ${QUIET="no"}
unset UPDATE_LIST
unset WGET_QUIET

vzcheckvar TEMPLATE
TCACHEDIR=$TEMPLATE/cache
SELF=$(basename $0)

usage()
{
	cat << =EOF= 1>&2
Usage:
  $SELF [option ...] <template> [<template> ...]
  $SELF [option ...] --update-all
  $SELF --list-remove | --list-local | --list-all | --list-orphans
  $SELF --config | --help
Options:
  --gpg-check		Check GPG signatures of downloaded files
  --no-gpg-check	Do not check GPG signatures
  --ignore-errors	Don't abort if a template can't be downloaded
  --update		Update templates even if they exist locally
  --no-update		Do not try to update existing templates
  --quiet		Be less talkative (shut up wget)
  --no-quiet		Be more talkative
  --update-all		Try to update all locally available templates
  --list-remote		Output list of templates available for download
  --list-local		Output list of templates available locally
  --list-all		Output combined list of templates
  --list-orphans	Output list of local templates NOT available remotely
  --config		Output current configuration
  --help		Print this help
Arguments:
  <template>		An OS template name (like centos-6-x86_64)
=EOF=
	exit $1
}

gpg_working()
{
	test "x$CHECK_TEMPLATE_SIG" != "xyes" && return 0

	# Check if gpg is installed
	if ! gpg --version >/dev/null; then
		CHECK_TEMPLATE_SIG=no
		echo "$SELF WARNING: gpg binary not found," \
			"signature check disabled" 1>&2
		return 1
	fi

	# ... and our key is there
	if ! gpg -k "$GPG_KEY" >/dev/null 2>&1; then
		CHECK_TEMPLATE_SIG=no
		cat << =EOF= 1>&2

$SELF WARNING: no public gpg key $GPG_KEY found,
disabling signature check. To import the public key, see
http://wiki.openvz.org/Package_signatures#Importing_the_public_key

=EOF=
		return 2
	fi
}

show_config()
{
	local url

	gpg_working

	cat << =EOF=
Current $SELF configuration is below. Defaults are built-in and can be
overwritten by setting an appropriate variables in /etc/vz/download.conf

* Try to update template files (\$UPDATE_TEMPLATE): $UPDATE_TEMPLATE
* Check template signatures (\$CHECK_TEMPLATE_SIG): $CHECK_TEMPLATE_SIG
* GPG public key name to check (\$GPG_KEY):         $GPG_KEY
* List of template suffixes (\$TMPL_SUFFIXES):      $TMPL_SUFFIXES
* Prefix to template cache repository URL (\$TMPL_REPO_PREFIX):
  $TMPL_REPO_PREFIX
* List of template URLs to try (\$TEMPLATE_REPOS):
=EOF=

	for url in $TEMPLATE_REPOS; do
		echo "  ${url}"
	done
}

# There's no generic way to ask a web server about list of files
# in a directory, so we rely on having a .listing file next to templates.
list_remote()
{
	local url
	local cache=/tmp/$SELF-list

	umask 0770
	# Cache the result for 1 minute
	if test -z "$(find $cache -mmin -1 2>/dev/null)"; then
		for url in $TEMPLATE_REPOS; do
			wget -q -O - $url/.listing
		done > $cache
	fi

	cat $cache
}

list_local()
{
	ls ${TCACHEDIR}/*.tar    ${TCACHEDIR}/*.tar.gz  \
	   ${TCACHEDIR}/*.tar.xz ${TCACHEDIR}/*.tar.bz2	2>/dev/null |
		sed -e "s#^${TCACHEDIR}/##" -e 's#\.tar\.*[gbxz2]*$##'
}

list_orphans()
{
	local LOCAL=$(list_local)
	local REMOTE=$(list_remote)
	local t

	for t in $LOCAL; do
		if ! echo "$REMOTE" | grep -q "^$t$"; then
			echo $t
		fi
	done | sort | uniq
}

# Parse arguments
while echo $1 | grep -q '^-'; do
	case $1 in
	   --gpg-check)
		CHECK_TEMPLATE_SIG=yes
		shift
		;;
	   --no-gpg-check)
		CHECK_TEMPLATE_SIG=no
		shift
		;;
	   --ignore-errors)
		IGNORE_ERRORS=yes
		shift
		;;
	   --update)
		UPDATE_TEMPLATE=yes
		shift
		;;
	   --no-update)
		UPDATE_TEMPLATE=no
		shift
		;;
	   --quiet)
		QUIET=yes
		shift
		;;
	   --no-quiet)
		QUIET=no
		shift
		;;
	   --update-all)
		UPDATE_LIST=$(list_local)
		UPDATE_TEMPLATE=yes
		IGNORE_ERRORS=yes
		shift
		;;
	   --config)
		show_config
		exit 0
		;;
	   --list-all)
		(list_local; list_remote) | sort | uniq
		exit 0
		;;
	   --list-remote)
		list_remote
		exit 0
		;;
	   --list-local)
		list_local
		exit 0
		;;
	   --list-orphans)
		list_orphans
		exit 0
		;;
	   --help)
		usage 0
		;;
	   -*)
		echo "$SELF ERROR: unknown option: $1" 1>&2
		usage 3
		;;
	esac
done

if [ "$QUIET" = "yes" ]; then
	WGET_QUIET="--quiet"
fi

if [ -n "$UPDATE_LIST" ]; then
	if [ $# -gt 1 ]; then
		echo "$SELF ERROR: too many arguments" 1>&2
		usage 3
	fi
else
	if [ $# -lt 1 ]; then
		echo "$SELF ERROR: no arguments" 1>&2
		usage 3
	fi
fi

check_sig()
{
	test "x${CHECK_TEMPLATE_SIG}" = "xyes" || return 0

	local sig=$1.asc
	local file=$2
	local ret

	echo "Checking template signature..."

	wget -q $sig || return 1
	sig=$(basename $sig)

	gpg --verify $sig $file
	ret=$?
	rm -f $sig

	if test "$ret" != "0"; then
		echo "$SELF ERROR: signature check failed!" 1>&2
		return 5
	else
		echo "Signature check passed."
		return 0
	fi
}

do_download()
{
	local src=$1
	local dst=$2
	local ret

	trap "rm -f ${dst}" INT TERM
	wget $WGET_QUIET -P $(dirname ${dst}) -N ${src}
	ret=$?
	trap - INT TERM
	if test $ret -eq 0; then
		check_sig $src $dst
		return
	else
		echo "$SELF ERROR: failed to download ${src}!" 1>&2
		rm -f $dst
		return 1
	fi
}

download()
{
	local prefix suffix src dst
	local tmpl=$1

	for prefix in $TEMPLATE_REPOS; do
		for suffix in $TMPL_SUFFIXES; do
			src=${prefix}/${tmpl}.${suffix}
			dst=$TCACHEDIR/${tmpl}.${suffix}
			# Check for local copy
			if test -f $dst -a "$UPDATE_TEMPLATE" = "no"; then
				echo "$SELF ERROR: file $dst is present," \
					"not updating." 1>&2
				return 2
			fi
			# Check if the file is there
			if wget -q --spider -P $(dirname ${dst}) ${src}; then
				# Download it
				do_download "$src" "$dst"
				return
			fi
		done
	done
	echo "$SELF ERROR: template $tmpl not found!" 1>&2
	return 1
}

gpg_working

FAILED_TMPL=""
for TMPL in ${UPDATE_LIST:-$*}; do
	download $TMPL
	RET=$?
	if [ $RET -ne 0 ]; then
		if [ "$IGNORE_ERRORS" = "yes" ]; then
			FAILED_TMPL="$FAILED_TMPL $TMPL"
		else
			exit $RET
		fi
	fi
done

if [ ! -z "$FAILED_TMPL" ]; then
	echo WARNING: the following templates were not found remotely and can\'t be updated:
	for TMPL in $FAILED_TMPL; do
		echo " " $TMPL 1>&2
	done
fi