Skip to content

Commit

Permalink
add cleaner exception handling and a consistent error message
Browse files Browse the repository at this point in the history
Signed-off-by: Jacob Salmela <me@jacobsalmela.com>
  • Loading branch information
jacobsalmela committed Oct 3, 2021
1 parent b78365b commit 1a76d8d
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions tccutil.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,8 +236,11 @@ def insert_client(client):
verbose_output("Inserting \"%s\" into Database..." % (client))
# Big Sur and later
if osx_version >= version('10.16'):
c.execute("INSERT or REPLACE INTO access VALUES('%s','%s',%s,2,4,1,NULL,NULL,0,'UNUSED',NULL,0,0)"
% (service, client, client_type))
try:
c.execute("INSERT or REPLACE INTO access VALUES('%s','%s',%s,2,4,1,NULL,NULL,0,'UNUSED',NULL,0,0)"
% (service, client, client_type))
except sqlite3.OperationalError:
print("Attempting to write a readonly database. You probably need to disable SIP.")
# Mojave through Big Sur
elif osx_version >= version('10.14'):
c.execute("INSERT or REPLACE INTO access VALUES('%s','%s',%s,1,1,NULL,NULL,NULL,'UNUSED',NULL,0,0)"
Expand All @@ -257,7 +260,10 @@ def delete_client(client):
"""Remove a client from the database."""
open_database()
verbose_output("Removing \"%s\" from Database..." % (client))
c.execute("DELETE from access where client IS '%s' AND service IS '%s'" % (client, service))
try:
c.execute("DELETE from access where client IS '%s' AND service IS '%s'" % (client, service))
except sqlite3.OperationalError:
print("Attempting to write a readonly database. You probably need to disable SIP.")
commit_changes()


Expand All @@ -269,7 +275,10 @@ def enable(client):
# right away (without closing the window).
# Set to 1 to enable the client.
enable_mode_name = 'auth_value' if osx_version >= version('10.16') else 'allowed'
c.execute("UPDATE access SET %s='1' WHERE client='%s' AND service IS '%s'" % (enable_mode_name, client, service))
try:
c.execute("UPDATE access SET %s='1' WHERE client='%s' AND service IS '%s'" % (enable_mode_name, client, service))
except sqlite3.OperationalError:
print("Attempting to write a readonly database. You probably need to disable SIP.")
commit_changes()


Expand All @@ -281,7 +290,10 @@ def disable(client):
# right away (without closing the window).
# Set to 0 to disable the client.
enable_mode_name = 'auth_value' if osx_version >= version('10.16') else 'allowed'
c.execute("UPDATE access SET %s='0' WHERE client='%s' AND service IS '%s'" % (enable_mode_name, client, service))
try:
c.execute("UPDATE access SET %s='0' WHERE client='%s' AND service IS '%s'" % (enable_mode_name, client, service))
except sqlite3.OperationalError:
print("Attempting to write a readonly database. You probably need to disable SIP.")
commit_changes()


Expand Down

0 comments on commit 1a76d8d

Please sign in to comment.