Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mac: fix Apple Silicon GPU errors after MacOS update #5502

Merged
merged 1 commit into from
Jan 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 40 additions & 26 deletions client/check_security.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,17 @@ int use_sandbox, int isManager, char* path_to_error, int len
struct stat sbuf;
int retval;
int useFakeProjectUserAndGroup = 0;
int isMacInstaller = 0;

useFakeProjectUserAndGroup = ! use_sandbox;
#ifdef _DEBUG
#ifdef DEBUG_WITH_FAKE_PROJECT_USER_AND_GROUP
useFakeProjectUserAndGroup = 1;
#endif
#ifdef _MAC_INSTALLER
isMacInstaller = 1;
#endif

#if (defined(__APPLE__) && ! defined(_MAC_INSTALLER))
// Debugging Mac client or Mac BOINC Manager
// Normally, the Mac Development (Debug) builds do not define SANDBOX, so
Expand Down Expand Up @@ -153,33 +158,37 @@ int use_sandbox, int isManager, char* path_to_error, int len
boinc_master_gid = getegid();
}

#ifdef _MAC_INSTALLER
// Require absolute owner and group boinc_master:boinc_master
strlcpy(boinc_master_user_name, REAL_BOINC_MASTER_NAME, sizeof(boinc_master_user_name));
pw = getpwnam(boinc_master_user_name);
if (pw == NULL)
return -1006; // User boinc_master does not exist
boinc_master_uid = pw->pw_uid;

strlcpy(boinc_master_group_name, REAL_BOINC_MASTER_NAME, sizeof(boinc_master_group_name));
grp = getgrnam(boinc_master_group_name);
if (grp == NULL)
return -1007; // Group boinc_master does not exist
boinc_master_gid = grp->gr_gid;

#else // Use current user and group (see comment above)

pw = getpwuid(boinc_master_uid);
if (pw == NULL)
return -1008; // Should never happen
strlcpy(boinc_master_user_name, pw->pw_name, sizeof(boinc_master_user_name));

grp = getgrgid(boinc_master_gid);
if (grp == NULL)
return -1009;
strlcpy(boinc_master_group_name, grp->gr_name, sizeof(boinc_master_group_name));
if ((!useFakeProjectUserAndGroup) || isMacInstaller) {
// Require absolute owner and group boinc_master:boinc_master
strlcpy(boinc_master_user_name, REAL_BOINC_MASTER_NAME, sizeof(boinc_master_user_name));
pw = getpwnam(boinc_master_user_name);
if (pw == NULL)
return -1006; // User boinc_master does not exist
boinc_master_uid = pw->pw_uid;

#endif
strlcpy(boinc_master_group_name, REAL_BOINC_MASTER_NAME, sizeof(boinc_master_group_name));
grp = getgrnam(boinc_master_group_name);
if (grp == NULL)
return -1007; // Group boinc_master does not exist
boinc_master_gid = grp->gr_gid;

// A MacOS update sometimes changes the PrimaryGroupID of user boinc_master to staff (20).
if (pw->pw_gid != grp->gr_gid) {
return -1301;
}
} else { // Use current user and group (see comment above)

pw = getpwuid(boinc_master_uid);
if (pw == NULL)
return -1008; // Should never happen
strlcpy(boinc_master_user_name, pw->pw_name, sizeof(boinc_master_user_name));

grp = getgrgid(boinc_master_gid);
if (grp == NULL)
return -1009;
strlcpy(boinc_master_group_name, grp->gr_name, sizeof(boinc_master_group_name));

}

if (useFakeProjectUserAndGroup) {
// For easier debugging of project applications
Expand All @@ -199,6 +208,11 @@ int use_sandbox, int isManager, char* path_to_error, int len
if (grp == NULL)
return -1011; // Group boinc_project does not exist
boinc_project_gid = grp->gr_gid;

// A MacOS update sometimes changes the PrimaryGroupID of user boinc_project to staff (20).
if (pw->pw_gid != grp->gr_gid) {
return -1302;
}
}

#if 0 // Manager is no longer setgid
Expand Down
10 changes: 8 additions & 2 deletions clientgui/mac/SetupSecurity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -776,7 +776,7 @@ static OSStatus CreateUserAndGroup(char * user_name, char * group_name) {
sprintf(buf2, "/users/%s", user_name);

if ( userExists && groupExists )
goto setRealName; // User and group already exist
goto setGroupForUser; // User and group already exist

// If only user or only group exists, try to use the same ID for the one we create
if (userExists) { // User exists but group does not
Expand Down Expand Up @@ -865,13 +865,19 @@ static OSStatus CreateUserAndGroup(char * user_name, char * group_name) {
return err;
} // if (! userExists)

setGroupForUser:
// A MacOS update sometimes changes the PrimaryGroupID of users boinc_master
// and boincproject to staff (20).
// This sets the correct PrimaryGroupId whether or not we just created the user.
sprintf(buf2, "/users/%s", user_name);
sprintf(buf3, "%d", groupid);

// Always set the user gid if we created either the user or the group or both
// Something like "dscl . -create /users/boinc_master gid 33"
err = DoSudoPosixSpawn(dsclPath, ".", "-create", buf2, "gid", buf3, NULL);
if (err)
return err;

setRealName:
// Always set the RealName field to an empty string
// Note: create RealName with empty string fails under OS 10.7, but
// creating it with non-empty string and changing to empty string does work.
Expand Down
Loading