From 0aca794e5efdc278fa261cb69178ad7c79d7a441 Mon Sep 17 00:00:00 2001 From: Charlie Fenton Date: Thu, 11 Aug 2011 10:20:25 +0000 Subject: [PATCH] Mac installer: Bug fixes for OS 10.7 Lion, Charity Engine svn path=/trunk/boinc/; revision=23985 --- checkin_notes | 16 ++++ mac_build/boinc.xcodeproj/project.pbxproj | 10 -- mac_installer/AddRemoveUser.cpp | 48 ++++------ mac_installer/PostInstall.cpp | 106 ++++++++++------------ mac_installer/uninstall.cpp | 59 ++++++------ 5 files changed, 109 insertions(+), 130 deletions(-) diff --git a/checkin_notes b/checkin_notes index 55b2c58f9b..3120164d91 100644 --- a/checkin_notes +++ b/checkin_notes @@ -4871,3 +4871,19 @@ David 10 Aug 2011 time_stats.cpp app.cpp current_version.cpp + +Charlie 11 Aug 2011 + - Mac installer: Bug fixes for OS 10.7 Lion: LoginItemAPI.c did not + set hidden properlty for login items, so use AppleScript instead, + to prevent Lion from opening BOINC windows at system startup. + - Fix a bug I introduced on 8 August which prevented launching + WaitPermissions.app. + - Mac uninstaller: Remove Charity Engine BOINC app if present. + + mac_installer/ + AddRemoveUser.cpp + PostInstall.cpp + Uninstall.cpp + mac_build/ + boinc.xcodeproj/ + project.pbxproj diff --git a/mac_build/boinc.xcodeproj/project.pbxproj b/mac_build/boinc.xcodeproj/project.pbxproj index 41aed586f3..c1f836e744 100755 --- a/mac_build/boinc.xcodeproj/project.pbxproj +++ b/mac_build/boinc.xcodeproj/project.pbxproj @@ -42,7 +42,6 @@ DD0A06F50869A2D2007CD86E /* prefs.cpp in Sources */ = {isa = PBXBuildFile; fileRef = DD344BE407C5B1670043025C /* prefs.cpp */; }; DD0A87FF11D950E00067C1F2 /* BOINCInternetFSHandler.cpp in Sources */ = {isa = PBXBuildFile; fileRef = DD0A87FD11D950E00067C1F2 /* BOINCInternetFSHandler.cpp */; }; DD0C5A8B0816711400CEC5D7 /* boinc.jpg in Resources */ = {isa = PBXBuildFile; fileRef = DD0C5A8A0816711400CEC5D7 /* boinc.jpg */; }; - DD1277C2081F3E73007B5DE1 /* LoginItemAPI.c in Sources */ = {isa = PBXBuildFile; fileRef = DD1277BE081F3E73007B5DE1 /* LoginItemAPI.c */; }; DD1277C4081F3E73007B5DE1 /* PostInstall.cpp in Sources */ = {isa = PBXBuildFile; fileRef = DD1277C0081F3E73007B5DE1 /* PostInstall.cpp */; }; DD1277E6081F44C1007B5DE1 /* Carbon.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 20286C33FDCF999611CA2CEA /* Carbon.framework */; }; DD130E740820C422001A0291 /* ScreenSaver.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = DD7C5E7508110AE3002FCE1E /* ScreenSaver.framework */; }; @@ -307,7 +306,6 @@ DDB874480C850D3000E0DE1F /* graphics2.cpp in Sources */ = {isa = PBXBuildFile; fileRef = DDB874460C850D3000E0DE1F /* graphics2.cpp */; }; DDBB7E7611D2BCD400598DC1 /* NoticeListCtrl.cpp in Sources */ = {isa = PBXBuildFile; fileRef = DDBB7E7511D2BCD400598DC1 /* NoticeListCtrl.cpp */; }; DDBC6CA50D5D458700564C49 /* boinc_ss_logo.png in Resources */ = {isa = PBXBuildFile; fileRef = DDBC6CA40D5D458700564C49 /* boinc_ss_logo.png */; }; - DDBD51760C169B770074905B /* LoginItemAPI.c in Sources */ = {isa = PBXBuildFile; fileRef = DD1277BE081F3E73007B5DE1 /* LoginItemAPI.c */; }; DDBE74390C03B1C600453BB8 /* cs_platforms.cpp in Sources */ = {isa = PBXBuildFile; fileRef = DDBE74380C03B1C600453BB8 /* cs_platforms.cpp */; }; DDC06AB410A3E93F00C8D9A5 /* url.cpp in Sources */ = {isa = PBXBuildFile; fileRef = DDC06AB210A3E93F00C8D9A5 /* url.cpp */; }; DDC06AB810A3E97700C8D9A5 /* url.cpp in Sources */ = {isa = PBXBuildFile; fileRef = DDC06AB210A3E93F00C8D9A5 /* url.cpp */; }; @@ -323,7 +321,6 @@ DDD0697312D70C9400120920 /* sg_TaskPanel.cpp in Sources */ = {isa = PBXBuildFile; fileRef = DDD0697112D70C9400120920 /* sg_TaskPanel.cpp */; }; DDD095490A3EDF2D00C95BA4 /* switcher.cpp in Sources */ = {isa = PBXBuildFile; fileRef = DDD095480A3EDF2D00C95BA4 /* switcher.cpp */; }; DDD3370A106224E800867C7D /* AddRemoveUser.cpp in Sources */ = {isa = PBXBuildFile; fileRef = DDD33709106224E800867C7D /* AddRemoveUser.cpp */; }; - DDD3370F10622C6C00867C7D /* LoginItemAPI.c in Sources */ = {isa = PBXBuildFile; fileRef = DD1277BE081F3E73007B5DE1 /* LoginItemAPI.c */; }; DDD3371310622D0800867C7D /* Carbon.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 20286C33FDCF999611CA2CEA /* Carbon.framework */; }; DDD52DCA0C03CAE6009B5FC0 /* ViewProjects.cpp in Sources */ = {isa = PBXBuildFile; fileRef = DDD52DC40C03CAE6009B5FC0 /* ViewProjects.cpp */; }; DDD52DCC0C03CAE6009B5FC0 /* ViewTransfers.cpp in Sources */ = {isa = PBXBuildFile; fileRef = DDD52DC60C03CAE6009B5FC0 /* ViewTransfers.cpp */; }; @@ -641,8 +638,6 @@ DD0C5A8A0816711400CEC5D7 /* boinc.jpg */ = {isa = PBXFileReference; lastKnownFileType = image.jpeg; name = boinc.jpg; path = ../clientscr/res/boinc.jpg; sourceTree = SOURCE_ROOT; }; DD1277B3081F3D67007B5DE1 /* PostInstall.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = PostInstall.app; sourceTree = BUILT_PRODUCTS_DIR; }; DD1277B5081F3D67007B5DE1 /* PostInstall-Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = "PostInstall-Info.plist"; sourceTree = ""; }; - DD1277BE081F3E73007B5DE1 /* LoginItemAPI.c */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.c; name = LoginItemAPI.c; path = ../mac_installer/LoginItemAPI.c; sourceTree = SOURCE_ROOT; }; - DD1277BF081F3E73007B5DE1 /* LoginItemAPI.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = LoginItemAPI.h; path = ../mac_installer/LoginItemAPI.h; sourceTree = SOURCE_ROOT; }; DD1277C0081F3E73007B5DE1 /* PostInstall.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; name = PostInstall.cpp; path = ../mac_installer/PostInstall.cpp; sourceTree = SOURCE_ROOT; }; DD127880081F464E007B5DE1 /* postupgrade */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = text.script.csh; name = postupgrade; path = ../mac_installer/postupgrade; sourceTree = SOURCE_ROOT; }; DD16BF7B099D6C90003E4B69 /* cpu_sched.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = cpu_sched.cpp; sourceTree = ""; }; @@ -1296,8 +1291,6 @@ isa = PBXGroup; children = ( DD1AFEE70A51301C00EE5B82 /* Installer.cpp */, - DD1277BE081F3E73007B5DE1 /* LoginItemAPI.c */, - DD1277BF081F3E73007B5DE1 /* LoginItemAPI.h */, DD1277C0081F3E73007B5DE1 /* PostInstall.cpp */, DD4688590C1661970089F500 /* uninstall.cpp */, DDF1F47A09822C3400482C89 /* preinstall */, @@ -2419,7 +2412,6 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( - DD1277C2081F3E73007B5DE1 /* LoginItemAPI.c in Sources */, DD1277C4081F3E73007B5DE1 /* PostInstall.cpp in Sources */, DDA12AA20A369B5500FBDD12 /* SetupSecurity.cpp in Sources */, DD51DC8F0A4943A300BD24E6 /* check_security.cpp in Sources */, @@ -2618,7 +2610,6 @@ buildActionMask = 2147483647; files = ( DD46885A0C1661970089F500 /* uninstall.cpp in Sources */, - DDBD51760C169B770074905B /* LoginItemAPI.c in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -2790,7 +2781,6 @@ buildActionMask = 2147483647; files = ( DDD3370A106224E800867C7D /* AddRemoveUser.cpp in Sources */, - DDD3370F10622C6C00867C7D /* LoginItemAPI.c in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/mac_installer/AddRemoveUser.cpp b/mac_installer/AddRemoveUser.cpp index 3743899628..133002686c 100644 --- a/mac_installer/AddRemoveUser.cpp +++ b/mac_installer/AddRemoveUser.cpp @@ -27,7 +27,7 @@ #include "LoginItemAPI.h" //please take a look at LoginItemAPI.h for an explanation of the routines available to you. void printUsage(void); -void SetLoginItem(Boolean addLogInItem); +void SetLoginItem(char *user, Boolean addLogInItem); static char * PersistentFGets(char *buf, size_t buflen, FILE *f); @@ -143,7 +143,7 @@ int main(int argc, char *argv[]) saved_uid = geteuid(); seteuid(pw->pw_uid); // Temporarily set effective uid to this user - SetLoginItem(AddUsers); // Set or remove login item for this user + SetLoginItem(pw->pw_name, AddUsers); // Set or remove login item for this user if (OSVersion < 0x1060) { sprintf(s, "sudo -u %s defaults -currentHost read com.apple.screensaver moduleName", @@ -198,6 +198,9 @@ int main(int argc, char *argv[]) seteuid(saved_uid); // Set effective uid back to privileged user } + if (AddUsers) { + printf("WARNING: Changes may require a system restart to take effect.\n"); + } return 0; } @@ -210,35 +213,24 @@ void printUsage() { printf("\n"); } -void SetLoginItem(Boolean addLogInItem){ - Boolean Success; - int NumberOfLoginItems, Counter; - char *p, *q; +void SetLoginItem(char *user, Boolean addLogInItem){ + char cmd[2048]; + OSErr err; + + sprintf(cmd, "sudo -u %s osascript -e 'tell application \"System Events\"' -e 'delete (every login item whose path contains \"BOINCManager\")' -e 'end tell'", user); - Success = false; - - NumberOfLoginItems = GetCountOfLoginItems(kCurrentUser); - - // Search existing login items in reverse order, deleting any duplicates of ours - for (Counter = NumberOfLoginItems ; Counter > 0 ; Counter--) - { - p = ReturnLoginItemPropertyAtIndex(kCurrentUser, kApplicationNameInfo, Counter-1); - if (p == NULL) continue; - q = p; - while (*q) - { - // It is OK to modify the returned string because we "own" it - *q = toupper(*q); // Make it case-insensitive - q++; - } - - if (strcmp(p, "BOINCMANAGER.APP") == 0) { - Success = RemoveLoginItemAtIndex(kCurrentUser, Counter-1); - } + err = system(cmd); + if (err) { + printf("Delete BOINCManager login item for user %s returned error %d\n", user, err); } - + if (addLogInItem) { - Success = AddLoginItemWithPropertiesToUser(kCurrentUser, "/Applications/BOINCManager.app", kHideOnLaunch); + sprintf(cmd, "sudo -u %s osascript -e 'tell application \"System Events\"' -e 'make new login item at end with properties {path:\"/Applications/BOINCManager.app\", hidden:true, kind:Application, name:\"BOINCManager\"}' -e 'end tell'", user); + + err = system(cmd); + if (err) { + printf("Add BOINCManager login item for user %s returned error %d\n", user, err); + } } } diff --git a/mac_installer/PostInstall.cpp b/mac_installer/PostInstall.cpp index 757de4a1dc..5fe9236af2 100755 --- a/mac_installer/PostInstall.cpp +++ b/mac_installer/PostInstall.cpp @@ -71,8 +71,6 @@ #include #include // for time() -#include "LoginItemAPI.h" //please take a look at LoginItemAPI.h for an explanation of the routines available to you. - #include "SetupSecurity.h" @@ -122,7 +120,8 @@ static char *saverName[NUMBRANDS]; static char *saverNameEscaped[NUMBRANDS]; static char *brandName[NUMBRANDS]; static char *appName[NUMBRANDS]; -static char *appNameEscaped[NUMBRANDS]; +static char *appPath[NUMBRANDS]; +static char *appPathEscaped[NUMBRANDS]; static char *receiptNameEscaped[NUMBRANDS]; enum { launchWhenDone, @@ -162,29 +161,33 @@ int main(int argc, char *argv[]) group *grp; #endif // SANDBOX - appName[0] = "/Applications/BOINCManager.app"; - appNameEscaped[0] = "/Applications/BOINCManager.app"; + appName[0] = "BOINCManager"; + appPath[0] = "/Applications/BOINCManager.app"; + appPathEscaped[0] = "/Applications/BOINCManager.app"; brandName[0] = "BOINC"; saverName[0] = "BOINCSaver"; saverNameEscaped[0] = "BOINCSaver"; receiptNameEscaped[0] = "/Library/Receipts/BOINC\\ Installer.pkg"; - appName[1] = "/Applications/GridRepublic Desktop.app"; - appNameEscaped[1] = "/Applications/GridRepublic\\ Desktop.app"; + appName[1] = "GridRepublic Desktop"; + appPath[1] = "/Applications/GridRepublic Desktop.app"; + appPathEscaped[1] = "/Applications/GridRepublic\\ Desktop.app"; brandName[1] = "GridRepublic"; saverName[1] = "GridRepublic"; saverNameEscaped[1] = "GridRepublic"; receiptNameEscaped[1] = "/Library/Receipts/GridRepublic\\ Installer.pkg"; - appName[2] = "/Applications/Progress Thru Processors Desktop.app"; - appNameEscaped[2] = "/Applications/Progress\\ Thru\\ Processors\\ Desktop.app"; + appName[2] = "Progress Thru Processors Desktop"; + appPath[2] = "/Applications/Progress Thru Processors Desktop.app"; + appPathEscaped[2] = "/Applications/Progress\\ Thru\\ Processors\\ Desktop.app"; brandName[2] = "Progress Thru Processors"; saverName[2] = "Progress Thru Processors"; saverNameEscaped[2] = "Progress\\ Thru\\ Processors"; receiptNameEscaped[2] = "/Library/Receipts/Progress\\ Thru\\ Processors\\ Installer.pkg"; - appName[3] = "/Applications/Charity Engine Desktop.app"; - appNameEscaped[3] = "/Applications/Charity\\ Engine\\ Desktop.app"; + appName[3] = "Charity Engine Desktop"; + appPath[3] = "/Applications/Charity Engine Desktop.app"; + appPathEscaped[3] = "/Applications/Charity\\ Engine\\ Desktop.app"; brandName[3] = "Charity Engine"; saverName[3] = "Charity Engine"; saverNameEscaped[3] = "Charity\\ Engine"; @@ -241,7 +244,7 @@ int main(int argc, char *argv[]) StandardAlert (kAlertStopAlert, (StringPtr)s, NULL, NULL, &itemHit); // "rm -rf /Applications/GridRepublic\\ Desktop.app" - sprintf(s, "rm -rf %s", appNameEscaped[brandID]); + sprintf(s, "rm -rf %s", appPathEscaped[brandID]); system (s); // "rm -rf /Library/Screen\\ Savers/GridRepublic.saver" @@ -286,7 +289,7 @@ int main(int argc, char *argv[]) } // err = SetBOINCAppOwnersGroupsAndPermissions("/Applications/GridRepublic Desktop.app"); - err = SetBOINCAppOwnersGroupsAndPermissions(appName[brandID]); + err = SetBOINCAppOwnersGroupsAndPermissions(appPath[brandID]); if (err != noErr) { // print_to_log_file("SetBOINCAppOwnersGroupsAndPermissions returned %d (repetition=%d)", err, i); @@ -299,7 +302,7 @@ int main(int argc, char *argv[]) continue; } - err = check_security(appName[brandID], "/Library/Application Support/BOINC Data", true, false); + err = check_security(appPath[brandID], "/Library/Application Support/BOINC Data", true, false); if (err == noErr) break; // print_to_log_file("check_security returned %d (repetition=%d)", err, i); @@ -335,7 +338,7 @@ int main(int argc, char *argv[]) // Set owner of branded BOINCManager and contents, including core client // "chown -Rf username /Applications/GridRepublic\\ Desktop.app" - sprintf(s, "chown -Rf %s %s", p, appNameEscaped[brandID]); + sprintf(s, "chown -Rf %s %s", p, appPathEscaped[brandID]); system (s); // Set owner of BOINC Screen Saver @@ -349,7 +352,7 @@ int main(int argc, char *argv[]) system (s); // "chmod -R a+s /Applications/GridRepublic\\ Desktop.app" - sprintf(s, "chmod -R a+s %s", appNameEscaped[brandID]); + sprintf(s, "chmod -R a+s %s", appPathEscaped[brandID]); system (s); #endif // ! defined(SANDBOX) @@ -359,7 +362,7 @@ int main(int argc, char *argv[]) if (i == brandID) continue; // "rm -rf /Applications/GridRepublic\\ Desktop.app" - sprintf(s, "rm -rf %s", appNameEscaped[i]); + sprintf(s, "rm -rf %s", appPathEscaped[i]); system (s); // "rm -rf /Library/Screen\\ Savers/GridRepublic.saver" @@ -372,7 +375,7 @@ int main(int argc, char *argv[]) } // err_fsref = FSPathMakeRef((StringPtr)"/Applications/GridRepublic Desktop.app", &fileRef, NULL); - err_fsref = FSPathMakeRef((StringPtr)appName[brandID], &fileRef, NULL); + err_fsref = FSPathMakeRef((StringPtr)appPath[brandID], &fileRef, NULL); if (err_fsref == noErr) err = LSRegisterFSRef(&fileRef, true); @@ -405,11 +408,13 @@ int main(int argc, char *argv[]) seteuid(saved_euid); - return 0; FSRef theFSRef; err = FSPathMakeRef((StringPtr)"/Library/Application Support/BOINC Data/WaitPermissions.app", &theFSRef, NULL); + if (err) { + printf("FSPathMakeRef(WaitPermissions) returned error %ld\n", err); + } // When we first create the boinc_master group and add the current user to the // new group, there is a delay before the new group membership is recognized. @@ -422,7 +427,9 @@ int main(int argc, char *argv[]) // The WaitPermissions application loops until it can access the switcher // application. err = LSOpenFSRef(&theFSRef, NULL); - + if (err) { + printf("LSOpenFSRef(WaitPermissions) returned error %ld\n", err); + } waitPermissionsStartTime = time(NULL); for (i=0; i<15; i++) { // Show "Please wait..." alert after 15 seconds waitPermissionsPID = FindProcessPID("WaitPermissions", 0); @@ -508,7 +515,7 @@ int DeleteReceipt() system (s); // err_fsref = FSPathMakeRef((StringPtr)"/Applications/GridRepublic Desktop.app", &fileRef, NULL); - err_fsref = FSPathMakeRef((StringPtr)appName[brandID], &fileRef, NULL); + err_fsref = FSPathMakeRef((StringPtr)appPath[brandID], &fileRef, NULL); if (finalInstallAction == launchWhenDone) { // If system is set up to run BOINC Client as a daemon using launchd, launch it @@ -724,56 +731,37 @@ void CheckUserAndGroupConflicts() Boolean SetLoginItem(long brandID, Boolean deleteLogInItem) { - Boolean Success; - int NumberOfLoginItems, Counter; - char *p, *q; - char s[256]; int i; + char cmd[2048]; + OSErr err; - Success = false; + fflush(stdout); + fprintf(stdout, "Adjusting login items for user\n"); - NumberOfLoginItems = GetCountOfLoginItems(kCurrentUser); - - // Search existing login items in reverse order, deleting any duplicates of ours - for (Counter = NumberOfLoginItems ; Counter > 0 ; Counter--) - { - p = ReturnLoginItemPropertyAtIndex(kCurrentUser, kApplicationNameInfo, Counter-1); - q = p; - while (*q) - { - // It is OK to modify the returned string because we "own" it - *q = toupper(*q); // Make it case-insensitive - q++; - } - - for (i=0; i #include // for MAXPATHLEN -#include "LoginItemAPI.h" //please take a look at LoginItemAPI.h for an explanation of the routines available to you. - static OSStatus DoUninstall(void); static OSStatus GetpathToBOINCManagerApp(char* path, int maxLen, FSRef *theFSRef); static OSStatus CleanupAllVisibleUsers(void); static OSStatus DeleteOurBundlesFromDirectory(CFStringRef bundleID, char *extension, char *dirPath); static OSStatus GetAuthorization(AuthorizationRef * authRef, const char *pathToTool, char *brandName); static OSStatus DoPrivilegedExec(char *brandName, const char *pathToTool, char *arg1, char *arg2, char *arg3, char *arg4, char *arg5); -static void DeleteLoginItem(void); +static void DeleteLoginItem(char* user, char* appName); static char * PersistentFGets(char *buf, size_t buflen, FILE *f); static pid_t FindProcessPID(char* name, pid_t thePID); static OSStatus QuitBOINCManager(OSType signature); @@ -197,7 +195,8 @@ static OSStatus DoUninstall(void) { err = DeleteOurBundlesFromDirectory(CFSTR("edu.berkeley.boincsaver"), "saver", "/Library/Screen Savers"); // Phase 4: Delete our files and directories at our installer's default locations - // Remove everything we've installed, whether BOINC, GridRepublic or Progress Thru Processors + // Remove everything we've installed, whether BOINC, GridRepublic, Progress Thru Processors or + // Charity Engine // These first 4 should already have been deleted by the above code, but do them anyway for safety system ("rm -rf /Applications/BOINCManager.app"); system ("rm -rf \"/Library/Screen Savers/BOINCSaver.saver\""); @@ -207,16 +206,21 @@ static OSStatus DoUninstall(void) { system ("rm -rf \"/Applications/Progress\\ Thru\\ Processors\\ Desktop.app\""); system ("rm -rf \"/Library/Screen Savers/Progress\\ Thru\\ Processors.saver\""); - + + system ("rm -rf \"/Applications/Charity\\ Engine\\ Desktop.app\""); + system ("rm -rf \"/Library/Screen Savers/Charity\\ Engine.saver\""); + // Delete any receipt from an older installer (which had // a wrapper application around the installer package.) system ("rm -rf /Library/Receipts/GridRepublic.pkg"); system ("rm -rf /Library/Receipts/Progress\\ Thru\\ Processors.pkg"); + system ("rm -rf /Library/Receipts/Charity\\ Engine.pkg"); system ("rm -rf /Library/Receipts/BOINC.pkg"); // Delete any receipt from a newer installer (a bare package.) system ("rm -rf /Library/Receipts/GridRepublic\\ Installer.pkg"); system ("rm -rf /Library/Receipts/Progress\\ Thru\\ Processors\\ Installer.pkg"); + system ("rm -rf /Library/Receipts/Charity\\ Engine\\ Installer.pkg"); system ("rm -rf /Library/Receipts/BOINC\\ Installer.pkg"); // Phase 5: Set BOINC Data owner and group to logged in user @@ -414,13 +418,17 @@ static OSStatus CleanupAllVisibleUsers(void) } seteuid(pw->pw_uid); // Temporarily set effective uid to this user - DeleteLoginItem(); // Delete our login item(s) for this user + // Delete our login item(s) for this user + DeleteLoginItem(dp->d_name, "BOINCSaver"); + DeleteLoginItem(dp->d_name, "GridRepublic"); + DeleteLoginItem(dp->d_name, "Progress Thru Processors"); + DeleteLoginItem(dp->d_name, "Charity Engine"); // sprintf(s, "rm -f \"/Users/%s/Library/Preferences/BOINC Manager Preferences\"", dp->d_name); // system (s); // Set screensaver to "Computer Name" default screensaver only - // if it was BOINC, GridRepublic or Progress Thru Processors. + // if it was BOINC, GridRepublic, Progress Thru Processors or Charity Engine. changeSaver = false; if (OSVersion < 0x1060) { f = popen("defaults -currentHost read com.apple.screensaver moduleName", "r"); @@ -443,6 +451,10 @@ static OSStatus CleanupAllVisibleUsers(void) changeSaver = true; break; } + if (strstr(s, "Charity Engine")) { + changeSaver = true; + break; + } } pclose(f); } @@ -571,34 +583,15 @@ if (err != noErr) } -static void DeleteLoginItem(void) +static void DeleteLoginItem(char* user, char* appName) { - Boolean Success; - int NumberOfLoginItems, Counter; - char *p, *q; + char cmd[2048]; + OSErr err; - Success = false; - - NumberOfLoginItems = GetCountOfLoginItems(kCurrentUser); - - // Search existing login items in reverse order, deleting ours - for (Counter = NumberOfLoginItems ; Counter > 0 ; Counter--) - { - p = ReturnLoginItemPropertyAtIndex(kCurrentUser, kApplicationNameInfo, Counter-1); - q = p; - while (*q) - { - // It is OK to modify the returned string because we "own" it - *q = toupper(*q); // Make it case-insensitive - q++; - } - - if (strcmp(p, "BOINCMANAGER.APP") == 0) - Success = RemoveLoginItemAtIndex(kCurrentUser, Counter-1); - if (strcmp(p, "GRIDREPUBLIC DESKTOP.APP") == 0) - Success = RemoveLoginItemAtIndex(kCurrentUser, Counter-1); - if (strcmp(p, "PROGRESS THRU PROCESSORS DESKTOP.APP") == 0) - Success = RemoveLoginItemAtIndex(kCurrentUser, Counter-1); + sprintf(cmd, "sudo -u %s osascript -e 'tell application \"System Events\"' -e 'delete (every login item whose path contains \"%s\")' -e 'end tell'", user, appName); + err = system(cmd); + if (err) { + printf("[2] Delete login item containing %s for user %s returned error %d\n", appName, user, err); } }