Skip to content

Commit 67440de

Browse files
authored
Merge pull request #6966 from RedesignedRobot/fix/macos-installer-permissions-tahoe
macOS: fix chflags failure on fresh installs breaking permission setup
2 parents c2fc358 + f023c61 commit 67440de

2 files changed

Lines changed: 41 additions & 27 deletions

File tree

clientgui/mac/SetupSecurity.cpp

Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -986,25 +986,30 @@ static OSStatus CreateUserAndGroup(char * user_name, char * group_name) {
986986

987987
// Hide the home directory and share point https://support.apple.com/en-mn/102099
988988
// Something like "sudo chflags hidden /Users/boinc_master"
989-
args[0] = "/usr/bin/sudo";
990-
args[1] = "chflags";
991-
args[2] = "hidden";
992-
args[3] = buf2;
993-
args[4] = NULL;
994-
err = posix_spawnp(&thePid, "/usr/bin/sudo", NULL, NULL, args, environ);
995-
waitpid(thePid, &status, WUNTRACED);
996-
if (status != 0) {
997-
err = status;
998-
} else {
999-
if (WIFEXITED(status)) {
1000-
err = WEXITSTATUS(status);
1001-
if (err == 1) {
1002-
err = errno;
1003-
}
1004-
} // end if (WIFEXITED(status)) else
1005-
} // end if waitpid returned 0 sstaus else
1006-
if (err)
1007-
return err;
989+
// buf2 was overwritten to DSCL path "/users/<name>" above; rebuild filesystem path.
990+
// Skip if the directory doesn't exist (fresh installs set home to /var/empty).
991+
sprintf(buf2, "/Users/%s", user_name);
992+
if (access(buf2, F_OK) == 0) {
993+
args[0] = "/usr/bin/sudo";
994+
args[1] = "chflags";
995+
args[2] = "hidden";
996+
args[3] = buf2;
997+
args[4] = NULL;
998+
err = posix_spawnp(&thePid, "/usr/bin/sudo", NULL, NULL, args, environ);
999+
waitpid(thePid, &status, WUNTRACED);
1000+
if (status != 0) {
1001+
err = status;
1002+
} else {
1003+
if (WIFEXITED(status)) {
1004+
err = WEXITSTATUS(status);
1005+
if (err == 1) {
1006+
err = errno;
1007+
}
1008+
} // end if (WIFEXITED(status)) else
1009+
} // end if waitpid returned 0 sstaus else
1010+
if (err)
1011+
return err;
1012+
}
10081013

10091014
err = ResynchDSSystem();
10101015
if (err != noErr)

mac_installer/PostInstall.cpp

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -384,27 +384,27 @@ int main(int argc, char *argv[])
384384
for (i=0; i<RETRY_LIMIT; ++i) {
385385
err = CreateBOINCUsersAndGroups();
386386
if (err != noErr) {
387-
printf("CreateBOINCUsersAndGroups returned %d (repetition=%d)", err, i);
387+
printf("CreateBOINCUsersAndGroups returned %d (repetition=%d)\n", err, i);
388388
fflush(stdout);
389-
REPORT_ERROR(i >= RETRY_LIMIT);
389+
REPORT_ERROR(i >= RETRY_LIMIT - 1);
390390
continue;
391391
}
392392

393393
// err = SetBOINCAppOwnersGroupsAndPermissions("/Applications/GridRepublic Desktop.app");
394394
err = SetBOINCAppOwnersGroupsAndPermissions(appPath[brandID]);
395395

396396
if (err != noErr) {
397-
printf("SetBOINCAppOwnersGroupsAndPermissions returned %d (repetition=%d)", err, i);
397+
printf("SetBOINCAppOwnersGroupsAndPermissions returned %d (repetition=%d)\n", err, i);
398398
fflush(stdout);
399-
REPORT_ERROR(i >= RETRY_LIMIT);
399+
REPORT_ERROR(i >= RETRY_LIMIT - 1);
400400
continue;
401401
}
402402

403403
err = SetBOINCDataOwnersGroupsAndPermissions();
404404
if (err != noErr) {
405-
printf("SetBOINCDataOwnersGroupsAndPermissions returned %d (repetition=%d)", err, i);
405+
printf("SetBOINCDataOwnersGroupsAndPermissions returned %d (repetition=%d)\n", err, i);
406406
fflush(stdout);
407-
REPORT_ERROR(i >= RETRY_LIMIT);
407+
REPORT_ERROR(i >= RETRY_LIMIT - 1);
408408
continue;
409409
}
410410

@@ -414,14 +414,23 @@ int main(int argc, char *argv[])
414414
true, false, NULL, 0
415415
);
416416
if (err != noErr) {
417-
printf("check_security returned %d (repetition=%d)", err, i);
417+
printf("check_security returned %d (repetition=%d)\n", err, i);
418418
fflush(stdout);
419-
REPORT_ERROR(i >= RETRY_LIMIT);
419+
REPORT_ERROR(i >= RETRY_LIMIT - 1);
420420
} else {
421421
break;
422422
}
423423
}
424424

425+
// If security setup failed after all retries, report failure to the
426+
// macOS Installer so it does not show "Installation Successful" when
427+
// permissions were never set correctly.
428+
if (err != noErr) {
429+
printf("BOINC security setup failed after %d attempts (last error=%d)\n", RETRY_LIMIT, err);
430+
fflush(stdout);
431+
return err;
432+
}
433+
425434
#else // ! defined(SANDBOX)
426435

427436
Boolean Success = false;

0 commit comments

Comments
 (0)