Skip to content

Commit

Permalink
attempt to improve error reporting on root_child spawn
Browse files Browse the repository at this point in the history
This commit attempts to improve the GUI's error reporting when it fails to spawn a root_child process.

We're attempting to throw exceptions inside the buskill class, and attempting to catch them in the GUI scripts that call those functions.

 * #77 (comment)
  • Loading branch information
maltfield committed Jul 24, 2024
1 parent 693f4e0 commit a7a0aba
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 5 deletions.
24 changes: 21 additions & 3 deletions src/buskill_gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -1083,7 +1083,7 @@ def refresh_values(self):
# user expects it to trigger)
def rearm_if_required(self):

# this changes to true if we have to disarm & arm BusKill again i norder to
# this changes to true if we have to disarm & arm BusKill again in order to
# apply the settings that the user changed
rearm_required = False

Expand All @@ -1093,8 +1093,26 @@ def rearm_if_required(self):

# was the trigger just changed by the user?
if old_trigger != new_trigger:
# the trigger was changed; update the runtime bk instance
self.bk.set_trigger( new_trigger )
try:
# the trigger was changed; update the runtime bk instance
self.bk.set_trigger( new_trigger )
except Exception as e:

# TODO: add logic to determine if set_trigger() failed (eg if we were
# unable to launch a root_child process) and: raise GUI error message
# && reset back to the previous trigger
msg = "e:|" +str(e)+ "|"
print( msg )
self.dialog = DialogConfirmation(
title = '[font=mdicons][size=30]\ue002[/size][/font] Error',
body = msg,
button='',
continue_function = None
)
self.dialog.b_cancel.text = "OK"
self.dialog.open()

return False

# is BusKill currently armed?
if self.bk.is_armed == True:
Expand Down
11 changes: 9 additions & 2 deletions src/packages/buskill/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -628,7 +628,7 @@ def spawn_root_child(self):
msg = "DEBUG: No root_child detected. Attempting to spawn one."
print( msg ); logger.debug( msg )

msg = "INFO: You have requested BusKill to do something that requires elevated privliges on your platform. If you'd like to proceed, please authorize BusKill to preform actions as Administrator. Your system may prompt you for your password to proceed."
msg = "INFO: You have requested BusKill to do something that requires elevated privileges on your platform. If you'd like to proceed, please authorize BusKill to preform actions as Administrator. Your system may prompt you for your password to proceed."
print( msg ); logger.info( msg )

# To spawn a child process as root in MacOS, we use
Expand Down Expand Up @@ -686,9 +686,10 @@ def spawn_root_child(self):
if mode != '0500':
msg = 'ERROR: Permissions on root_child are not 0500. Refusing to spawn script as root!'
print( msg ); logger.error( msg )
raise PermissionError( msg )
return False

# unfortunaetly we can't package a .dmg with a file owned by root, so on
# unfortunately we can't package a .dmg with a file owned by root, so on
# first run, we expect that the root child script will be owned by the
# user that executed the BusKill app
# https://github.com/BusKill/buskill-app/issues/14#issuecomment-1279975783
Expand All @@ -697,18 +698,21 @@ def spawn_root_child(self):
if owner != 0 and owner != os.getuid():
msg = 'ERROR: root_child is not owned by root nor your user. Refusing to spawn script as root!'
print( msg ); logger.error( msg )
raise PermissionError( msg )
return False

# verify the file is owned by group = root (or current group)
if group != 0 and group != 80 and group != os.getgid():
msg = 'ERROR: root_child is not owned by gid=0, admin, nor your group. Refusing to spawn script as root!'
print( msg ); logger.error( msg )
raise PermissionError( msg )
return False

# verify the "file" isn't actually a symlink
if os.path.islink( root_child_path ):
msg = 'ERROR: root_child is a link. Refusing to spawn script as root!'
print( msg ); logger.error( msg )
raise OSError( msg )
return False

# import some C libraries for interacting via ctypes with the MacOS API
Expand Down Expand Up @@ -750,18 +754,21 @@ def spawn_root_child(self):
# https://developer.apple.com/documentation/security/1540004-authorization_services_result_co/errauthorizationinteractionnotallowed
msg = 'ERROR: root_child spwan attempt returned errAuthorizationInteractionNotAllowed = -60007. Did you execute BusKill from a headless CLI? The credential challenge requires a GUI when launching a child process as root.'
print( msg ); logger.error( msg )
raise OSError( msg )
return False

elif err == -60031:
# https://developer.apple.com/documentation/security/1540004-authorization_services_result_co/errauthorizationtoolexecutefailure
msg = 'ERROR: root_child spwan attempt returned errAuthorizationToolExecuteFailure = -60031. Is the root child binary executable? Check permissions.'
print( msg ); logger.error( msg )
raise OSError( msg )
return False

elif err != 0:
# catch all other errors
msg = 'ERROR: root_child spawn attempt returned ' +str(err)+ '. Please see reference documentation for Apple Authorization Services Result Codes @ https://developer.apple.com/documentation/security/1540004-authorization_services_result_co'
print( msg ); logger.error( msg )
raise OSError( msg )
return False

msg = "DEBUG: Root child spawned successfully!"
Expand Down

0 comments on commit a7a0aba

Please sign in to comment.