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.
This commit is contained in:
Kelvin Sherlock 2020-09-30 19:19:03 -04:00
parent 6e7acb88e2
commit f3137585c1
1 changed files with 13 additions and 2 deletions

View File

@ -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);