aboutsummaryrefslogtreecommitdiff
path: root/applets/busybox.mksuid
blob: 6492c079a325abc67242c11a8fe144742faba286 (plain)
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
#!/bin/sh
# Make list of configuration variables regarding suid handling

# input $1: full path to autoconf.h
# input $2: full path to applets.h
# input $3: full path to .config
# output (stdout): list of CONFIG_ that do or may require suid

# If the environment variable SUID is not set or set to DROP,
# lists all config options that do not require suid permissions.
# Otherwise, lists all config options for applets that DO or MAY require
# suid permissions.

# Maintainer: Bernhard Reutner-Fischer

export LC_ALL=POSIX
export LC_CTYPE=POSIX

CONFIG_H=${1:-include/autoconf.h}
APPLETS_H=${2:-include/applets.h}
DOT_CONFIG=${3:-.config}

case ${SUID:-DROP} in
[dD][rR][oO][pP]) USE="DROP" ;;
*) USE="suid" ;;
esac

$HOSTCC -E -DMAKE_SUID -include $CONFIG_H $APPLETS_H |
  awk -v USE=${USE} '
    /^SUID[ \t]/{
      if (USE == "DROP") {
        if ($2 != "BB_SUID_DROP") next
      } else {
        if ($2 == "BB_SUID_DROP") next
      }
      cfg = $NF
      gsub("\"", "", cfg)
      cfg = substr(cfg, 8)
      s[i++] = "CONFIG_" cfg
      s[i++] = "CONFIG_FEATURE_" cfg "_.*"
    }
    END{
      while (getline < ARGV[2]) {
        for (j in s) {
          if ($0 ~ "^" s[j] "=y$") {
            sub(/=.*/, "")
            print
            if (s[j] !~ /\*$/) delete s[j] # can drop this applet now
          }
        }
      }
    }
' - $DOT_CONFIG