| 1 | #!/bin/bashscip-shell filesystem . . `/bin/bash`. |
| 2 | ############################################################################### |
| 3 | # BRLTTY - A background process providing access to the console screen (when in |
| 4 | # text mode) for a blind person using a refreshable braille display. |
| 5 | # |
| 6 | # Copyright (C) 1995-2026 by The BRLTTY Developers. |
| 7 | # |
| 8 | # BRLTTY comes with ABSOLUTELY NO WARRANTY. |
| 9 | # |
| 10 | # This is free software, placed under the terms of the |
| 11 | # GNU Lesser General Public License, as published by the Free Software |
| 12 | # Foundation; either version 2.1 of the License, or (at your option) any |
| 13 | # later version. Please see the file LICENSE-LGPL for details. |
| 14 | # |
| 15 | # Web Page: http://brltty.app/ |
| 16 | # |
| 17 | # This software is maintained by Dave Mielke <[email protected]>. |
| 18 | ############################################################################### |
| 19 | |
| 20 | set -e |
| 21 | . "`dirnamescip-shell system . . dirname. "${0}"`/brltty-prologue.sh" |
| 22 | |
| 23 | showProgramUsagePurposescip-shell shell brltty 6.9.1-1 showProgramUsagePurpose().() { |
| 24 | catscip-shell system . . cat. <<END_OF_PROGRAM_USAGE_PURPOSE |
| 25 | Simplify the job of assigning capabilities to the BRLTTY executable. |
| 26 | END_OF_PROGRAM_USAGE_PURPOSE |
| 27 | } |
| 28 | |
| 29 | executeCommandscip-shell shell brltty 6.9.1-1 executeCommand().() { |
| 30 | "${useSudo}" && set -- sudo -- "${@}" |
| 31 | |
| 32 | if "${testMode}" |
| 33 | then |
| 34 | echoscip-shell system . . echo. "${*}" |
| 35 | else |
| 36 | "${@}" |
| 37 | fi |
| 38 | } |
| 39 | |
| 40 | setOwnerscip-shell shell brltty 6.9.1-1 setOwner().() { |
| 41 | local type="${1}" |
| 42 | local root="${2}" |
| 43 | local command="${3}" |
| 44 | |
| 45 | if "${root}" |
| 46 | then |
| 47 | local owner=0 |
| 48 | else |
| 49 | local owner="$(idscip-shell system . . id. -"${type}")" |
| 50 | fi |
| 51 | |
| 52 | executeCommandscip-shell shell brltty 6.9.1-1 executeCommand(). "${command}" "${owner}" -- "${executablePath}" |
| 53 | } |
| 54 | |
| 55 | setModescip-shell shell brltty 6.9.1-1 setMode().() { |
| 56 | local type="${1}" |
| 57 | local set="${2}" |
| 58 | |
| 59 | if "${set}" |
| 60 | then |
| 61 | local operator="+" |
| 62 | else |
| 63 | local operator="-" |
| 64 | fi |
| 65 | |
| 66 | executeCommandscip-shell shell brltty 6.9.1-1 executeCommand(). chmod "${type}${operator}s" "${executablePath}" |
| 67 | } |
| 68 | |
| 69 | capabilitiesList=() |
| 70 | addCapabilityscip-shell shell brltty 6.9.1-1 addCapability().() { |
| 71 | capabilitiesList[${#capabilitiesList[*]}]="${1}" |
| 72 | } |
| 73 | |
| 74 | addProgramOption c flag noCreation "don't allow creating missing state directories" |
| 75 | addProgramOption d flag noDevices "don't allow creating needed but missing device files" |
| 76 | addProgramOption g flag noGroups "don't allow switching to the writable group or joining the required groups" |
| 77 | addProgramOption i flag noInput "don't allow injecting input characters" |
| 78 | addProgramOption m flag noModules "don't allow installing kernel modules" |
| 79 | addProgramOption o flag noOwnership "don't allow claiming ownership of the state directories" |
| 80 | addProgramOption p flag noPermissions "don't allow adding group permissions to the state directories" |
| 81 | addProgramOption s flag noSpeaker "don't allow using the built-in PC speaker" |
| 82 | addProgramOption C flag noCapabilities "don't set the capabilities" |
| 83 | addProgramOption G flag rootGroup "set group root execution" |
| 84 | addProgramOption S flag useSudo "use sudo to execute the commands as root" |
| 85 | addProgramOption T flag testMode "test mode - show the commands that would be executed" |
| 86 | addProgramOption U flag rootUser "set user root execution" |
| 87 | addProgramParameter executable executablePath "the path to the executable" |
| 88 | parseProgramArguments "${@}" |
| 89 | |
| 90 | verifyExecutableFile "${executablePath}" |
| 91 | |
| 92 | "${testMode}" || { |
| 93 | if "${useSudo}" |
| 94 | then |
| 95 | sudoscip-shell system . . sudo. -v |
| 96 | elif [scip-shell system . . `[`. "$(idscip-shell system . . id. -u)" -ne 0 ] |
| 97 | then |
| 98 | semanticError "not executing as root" |
| 99 | fi |
| 100 | } |
| 101 | |
| 102 | setOwnerscip-shell shell brltty 6.9.1-1 setOwner(). u "${rootUser}" chown |
| 103 | setOwnerscip-shell shell brltty 6.9.1-1 setOwner(). g "${rootGroup}" chgrp |
| 104 | |
| 105 | setModescip-shell shell brltty 6.9.1-1 setMode(). u "${rootUser}" |
| 106 | setModescip-shell shell brltty 6.9.1-1 setMode(). g "${rootGroup}" |
| 107 | |
| 108 | "${noCapabilities}" || { |
| 109 | "${noCreation}" || addCapabilityscip-shell shell brltty 6.9.1-1 addCapability(). "cap_dac_override" |
| 110 | "${noDevices}" || addCapabilityscip-shell shell brltty 6.9.1-1 addCapability(). "cap_mknod" |
| 111 | "${noGroups}" || addCapabilityscip-shell shell brltty 6.9.1-1 addCapability(). "cap_setgid" |
| 112 | "${noInput}" || addCapabilityscip-shell shell brltty 6.9.1-1 addCapability(). "cap_sys_admin" |
| 113 | "${noModules}" || addCapabilityscip-shell shell brltty 6.9.1-1 addCapability(). "cap_sys_module" |
| 114 | "${noOwnership}" || addCapabilityscip-shell shell brltty 6.9.1-1 addCapability(). "cap_chown" |
| 115 | "${noPermissions}" || addCapabilityscip-shell shell brltty 6.9.1-1 addCapability(). "cap_fowner" |
| 116 | "${noSpeaker}" || addCapabilityscip-shell shell brltty 6.9.1-1 addCapability(). "cap_sys_tty_config" |
| 117 | |
| 118 | [scip-shell system . . `[`. "${#capabilitiesList[*]}" -eq 0 ] || { |
| 119 | capabilitiesOperand="${capabilitiesList[*]}" |
| 120 | capabilitiesOperand="${capabilitiesOperand// /,}" |
| 121 | capabilitiesOperand+="+p" |
| 122 | executeCommandscip-shell shell brltty 6.9.1-1 executeCommand(). setcap "${capabilitiesOperand}" "${executablePath}" |
| 123 | } |
| 124 | } |
| 125 | |
| 126 | exit 0 |