Skip to content

Commit 684ec7c

Browse files
authored
Merge pull request #1 from kenchan0130/dev
Release 0.2.0
2 parents 7a483eb + 809e23d commit 684ec7c

File tree

3 files changed

+53
-29
lines changed

3 files changed

+53
-29
lines changed

CHANGELOG.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Changelog
22

3-
## v0.1.0 (2020-12-03)
3+
## 0.3.0 - devlopment
4+
5+
## 0.2.0 - 2020-12-03
6+
7+
- Supported to receive multiple TCC service names
8+
9+
## 0.1.0 - 2020-12-03
410

511
- Initial Commit

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,12 @@ sqlite3 -header "$HOME/Library/Application Support/com.apple.TCC/TCC.db" "SELECT
6363
You can specify one of the following list
6464
It is case-insensitive.
6565

66+
If you want to specify more than one, you can use comma-separated values like:
67+
68+
```sh
69+
./TCC-Permitter.sh "us.zoom.xos" "Camera,Microphone,ScreenCapture"
70+
```
71+
6672
* Accessibility
6773
* AddressBook
6874
* All

TCC-Permitter.sh

Lines changed: 40 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
# Arguments:
55
# $1: Bundle ID or Binary path
66
# $2: TCC service name, case sensitive
7+
# Multiple can be specified separated by commas
78
# - Accessibility
89
# - AddressBook
910
# - All
@@ -46,7 +47,7 @@
4647
# - Willow
4748
#######################################
4849

49-
VERSION='0.1.0'
50+
VERSION='0.2.0'
5051
export PATH=/usr/bin:/bin:/usr/sbin:/sbin
5152

5253
# MARK: Functions
@@ -59,7 +60,8 @@ export PATH=/usr/bin:/bin:/usr/sbin:/sbin
5960
# $@: Script to run
6061
#######################################
6162
run_as_user() {
62-
local uid=$(id -u "${CURRENT_USER}")
63+
local uid
64+
uid=$(id -u "${CURRENT_USER}")
6365
launchctl asuser "${uid}" sudo -u "${CURRENT_USER}" "$@"
6466
}
6567

