2008-08-06 18:36:30 +00:00
|
|
|
// This file is part of BOINC.
|
2007-06-06 12:52:37 +00:00
|
|
|
// http://boinc.berkeley.edu
|
2008-08-06 18:36:30 +00:00
|
|
|
// Copyright (C) 2008 University of California
|
2007-06-06 12:52:37 +00:00
|
|
|
//
|
2008-08-06 18:36:30 +00:00
|
|
|
// BOINC is free software; you can redistribute it and/or modify it
|
|
|
|
// under the terms of the GNU Lesser General Public License
|
|
|
|
// as published by the Free Software Foundation,
|
|
|
|
// either version 3 of the License, or (at your option) any later version.
|
2007-06-06 12:52:37 +00:00
|
|
|
//
|
2008-08-06 18:36:30 +00:00
|
|
|
// BOINC is distributed in the hope that it will be useful,
|
2007-06-06 12:52:37 +00:00
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
// See the GNU Lesser General Public License for more details.
|
|
|
|
//
|
2008-08-06 18:36:30 +00:00
|
|
|
// You should have received a copy of the GNU Lesser General Public License
|
|
|
|
// along with BOINC. If not, see <http://www.gnu.org/licenses/>.
|
2007-06-06 12:52:37 +00:00
|
|
|
|
|
|
|
/* uninstall.cpp */
|
|
|
|
|
2012-05-03 14:09:47 +00:00
|
|
|
#define TESTING 0 /* for debugging */
|
2007-06-06 12:52:37 +00:00
|
|
|
|
|
|
|
#include <Carbon/Carbon.h>
|
|
|
|
#include <Security/Authorization.h>
|
|
|
|
#include <Security/AuthorizationTags.h>
|
|
|
|
|
|
|
|
#include <grp.h>
|
|
|
|
|
|
|
|
#include <unistd.h> // geteuid, seteuid
|
|
|
|
#include <pwd.h> // passwd, getpwnam
|
|
|
|
#include <dirent.h>
|
|
|
|
#include <sys/param.h> // for MAXPATHLEN
|
2013-06-18 11:03:24 +00:00
|
|
|
#include <sys/stat.h> // For stat()
|
2012-03-29 09:42:32 +00:00
|
|
|
#include <string.h>
|
|
|
|
#include <vector>
|
|
|
|
#include <string>
|
|
|
|
|
|
|
|
using std::vector;
|
|
|
|
using std::string;
|
2007-06-06 12:52:37 +00:00
|
|
|
|
2012-05-03 11:40:55 +00:00
|
|
|
#define SEARCHFORALLBOINCMANAGERS 0
|
2013-06-18 11:03:24 +00:00
|
|
|
#define MAX_LANGUAGES_TO_TRY 5
|
2012-05-03 11:40:55 +00:00
|
|
|
|
2013-06-18 11:03:24 +00:00
|
|
|
#include "translate.h"
|
2011-09-24 12:43:19 +00:00
|
|
|
|
2007-06-06 12:52:37 +00:00
|
|
|
static OSStatus DoUninstall(void);
|
2007-06-07 12:24:29 +00:00
|
|
|
static OSStatus CleanupAllVisibleUsers(void);
|
|
|
|
static OSStatus DeleteOurBundlesFromDirectory(CFStringRef bundleID, char *extension, char *dirPath);
|
2007-06-06 12:52:37 +00:00
|
|
|
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);
|
2011-09-24 12:43:19 +00:00
|
|
|
static void DeleteLoginItemOSAScript(char* user, char* appName);
|
2012-06-18 11:11:44 +00:00
|
|
|
static void DeleteLoginItemFromPListFile(void);
|
2007-06-06 12:52:37 +00:00
|
|
|
static char * PersistentFGets(char *buf, size_t buflen, FILE *f);
|
2012-06-16 15:03:11 +00:00
|
|
|
OSErr GetCurrentScreenSaverSelection(char *moduleName, size_t maxLen);
|
|
|
|
OSErr SetScreenSaverSelection(char *moduleName, char *modulePath, int type);
|
2012-06-18 11:11:44 +00:00
|
|
|
int GetCountOfLoginItemsFromPlistFile(void);
|
|
|
|
OSErr GetLoginItemNameAtIndexFromPlistFile(int index, char *name, size_t maxLen);
|
|
|
|
OSErr DeleteLoginItemNameAtIndexFromPlistFile(int index);
|
2012-05-03 11:33:03 +00:00
|
|
|
static OSErr FindProcess (OSType typeToFind, OSType creatorToFind, ProcessSerialNumberPtr processSN);
|
2007-06-06 12:52:37 +00:00
|
|
|
static pid_t FindProcessPID(char* name, pid_t thePID);
|
2012-05-03 11:33:03 +00:00
|
|
|
static OSStatus QuitOneProcess(OSType signature);
|
2014-01-21 12:20:53 +00:00
|
|
|
static void KillVBoxProcess(char* name);
|
2012-05-06 08:22:37 +00:00
|
|
|
static void SleepTicks(UInt32 ticksToSleep);
|
2013-06-18 11:03:24 +00:00
|
|
|
static void GetPreferredLanguages();
|
|
|
|
static void LoadPreferredLanguages();
|
2014-01-21 12:20:53 +00:00
|
|
|
static Boolean ShowMessage(Boolean allowCancel, Boolean continueButton, Boolean yesNoButtons, const char *format, ...);
|
2012-05-03 11:40:55 +00:00
|
|
|
#if SEARCHFORALLBOINCMANAGERS
|
|
|
|
static OSStatus GetpathToBOINCManagerApp(char* path, int maxLen, FSRef *theFSRef);
|
|
|
|
#endif
|
2013-11-15 13:02:04 +00:00
|
|
|
static int compareOSVersionTo(int toMajor, int toMinor);
|
2007-06-06 12:52:37 +00:00
|
|
|
|
2013-06-18 11:03:24 +00:00
|
|
|
static char gAppName[256];
|
|
|
|
static char gBrandName[256];
|
|
|
|
static char gCatalogsDir[MAXPATHLEN];
|
|
|
|
static char * gCatalog_Name = (char *)"BOINC-Setup";
|
|
|
|
static char * gTempFileName = "/tmp/BOINC_preferred_languages";
|
2007-06-06 12:52:37 +00:00
|
|
|
|
2013-06-04 00:57:09 +00:00
|
|
|
|
2013-06-18 11:03:24 +00:00
|
|
|
/* BEGIN TEMPORARY ITEMS TO ALLOW TRANSLATORS TO START WORK */
|
2013-06-04 00:57:09 +00:00
|
|
|
void notused() {
|
2014-01-21 12:20:53 +00:00
|
|
|
ShowMessage(true, false, false, (char *)_("OK"));
|
2013-06-04 00:57:09 +00:00
|
|
|
}
|
|
|
|
/* END TEMPORARY ITEMS TO ALLOW TRANSLATORS TO START WORK */
|
|
|
|
|
|
|
|
|
2007-06-06 12:52:37 +00:00
|
|
|
int main(int argc, char *argv[])
|
|
|
|
{
|
2014-01-21 12:20:53 +00:00
|
|
|
char pathToSelf[MAXPATHLEN], pathToVBoxUninstallTool[MAXPATHLEN], *p;
|
2007-06-06 12:52:37 +00:00
|
|
|
ProcessSerialNumber ourPSN;
|
|
|
|
FSRef ourFSRef;
|
2007-06-08 11:16:48 +00:00
|
|
|
Boolean cancelled = false;
|
2014-01-21 12:20:53 +00:00
|
|
|
struct stat sbuf;
|
2007-06-06 12:52:37 +00:00
|
|
|
OSStatus err = noErr;
|
|
|
|
|
|
|
|
// Get the full path to our executable inside this application's bundle
|
|
|
|
err = GetCurrentProcess (&ourPSN);
|
|
|
|
if (err == noErr) {
|
|
|
|
err = GetProcessBundleLocation(&ourPSN, &ourFSRef);
|
|
|
|
}
|
|
|
|
if (err == noErr) {
|
|
|
|
err = FSRefMakePath (&ourFSRef, (UInt8*)pathToSelf, sizeof(pathToSelf));
|
|
|
|
}
|
|
|
|
if (err != noErr) {
|
2014-01-21 12:20:53 +00:00
|
|
|
ShowMessage(false, false, false, "Couldn't get path to self. Error %d", err);
|
2007-06-06 12:52:37 +00:00
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2014-01-21 12:20:53 +00:00
|
|
|
strlcpy(pathToVBoxUninstallTool, pathToSelf, sizeof(pathToVBoxUninstallTool));
|
2014-03-07 12:28:32 +00:00
|
|
|
strlcat(pathToVBoxUninstallTool, "/Contents/Resources/VirtualBox_Uninstall.tool", sizeof(pathToVBoxUninstallTool));
|
2014-01-21 12:20:53 +00:00
|
|
|
|
2007-06-06 12:52:37 +00:00
|
|
|
// To allow for branding, assume name of executable inside bundle is same as name of bundle
|
|
|
|
p = strrchr(pathToSelf, '/'); // Assume name of executable inside bundle is same as name of bundle
|
|
|
|
if (p == NULL)
|
|
|
|
p = pathToSelf - 1;
|
2013-06-18 11:03:24 +00:00
|
|
|
strlcpy(gAppName, p+1, sizeof(gAppName));
|
|
|
|
p = strrchr(gAppName, '.'); // Strip off bundle extension (".app")
|
2007-06-06 12:52:37 +00:00
|
|
|
if (p)
|
|
|
|
*p = '\0';
|
|
|
|
|
2013-06-18 11:03:24 +00:00
|
|
|
strlcpy(gCatalogsDir, pathToSelf, sizeof(gCatalogsDir));
|
|
|
|
strlcat(gCatalogsDir, "/Contents/Resources/locale/", sizeof(gCatalogsDir));
|
|
|
|
|
2007-06-06 12:52:37 +00:00
|
|
|
strlcat(pathToSelf, "/Contents/MacOS/", sizeof(pathToSelf));
|
2013-06-18 11:03:24 +00:00
|
|
|
strlcat(pathToSelf, gAppName, sizeof(pathToSelf));
|
2007-06-06 12:52:37 +00:00
|
|
|
|
2013-06-18 11:03:24 +00:00
|
|
|
p = strchr(gAppName, ' ');
|
2007-06-06 12:52:37 +00:00
|
|
|
p += 1; // Point to brand name following "Uninstall "
|
2013-06-18 11:03:24 +00:00
|
|
|
strlcpy(gBrandName, p, sizeof(gBrandName));
|
|
|
|
|
|
|
|
// Determine whether this is the intial launch or the relaunch with privileges
|
|
|
|
if ( (argc == 2) && (strcmp(argv[1], "--privileged") == 0) ) {
|
|
|
|
LoadPreferredLanguages();
|
|
|
|
|
|
|
|
if (geteuid() != 0) { // Confirm that we are running as root
|
2014-01-21 12:20:53 +00:00
|
|
|
ShowMessage(false, false, false, (char *)_("Permission error after relaunch"));
|
2013-06-18 11:03:24 +00:00
|
|
|
BOINCTranslationCleanup();
|
|
|
|
return permErr;
|
|
|
|
}
|
|
|
|
|
2014-01-21 12:20:53 +00:00
|
|
|
ShowMessage(false, true, false, (char *)_("Removal may take several minutes.\nPlease be patient."));
|
2013-06-18 11:03:24 +00:00
|
|
|
|
|
|
|
err = DoUninstall();
|
|
|
|
|
|
|
|
BOINCTranslationCleanup();
|
2015-08-14 13:20:49 +00:00
|
|
|
|
|
|
|
printf("Done\n"); // Signal DoPrivilegedExec() that we finished
|
2013-06-18 11:03:24 +00:00
|
|
|
return err;
|
2007-09-06 01:40:05 +00:00
|
|
|
}
|
2007-06-08 11:16:48 +00:00
|
|
|
|
2013-06-18 11:03:24 +00:00
|
|
|
// This is the initial launch. Authenticate and relaunch ourselves with privileges.
|
|
|
|
|
|
|
|
GetPreferredLanguages(); // We must do this before switching to root user
|
|
|
|
LoadPreferredLanguages();
|
|
|
|
|
|
|
|
// Grid Republic uses generic dialog with Uninstall application's icon
|
2014-01-21 12:20:53 +00:00
|
|
|
cancelled = ! ShowMessage(true, true, false, (char *)_(
|
2013-06-18 11:03:24 +00:00
|
|
|
"Are you sure you want to completely remove %s from your computer?\n\n"
|
|
|
|
"This will remove the executables but will not touch %s data files."), p, p);
|
2012-06-16 15:03:11 +00:00
|
|
|
if (! cancelled) {
|
2007-06-08 11:16:48 +00:00
|
|
|
err = DoPrivilegedExec(p, pathToSelf, "--privileged", NULL, NULL, NULL, NULL);
|
2012-06-16 15:03:11 +00:00
|
|
|
}
|
2007-06-08 11:16:48 +00:00
|
|
|
|
|
|
|
if (cancelled || (err == errAuthorizationCanceled)) {
|
2014-01-21 12:20:53 +00:00
|
|
|
ShowMessage(false, false, false, (char *)_("Canceled: %s has not been touched."), p);
|
2013-06-18 11:03:24 +00:00
|
|
|
BOINCTranslationCleanup();
|
2007-06-06 12:52:37 +00:00
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2013-06-20 11:06:24 +00:00
|
|
|
|
2007-06-06 12:52:37 +00:00
|
|
|
#if TESTING
|
2014-01-21 12:20:53 +00:00
|
|
|
ShowMessage(false, false, false, "DoPrivilegedExec returned %d", err);
|
2007-06-06 12:52:37 +00:00
|
|
|
#endif
|
|
|
|
|
2013-06-20 11:06:24 +00:00
|
|
|
if (err) {
|
2014-01-21 12:20:53 +00:00
|
|
|
ShowMessage(false, false, false, (char *)_("An error occurred: error code %d"), err);
|
2013-06-20 11:06:24 +00:00
|
|
|
}else {
|
|
|
|
FSRef BOINCDataRef, UserPrefsRef;
|
|
|
|
CFStringRef CFBOINCDataPath, CFUserPrefsPath;
|
|
|
|
char BOINCDataPath[MAXPATHLEN], temp[MAXPATHLEN], PathToPrefs[MAXPATHLEN];
|
|
|
|
Boolean success = false;
|
|
|
|
char * loginName = getlogin();
|
2007-06-06 12:52:37 +00:00
|
|
|
|
2013-06-20 11:06:24 +00:00
|
|
|
err = FSPathMakeRef((StringPtr)"/Library", &BOINCDataRef, NULL);
|
|
|
|
if (err == noErr) {
|
|
|
|
err = LSCopyDisplayNameForRef(&BOINCDataRef, &CFBOINCDataPath);
|
|
|
|
}
|
|
|
|
if (err == noErr) {
|
|
|
|
success = CFStringGetCString(CFBOINCDataPath, temp,
|
|
|
|
sizeof(temp), kCFStringEncodingUTF8);
|
|
|
|
}
|
|
|
|
if (success) {
|
|
|
|
success = false;
|
|
|
|
strlcpy(BOINCDataPath, "/", sizeof(BOINCDataPath));
|
|
|
|
strlcat(BOINCDataPath, temp, sizeof(BOINCDataPath));
|
|
|
|
strlcat(BOINCDataPath, "/", sizeof(BOINCDataPath));
|
|
|
|
|
|
|
|
err = FSPathMakeRef((StringPtr)"/Library/Application Support", &BOINCDataRef, NULL);
|
|
|
|
if (err == noErr) {
|
|
|
|
err = LSCopyDisplayNameForRef(&BOINCDataRef, &CFBOINCDataPath);
|
|
|
|
}
|
|
|
|
if (err == noErr) {
|
|
|
|
success = CFStringGetCString(CFBOINCDataPath, temp,
|
|
|
|
sizeof(temp), kCFStringEncodingUTF8);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (success) {
|
|
|
|
strlcat(BOINCDataPath, temp, sizeof(BOINCDataPath));
|
|
|
|
strlcat(BOINCDataPath, "/BOINC Data", sizeof(BOINCDataPath));
|
|
|
|
} else {
|
|
|
|
strlcpy(BOINCDataPath,
|
|
|
|
"/Library/Application Support/BOINC Data",
|
|
|
|
sizeof(BOINCDataPath));
|
|
|
|
}
|
|
|
|
|
|
|
|
success = false;
|
|
|
|
|
|
|
|
// err = FSPathMakeRef((StringPtr)"/Users", &UserPrefsRef, NULL);
|
|
|
|
err = FSPathMakeRef((StringPtr)"/Users", &UserPrefsRef, NULL);
|
|
|
|
if (err == noErr) {
|
|
|
|
err = LSCopyDisplayNameForRef(&UserPrefsRef, &CFUserPrefsPath);
|
|
|
|
}
|
|
|
|
if (err == noErr) {
|
|
|
|
success = CFStringGetCString(CFUserPrefsPath, temp,
|
|
|
|
sizeof(temp), kCFStringEncodingUTF8);
|
|
|
|
}
|
|
|
|
if (success) {
|
|
|
|
success = false;
|
|
|
|
strlcpy(PathToPrefs, "/", sizeof(PathToPrefs));
|
|
|
|
strlcat(PathToPrefs, temp, sizeof(PathToPrefs));
|
|
|
|
strlcat(PathToPrefs, "/[", sizeof(PathToPrefs));
|
|
|
|
strlcat(PathToPrefs, (char *)_("name of user"), sizeof(PathToPrefs));
|
|
|
|
strlcat(PathToPrefs, "]/", sizeof(PathToPrefs));
|
|
|
|
|
|
|
|
sprintf(temp, "/Users/%s/Library", loginName);
|
|
|
|
err = FSPathMakeRef((StringPtr)temp, &UserPrefsRef, NULL);
|
|
|
|
if (err == noErr) {
|
|
|
|
err = LSCopyDisplayNameForRef(&UserPrefsRef, &CFUserPrefsPath);
|
|
|
|
}
|
|
|
|
if (err == noErr) {
|
|
|
|
success = CFStringGetCString(CFUserPrefsPath, temp,
|
|
|
|
sizeof(temp), kCFStringEncodingUTF8);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (success) {
|
|
|
|
success = false;
|
|
|
|
strlcat(PathToPrefs, temp, sizeof(PathToPrefs));
|
|
|
|
strlcat(PathToPrefs, "/", sizeof(PathToPrefs));
|
|
|
|
|
|
|
|
sprintf(temp, "/Users/%s/Library/Preferences", loginName);
|
|
|
|
err = FSPathMakeRef((StringPtr)temp, &UserPrefsRef, NULL);
|
|
|
|
if (err == noErr) {
|
|
|
|
err = LSCopyDisplayNameForRef(&UserPrefsRef, &CFUserPrefsPath);
|
|
|
|
}
|
|
|
|
if (err == noErr) {
|
|
|
|
success = CFStringGetCString(CFUserPrefsPath, temp,
|
|
|
|
sizeof(temp), kCFStringEncodingUTF8);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (success) {
|
|
|
|
strlcat(PathToPrefs, temp, sizeof(PathToPrefs));
|
|
|
|
strlcat(PathToPrefs, "/BOINC Manager Preferences", sizeof(PathToPrefs));
|
|
|
|
} else {
|
|
|
|
strlcpy(PathToPrefs,
|
|
|
|
"/Users/[username]/Library/Preferences/BOINC Manager Preferences",
|
|
|
|
sizeof(PathToPrefs));
|
|
|
|
}
|
|
|
|
|
2014-01-21 12:20:53 +00:00
|
|
|
// stat() returns zero on success
|
|
|
|
if (stat(pathToVBoxUninstallTool, &sbuf) == 0) {
|
|
|
|
char cmd[MAXPATHLEN+30];
|
|
|
|
|
|
|
|
cancelled = ! ShowMessage(true, false, true, (char *)_(
|
|
|
|
"Do you also want to remove VirtualBox from your computer?\n"
|
|
|
|
"(VirtualBox was installed along with BOINC.)"));
|
|
|
|
if (! cancelled) {
|
2014-01-22 11:04:16 +00:00
|
|
|
err = QuitOneProcess('VBOX');
|
|
|
|
if (err != procNotFound) {
|
|
|
|
sleep(5);
|
|
|
|
}
|
2014-01-21 12:20:53 +00:00
|
|
|
// List of processes to kill taken from my_processes
|
|
|
|
// array in VirtualBox_Uninstall.tool script:
|
|
|
|
KillVBoxProcess("VirtualBox");
|
|
|
|
KillVBoxProcess("VirtualBox-amd64");
|
|
|
|
KillVBoxProcess("VirtualBox-x86");
|
|
|
|
KillVBoxProcess("VirtualBoxVM");
|
|
|
|
KillVBoxProcess("VirtualBoxVM-amd64");
|
|
|
|
KillVBoxProcess("VirtualBoxVM-x86");
|
|
|
|
KillVBoxProcess("VBoxManage");
|
|
|
|
KillVBoxProcess("VBoxManage-amd64");
|
|
|
|
KillVBoxProcess("VBoxManage-x86");
|
|
|
|
KillVBoxProcess("VBoxHeadless");
|
|
|
|
KillVBoxProcess("VBoxHeadless-amd64");
|
|
|
|
KillVBoxProcess("VBoxHeadless-x86");
|
|
|
|
KillVBoxProcess("vboxwebsrv");
|
|
|
|
KillVBoxProcess("vboxwebsrv-amd64");
|
|
|
|
KillVBoxProcess("vboxwebsrv-x86");
|
|
|
|
KillVBoxProcess("VBoxXPCOMIPCD");
|
|
|
|
KillVBoxProcess("VBoxXPCOMIPCD-amd64");
|
|
|
|
KillVBoxProcess("VBoxXPCOMIPCD-x86");
|
|
|
|
KillVBoxProcess("VBoxSVC");
|
|
|
|
KillVBoxProcess("VBoxSVC-amd64");
|
|
|
|
KillVBoxProcess("VBoxSVC-x86");
|
|
|
|
KillVBoxProcess("VBoxNetDHCP");
|
|
|
|
KillVBoxProcess("VBoxNetDHCP-amd64");
|
|
|
|
KillVBoxProcess("VBoxNetDHCP-x86");
|
|
|
|
sleep(2);
|
|
|
|
|
2014-01-22 11:04:16 +00:00
|
|
|
snprintf(cmd, sizeof(cmd), "source \"%s\" --unattended", pathToVBoxUninstallTool);
|
2014-01-21 12:20:53 +00:00
|
|
|
system(cmd);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ShowMessage(false, false, false, (char *)_("Removal completed.\n\n You may want to remove the following remaining items using the Finder: \n"
|
2013-06-20 11:06:24 +00:00
|
|
|
"the directory \"%s\"\n\nfor each user, the file\n"
|
|
|
|
"\"%s\"."), BOINCDataPath, PathToPrefs);
|
|
|
|
}
|
|
|
|
|
2013-06-18 11:03:24 +00:00
|
|
|
BOINCTranslationCleanup();
|
2007-06-06 12:52:37 +00:00
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static OSStatus DoUninstall(void) {
|
|
|
|
pid_t coreClientPID = 0;
|
2014-03-07 12:28:32 +00:00
|
|
|
pid_t BOINCManagerPID = 0;
|
2009-11-19 10:41:47 +00:00
|
|
|
char cmd[1024];
|
2012-05-03 11:40:55 +00:00
|
|
|
char *p;
|
2009-11-19 10:41:47 +00:00
|
|
|
passwd *pw;
|
2007-06-07 12:24:29 +00:00
|
|
|
OSStatus err = noErr;
|
2012-05-03 11:40:55 +00:00
|
|
|
#if SEARCHFORALLBOINCMANAGERS
|
|
|
|
char myRmCommand[MAXPATHLEN+10], plistRmCommand[MAXPATHLEN+10];
|
|
|
|
char notBoot[] = "/Volumes/";
|
|
|
|
FSRef theFSRef;
|
|
|
|
int pathOffset, i;
|
|
|
|
#endif
|
2007-06-06 12:52:37 +00:00
|
|
|
|
|
|
|
#if TESTING
|
2014-01-21 12:20:53 +00:00
|
|
|
ShowMessage(false, false, false, "Permission OK after relaunch");
|
2007-06-06 12:52:37 +00:00
|
|
|
#endif
|
|
|
|
|
2014-03-07 12:28:32 +00:00
|
|
|
//TODO: It would be nice to get the app name from the bundle ID or signature
|
|
|
|
// so we don't have to try all 4 and to allow for future branded versions
|
|
|
|
|
|
|
|
for (;;) {
|
|
|
|
BOINCManagerPID = FindProcessPID("BOINCManager", 0);
|
|
|
|
if (BOINCManagerPID == 0) break;
|
|
|
|
kill(BOINCManagerPID, SIGTERM);
|
|
|
|
sleep(2);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (;;) {
|
|
|
|
BOINCManagerPID = FindProcessPID("GridRepublic Desktop", 0);
|
|
|
|
if (BOINCManagerPID == 0) break;
|
|
|
|
kill(BOINCManagerPID, SIGTERM);
|
|
|
|
sleep(2);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (;;) {
|
|
|
|
BOINCManagerPID = FindProcessPID("Progress Thru Processors Desktop", 0);
|
|
|
|
if (BOINCManagerPID == 0) break;
|
|
|
|
kill(BOINCManagerPID, SIGTERM);
|
|
|
|
sleep(2);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (;;) {
|
|
|
|
BOINCManagerPID = FindProcessPID("Charity Engine Desktop", 0);
|
|
|
|
if (BOINCManagerPID == 0) break;
|
|
|
|
kill(BOINCManagerPID, SIGTERM);
|
|
|
|
sleep(2);
|
|
|
|
}
|
2007-06-06 12:52:37 +00:00
|
|
|
|
|
|
|
// Core Client may still be running if it was started without Manager
|
|
|
|
coreClientPID = FindProcessPID("boinc", 0);
|
|
|
|
if (coreClientPID)
|
|
|
|
kill(coreClientPID, SIGTERM); // boinc catches SIGTERM & exits gracefully
|
|
|
|
|
2012-05-03 11:40:55 +00:00
|
|
|
#if SEARCHFORALLBOINCMANAGERS
|
2007-06-07 12:24:29 +00:00
|
|
|
// Phase 1: try to find all our applications using LaunchServices
|
|
|
|
for (i=0; i<100; i++) {
|
|
|
|
strlcpy(myRmCommand, "rm -rf \"", 10);
|
|
|
|
pathOffset = strlen(myRmCommand);
|
|
|
|
|
|
|
|
err = GetpathToBOINCManagerApp(myRmCommand+pathOffset, MAXPATHLEN, &theFSRef);
|
|
|
|
if (err)
|
|
|
|
break;
|
|
|
|
|
|
|
|
strlcat(myRmCommand, "\"", sizeof(myRmCommand));
|
|
|
|
|
|
|
|
#if TESTING
|
2014-01-21 12:20:53 +00:00
|
|
|
ShowMessage(false, false, false, "manager: %s", myRmCommand);
|
2007-06-07 12:24:29 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
p = strstr(myRmCommand, notBoot);
|
|
|
|
|
|
|
|
if (p == myRmCommand+pathOffset) {
|
|
|
|
#if TESTING
|
2014-01-21 12:20:53 +00:00
|
|
|
ShowMessage(false, false, false, "Not on boot volume: %s", myRmCommand);
|
2007-06-07 12:24:29 +00:00
|
|
|
#endif
|
|
|
|
break;
|
|
|
|
} else {
|
|
|
|
|
|
|
|
// First delete just the application's info.plist file and update the
|
2009-06-13 00:54:29 +00:00
|
|
|
// LaunchServices Database; otherwise LSFindApplicationForInfo might
|
2007-06-07 12:24:29 +00:00
|
|
|
// return this application again after it's been deleted.
|
|
|
|
strlcpy(plistRmCommand, myRmCommand, sizeof(plistRmCommand));
|
|
|
|
strlcat(plistRmCommand, "/Contents/info.plist", sizeof(plistRmCommand));
|
|
|
|
#if TESTING
|
2014-01-21 12:20:53 +00:00
|
|
|
ShowMessage(false, false, false, "Deleting info.plist: %s", plistRmCommand);
|
2007-06-07 12:24:29 +00:00
|
|
|
#endif
|
|
|
|
system(plistRmCommand);
|
|
|
|
err = LSRegisterFSRef(&theFSRef, true);
|
|
|
|
#if TESTING
|
|
|
|
if (err)
|
2014-01-21 12:20:53 +00:00
|
|
|
ShowMessage(false, false, false, "LSRegisterFSRef returned error %d", err);
|
2007-06-07 12:24:29 +00:00
|
|
|
#endif
|
|
|
|
system(myRmCommand);
|
|
|
|
}
|
|
|
|
}
|
2012-05-03 11:33:03 +00:00
|
|
|
#endif
|
2007-06-07 12:24:29 +00:00
|
|
|
|
|
|
|
// Phase 2: step through default Applications directory searching for our applications
|
|
|
|
err = DeleteOurBundlesFromDirectory(CFSTR("edu.berkeley.boinc"), "app", "/Applications");
|
|
|
|
|
|
|
|
// Phase 3: step through default Screen Savers directory searching for our screen savers
|
|
|
|
err = DeleteOurBundlesFromDirectory(CFSTR("edu.berkeley.boincsaver"), "saver", "/Library/Screen Savers");
|
|
|
|
|
|
|
|
// Phase 4: Delete our files and directories at our installer's default locations
|
2011-08-11 10:20:25 +00:00
|
|
|
// Remove everything we've installed, whether BOINC, GridRepublic, Progress Thru Processors or
|
|
|
|
// Charity Engine
|
2014-03-07 12:28:32 +00:00
|
|
|
|
|
|
|
//TODO: It would be nice to get the app name from the bundle ID or signature
|
|
|
|
// so we don't have to try all 4 and to allow for future branded versions
|
|
|
|
|
2007-06-07 12:24:29 +00:00
|
|
|
// These first 4 should already have been deleted by the above code, but do them anyway for safety
|
2007-06-06 12:52:37 +00:00
|
|
|
system ("rm -rf /Applications/BOINCManager.app");
|
|
|
|
system ("rm -rf \"/Library/Screen Savers/BOINCSaver.saver\"");
|
|
|
|
|
|
|
|
system ("rm -rf \"/Applications/GridRepublic Desktop.app\"");
|
|
|
|
system ("rm -rf \"/Library/Screen Savers/GridRepublic.saver\"");
|
2009-06-10 10:49:46 +00:00
|
|
|
|
2014-03-07 12:28:32 +00:00
|
|
|
system ("rm -rf \"/Applications/Progress Thru Processors Desktop.app\"");
|
|
|
|
system ("rm -rf \"/Library/Screen Savers/Progress Thru Processors.saver\"");
|
2011-08-11 10:20:25 +00:00
|
|
|
|
2014-03-07 12:28:32 +00:00
|
|
|
system ("rm -rf \"/Applications/Charity Engine Desktop.app\"");
|
|
|
|
system ("rm -rf \"/Library/Screen Savers/Charity Engine.saver\"");
|
2011-08-11 10:20:25 +00:00
|
|
|
|
2011-02-15 11:02:40 +00:00
|
|
|
// Delete any receipt from an older installer (which had
|
|
|
|
// a wrapper application around the installer package.)
|
2007-06-06 12:52:37 +00:00
|
|
|
system ("rm -rf /Library/Receipts/GridRepublic.pkg");
|
2009-06-11 01:57:35 +00:00
|
|
|
system ("rm -rf /Library/Receipts/Progress\\ Thru\\ Processors.pkg");
|
2011-08-11 10:20:25 +00:00
|
|
|
system ("rm -rf /Library/Receipts/Charity\\ Engine.pkg");
|
2007-06-07 12:24:29 +00:00
|
|
|
system ("rm -rf /Library/Receipts/BOINC.pkg");
|
2007-06-06 12:52:37 +00:00
|
|
|
|
2011-02-15 11:02:40 +00:00
|
|
|
// 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");
|
2011-08-11 10:20:25 +00:00
|
|
|
system ("rm -rf /Library/Receipts/Charity\\ Engine\\ Installer.pkg");
|
2011-02-15 11:02:40 +00:00
|
|
|
system ("rm -rf /Library/Receipts/BOINC\\ Installer.pkg");
|
|
|
|
|
2009-11-19 10:41:47 +00:00
|
|
|
// Phase 5: Set BOINC Data owner and group to logged in user
|
2007-06-06 12:52:37 +00:00
|
|
|
// We don't customize BOINC Data directory name for branding
|
2009-06-13 00:54:29 +00:00
|
|
|
// system ("rm -rf \"/Library/Application Support/BOINC Data\"");
|
2009-11-19 10:41:47 +00:00
|
|
|
p = getlogin();
|
|
|
|
pw = getpwnam(p);
|
|
|
|
sprintf(cmd, "chown -R %d:%d \"/Library/Application Support/BOINC Data\"", pw->pw_uid, pw->pw_gid);
|
|
|
|
system (cmd);
|
|
|
|
system("chmod -R u+rw-s,g+r-w-s,o+r-w \"/Library/Application Support/BOINC Data\"");
|
|
|
|
system("chmod 600 \"/Library/Application Support/BOINC Data/gui_rpc_auth.cfg\"");
|
|
|
|
|
|
|
|
// Phase 6: step through all users and do user-specific cleanup
|
2007-06-06 12:52:37 +00:00
|
|
|
CleanupAllVisibleUsers();
|
|
|
|
|
|
|
|
system ("dscl . -delete /users/boinc_master");
|
|
|
|
system ("dscl . -delete /groups/boinc_master");
|
|
|
|
system ("dscl . -delete /users/boinc_project");
|
|
|
|
system ("dscl . -delete /groups/boinc_project");
|
2009-11-19 10:41:47 +00:00
|
|
|
|
|
|
|
|
2007-10-25 09:34:16 +00:00
|
|
|
return 0;
|
2007-06-07 12:24:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static OSStatus DeleteOurBundlesFromDirectory(CFStringRef bundleID, char *extension, char *dirPath) {
|
|
|
|
DIR *dirp;
|
|
|
|
dirent *dp;
|
|
|
|
CFStringRef urlStringRef = NULL;
|
|
|
|
int index;
|
|
|
|
CFStringRef thisID = NULL;
|
|
|
|
CFBundleRef thisBundle = NULL;
|
|
|
|
CFURLRef bundleURLRef = NULL;
|
|
|
|
char myRmCommand[MAXPATHLEN+10], *p;
|
|
|
|
int pathOffset;
|
|
|
|
|
|
|
|
dirp = opendir(dirPath);
|
|
|
|
if (dirp == NULL) { // Should never happen
|
2014-01-21 12:20:53 +00:00
|
|
|
ShowMessage(false, false, false, "Error: opendir(\"%s\") failed", dirPath);
|
2007-06-07 12:24:29 +00:00
|
|
|
return -1;
|
|
|
|
}
|
2007-06-06 12:52:37 +00:00
|
|
|
|
2007-06-07 12:24:29 +00:00
|
|
|
index = -1;
|
|
|
|
while (true) {
|
|
|
|
index++;
|
|
|
|
|
|
|
|
dp = readdir(dirp);
|
|
|
|
if (dp == NULL)
|
|
|
|
break; // End of list
|
|
|
|
|
|
|
|
p = strrchr(dp->d_name, '.');
|
|
|
|
if (p == NULL)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (strcmp(p+1, extension))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
strlcpy(myRmCommand, "rm -rf \"", 10);
|
|
|
|
pathOffset = strlen(myRmCommand);
|
|
|
|
strlcat(myRmCommand, dirPath, sizeof(myRmCommand));
|
|
|
|
strlcat(myRmCommand, "/", sizeof(myRmCommand));
|
|
|
|
strlcat(myRmCommand, dp->d_name, sizeof(myRmCommand));
|
|
|
|
urlStringRef = CFStringCreateWithCString(kCFAllocatorDefault, myRmCommand+pathOffset, CFStringGetSystemEncoding());
|
|
|
|
if (urlStringRef) {
|
|
|
|
bundleURLRef = CFURLCreateWithFileSystemPath(kCFAllocatorDefault, urlStringRef, kCFURLPOSIXPathStyle, false);
|
|
|
|
if (bundleURLRef) {
|
|
|
|
thisBundle = CFBundleCreate( kCFAllocatorDefault, bundleURLRef );
|
|
|
|
if (thisBundle) {
|
|
|
|
thisID = CFBundleGetIdentifier(thisBundle);
|
|
|
|
if (thisID) {
|
|
|
|
strlcat(myRmCommand, "\"", sizeof(myRmCommand));
|
|
|
|
if (CFStringCompare(thisID, bundleID, 0) == kCFCompareEqualTo) {
|
|
|
|
#if TESTING
|
2014-01-21 12:20:53 +00:00
|
|
|
ShowMessage(false, false, false, "Bundles: %s", myRmCommand);
|
2007-06-07 12:24:29 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
system(myRmCommand);
|
|
|
|
} else {
|
|
|
|
#if TESTING
|
2014-01-21 12:20:53 +00:00
|
|
|
// ShowMessage(false, false, false, "Bundles: Not deleting %s", myRmCommand+pathOffset);
|
2007-06-07 12:24:29 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
} // if (thisID)
|
|
|
|
#if TESTING
|
|
|
|
else
|
2014-01-21 12:20:53 +00:00
|
|
|
ShowMessage(false, false, false, "CFBundleGetIdentifier failed for index %d", index);
|
2007-06-07 12:24:29 +00:00
|
|
|
#endif
|
|
|
|
CFRelease(thisBundle);
|
|
|
|
} //if (thisBundle)
|
|
|
|
#if TESTING
|
|
|
|
else
|
2014-01-21 12:20:53 +00:00
|
|
|
ShowMessage(false, false, false, "CFBundleCreate failed for index %d", index);
|
2007-06-07 12:24:29 +00:00
|
|
|
#endif
|
|
|
|
CFRelease(bundleURLRef);
|
|
|
|
} // if (bundleURLRef)
|
|
|
|
#if TESTING
|
|
|
|
else
|
2014-01-21 12:20:53 +00:00
|
|
|
ShowMessage(false, false, false, "CFURLCreateWithFileSystemPath failed");
|
2007-06-07 12:24:29 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
CFRelease(urlStringRef);
|
|
|
|
} // if (urlStringRef)
|
|
|
|
#if TESTING
|
|
|
|
else
|
2014-01-21 12:20:53 +00:00
|
|
|
ShowMessage(false, false, false, "CFStringCreateWithCString failed");
|
2007-06-07 12:24:29 +00:00
|
|
|
#endif
|
|
|
|
} // while true
|
2007-06-06 12:52:37 +00:00
|
|
|
|
2007-06-07 12:24:29 +00:00
|
|
|
closedir(dirp);
|
|
|
|
|
|
|
|
return noErr;
|
2007-06-06 12:52:37 +00:00
|
|
|
}
|
|
|
|
|
2007-06-07 12:24:29 +00:00
|
|
|
|
2012-05-03 11:33:03 +00:00
|
|
|
enum {
|
|
|
|
kSystemEventsCreator = 'sevs'
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2007-06-06 12:52:37 +00:00
|
|
|
// Find all visible users and delete their login item to launch BOINC Manager.
|
|
|
|
// Remove each user from groups boinc_master and boinc_project.
|
2009-06-13 00:54:29 +00:00
|
|
|
// For now, don't delete user's BOINC Preferences file.
|
2007-06-07 12:24:29 +00:00
|
|
|
static OSStatus CleanupAllVisibleUsers(void)
|
2007-06-06 12:52:37 +00:00
|
|
|
{
|
|
|
|
passwd *pw;
|
2012-03-29 09:42:32 +00:00
|
|
|
vector<string> human_user_names;
|
|
|
|
vector<uid_t> human_user_IDs;
|
2009-12-16 12:50:40 +00:00
|
|
|
uid_t saved_uid, saved_euid;
|
2012-03-29 09:42:32 +00:00
|
|
|
char human_user_name[256];
|
2012-05-06 08:22:37 +00:00
|
|
|
int i;
|
2012-03-29 09:42:32 +00:00
|
|
|
int userIndex;
|
|
|
|
int flag;
|
|
|
|
char buf[256];
|
2007-06-06 12:52:37 +00:00
|
|
|
char s[1024];
|
2012-05-03 11:33:03 +00:00
|
|
|
char cmd[2048];
|
|
|
|
char systemEventsPath[1024];
|
|
|
|
ProcessSerialNumber SystemEventsPSN;
|
|
|
|
FSRef appRef;
|
2007-06-06 12:52:37 +00:00
|
|
|
FILE *f;
|
2012-03-29 09:42:32 +00:00
|
|
|
char *p;
|
|
|
|
int id;
|
2009-12-16 12:50:40 +00:00
|
|
|
OSStatus err;
|
2007-06-06 12:52:37 +00:00
|
|
|
Boolean changeSaver;
|
|
|
|
|
2009-12-16 12:50:40 +00:00
|
|
|
saved_uid = getuid();
|
|
|
|
saved_euid = geteuid();
|
|
|
|
|
2012-03-29 09:42:32 +00:00
|
|
|
// First, find all users on system
|
|
|
|
f = popen("dscl . list /Users UniqueID", "r");
|
|
|
|
if (f) {
|
|
|
|
while (PersistentFGets(buf, sizeof(buf), f)) {
|
|
|
|
p = strrchr(buf, ' ');
|
|
|
|
if (p) {
|
|
|
|
id = atoi(p+1);
|
|
|
|
if (id < 501) {
|
|
|
|
#if TESTING
|
|
|
|
// printf("skipping user ID %d\n", id);
|
|
|
|
// fflush(stdout);
|
|
|
|
#endif
|
|
|
|
continue;
|
|
|
|
}
|
2012-08-15 07:11:08 +00:00
|
|
|
|
|
|
|
while (p > buf) {
|
|
|
|
if (*p != ' ') break;
|
|
|
|
--p;
|
|
|
|
}
|
|
|
|
|
|
|
|
*(p+1) = '\0';
|
2012-03-29 09:42:32 +00:00
|
|
|
human_user_names.push_back(string(buf));
|
|
|
|
human_user_IDs.push_back((uid_t)id);
|
|
|
|
#if TESTING
|
2014-01-21 12:20:53 +00:00
|
|
|
ShowMessage(false, false, false, "user ID %d: %s\n", id, buf);
|
2012-03-29 09:42:32 +00:00
|
|
|
#endif
|
2012-08-15 07:11:08 +00:00
|
|
|
*(p+1) = ' ';
|
2012-03-29 09:42:32 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
pclose(f);
|
|
|
|
}
|
2007-06-06 12:52:37 +00:00
|
|
|
|
2012-03-29 09:42:32 +00:00
|
|
|
for (userIndex=human_user_names.size(); userIndex>0; --userIndex) {
|
|
|
|
flag = 0;
|
|
|
|
strlcpy(human_user_name, human_user_names[userIndex-1].c_str(), sizeof(human_user_name));
|
|
|
|
|
|
|
|
// Check whether this user is a login (human) user
|
2012-08-15 07:11:08 +00:00
|
|
|
sprintf(s, "dscl . -read \"/Users/%s\" NFSHomeDirectory", human_user_name);
|
2012-03-29 09:42:32 +00:00
|
|
|
f = popen(s, "r");
|
|
|
|
if (f) {
|
|
|
|
while (PersistentFGets(buf, sizeof(buf), f)) {
|
|
|
|
p = strrchr(buf, ' ');
|
|
|
|
if (p) {
|
2012-08-15 07:11:08 +00:00
|
|
|
if (strstr(p, "/var/empty") != NULL) flag = 1;
|
2012-03-29 09:42:32 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
pclose(f);
|
|
|
|
}
|
|
|
|
|
2012-08-15 07:11:08 +00:00
|
|
|
sprintf(s, "dscl . -read \"/Users/%s\" UserShell", human_user_name);
|
2012-03-29 09:42:32 +00:00
|
|
|
f = popen(s, "r");
|
|
|
|
if (f) {
|
|
|
|
while (PersistentFGets(buf, sizeof(buf), f)) {
|
|
|
|
p = strrchr(buf, ' ');
|
|
|
|
if (p) {
|
2012-08-15 07:11:08 +00:00
|
|
|
if (strstr(p, "/usr/bin/false") != NULL) flag |= 2;
|
2012-03-29 09:42:32 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
pclose(f);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Skip all non-human (non-login) users
|
|
|
|
if (flag == 3) { // if (Home Directory == "/var/empty") && (UserShell == "/usr/bin/false")
|
|
|
|
#if TESTING
|
2014-01-21 12:20:53 +00:00
|
|
|
ShowMessage(false, false, false, "Flag=3: skipping user ID %d: %s", human_user_IDs[userIndex-1], buf);
|
2012-03-29 09:42:32 +00:00
|
|
|
#endif
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
pw = getpwnam(human_user_name);
|
2012-08-15 07:11:08 +00:00
|
|
|
if (pw == NULL)
|
2007-06-06 12:52:37 +00:00
|
|
|
continue;
|
|
|
|
|
2012-03-29 09:42:32 +00:00
|
|
|
#if TESTING
|
2014-01-21 12:20:53 +00:00
|
|
|
ShowMessage(false, false, false, "Deleting login item for user %s: Posix name=%s, Full name=%s, UID=%d",
|
2012-03-29 09:42:32 +00:00
|
|
|
human_user_name, pw->pw_name, pw->pw_gecos, pw->pw_uid);
|
|
|
|
#endif
|
|
|
|
|
2007-06-06 12:52:37 +00:00
|
|
|
// Remove user from groups boinc_master and boinc_project
|
2012-08-15 07:11:08 +00:00
|
|
|
sprintf(s, "dscl . -delete /groups/boinc_master users \"%s\"", human_user_name);
|
2007-06-06 12:52:37 +00:00
|
|
|
system (s);
|
|
|
|
|
2012-08-15 07:11:08 +00:00
|
|
|
sprintf(s, "dscl . -delete /groups/boinc_project users \"%s\"", human_user_name);
|
2007-06-06 12:52:37 +00:00
|
|
|
system (s);
|
|
|
|
|
|
|
|
#if TESTING
|
2014-01-21 12:20:53 +00:00
|
|
|
// ShowMessage(false, false, false, "Before seteuid(%d) for user %s, euid = %d", pw->pw_uid, human_user_name, geteuid());
|
2007-06-06 12:52:37 +00:00
|
|
|
#endif
|
2014-02-25 15:44:13 +00:00
|
|
|
setuid(0);
|
2011-08-11 10:20:25 +00:00
|
|
|
// Delete our login item(s) for this user
|
2014-02-25 15:44:13 +00:00
|
|
|
if (compareOSVersionTo(10, 8) >= 0) {
|
2012-06-18 11:11:44 +00:00
|
|
|
seteuid(pw->pw_uid); // Temporarily set effective uid to this user
|
|
|
|
DeleteLoginItemFromPListFile();
|
|
|
|
seteuid(saved_euid); // Set effective uid back to privileged user
|
|
|
|
} else { // OS 10.7.x
|
2012-05-03 11:33:03 +00:00
|
|
|
// We must leave effective user ID as privileged user (root)
|
|
|
|
// because the target user may not be in the sudoers file.
|
|
|
|
|
|
|
|
// We must launch the System Events application for the target user
|
|
|
|
|
2012-05-06 08:22:37 +00:00
|
|
|
#if TESTING
|
2014-01-21 12:20:53 +00:00
|
|
|
ShowMessage(false, false, false, "Telling System Events to quit (before DeleteLoginItemOSAScript)");
|
2012-05-06 08:22:37 +00:00
|
|
|
#endif
|
2012-05-03 11:33:03 +00:00
|
|
|
// Find SystemEvents process. If found, quit it in case
|
|
|
|
// it is running under a different user.
|
2012-05-06 08:22:37 +00:00
|
|
|
err = QuitOneProcess(kSystemEventsCreator);
|
2012-05-03 11:33:03 +00:00
|
|
|
#if TESTING
|
2012-05-06 08:22:37 +00:00
|
|
|
if (err != noErr) {
|
2014-01-21 12:20:53 +00:00
|
|
|
ShowMessage(false, false, false, "QuitOneProcess(kSystemEventsCreator) returned error %d ", (int) err);
|
2012-05-06 08:22:37 +00:00
|
|
|
}
|
2012-05-03 11:33:03 +00:00
|
|
|
#endif
|
2012-05-06 08:22:37 +00:00
|
|
|
// Wait for the process to be gone
|
|
|
|
for (i=0; i<50; ++i) { // 5 seconds max delay
|
|
|
|
SleepTicks(6); // 6 Ticks == 1/10 second
|
|
|
|
err = FindProcess ('APPL', kSystemEventsCreator, &SystemEventsPSN);
|
|
|
|
if (err != noErr) break;
|
|
|
|
}
|
2012-05-03 11:33:03 +00:00
|
|
|
#if TESTING
|
2012-06-16 15:03:11 +00:00
|
|
|
if (i >= 50) {
|
2014-01-21 12:20:53 +00:00
|
|
|
ShowMessage(false, false, false, "Failed to make System Events quit");
|
2012-05-03 11:33:03 +00:00
|
|
|
}
|
2012-05-06 08:22:37 +00:00
|
|
|
#endif
|
2012-06-16 15:03:11 +00:00
|
|
|
sleep(2);
|
2012-05-03 11:33:03 +00:00
|
|
|
|
|
|
|
err = LSFindApplicationForInfo(kSystemEventsCreator, NULL, NULL, &appRef, NULL);
|
|
|
|
if (err != noErr) {
|
|
|
|
#if TESTING
|
2014-01-21 12:20:53 +00:00
|
|
|
ShowMessage(false, false, false, "LSFindApplicationForInfo(kSystemEventsCreator) returned error %d ", (int) err);
|
2012-05-03 11:33:03 +00:00
|
|
|
#endif
|
|
|
|
} else {
|
|
|
|
FSRefMakePath(&appRef, (UInt8*)systemEventsPath, sizeof(systemEventsPath));
|
2012-06-16 15:03:11 +00:00
|
|
|
#if TESTING
|
2014-01-21 12:20:53 +00:00
|
|
|
ShowMessage(false, false, false, "SystemEvents is at %s", systemEventsPath);
|
|
|
|
ShowMessage(false, false, false, "Launching SystemEvents for user %s", pw->pw_name);
|
2012-05-03 11:33:03 +00:00
|
|
|
#endif
|
|
|
|
|
2014-02-25 15:44:13 +00:00
|
|
|
sprintf(cmd, "sudo -u \"%s\" \"%s/Contents/MacOS/System Events\" &", pw->pw_name, systemEventsPath);
|
2012-05-03 11:33:03 +00:00
|
|
|
err = system(cmd);
|
2012-06-16 15:03:11 +00:00
|
|
|
if (err == noErr) {
|
|
|
|
// Wait for the process to start
|
|
|
|
for (i=0; i<50; ++i) { // 5 seconds max delay
|
|
|
|
SleepTicks(6); // 6 Ticks == 1/10 second
|
|
|
|
err = FindProcess ('APPL', kSystemEventsCreator, &SystemEventsPSN);
|
|
|
|
if (err == noErr) break;
|
|
|
|
}
|
2012-05-03 11:33:03 +00:00
|
|
|
#if TESTING
|
2012-06-16 15:03:11 +00:00
|
|
|
if (i >= 50) {
|
2014-01-21 12:20:53 +00:00
|
|
|
ShowMessage(false, false, false, "Failed to launch System Events for user %s", pw->pw_name);
|
2012-06-16 15:03:11 +00:00
|
|
|
}
|
2012-05-06 08:22:37 +00:00
|
|
|
#endif
|
2012-06-16 15:03:11 +00:00
|
|
|
sleep(2);
|
|
|
|
|
|
|
|
DeleteLoginItemOSAScript(pw->pw_name, "BOINCManager");
|
|
|
|
DeleteLoginItemOSAScript(pw->pw_name, "GridRepublic Desktop");
|
|
|
|
DeleteLoginItemOSAScript(pw->pw_name, "Progress Thru Processors Desktop");
|
|
|
|
DeleteLoginItemOSAScript(pw->pw_name, "Charity Engine Desktop");
|
2012-05-06 08:22:37 +00:00
|
|
|
#if TESTING
|
2012-06-16 15:03:11 +00:00
|
|
|
} else {
|
2014-01-21 12:20:53 +00:00
|
|
|
ShowMessage(false, false, false, "[2] Command: %s returned error %d", cmd, (int) err);
|
2012-05-03 11:33:03 +00:00
|
|
|
#endif
|
2012-06-16 15:03:11 +00:00
|
|
|
}
|
2012-05-03 11:33:03 +00:00
|
|
|
}
|
2011-09-24 12:43:19 +00:00
|
|
|
}
|
2012-05-03 11:33:03 +00:00
|
|
|
|
|
|
|
// We don't delete the user's BOINC Manager preferences
|
2012-03-29 09:42:32 +00:00
|
|
|
// sprintf(s, "rm -f \"/Users/%s/Library/Preferences/BOINC Manager Preferences\"", human_user_name);
|
2009-06-13 00:54:29 +00:00
|
|
|
// system (s);
|
2007-06-06 12:52:37 +00:00
|
|
|
|
2014-03-07 12:28:32 +00:00
|
|
|
// Delete per-user BOINC Manager and screensaver files
|
|
|
|
sprintf(s, "rm -fR \"/Users/%s/Library/Application Support/BOINC\"", human_user_name);
|
|
|
|
system (s);
|
|
|
|
|
2009-06-10 10:49:46 +00:00
|
|
|
// Set screensaver to "Computer Name" default screensaver only
|
2011-08-11 10:20:25 +00:00
|
|
|
// if it was BOINC, GridRepublic, Progress Thru Processors or Charity Engine.
|
2007-06-06 12:52:37 +00:00
|
|
|
changeSaver = false;
|
2012-06-16 15:03:11 +00:00
|
|
|
seteuid(pw->pw_uid); // Temporarily set effective uid to this user
|
2013-11-15 13:02:04 +00:00
|
|
|
if (compareOSVersionTo(10, 6) < 0) {
|
2009-12-16 12:50:40 +00:00
|
|
|
f = popen("defaults -currentHost read com.apple.screensaver moduleName", "r");
|
2012-06-16 15:03:11 +00:00
|
|
|
if (f) {
|
|
|
|
while (PersistentFGets(s, sizeof(s), f)) {
|
|
|
|
if (strstr(s, "BOINCSaver")) {
|
|
|
|
changeSaver = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (strstr(s, "GridRepublic")) {
|
|
|
|
changeSaver = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (strstr(s, "Progress Thru Processors")) {
|
|
|
|
changeSaver = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (strstr(s, "Charity Engine")) {
|
|
|
|
changeSaver = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
pclose(f);
|
|
|
|
}
|
2009-12-16 12:50:40 +00:00
|
|
|
} else {
|
2012-06-16 15:03:11 +00:00
|
|
|
err = GetCurrentScreenSaverSelection(s, sizeof(s) -1);
|
|
|
|
if (err == noErr) {
|
2009-12-16 12:50:40 +00:00
|
|
|
if (strstr(s, "BOINCSaver")) {
|
|
|
|
changeSaver = true;
|
|
|
|
}
|
|
|
|
if (strstr(s, "GridRepublic")) {
|
|
|
|
changeSaver = true;
|
|
|
|
}
|
|
|
|
if (strstr(s, "Progress Thru Processors")) {
|
|
|
|
changeSaver = true;
|
|
|
|
}
|
2011-08-11 10:20:25 +00:00
|
|
|
if (strstr(s, "Charity Engine")) {
|
|
|
|
changeSaver = true;
|
|
|
|
}
|
2009-12-16 12:50:40 +00:00
|
|
|
}
|
2007-06-06 12:52:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (changeSaver) {
|
2013-11-15 13:02:04 +00:00
|
|
|
if (compareOSVersionTo(10, 6) < 0) {
|
2009-12-16 12:50:40 +00:00
|
|
|
system ("defaults -currentHost write com.apple.screensaver moduleName \"Computer Name\"");
|
|
|
|
system ("defaults -currentHost write com.apple.screensaver modulePath \"/System/Library/Frameworks/ScreenSaver.framework/Versions/A/Resources/Computer Name.saver\"");
|
|
|
|
} else {
|
2012-06-16 15:03:11 +00:00
|
|
|
err = SetScreenSaverSelection("Computer Name",
|
|
|
|
"/System/Library/Frameworks/ScreenSaver.framework/Versions/A/Resources/Computer Name.saver", 0);
|
2009-12-16 12:50:40 +00:00
|
|
|
}
|
2007-06-06 12:52:37 +00:00
|
|
|
}
|
2012-05-03 11:33:03 +00:00
|
|
|
|
2012-06-16 15:03:11 +00:00
|
|
|
seteuid(saved_euid); // Set effective uid back to privileged user
|
2007-06-06 12:52:37 +00:00
|
|
|
|
|
|
|
#if TESTING
|
2014-01-21 12:20:53 +00:00
|
|
|
// ShowMessage(false, false, false, "After seteuid(%d) for user %s, euid = %d, saved_uid = %d", pw->pw_uid, human_user_name, geteuid(), saved_uid);
|
2007-06-06 12:52:37 +00:00
|
|
|
#endif
|
2012-06-16 15:03:11 +00:00
|
|
|
} // End userIndex loop
|
|
|
|
|
|
|
|
sleep(1);
|
2007-06-06 12:52:37 +00:00
|
|
|
|
2013-11-15 13:02:04 +00:00
|
|
|
if (compareOSVersionTo(10, 7) >= 0) {
|
2012-05-03 11:33:03 +00:00
|
|
|
#if TESTING
|
2014-01-21 12:20:53 +00:00
|
|
|
ShowMessage(false, false, false, "Telling System Events to quit (at end)");
|
2012-05-03 11:33:03 +00:00
|
|
|
#endif
|
|
|
|
err = QuitOneProcess(kSystemEventsCreator);
|
|
|
|
#if TESTING
|
|
|
|
if (err != noErr) {
|
2014-01-21 12:20:53 +00:00
|
|
|
ShowMessage(false, false, false, "QuitOneProcess(kSystemEventsCreator) returned error %d ", (int) err);
|
2012-05-03 11:33:03 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2007-06-06 12:52:37 +00:00
|
|
|
return noErr;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static OSStatus GetAuthorization(AuthorizationRef * authRef, const char *pathToTool, char *brandName) {
|
|
|
|
static Boolean sIsAuthorized = false;
|
|
|
|
AuthorizationRights ourAuthRights;
|
|
|
|
AuthorizationFlags ourAuthFlags;
|
|
|
|
AuthorizationItem ourAuthRightsItem[1];
|
|
|
|
AuthorizationEnvironment ourAuthEnvironment;
|
|
|
|
AuthorizationItem ourAuthEnvItem[1];
|
|
|
|
char prompt[256];
|
|
|
|
OSStatus err = noErr;
|
|
|
|
|
|
|
|
if (sIsAuthorized)
|
|
|
|
return noErr;
|
|
|
|
|
2013-06-18 11:03:24 +00:00
|
|
|
sprintf(prompt, (char *)_("Enter your administrator password to completely remove %s from you computer.\n\n"), brandName);
|
2007-06-06 12:52:37 +00:00
|
|
|
|
|
|
|
ourAuthRights.count = 0;
|
|
|
|
ourAuthRights.items = NULL;
|
|
|
|
|
|
|
|
err = AuthorizationCreate (&ourAuthRights, kAuthorizationEmptyEnvironment, kAuthorizationFlagDefaults, authRef);
|
|
|
|
if (err != noErr) {
|
2014-01-21 12:20:53 +00:00
|
|
|
ShowMessage(false, false, false, "AuthorizationCreate returned error %d", err);
|
2007-06-06 12:52:37 +00:00
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
ourAuthRightsItem[0].name = kAuthorizationRightExecute;
|
|
|
|
ourAuthRightsItem[0].value = (void *)pathToTool;
|
|
|
|
ourAuthRightsItem[0].valueLength = strlen (pathToTool);
|
|
|
|
ourAuthRightsItem[0].flags = 0;
|
|
|
|
ourAuthRights.count = 1;
|
|
|
|
ourAuthRights.items = ourAuthRightsItem;
|
|
|
|
|
|
|
|
ourAuthEnvItem[0].name = kAuthorizationEnvironmentPrompt;
|
|
|
|
ourAuthEnvItem[0].value = prompt;
|
|
|
|
ourAuthEnvItem[0].valueLength = strlen (prompt);
|
|
|
|
ourAuthEnvItem[0].flags = 0;
|
|
|
|
|
|
|
|
ourAuthEnvironment.count = 1;
|
|
|
|
ourAuthEnvironment.items = ourAuthEnvItem;
|
|
|
|
|
|
|
|
|
|
|
|
ourAuthFlags = kAuthorizationFlagInteractionAllowed | kAuthorizationFlagExtendRights;
|
|
|
|
|
|
|
|
// When this is called from the installer, the installer has already authenticated.
|
|
|
|
// In that case we are already running with full root privileges so AuthorizationCopyRights()
|
|
|
|
// does not request a password from the user again.
|
|
|
|
err = AuthorizationCopyRights (*authRef, &ourAuthRights, &ourAuthEnvironment, ourAuthFlags, NULL);
|
|
|
|
|
|
|
|
if (err == noErr)
|
|
|
|
sIsAuthorized = true;
|
|
|
|
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static OSStatus DoPrivilegedExec(char *brandName, const char *pathToTool, char *arg1, char *arg2, char *arg3, char *arg4, char *arg5) {
|
|
|
|
AuthorizationRef authRef = NULL;
|
|
|
|
short i;
|
|
|
|
char *args[8];
|
|
|
|
OSStatus err;
|
|
|
|
FILE *ioPipe;
|
|
|
|
char *p, junk[256];
|
|
|
|
|
|
|
|
err = GetAuthorization(&authRef, pathToTool, brandName);
|
|
|
|
if (err != noErr) {
|
|
|
|
if (err != errAuthorizationCanceled)
|
2014-01-21 12:20:53 +00:00
|
|
|
ShowMessage(false, false, false, "GetAuthorization returned error %d", err);
|
2007-06-06 12:52:37 +00:00
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i=0; i<5; i++) { // Retry 5 times if error
|
|
|
|
args[0] = arg1;
|
|
|
|
args[1] = arg2;
|
|
|
|
args[2] = arg3;
|
|
|
|
args[3] = arg4;
|
|
|
|
args[4] = arg5;
|
|
|
|
args[5] = NULL;
|
|
|
|
|
|
|
|
err = AuthorizationExecuteWithPrivileges (authRef, pathToTool, 0, args, &ioPipe);
|
|
|
|
// We use the pipe to signal us when the command has completed
|
|
|
|
if (ioPipe) {
|
|
|
|
do {
|
|
|
|
p = fgets(junk, sizeof(junk), ioPipe);
|
2015-08-14 13:20:49 +00:00
|
|
|
// On some older versions of OS X, the pipe does not send EOF when our tool exits
|
|
|
|
if (!strcmp(p, "Done\n")) break;
|
2007-06-06 12:52:37 +00:00
|
|
|
} while (p);
|
|
|
|
|
|
|
|
fclose (ioPipe);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (err == noErr)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (err != noErr)
|
2014-01-21 12:20:53 +00:00
|
|
|
ShowMessage(false, false, false, "\"%s %s %s %s %s %s\" returned error %d", pathToTool,
|
2007-06-06 12:52:37 +00:00
|
|
|
arg1 ? arg1 : "", arg2 ? arg2 : "", arg3 ? arg3 : "",
|
|
|
|
arg4 ? arg4 : "", arg5 ? arg5 : "", err);
|
|
|
|
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-02-25 15:44:13 +00:00
|
|
|
// Used for OS <= 10.7
|
2011-09-24 12:43:19 +00:00
|
|
|
static void DeleteLoginItemOSAScript(char* user, char* appName)
|
2007-06-06 12:52:37 +00:00
|
|
|
{
|
2011-08-11 10:20:25 +00:00
|
|
|
char cmd[2048];
|
|
|
|
OSErr err;
|
2007-06-06 12:52:37 +00:00
|
|
|
|
2012-06-16 15:03:11 +00:00
|
|
|
sprintf(cmd, "sudo -u \"%s\" osascript -e 'tell application \"System Events\"' -e 'delete (every login item whose name contains \"%s\")' -e 'end tell'", user, appName);
|
2011-08-11 10:20:25 +00:00
|
|
|
err = system(cmd);
|
2012-05-03 11:33:03 +00:00
|
|
|
#if TESTING
|
2011-08-11 10:20:25 +00:00
|
|
|
if (err) {
|
2014-01-21 12:20:53 +00:00
|
|
|
ShowMessage(false, false, false, "Command: %s returned error %d", cmd, err);
|
2007-06-06 12:52:37 +00:00
|
|
|
}
|
2012-05-03 11:33:03 +00:00
|
|
|
#endif
|
2007-06-06 12:52:37 +00:00
|
|
|
}
|
2011-09-24 12:43:19 +00:00
|
|
|
|
2012-06-18 11:11:44 +00:00
|
|
|
|
2014-02-25 15:44:13 +00:00
|
|
|
// Used for OS >= 10.8
|
2012-06-18 11:11:44 +00:00
|
|
|
static void DeleteLoginItemFromPListFile(void)
|
|
|
|
{
|
|
|
|
Boolean success;
|
|
|
|
int numberOfLoginItems, counter;
|
|
|
|
char theName[256], *q;
|
|
|
|
|
|
|
|
success = false;
|
|
|
|
|
|
|
|
numberOfLoginItems = GetCountOfLoginItemsFromPlistFile();
|
|
|
|
|
|
|
|
// Search existing login items in reverse order, deleting ours
|
|
|
|
for (counter = numberOfLoginItems ; counter > 0 ; counter--)
|
|
|
|
{
|
|
|
|
GetLoginItemNameAtIndexFromPlistFile(counter-1, theName, sizeof(theName));
|
|
|
|
q = theName;
|
|
|
|
while (*q)
|
|
|
|
{
|
|
|
|
// It is OK to modify the returned string because we "own" it
|
|
|
|
*q = toupper(*q); // Make it case-insensitive
|
|
|
|
q++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (strstr(theName, "BOINCMANAGER"))
|
|
|
|
success = DeleteLoginItemNameAtIndexFromPlistFile(counter-1);
|
|
|
|
if (strstr(theName, "GRIDREPUBLIC DESKTOP"))
|
|
|
|
success = DeleteLoginItemNameAtIndexFromPlistFile(counter-1);
|
|
|
|
if (strstr(theName, "PROGRESS THRU PROCESSORS DESKTOP"))
|
|
|
|
success = DeleteLoginItemNameAtIndexFromPlistFile(counter-1);
|
|
|
|
if (strstr(theName, "CHARITY ENGINE DESKTOP"))
|
|
|
|
success = DeleteLoginItemNameAtIndexFromPlistFile(counter-1);
|
2011-09-24 12:43:19 +00:00
|
|
|
}
|
|
|
|
}
|
2007-06-06 12:52:37 +00:00
|
|
|
|
|
|
|
|
|
|
|
static char * PersistentFGets(char *buf, size_t buflen, FILE *f) {
|
|
|
|
char *p = buf;
|
|
|
|
size_t len = buflen;
|
|
|
|
size_t datalen = 0;
|
|
|
|
|
|
|
|
*buf = '\0';
|
|
|
|
while (datalen < (buflen - 1)) {
|
|
|
|
fgets(p, len, f);
|
|
|
|
if (feof(f)) break;
|
|
|
|
if (ferror(f) && (errno != EINTR)) break;
|
|
|
|
if (strchr(buf, '\n')) break;
|
|
|
|
datalen = strlen(buf);
|
|
|
|
p = buf + datalen;
|
|
|
|
len -= datalen;
|
|
|
|
}
|
|
|
|
return (buf[0] ? buf : NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-06-16 15:03:11 +00:00
|
|
|
OSErr GetCurrentScreenSaverSelection(char *moduleName, size_t maxLen) {
|
|
|
|
OSErr err = noErr;
|
|
|
|
CFStringRef nameKey = CFStringCreateWithCString(NULL,"moduleName",kCFStringEncodingASCII);
|
|
|
|
CFStringRef moduleNameAsCFString;
|
|
|
|
CFDictionaryRef theData;
|
|
|
|
|
|
|
|
theData = (CFDictionaryRef)CFPreferencesCopyValue(CFSTR("moduleDict"),
|
|
|
|
CFSTR("com.apple.screensaver"),
|
|
|
|
kCFPreferencesCurrentUser,
|
|
|
|
kCFPreferencesCurrentHost
|
|
|
|
);
|
|
|
|
if (theData == NULL) {
|
|
|
|
CFRelease(nameKey);
|
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (CFDictionaryContainsKey(theData, nameKey) == false)
|
|
|
|
{
|
|
|
|
moduleName[0] = 0;
|
|
|
|
CFRelease(nameKey);
|
|
|
|
CFRelease(theData);
|
|
|
|
return(-1);
|
|
|
|
}
|
|
|
|
|
|
|
|
moduleNameAsCFString = CFStringCreateCopy(NULL, (CFStringRef)CFDictionaryGetValue(theData, nameKey));
|
|
|
|
CFStringGetCString(moduleNameAsCFString, moduleName, maxLen, kCFStringEncodingASCII);
|
|
|
|
|
|
|
|
CFRelease(nameKey);
|
|
|
|
CFRelease(theData);
|
2012-06-18 11:11:44 +00:00
|
|
|
CFRelease(moduleNameAsCFString);
|
2012-06-16 15:03:11 +00:00
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
OSErr SetScreenSaverSelection(char *moduleName, char *modulePath, int type) {
|
|
|
|
OSErr err = noErr;
|
|
|
|
CFStringRef preferenceName = CFSTR("com.apple.screensaver");
|
|
|
|
CFStringRef mainKeyName = CFSTR("moduleDict");
|
|
|
|
CFDictionaryRef emptyData;
|
|
|
|
CFMutableDictionaryRef newData;
|
|
|
|
Boolean success;
|
|
|
|
|
|
|
|
CFStringRef nameKey = CFStringCreateWithCString(NULL, "moduleName", kCFStringEncodingASCII);
|
|
|
|
CFStringRef nameValue = CFStringCreateWithCString(NULL, moduleName, kCFStringEncodingASCII);
|
|
|
|
|
|
|
|
CFStringRef pathKey = CFStringCreateWithCString(NULL, "path", kCFStringEncodingASCII);
|
|
|
|
CFStringRef pathValue = CFStringCreateWithCString(NULL, modulePath, kCFStringEncodingASCII);
|
|
|
|
|
|
|
|
CFStringRef typeKey = CFStringCreateWithCString(NULL, "type", kCFStringEncodingASCII);
|
|
|
|
CFNumberRef typeValue = CFNumberCreate(NULL, kCFNumberIntType, &type);
|
|
|
|
|
|
|
|
emptyData = CFDictionaryCreate(NULL, NULL, NULL, 0, NULL, NULL);
|
|
|
|
if (emptyData == NULL) {
|
|
|
|
CFRelease(nameKey);
|
|
|
|
CFRelease(nameValue);
|
|
|
|
CFRelease(pathKey);
|
|
|
|
CFRelease(pathValue);
|
|
|
|
CFRelease(typeKey);
|
|
|
|
CFRelease(typeValue);
|
|
|
|
return(-1);
|
|
|
|
}
|
|
|
|
|
|
|
|
newData = CFDictionaryCreateMutableCopy(NULL,0, emptyData);
|
|
|
|
|
|
|
|
if (newData == NULL)
|
|
|
|
{
|
|
|
|
CFRelease(nameKey);
|
|
|
|
CFRelease(nameValue);
|
|
|
|
CFRelease(pathKey);
|
|
|
|
CFRelease(pathValue);
|
|
|
|
CFRelease(typeKey);
|
|
|
|
CFRelease(typeValue);
|
|
|
|
CFRelease(emptyData);
|
|
|
|
return(-1);
|
|
|
|
}
|
|
|
|
|
|
|
|
CFDictionaryAddValue(newData, nameKey, nameValue);
|
|
|
|
CFDictionaryAddValue(newData, pathKey, pathValue);
|
|
|
|
CFDictionaryAddValue(newData, typeKey, typeValue);
|
|
|
|
|
|
|
|
CFPreferencesSetValue(mainKeyName, newData, preferenceName, kCFPreferencesCurrentUser, kCFPreferencesCurrentHost);
|
|
|
|
success = CFPreferencesSynchronize(preferenceName, kCFPreferencesCurrentUser, kCFPreferencesCurrentHost);
|
|
|
|
|
|
|
|
if (!success) {
|
|
|
|
err = -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
CFRelease(nameKey);
|
|
|
|
CFRelease(nameValue);
|
|
|
|
CFRelease(pathKey);
|
|
|
|
CFRelease(pathValue);
|
|
|
|
CFRelease(typeKey);
|
|
|
|
CFRelease(typeValue);
|
|
|
|
CFRelease(emptyData);
|
|
|
|
CFRelease(newData);
|
|
|
|
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-06-18 11:11:44 +00:00
|
|
|
int GetCountOfLoginItemsFromPlistFile() {
|
|
|
|
CFArrayRef arrayOfLoginItemsFixed;
|
|
|
|
int valueToReturn = -1;
|
|
|
|
CFStringRef loginItemArrayKeyName = CFSTR("CustomListItems");
|
|
|
|
CFDictionaryRef topLevelDict;
|
|
|
|
|
|
|
|
topLevelDict = (CFDictionaryRef)CFPreferencesCopyValue(CFSTR("SessionItems"), CFSTR("com.apple.loginitems"), kCFPreferencesCurrentUser, kCFPreferencesAnyHost);
|
|
|
|
if (topLevelDict == NULL) {
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (CFDictionaryContainsKey(topLevelDict, loginItemArrayKeyName) == false)
|
|
|
|
{
|
|
|
|
CFRelease(topLevelDict);
|
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
arrayOfLoginItemsFixed = (CFArrayRef)CFDictionaryGetValue(topLevelDict, loginItemArrayKeyName);
|
|
|
|
if( arrayOfLoginItemsFixed == NULL)
|
|
|
|
{
|
|
|
|
CFRelease(topLevelDict);
|
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
valueToReturn = (int) CFArrayGetCount(arrayOfLoginItemsFixed);
|
|
|
|
|
|
|
|
CFRelease(topLevelDict);
|
|
|
|
return(valueToReturn);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Returns empty string on failure
|
|
|
|
OSErr GetLoginItemNameAtIndexFromPlistFile(int index, char *name, size_t maxLen) {
|
|
|
|
CFArrayRef arrayOfLoginItemsFixed = NULL;
|
|
|
|
CFStringRef loginItemArrayKeyName = CFSTR("CustomListItems");
|
|
|
|
CFDictionaryRef topLevelDict = NULL;
|
|
|
|
CFDictionaryRef loginItemDict = NULL;
|
|
|
|
CFStringRef nameKey = CFSTR("Name");
|
|
|
|
CFStringRef nameAsCFString = NULL;
|
|
|
|
|
|
|
|
*name = 0; // Prepare for failure
|
|
|
|
|
|
|
|
topLevelDict = (CFDictionaryRef)CFPreferencesCopyValue(CFSTR("SessionItems"), CFSTR("com.apple.loginitems"), kCFPreferencesCurrentUser, kCFPreferencesAnyHost);
|
|
|
|
if (topLevelDict == NULL) {
|
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (CFDictionaryContainsKey(topLevelDict, loginItemArrayKeyName) == false)
|
|
|
|
{
|
|
|
|
CFRelease(topLevelDict);
|
|
|
|
return(-1);
|
|
|
|
}
|
|
|
|
|
|
|
|
arrayOfLoginItemsFixed = (CFArrayRef) CFDictionaryGetValue(topLevelDict, loginItemArrayKeyName);
|
|
|
|
if( arrayOfLoginItemsFixed == NULL)
|
|
|
|
{
|
|
|
|
CFRelease(topLevelDict);
|
|
|
|
return(-1);
|
|
|
|
}
|
|
|
|
|
|
|
|
loginItemDict = (CFDictionaryRef) CFArrayGetValueAtIndex(arrayOfLoginItemsFixed, (CFIndex)index);
|
|
|
|
if (loginItemDict == NULL)
|
|
|
|
{
|
|
|
|
CFRelease(topLevelDict);
|
|
|
|
return(-1);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (CFDictionaryContainsKey(loginItemDict, nameKey) == false)
|
|
|
|
{
|
|
|
|
CFRelease(topLevelDict);
|
|
|
|
return(-1);
|
|
|
|
}
|
|
|
|
|
|
|
|
nameAsCFString = CFStringCreateCopy(NULL, (CFStringRef)CFDictionaryGetValue(loginItemDict, nameKey));
|
|
|
|
CFStringGetCString(nameAsCFString, name, maxLen, kCFStringEncodingASCII);
|
|
|
|
|
|
|
|
CFRelease(topLevelDict);
|
|
|
|
CFRelease(nameAsCFString);
|
|
|
|
return(noErr);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
OSErr DeleteLoginItemNameAtIndexFromPlistFile(int index){
|
|
|
|
CFArrayRef arrayOfLoginItemsFixed = NULL;
|
|
|
|
CFMutableArrayRef arrayOfLoginItemsModifiable;
|
|
|
|
CFStringRef topLevelKeyName = CFSTR("SessionItems");
|
|
|
|
CFStringRef preferenceName = CFSTR("com.apple.loginitems");
|
|
|
|
CFStringRef loginItemArrayKeyName = CFSTR("CustomListItems");
|
|
|
|
CFDictionaryRef oldTopLevelDict = NULL;
|
|
|
|
CFMutableDictionaryRef newTopLevelDict = NULL;
|
|
|
|
Boolean success;
|
|
|
|
OSErr err = noErr;
|
|
|
|
|
|
|
|
oldTopLevelDict = (CFDictionaryRef)CFPreferencesCopyValue(topLevelKeyName, preferenceName, kCFPreferencesCurrentUser, kCFPreferencesAnyHost);
|
|
|
|
if (oldTopLevelDict == NULL) {
|
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (CFDictionaryContainsKey(oldTopLevelDict, loginItemArrayKeyName) == false)
|
|
|
|
{
|
|
|
|
CFRelease(oldTopLevelDict);
|
|
|
|
return(-1);
|
|
|
|
}
|
|
|
|
|
|
|
|
arrayOfLoginItemsFixed = (CFArrayRef) CFDictionaryGetValue(oldTopLevelDict, loginItemArrayKeyName);
|
|
|
|
if( arrayOfLoginItemsFixed == NULL)
|
|
|
|
{
|
|
|
|
CFRelease(oldTopLevelDict);
|
|
|
|
return(-1);
|
|
|
|
}
|
|
|
|
|
|
|
|
arrayOfLoginItemsModifiable = CFArrayCreateMutableCopy(NULL, 0, arrayOfLoginItemsFixed);
|
|
|
|
if( arrayOfLoginItemsModifiable == NULL)
|
|
|
|
{
|
|
|
|
CFRelease(oldTopLevelDict);
|
|
|
|
return(-1);
|
|
|
|
}
|
|
|
|
|
|
|
|
CFArrayRemoveValueAtIndex(arrayOfLoginItemsModifiable, (CFIndex) index);
|
|
|
|
|
|
|
|
newTopLevelDict = CFDictionaryCreateMutableCopy(NULL, 0, oldTopLevelDict);
|
|
|
|
CFDictionaryReplaceValue(newTopLevelDict, loginItemArrayKeyName, arrayOfLoginItemsModifiable);
|
|
|
|
|
|
|
|
CFPreferencesSetValue(topLevelKeyName, newTopLevelDict, preferenceName, kCFPreferencesCurrentUser, kCFPreferencesAnyHost);
|
|
|
|
success = CFPreferencesSynchronize(preferenceName, kCFPreferencesCurrentUser, kCFPreferencesAnyHost);
|
|
|
|
|
|
|
|
if (!success) {
|
|
|
|
err = -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
CFRelease(oldTopLevelDict);
|
|
|
|
CFRelease(newTopLevelDict);
|
|
|
|
|
|
|
|
return(err);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-05-03 11:33:03 +00:00
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
/* This runs through the process list looking for the indicated application */
|
|
|
|
/* Searches for process by file type and signature (creator code) */
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
static OSErr FindProcess (OSType typeToFind, OSType creatorToFind, ProcessSerialNumberPtr processSN)
|
|
|
|
{
|
|
|
|
ProcessInfoRec tempInfo;
|
|
|
|
FSSpec procSpec;
|
|
|
|
Str31 processName;
|
|
|
|
OSErr myErr = noErr;
|
|
|
|
/* null out the PSN so we're starting at the beginning of the list */
|
|
|
|
processSN->lowLongOfPSN = kNoProcess;
|
|
|
|
processSN->highLongOfPSN = kNoProcess;
|
|
|
|
/* initialize the process information record */
|
|
|
|
tempInfo.processInfoLength = sizeof(ProcessInfoRec);
|
|
|
|
tempInfo.processName = processName;
|
|
|
|
tempInfo.processAppSpec = &procSpec;
|
|
|
|
/* loop through all the processes until we */
|
|
|
|
/* 1) find the process we want */
|
|
|
|
/* 2) error out because of some reason (usually, no more processes) */
|
|
|
|
do {
|
|
|
|
myErr = GetNextProcess(processSN);
|
|
|
|
if (myErr == noErr)
|
|
|
|
GetProcessInformation(processSN, &tempInfo);
|
|
|
|
}
|
|
|
|
while ((tempInfo.processSignature != creatorToFind || tempInfo.processType != typeToFind) &&
|
|
|
|
myErr == noErr);
|
|
|
|
return(myErr);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-06-06 12:52:37 +00:00
|
|
|
static pid_t FindProcessPID(char* name, pid_t thePID)
|
|
|
|
{
|
|
|
|
FILE *f;
|
|
|
|
char buf[1024];
|
|
|
|
size_t n = 0;
|
|
|
|
pid_t aPID;
|
|
|
|
|
|
|
|
if (name != NULL) // Search ny name
|
|
|
|
n = strlen(name);
|
|
|
|
|
|
|
|
f = popen("ps -a -x -c -o command,pid", "r");
|
|
|
|
if (f == NULL)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
while (PersistentFGets(buf, sizeof(buf), f))
|
|
|
|
{
|
|
|
|
if (name != NULL) { // Search by name
|
|
|
|
if (strncmp(buf, name, n) == 0)
|
|
|
|
{
|
|
|
|
aPID = atol(buf+16);
|
|
|
|
pclose(f);
|
|
|
|
return aPID;
|
|
|
|
}
|
|
|
|
} else { // Search by PID
|
|
|
|
aPID = atol(buf+16);
|
|
|
|
if (aPID == thePID) {
|
|
|
|
pclose(f);
|
|
|
|
return aPID;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
pclose(f);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-05-03 11:33:03 +00:00
|
|
|
static OSStatus QuitOneProcess(OSType signature) {
|
2007-06-06 12:52:37 +00:00
|
|
|
bool done = false;
|
|
|
|
ProcessSerialNumber thisPSN;
|
|
|
|
ProcessInfoRec thisPIR;
|
2007-06-07 12:24:29 +00:00
|
|
|
OSStatus err = noErr;
|
2007-06-06 12:52:37 +00:00
|
|
|
Str63 thisProcessName;
|
|
|
|
AEAddressDesc thisPSNDesc;
|
|
|
|
AppleEvent thisQuitEvent, thisReplyEvent;
|
|
|
|
|
|
|
|
|
|
|
|
thisPIR.processInfoLength = sizeof (ProcessInfoRec);
|
|
|
|
thisPIR.processName = thisProcessName;
|
|
|
|
thisPIR.processAppSpec = nil;
|
|
|
|
|
|
|
|
thisPSN.highLongOfPSN = 0;
|
|
|
|
thisPSN.lowLongOfPSN = kNoProcess;
|
|
|
|
|
|
|
|
while (done == false) {
|
|
|
|
err = GetNextProcess(&thisPSN);
|
|
|
|
if (err == procNotFound)
|
2014-01-22 11:04:16 +00:00
|
|
|
done = true; // apparently the app isn't running.
|
2007-06-06 12:52:37 +00:00
|
|
|
else {
|
|
|
|
err = GetProcessInformation(&thisPSN,&thisPIR);
|
|
|
|
if (err != noErr)
|
|
|
|
goto bail;
|
|
|
|
|
2014-01-22 11:04:16 +00:00
|
|
|
if (thisPIR.processSignature == signature) { // is it our target process?
|
2007-06-06 12:52:37 +00:00
|
|
|
err = AECreateDesc(typeProcessSerialNumber, (Ptr)&thisPSN,
|
|
|
|
sizeof(thisPSN), &thisPSNDesc);
|
|
|
|
if (err != noErr)
|
|
|
|
goto bail;
|
|
|
|
|
|
|
|
// Create the 'quit' Apple event for this process.
|
|
|
|
err = AECreateAppleEvent(kCoreEventClass, kAEQuitApplication, &thisPSNDesc,
|
|
|
|
kAutoGenerateReturnID, kAnyTransactionID, &thisQuitEvent);
|
|
|
|
if (err != noErr) {
|
|
|
|
AEDisposeDesc (&thisPSNDesc);
|
|
|
|
goto bail; // don't know how this could happen, but limp gamely onward
|
|
|
|
}
|
|
|
|
|
|
|
|
// send the event
|
|
|
|
err = AESend(&thisQuitEvent, &thisReplyEvent, kAEWaitReply,
|
|
|
|
kAENormalPriority, kAEDefaultTimeout, 0L, 0L);
|
|
|
|
AEDisposeDesc (&thisQuitEvent);
|
|
|
|
AEDisposeDesc (&thisPSNDesc);
|
|
|
|
#if 0
|
|
|
|
if (err == errAETimeout) {
|
|
|
|
pid_t thisPID;
|
|
|
|
|
|
|
|
err = GetProcessPID(&thisPSN , &thisPID);
|
|
|
|
if (err == noErr)
|
|
|
|
err = kill(thisPID, SIGKILL);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
done = true; // we've killed the process, presumably
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bail:
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2012-05-06 08:22:37 +00:00
|
|
|
|
2014-01-21 12:20:53 +00:00
|
|
|
// Kill a process if it exists
|
|
|
|
static void KillVBoxProcess(char* name) {
|
|
|
|
pid_t VBoxPid;
|
|
|
|
|
|
|
|
VBoxPid = FindProcessPID(name, 0);
|
|
|
|
if (!VBoxPid) return; // No such process
|
|
|
|
|
|
|
|
kill(VBoxPid, SIGQUIT);
|
|
|
|
sleep(2);
|
|
|
|
if (FindProcessPID(NULL, VBoxPid)) {
|
|
|
|
kill(VBoxPid, SIGKILL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-06-06 12:52:37 +00:00
|
|
|
// Uses usleep to sleep for full duration even if a signal is received
|
|
|
|
static void SleepTicks(UInt32 ticksToSleep) {
|
|
|
|
UInt32 endSleep, timeNow, ticksRemaining;
|
|
|
|
|
|
|
|
timeNow = TickCount();
|
|
|
|
ticksRemaining = ticksToSleep;
|
|
|
|
endSleep = timeNow + ticksToSleep;
|
|
|
|
while ( (timeNow < endSleep) && (ticksRemaining <= ticksToSleep) ) {
|
|
|
|
usleep(16667 * ticksRemaining);
|
|
|
|
timeNow = TickCount();
|
|
|
|
ticksRemaining = endSleep - timeNow;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-06-18 11:03:24 +00:00
|
|
|
// Because language preferences are set on a per-user basis, we
|
|
|
|
// must get the preferred languages while set to the current
|
2013-06-18 11:40:54 +00:00
|
|
|
// user, before we switch to root in our second pass.
|
2013-06-18 11:03:24 +00:00
|
|
|
// So we get the preferred languages here and write them to a
|
2013-06-18 11:40:54 +00:00
|
|
|
// temporary file to be retrieved by our second pass.
|
2013-07-02 10:53:02 +00:00
|
|
|
// We must do it this way because, for unknown reasons, the
|
|
|
|
// CFBundleCopyLocalizationsForPreferences() API does not work
|
|
|
|
// correctly if we seteuid and setuid to the logged in user
|
|
|
|
// after running as root.
|
|
|
|
|
2013-06-18 11:03:24 +00:00
|
|
|
static void GetPreferredLanguages() {
|
|
|
|
DIR *dirp;
|
|
|
|
struct dirent *dp;
|
|
|
|
char searchPath[MAXPATHLEN];
|
|
|
|
struct stat sbuf;
|
|
|
|
CFMutableArrayRef supportedLanguages;
|
|
|
|
CFStringRef aLanguage;
|
2013-08-15 11:24:20 +00:00
|
|
|
char shortLanguage[32];
|
2013-06-18 11:03:24 +00:00
|
|
|
CFArrayRef preferredLanguages;
|
|
|
|
int i, j, k;
|
|
|
|
char * language;
|
2013-08-15 11:24:20 +00:00
|
|
|
char *uscore;
|
2013-06-18 11:03:24 +00:00
|
|
|
FILE *f;
|
|
|
|
|
|
|
|
// Create an array of all our supported languages
|
2013-10-17 11:22:05 +00:00
|
|
|
supportedLanguages = CFArrayCreateMutable(kCFAllocatorDefault, 100, &kCFTypeArrayCallBacks);
|
2013-06-18 11:03:24 +00:00
|
|
|
|
|
|
|
aLanguage = CFStringCreateWithCString(NULL, "en", kCFStringEncodingMacRoman);
|
|
|
|
CFArrayAppendValue(supportedLanguages, aLanguage);
|
|
|
|
aLanguage = NULL;
|
|
|
|
|
|
|
|
dirp = opendir(gCatalogsDir);
|
2013-07-02 09:08:21 +00:00
|
|
|
if (!dirp) goto bail;
|
2013-06-18 11:03:24 +00:00
|
|
|
while (true) {
|
|
|
|
dp = readdir(dirp);
|
|
|
|
if (dp == NULL)
|
|
|
|
break; // End of list
|
|
|
|
|
|
|
|
if (dp->d_name[0] == '.')
|
|
|
|
continue; // Ignore names beginning with '.'
|
|
|
|
|
|
|
|
strlcpy(searchPath, gCatalogsDir, sizeof(searchPath));
|
|
|
|
strlcat(searchPath, dp->d_name, sizeof(searchPath));
|
|
|
|
strlcat(searchPath, "/", sizeof(searchPath));
|
|
|
|
strlcat(searchPath, gCatalog_Name, sizeof(searchPath));
|
|
|
|
strlcat(searchPath, ".mo", sizeof(searchPath));
|
2014-01-21 12:20:53 +00:00
|
|
|
// stat() returns zero on success
|
2013-06-18 11:03:24 +00:00
|
|
|
if (stat(searchPath, &sbuf) != 0) continue;
|
|
|
|
// printf("Adding %s to supportedLanguages array\n", dp->d_name);
|
|
|
|
aLanguage = CFStringCreateWithCString(NULL, dp->d_name, kCFStringEncodingMacRoman);
|
|
|
|
CFArrayAppendValue(supportedLanguages, aLanguage);
|
|
|
|
aLanguage = NULL;
|
2013-08-15 11:24:20 +00:00
|
|
|
|
|
|
|
// If it has a region code ("it_IT") also try without region code ("it")
|
|
|
|
// TODO: Find a more general solution
|
|
|
|
strlcpy(shortLanguage, dp->d_name, sizeof(shortLanguage));
|
|
|
|
uscore = strchr(shortLanguage, '_');
|
|
|
|
if (uscore) {
|
|
|
|
*uscore = '\0';
|
|
|
|
aLanguage = CFStringCreateWithCString(NULL, shortLanguage, kCFStringEncodingMacRoman);
|
|
|
|
CFArrayAppendValue(supportedLanguages, aLanguage);
|
|
|
|
aLanguage = NULL;
|
|
|
|
}
|
2013-06-18 11:03:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
closedir(dirp);
|
|
|
|
|
|
|
|
// Write a temp file to tell our PostInstall.app our preferred languages
|
|
|
|
f = fopen(gTempFileName, "w");
|
|
|
|
|
|
|
|
for (i=0; i<MAX_LANGUAGES_TO_TRY; ++i) {
|
|
|
|
|
|
|
|
preferredLanguages = CFBundleCopyLocalizationsForPreferences(supportedLanguages, NULL );
|
|
|
|
|
|
|
|
#if 0 // For testing
|
|
|
|
int c = CFArrayGetCount(preferredLanguages);
|
|
|
|
for (k=0; k<c; ++k) {
|
|
|
|
CFStringRef s = (CFStringRef)CFArrayGetValueAtIndex(preferredLanguages, k);
|
|
|
|
printf("Preferred language %u is %s\n", k, CFStringGetCStringPtr(s, kCFStringEncodingMacRoman));
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
for (j=0; j<CFArrayGetCount(preferredLanguages); ++j) {
|
|
|
|
aLanguage = (CFStringRef)CFArrayGetValueAtIndex(preferredLanguages, j);
|
|
|
|
language = (char *)CFStringGetCStringPtr(aLanguage, kCFStringEncodingMacRoman);
|
|
|
|
if (f) {
|
|
|
|
fprintf(f, "%s\n", language);
|
|
|
|
}
|
|
|
|
|
2013-08-16 12:11:32 +00:00
|
|
|
// Remove all copies of this language from our list of supported languages
|
|
|
|
// so we can get the next preferred language in order of priority
|
|
|
|
for (k=CFArrayGetCount(supportedLanguages)-1; k>=0; --k) {
|
2013-06-18 11:03:24 +00:00
|
|
|
if (CFStringCompare(aLanguage, (CFStringRef)CFArrayGetValueAtIndex(supportedLanguages, k), 0) == kCFCompareEqualTo) {
|
|
|
|
CFArrayRemoveValueAtIndex(supportedLanguages, k);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Since the original strings are English, no
|
|
|
|
// further translation is needed for language en.
|
|
|
|
if (!strcmp(language, "en")) {
|
|
|
|
fclose(f);
|
2013-07-02 09:08:21 +00:00
|
|
|
CFRelease(preferredLanguages);
|
|
|
|
preferredLanguages = NULL;
|
|
|
|
CFArrayRemoveAllValues(supportedLanguages);
|
|
|
|
CFRelease(supportedLanguages);
|
|
|
|
supportedLanguages = NULL;
|
2013-06-18 11:03:24 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2013-07-02 09:08:21 +00:00
|
|
|
|
|
|
|
CFRelease(preferredLanguages);
|
|
|
|
preferredLanguages = NULL;
|
|
|
|
|
2013-06-18 11:03:24 +00:00
|
|
|
}
|
|
|
|
fclose(f);
|
2013-07-02 09:08:21 +00:00
|
|
|
|
|
|
|
bail:
|
|
|
|
CFArrayRemoveAllValues(supportedLanguages);
|
|
|
|
CFRelease(supportedLanguages);
|
|
|
|
supportedLanguages = NULL;
|
2013-06-18 11:03:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void LoadPreferredLanguages(){
|
|
|
|
FILE *f;
|
|
|
|
int i;
|
|
|
|
char *p;
|
|
|
|
char language[32];
|
|
|
|
|
|
|
|
BOINCTranslationInit();
|
|
|
|
|
|
|
|
// First pass wrote a list of our preferred languages to a temp file
|
|
|
|
f = fopen(gTempFileName, "r");
|
|
|
|
if (!f) return;
|
|
|
|
|
|
|
|
for (i=0; i<MAX_LANGUAGES_TO_TRY; ++i) {
|
|
|
|
fgets(language, sizeof(language), f);
|
|
|
|
if (feof(f)) break;
|
|
|
|
language[sizeof(language)-1] = '\0'; // Guarantee a null terminator
|
|
|
|
p = strchr(language, '\n');
|
|
|
|
if (p) *p = '\0'; // Replace newline with null terminator
|
|
|
|
if (language[0]) {
|
2013-08-16 12:11:32 +00:00
|
|
|
if (!BOINCTranslationAddCatalog(gCatalogsDir, language, gCatalog_Name)) {
|
2013-06-18 11:03:24 +00:00
|
|
|
printf("could not load catalog for langage %s\n", language);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
fclose(f);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-01-21 12:20:53 +00:00
|
|
|
static Boolean ShowMessage(Boolean allowCancel, Boolean continueButton, Boolean yesNoButtons, const char *format, ...) {
|
2007-06-06 12:52:37 +00:00
|
|
|
va_list args;
|
|
|
|
char s[1024];
|
2013-06-18 11:03:24 +00:00
|
|
|
CFOptionFlags responseFlags;
|
|
|
|
CFURLRef myIconURLRef = NULL;
|
|
|
|
CFBundleRef myBundleRef;
|
|
|
|
CFDictionaryRef myInfoPlistData;
|
|
|
|
CFStringRef appIconName;
|
|
|
|
ProcessSerialNumber ourProcess;
|
2014-01-21 12:20:53 +00:00
|
|
|
Boolean result;
|
2013-06-18 11:03:24 +00:00
|
|
|
|
|
|
|
myBundleRef = CFBundleGetMainBundle();
|
|
|
|
if (myBundleRef) {
|
|
|
|
if (!strcmp(gBrandName, "BOINC")) {
|
|
|
|
// For BOINC uninstaller use our special icon
|
|
|
|
myIconURLRef = CFBundleCopyResourceURL(myBundleRef, CFSTR("PutInTrash.icns"), NULL, NULL);
|
|
|
|
} else {
|
|
|
|
// For branded uninstaller (GR, CE, PtP) use uninstaller application icon
|
|
|
|
myInfoPlistData = CFBundleGetInfoDictionary(myBundleRef);
|
|
|
|
if (myInfoPlistData) {
|
|
|
|
appIconName = (CFStringRef)CFDictionaryGetValue(myInfoPlistData, CFSTR("CFBundleIconFile"));
|
|
|
|
myIconURLRef = CFBundleCopyResourceURL(myBundleRef, appIconName, NULL, NULL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2007-06-06 12:52:37 +00:00
|
|
|
|
|
|
|
va_start(args, format);
|
2013-06-18 11:03:24 +00:00
|
|
|
vsprintf(s, format, args);
|
2007-06-06 12:52:37 +00:00
|
|
|
va_end(args);
|
|
|
|
|
2013-06-18 11:03:24 +00:00
|
|
|
CFStringRef myString = CFStringCreateWithCString(NULL, s, kCFStringEncodingUTF8);
|
|
|
|
CFStringRef theTitle = CFStringCreateWithCString(NULL, gAppName, kCFStringEncodingUTF8);
|
|
|
|
CFStringRef cancelString = CFStringCreateWithCString(NULL, (char*)_("Cancel"), kCFStringEncodingUTF8);
|
2013-07-02 09:08:21 +00:00
|
|
|
CFStringRef continueString = CFStringCreateWithCString(NULL, (char*)_("Continue..."), kCFStringEncodingUTF8);
|
2014-01-21 12:20:53 +00:00
|
|
|
CFStringRef yesString = CFStringCreateWithCString(NULL, (char*)_("Yes"), kCFStringEncodingUTF8);
|
|
|
|
CFStringRef noString = CFStringCreateWithCString(NULL, (char*)_("No"), kCFStringEncodingUTF8);
|
2007-06-06 12:52:37 +00:00
|
|
|
|
|
|
|
::GetCurrentProcess (&ourProcess);
|
|
|
|
::SetFrontProcess(&ourProcess);
|
|
|
|
|
2014-01-21 12:20:53 +00:00
|
|
|
// Set default button to Continue, OK or No
|
|
|
|
// Set alternate button to Cancel, Yes, or hidden
|
2013-06-18 11:03:24 +00:00
|
|
|
SInt32 retval = CFUserNotificationDisplayAlert(0.0, kCFUserNotificationPlainAlertLevel,
|
|
|
|
myIconURLRef, NULL, NULL, theTitle, myString,
|
2014-01-21 12:20:53 +00:00
|
|
|
continueButton ? continueString : (yesNoButtons ? noString : NULL),
|
|
|
|
(allowCancel || yesNoButtons) ? (yesNoButtons ? yesString : cancelString) : NULL,
|
|
|
|
NULL, &responseFlags);
|
2007-06-08 11:16:48 +00:00
|
|
|
|
2013-06-18 12:03:45 +00:00
|
|
|
if (myIconURLRef) CFRelease(myIconURLRef);
|
|
|
|
if (myString) CFRelease(myString);
|
|
|
|
if (theTitle) CFRelease(theTitle);
|
|
|
|
if (cancelString) CFRelease(cancelString);
|
|
|
|
if (continueString) CFRelease(continueString);
|
2014-01-21 12:20:53 +00:00
|
|
|
if (yesString) CFRelease(yesString);
|
|
|
|
if (noString) CFRelease(noString);
|
2013-06-18 11:03:24 +00:00
|
|
|
|
|
|
|
if (retval) return false;
|
2014-01-21 12:20:53 +00:00
|
|
|
|
|
|
|
result = (responseFlags == kCFUserNotificationDefaultResponse);
|
|
|
|
// Return TRUE if user clicked Continue, Yes or OK, FALSE if user clicked Cancel or No
|
|
|
|
// Note: if yesNoButtons is true, we made default button "No" and alternate button "Yes"
|
|
|
|
return (yesNoButtons ? !result : result);
|
2007-06-06 12:52:37 +00:00
|
|
|
}
|
2012-05-03 11:40:55 +00:00
|
|
|
|
|
|
|
|
|
|
|
#if SEARCHFORALLBOINCMANAGERS
|
|
|
|
static OSStatus GetpathToBOINCManagerApp(char* path, int maxLen, FSRef *theFSRef)
|
|
|
|
{
|
|
|
|
CFStringRef bundleID = CFSTR("edu.berkeley.boinc");
|
|
|
|
OSType creator = 'BNC!';
|
|
|
|
OSStatus status = noErr;
|
|
|
|
|
|
|
|
status = LSFindApplicationForInfo(creator, bundleID, NULL, theFSRef, NULL);
|
|
|
|
if (status) {
|
|
|
|
#if TESTING
|
2014-01-21 12:20:53 +00:00
|
|
|
ShowMessage(false, false, false, "LSFindApplicationForInfo returned error %d", status);
|
2012-05-03 11:40:55 +00:00
|
|
|
#endif
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
|
|
|
status = FSRefMakePath(theFSRef, (unsigned char *)path, maxLen);
|
|
|
|
#if TESTING
|
|
|
|
if (status)
|
2014-01-21 12:20:53 +00:00
|
|
|
ShowMessage(false, false, false, "GetpathToBOINCManagerApp FSRefMakePath returned error %d, %s", status, path);
|
2012-05-03 11:40:55 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
#endif // SEARCHFORALLBOINCMANAGERS
|
2013-11-15 13:02:04 +00:00
|
|
|
|
|
|
|
|
|
|
|
static int compareOSVersionTo(int toMajor, int toMinor) {
|
|
|
|
SInt32 major, minor;
|
|
|
|
OSStatus err = noErr;
|
|
|
|
|
|
|
|
err = Gestalt(gestaltSystemVersionMajor, &major);
|
|
|
|
if (err != noErr) {
|
|
|
|
fprintf(stderr, "Gestalt(gestaltSystemVersionMajor) returned error %ld\n", err);
|
|
|
|
fflush(stderr);
|
2013-11-18 08:56:44 +00:00
|
|
|
return -1; // gestaltSystemVersionMajor selector was not available before OS 10.4
|
2013-11-15 13:02:04 +00:00
|
|
|
}
|
|
|
|
if (major < toMajor) return -1;
|
|
|
|
if (major > toMajor) return 1;
|
|
|
|
err = Gestalt(gestaltSystemVersionMinor, &minor);
|
|
|
|
if (err != noErr) {
|
|
|
|
fprintf(stderr, "Gestalt(gestaltSystemVersionMinor) returned error %ld\n", err);
|
|
|
|
fflush(stderr);
|
2013-11-18 08:56:44 +00:00
|
|
|
return -1; // gestaltSystemVersionMajor selector was not available before OS 10.4
|
2013-11-15 13:02:04 +00:00
|
|
|
}
|
|
|
|
if (minor < toMinor) return -1;
|
|
|
|
if (minor > toMinor) return 1;
|
|
|
|
return 0;
|
|
|
|
}
|