blob: 16299c40014162df0fb21d3dea650e93dd975009 [file] [log] [blame]
Jon Salz3d1d5072013-12-20 07:29:26 +08001#!/bin/bash
2
3# Copyright (c) 2014 The Chromium OS Authors. All rights reserved.
4# Use of this source code is governed by a BSD-style license that can be
5# found in the LICENSE file.
6
7# Opens "less" securely as the "nobody" user. Only piping from stdin
8# is supported (there may be no command line arguments).
9
Mike Frysinger20b62342016-09-13 14:17:38 -040010set -e
Jon Salz3d1d5072013-12-20 07:29:26 +080011
12if [ $# -ne 0 ]; then
13 echo "Usage: secure_less.sh" >& 2
14 echo "(no command-line arguments are allowed)" >& 2
15 exit 1
16fi
17
18# Disable EDITOR and SHELL, just in case. Always use busybox less,
19# since it has no fancy features that could enable exploits.
Mike Frysingera7ff8922016-09-12 01:49:12 -040020
21# We can switch back to only su if either of these bugs get fixed:
22# https://bugs.debian.org/663200
23# https://bugs.busybox.net/9231
24if sudo -h >/dev/null 2>&1; then
25 set -x
26 exec sudo -u nobody -s /bin/sh \
27 -c "EDITOR=/bin/false SHELL=/bin/false busybox less"
28else
29 set -x
30 exec su -s /bin/sh \
31 -c "EDITOR=/bin/false SHELL=/bin/false busybox less" - nobody
32fi