@@ -71,7 +73,8 @@ run_as_user() {
7173
# Writes a argument with timestamp to stdout
7274
#######################################
7375
print_info_log(){
74-
local timestamp=$(date +%F\ %T)
76+
local timestamp
77+
timestamp=$(date +%F\ %T)
7578

7679
echo "$timestamp [INFO] $1"
7780
}
@@ -84,11 +87,16 @@ print_info_log(){
8487
# Writes a argument with timestamp to stdout
8588
#######################################
8689
print_error_log(){
87-
local timestamp=$(date +%F\ %T)
90+
local timestamp
91+
timestamp=$(date +%F\ %T)
8892

8993
echo "$timestamp [ERROR] $1"
9094
}
9195

96+
get_ttc_services(){
97+
strings /System/Library/PrivateFrameworks/TCC.framework/TCC | grep kTCCService | grep -v '%'
98+
}
99+
92100
# MARK: Main script
93101

94102
autoload is-at-least
@@ -99,35 +107,36 @@ if ! is-at-least 10.14 "$(sw_vers -productVersion)";then
99107
exit 98
100108
fi
101109

102-
if [[ "${1}" == "/" ]];then
110+
if [[ "${1}" = "/" ]];then
103111
# Jamf uses sends '/' as the first argument
104112
print_info_log "Shifting arguments for Jamf."
105113
shift 3
106114
fi
107115

108-
if [[ "${1:l}" == "version" ]];then
116+
if [[ "${1:l}" = "version" ]];then
109117
echo "${VERSION}"
110118
exit 0
111119
fi
112120

113-
BUNDLE_ID_OR_BINARY_PATH="${1}"
114-
115-
if [[ ! "${BUNDLE_ID_OR_BINARY_PATH}" ]];then
121+
if [[ ! "${1}" ]];then
116122
print_error_log "You need to set Bundle ID or Binary path as first argument."
117123
exit 1
118124
fi
125+
BUNDLE_ID_OR_BINARY_PATH="${1}"
119126

120-
TCC_SERVICE_NAME="${2}"
121-
122-
if [[ ! "${TCC_SERVICE_NAME}" ]];then
127+
if [[ ! "${2}" ]];then
123128
print_error_log "You need to set service name as second argument."
124129
exit 1
125130
fi
131+
TCC_SERVICE_NAME_LIST=($(echo "${2}" | tr ',' ' '))
126132

127-
if [[ ! "$(strings /System/Library/PrivateFrameworks/TCC.framework/TCC | grep kTCCService | grep -v '%' | sed -e 's/kTCCService//' | sort | grep -E "^${TCC_SERVICE_NAME}$")" ]];then
128-
print_error_log "${TCC_SERVICE_NAME} is invalid name as TCC Service."
129-
exit 1
130-
fi
133+
for TCC_SERVICE_NAME in "${TCC_SERVICE_NAME_LIST[@]}";do
134+
echo $TCC_SERVICE_NAME
135+
if ! get_ttc_services | sed -e 's/kTCCService//' | sort | grep -qE "^${TCC_SERVICE_NAME}$";then
136+
print_error_log "${TCC_SERVICE_NAME} is invalid name as TCC Service."
137+
exit 1
138+
fi
139+
done
131140

132141
print_info_log "Start TCC-Permitter..."
133142

@@ -139,21 +148,24 @@ if [[ ! -e "${TCC_DB_PATH}" ]];then
139148
exit 1
140149
fi
141150

142-
TCC_NOT_ALLOWED_ACCESS_PRESENT=$(run_as_user sqlite3 "${TCC_DB_PATH}" "SELECT service FROM access WHERE allowed = '0' AND client = '${BUNDLE_ID_OR_BINARY_PATH}' AND service = 'kTCCService${TCC_SERVICE_NAME}'")
151+
for TCC_SERVICE_NAME in "${TCC_SERVICE_NAME_LIST[@]}";do
152+
print_info_log "Granting ${TCC_SERVICE_NAME}..."
143153

144-
if [[ ! "${TCC_NOT_ALLOWED_ACCESS_PRESENT}" ]];then
145-
TCC_ALLOWED_ACCESS_PRESENT=$(run_as_user sqlite3 "${TCC_DB_PATH}" "SELECT service FROM access WHERE allowed = '1' AND client = '${BUNDLE_ID_OR_BINARY_PATH}' AND service = 'kTCCService${TCC_SERVICE_NAME}'")
154+
TCC_NOT_ALLOWED_ACCESS_PRESENT=$(run_as_user sqlite3 "${TCC_DB_PATH}" "SELECT service FROM access WHERE allowed = '0' AND client = '${BUNDLE_ID_OR_BINARY_PATH}' AND service = 'kTCCService${TCC_SERVICE_NAME}'")
146155

147-
if [[ "${TCC_ALLOWED_ACCESS_PRESENT}" ]];then
148-
print_info_log "${TCC_SERVICE_NAME} of ${BUNDLE_ID_OR_BINARY_PATH} is already allowed."
149-
else
150-
print_info_log "There does not seem to be a single prompt for TCC access rights yet."
151-
fi
152-
exit 0
153-
fi
156+
if [[ ! "${TCC_NOT_ALLOWED_ACCESS_PRESENT}" ]];then
157+
TCC_ALLOWED_ACCESS_PRESENT=$(run_as_user sqlite3 "${TCC_DB_PATH}" "SELECT service FROM access WHERE allowed = '1' AND client = '${BUNDLE_ID_OR_BINARY_PATH}' AND service = 'kTCCService${TCC_SERVICE_NAME}'")
154158

155-
run_as_user sqlite3 "${TCC_DB_PATH}" "UPDATE access SET allowed = '1', last_modified = '$(date +%s)' WHERE allowed = '0' AND client = '${BUNDLE_ID_OR_BINARY_PATH}' AND service = 'kTCCService${TCC_SERVICE_NAME}'"
159+
if [[ "${TCC_ALLOWED_ACCESS_PRESENT}" ]];then
160+
print_info_log "${TCC_SERVICE_NAME} of ${BUNDLE_ID_OR_BINARY_PATH} is already allowed."
161+
else
162+
print_info_log "There does not seem to be a single prompt for TCC access rights yet."
163+
fi
164+
else
165+
run_as_user sqlite3 "${TCC_DB_PATH}" "UPDATE access SET allowed = '1', last_modified = '$(date +%s)' WHERE allowed = '0' AND client = '${BUNDLE_ID_OR_BINARY_PATH}' AND service = 'kTCCService${TCC_SERVICE_NAME}'"
156166

157-
print_info_log "Successfully allowed for ${TCC_SERVICE_NAME} TCC service of ${BUNDLE_ID_OR_BINARY_PATH}."
167+
print_info_log "Successfully allowed for ${TCC_SERVICE_NAME} TCC service of ${BUNDLE_ID_OR_BINARY_PATH}."
168+
fi
169+
done
158170

159171
exit 0

0 commit comments

Comments
 (0)