From f3137585c1fd37d8913db99975e536cad4d1ae70 Mon Sep 17 00:00:00 2001 From: Kelvin Sherlock Date: Wed, 30 Sep 2020 19:19:03 -0400 Subject: [PATCH] silly tweaks for the auth commands. When stepping in the debugger, it works fine. When running normally, the second command has a tendency not to run. adding a file pointer AND reading from it seems to allow the second command to run more consistently. --- Ample/PreferencesWindowController.m | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/Ample/PreferencesWindowController.m b/Ample/PreferencesWindowController.m index 9027ad4..f8e12ee 100644 --- a/Ample/PreferencesWindowController.m +++ b/Ample/PreferencesWindowController.m @@ -144,12 +144,23 @@ kAuthorizationEmptyEnvironment, myFlags, NULL); if (!myStatus) { + FILE *fp = NULL; + static char buffer[4096]; const char *cp = [path fileSystemRepresentation]; const char* args_chown[] = {"root", cp , NULL}; const char* args_chmod[] = {"+s", cp, NULL}; - myStatus = AuthorizationExecuteWithPrivileges(myAuthorizationRef, "/usr/sbin/chown", kAuthorizationFlagDefaults, (char**)args_chown, NULL); - myStatus = AuthorizationExecuteWithPrivileges(myAuthorizationRef, "/bin/chmod", kAuthorizationFlagDefaults, (char**)args_chmod, NULL); + // well ... the second command executes a lot more consistently when the (optional) fp is provided and the we fgets the buffer. + myStatus = AuthorizationExecuteWithPrivileges(myAuthorizationRef, "/usr/sbin/chown", kAuthorizationFlagDefaults, (char**)args_chown, &fp); + fgets(buffer, sizeof(buffer), fp); + fclose(fp); +// fprintf(stderr, "myStatus = %d\ndata: %s\n", myStatus, buffer); + + myStatus = AuthorizationExecuteWithPrivileges(myAuthorizationRef, "/bin/chmod", kAuthorizationFlagDefaults, (char**)args_chmod, &fp); + fgets(buffer, sizeof(buffer), fp); + fclose(fp); +// fprintf(stderr, "myStatus = %d\ndata: %s\n", myStatus, buffer); + } AuthorizationFree(myAuthorizationRef, kAuthorizationFlagDestroyRights);