File: check-permissions

package info (click to toggle)
mptcpd 0.12-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 1,232 kB
  • sloc: ansic: 9,258; makefile: 465; sh: 89; cpp: 62
file content (35 lines) | stat: -rwxr-xr-x 867 bytes parent folder | download | duplicates (2)
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 --dereference --format=%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