@@ -175,22 +175,21 @@ def __init__(self, path=None):
175
175
def _check_table_digest (self ):
176
176
# This logic comes from https://github.com/jacobsalmela/tccutil which is
177
177
# Licensed under GPL-2.0
178
- with self .connection as conn :
179
- cursor = conn .execute (
180
- "SELECT sql FROM sqlite_master WHERE name='access' and type='table'"
181
- )
182
- for row in cursor .fetchall ():
183
- digest = hashlib .sha1 (row ["sql" ].encode ()).hexdigest ()[:10 ]
184
- if digest in ("ecc443615f" , "80a4bb6912" ):
185
- # Mojave and Catalina
186
- self .ge_mojave_and_catalina = True
187
- elif digest in ("3d1c2a0e97" , "cef70648de" ):
188
- # BigSur and later
189
- self .ge_bigsur_and_later = True
190
- else :
191
- raise CommandExecutionError (
192
- "TCC Database structure unknown for digest '{}'" .format (digest )
193
- )
178
+ cursor = self .connection .execute (
179
+ "SELECT sql FROM sqlite_master WHERE name='access' and type='table'"
180
+ )
181
+ for row in cursor .fetchall ():
182
+ digest = hashlib .sha1 (row ["sql" ].encode ()).hexdigest ()[:10 ]
183
+ if digest in ("ecc443615f" , "80a4bb6912" ):
184
+ # Mojave and Catalina
185
+ self .ge_mojave_and_catalina = True
186
+ elif digest in ("3d1c2a0e97" , "cef70648de" ):
187
+ # BigSur and later
188
+ self .ge_bigsur_and_later = True
189
+ else :
190
+ raise CommandExecutionError (
191
+ "TCC Database structure unknown for digest '{}'" .format (digest )
192
+ )
194
193
195
194
def _get_client_type (self , app_id ):
196
195
if app_id [0 ] == "/" :
@@ -200,14 +199,13 @@ def _get_client_type(self, app_id):
200
199
return 0
201
200
202
201
def installed (self , app_id ):
203
- with self .connection as conn :
204
- cursor = conn .execute (
205
- "SELECT * from access WHERE client=? and service='kTCCServiceAccessibility'" ,
206
- (app_id ,),
207
- )
208
- for row in cursor .fetchall ():
209
- if row :
210
- return True
202
+ cursor = self .connection .execute (
203
+ "SELECT * from access WHERE client=? and service='kTCCServiceAccessibility'" ,
204
+ (app_id ,),
205
+ )
206
+ for row in cursor .fetchall ():
207
+ if row :
208
+ return True
211
209
return False
212
210
213
211
def install (self , app_id , enable = True ):
@@ -234,9 +232,8 @@ def install(self, app_id, enable=True):
234
232
# indirect_object_identifier
235
233
# ),
236
234
# FOREIGN KEY (policy_id) REFERENCES policies(id) ON DELETE CASCADE ON UPDATE CASCADE);
237
- with self .connection as conn :
238
- conn .execute (
239
- """
235
+ self .connection .execute (
236
+ """
240
237
INSERT or REPLACE INTO access VALUES (
241
238
'kTCCServiceAccessibility',
242
239
?,
@@ -253,8 +250,9 @@ def install(self, app_id, enable=True):
253
250
0
254
251
)
255
252
""" ,
256
- (app_id , client_type , auth_value ),
257
- )
253
+ (app_id , client_type , auth_value ),
254
+ )
255
+ self .connection .commit ()
258
256
elif self .ge_mojave_and_catalina :
259
257
# CREATE TABLE IF NOT EXISTS "access" (
260
258
# service TEXT NOT NULL,
@@ -276,9 +274,8 @@ def install(self, app_id, enable=True):
276
274
# indirect_object_identifier
277
275
# ),
278
276
# FOREIGN KEY (policy_id) REFERENCES policies(id) ON DELETE CASCADE ON UPDATE CASCADE);
279
- with self .connection as conn :
280
- conn .execute (
281
- """
277
+ self .connection .execute (
278
+ """
282
279
INSERT or REPLACE INTO access VALUES(
283
280
'kTCCServiceAccessibility',
284
281
?,
@@ -294,23 +291,23 @@ def install(self, app_id, enable=True):
294
291
0
295
292
)
296
293
""" ,
297
- (app_id , client_type , auth_value ),
298
- )
294
+ (app_id , client_type , auth_value ),
295
+ )
296
+ self .connection .commit ()
299
297
return True
300
298
301
299
def enabled (self , app_id ):
302
300
if self .ge_bigsur_and_later :
303
301
column = "auth_value"
304
302
elif self .ge_mojave_and_catalina :
305
303
column = "allowed"
306
- with self .connection as conn :
307
- cursor = conn .execute (
308
- "SELECT * from access WHERE client=? and service='kTCCServiceAccessibility'" ,
309
- (app_id ,),
310
- )
311
- for row in cursor .fetchall ():
312
- if row [column ]:
313
- return True
304
+ cursor = self .connection .execute (
305
+ "SELECT * from access WHERE client=? and service='kTCCServiceAccessibility'" ,
306
+ (app_id ,),
307
+ )
308
+ for row in cursor .fetchall ():
309
+ if row [column ]:
310
+ return True
314
311
return False
315
312
316
313
def enable (self , app_id ):
@@ -320,13 +317,13 @@ def enable(self, app_id):
320
317
column = "auth_value"
321
318
elif self .ge_mojave_and_catalina :
322
319
column = "allowed"
323
- with self .connection as conn :
324
- conn . execute (
325
- "UPDATE access SET {} = ? WHERE client=? AND service IS 'kTCCServiceAccessibility'" . format (
326
- column
327
- ),
328
- ( 1 , app_id ),
329
- )
320
+ self .connection . execute (
321
+ "UPDATE access SET {} = ? WHERE client=? AND service IS 'kTCCServiceAccessibility'" . format (
322
+ column
323
+ ),
324
+ ( 1 , app_id ),
325
+ )
326
+ self . connection . commit ( )
330
327
return True
331
328
332
329
def disable (self , app_id ):
@@ -336,23 +333,23 @@ def disable(self, app_id):
336
333
column = "auth_value"
337
334
elif self .ge_mojave_and_catalina :
338
335
column = "allowed"
339
- with self .connection as conn :
340
- conn . execute (
341
- "UPDATE access SET {} = ? WHERE client=? AND service IS 'kTCCServiceAccessibility'" . format (
342
- column
343
- ),
344
- ( 0 , app_id ),
345
- )
336
+ self .connection . execute (
337
+ "UPDATE access SET {} = ? WHERE client=? AND service IS 'kTCCServiceAccessibility'" . format (
338
+ column
339
+ ),
340
+ ( 0 , app_id ),
341
+ )
342
+ self . connection . commit ( )
346
343
return True
347
344
348
345
def remove (self , app_id ):
349
346
if not self .installed (app_id ):
350
347
return False
351
- with self .connection as conn :
352
- conn . execute (
353
- "DELETE from access where client IS ? AND service IS 'kTCCServiceAccessibility'" ,
354
- ( app_id ,),
355
- )
348
+ self .connection . execute (
349
+ "DELETE from access where client IS ? AND service IS 'kTCCServiceAccessibility'" ,
350
+ ( app_id ,) ,
351
+ )
352
+ self . connection . commit ( )
356
353
return True
357
354
358
355
def __enter__ (self ):
0 commit comments