File: check-permissions

package info (click to toggle)
mptcpd 0.14-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 3,612 kB
  • sloc: ansic: 9,472; sh: 5,154; makefile: 467; cpp: 61
file content (35 lines) | stat: -rwxr-xr-x 850 bytes parent folder | download
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
#! /bin/sh
# SPDX-License-Identifier: BSD-3-Clause
#
# Copyright (c) 2018, 2019, Intel Corporation

# Mptcpd expects key installation directories and files to only be
# writable by the owner and group.  This script verifies that the
# write mode for "other" is not set.

usage()
{
    echo "Usage: $0 file|directory ... "
    exit 1
}

test -z "$1" && usage

exit_status=0

for p in $@; do
    # Access rights in human readable form (e.g. "drwxrwxr-x")
    perms=`stat -L -c %A $p`

    # The write mode for "others".
    other_write=`echo $perms | sed -e 's/.*\(.\).$/\1/'`

    # Check if the file or directory is writable by "other".
    if test $other_write != "-"; then
       echo "ERROR: incorrect permissions ($perms) for '$p'"
       echo "ERROR: '$p' should only be owner/group writable"
       exit_status=1
    fi
done

exit $exit_status