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
|
2020-04-23 14:18:54 +00:00
|
|
|
// Copyright (C) 2020 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 */
|
|
|
|
|
2016-12-21 14:08:36 +00:00
|
|
|
#define TESTING 0 /* for debugging */
|
|
|
|
#define VERBOSE_TEST 0 /* for debugging callPosixSpawn */
|
2018-06-27 12:37:53 +00:00
|
|
|
/* if (TESTING!=0), set DEBUG_PRINT to 1 to print debug output to log file or 0 to display in dialogs */
|
|
|
|
#define DEBUG_PRINT 1
|
2016-12-21 14:08:36 +00:00
|
|
|
|
2018-06-26 13:38:51 +00:00
|
|
|
#define USE_OSASCRIPT_FOR_ALL_LOGGED_IN_USERS false
|
|
|
|
|
2007-06-06 12:52:37 +00:00
|
|
|
#include <Carbon/Carbon.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()
|
2016-12-21 14:08:36 +00:00
|
|
|
#include <sys/time.h>
|
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
|
|
|
|
2016-12-21 14:08:36 +00:00
|
|
|
|
|
|
|
// WARNING -- SEARCHFORALLBOINCMANAGERS CODE HAS NOT BEEN TESTED
|
2012-05-03 11:40:55 +00:00
|
|
|
#define SEARCHFORALLBOINCMANAGERS 0
|
2016-12-21 14:08:36 +00:00
|
|
|
|
2013-06-18 11:03:24 +00:00
|
|
|
#define MAX_LANGUAGES_TO_TRY 5
|
2018-06-26 13:38:51 +00:00
|
|
|
|
|
|
|
#define USE_OSASCRIPT_FOR_ALL_LOGGED_IN_USERS false
|
2012-05-03 11:40:55 +00:00
|
|
|
|
2016-12-21 14:08:36 +00:00
|
|
|
#include "mac_util.h"
|
2013-06-18 11:03:24 +00:00
|
|
|
#include "translate.h"
|
2018-06-26 13:38:51 +00:00
|
|
|
#include "file_names.h"
|
2018-07-11 10:59:34 +00:00
|
|
|
#include "mac_branding.h"
|
2011-09-24 12:43:19 +00:00
|
|
|
|
2016-12-21 14:08:36 +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);
|
2018-06-26 13:38:51 +00:00
|
|
|
static void DeleteLoginItemOSAScript(char *userName);
|
|
|
|
static Boolean DeleteLoginItemLaunchAgent(long brandID, passwd *pw);
|
2019-11-08 11:40:22 +00:00
|
|
|
static void DeleteScreenSaverLaunchAgent(passwd *pw);
|
2018-06-26 13:38:51 +00:00
|
|
|
long GetBrandID(char *path);
|
2019-12-06 13:32:28 +00:00
|
|
|
static Boolean IsUserLoggedIn(const char *userName);
|
2007-06-06 12:52:37 +00:00
|
|
|
static char * PersistentFGets(char *buf, size_t buflen, FILE *f);
|
2018-06-26 13:38:51 +00:00
|
|
|
OSErr GetCurrentScreenSaverSelection(passwd *pw, char *moduleName, size_t maxLen);
|
2012-06-16 15:03:11 +00:00
|
|
|
OSErr SetScreenSaverSelection(char *moduleName, char *modulePath, int type);
|
2007-06-06 12:52:37 +00:00
|
|
|
static pid_t FindProcessPID(char* name, pid_t thePID);
|
2016-12-21 14:08:36 +00:00
|
|
|
static int KillOneProcess(char* name);
|
|
|
|
static double dtime(void);
|
|
|
|
static void SleepSeconds(double seconds);
|
2013-06-18 11:03:24 +00:00
|
|
|
static void GetPreferredLanguages();
|
|
|
|
static void LoadPreferredLanguages();
|
2018-06-27 12:37:53 +00:00
|
|
|
static void showDebugMsg(const char *format, ...);
|
2014-01-21 12:20:53 +00:00
|
|
|
static Boolean ShowMessage(Boolean allowCancel, Boolean continueButton, Boolean yesNoButtons, const char *format, ...);
|
2016-12-21 14:08:36 +00:00
|
|
|
int callPosixSpawn(const char *cmd, bool delayForResult=false);
|
2018-06-27 12:37:53 +00:00
|
|
|
static void print_to_log_file(const char *format, ...);
|
2016-12-21 14:08:36 +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";
|
2018-06-26 13:38:51 +00:00
|
|
|
static char loginName[256];
|
|
|
|
|
|
|
|
|
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;
|
2016-12-21 14:08:36 +00:00
|
|
|
char cmd[MAXPATHLEN+64];
|
2007-06-08 11:16:48 +00:00
|
|
|
Boolean cancelled = false;
|
2017-07-14 11:12:16 +00:00
|
|
|
pid_t activeAppPID = 0;
|
2014-01-21 12:20:53 +00:00
|
|
|
struct stat sbuf;
|
2018-06-27 12:37:53 +00:00
|
|
|
FILE *f;
|
2007-06-06 12:52:37 +00:00
|
|
|
OSStatus err = noErr;
|
2018-06-26 13:38:51 +00:00
|
|
|
|
2016-12-21 14:08:36 +00:00
|
|
|
pathToSelf[0] = '\0';
|
2007-06-06 12:52:37 +00:00
|
|
|
// Get the full path to our executable inside this application's bundle
|
2016-12-21 14:08:36 +00:00
|
|
|
getPathToThisApp(pathToSelf, sizeof(pathToSelf));
|
|
|
|
if (!pathToSelf[0]) {
|
|
|
|
ShowMessage(false, false, false, "Couldn't get path to self.");
|
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
|
|
|
|
2018-07-11 10:59:34 +00:00
|
|
|
if (!check_branding_arrays(cmd, sizeof(cmd))) {
|
|
|
|
ShowMessage(false, false, false, (char *)_("Branding array has too few entries: %s"), cmd);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
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 "
|
2016-12-21 14:08:36 +00:00
|
|
|
|
2013-06-18 11:03:24 +00:00
|
|
|
strlcpy(gBrandName, p, sizeof(gBrandName));
|
|
|
|
|
2018-06-26 13:38:51 +00:00
|
|
|
// Determine whether this is the initial launch or the relaunch with privileges
|
2017-07-17 03:50:03 +00:00
|
|
|
if ( (argc == 3) && (strcmp(argv[1], "--privileged") == 0) ) {
|
2017-07-14 11:12:16 +00:00
|
|
|
// Prevent displaying "OSAScript" in menu bar on newer versions of OS X
|
|
|
|
activeAppPID = (pid_t)atol(argv[2]);
|
2017-07-17 03:50:03 +00:00
|
|
|
if (activeAppPID > 0) {
|
2017-07-14 11:12:16 +00:00
|
|
|
BringAppWithPidToFront(activeAppPID); // Usually Finder
|
|
|
|
}
|
2017-07-17 03:50:03 +00:00
|
|
|
// Give the run loop a chance to handle the BringAppWithPidToFront call
|
2017-07-15 09:40:44 +00:00
|
|
|
// CFRunLoopRunInMode(kCFRunLoopCommonModes, (CFTimeInterval)0.5, false);
|
|
|
|
// Apparently, usleep() lets run loop run
|
|
|
|
usleep(100000);
|
|
|
|
|
2013-06-18 11:03:24 +00:00
|
|
|
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();
|
|
|
|
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.
|
|
|
|
|
2018-06-27 12:37:53 +00:00
|
|
|
// getlogin() gives unreliable results under OS 10.6.2, so use environment
|
|
|
|
strncpy(loginName, getenv("USER"), sizeof(loginName)-1);
|
|
|
|
mkdir("/tmp/UninstallBOINC", 0777);
|
|
|
|
chmod("/tmp/UninstallBOINC", 0777); // Needed because mkdir sets permissions restricted by umask (022)
|
|
|
|
f = fopen("/tmp/UninstallBOINC/loginName", "w");
|
|
|
|
if (!f) {
|
|
|
|
ShowMessage(false, false, false, (char *)_("Error saving user name"), p);
|
|
|
|
return fnOpnErr;
|
|
|
|
}
|
|
|
|
fprintf(f, "%s", loginName);
|
|
|
|
fclose(f);
|
|
|
|
|
2013-06-18 11:03:24 +00:00
|
|
|
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);
|
2016-12-21 14:08:36 +00:00
|
|
|
|
2012-06-16 15:03:11 +00:00
|
|
|
if (! cancelled) {
|
2017-07-14 11:12:16 +00:00
|
|
|
// Prevent displaying "OSAScript" in menu bar on newer versions of OS X
|
2017-07-17 03:50:03 +00:00
|
|
|
activeAppPID = getActiveAppPid();
|
|
|
|
// ShowMessage(false, true, false, "active app = %d", activeAppPID); // for debugging
|
2017-07-14 11:12:16 +00:00
|
|
|
|
|
|
|
// The "activate" command brings the password dialog to the front and makes it the active window.
|
2016-12-21 14:08:36 +00:00
|
|
|
// "with administrator privileges" launches the helper application as user root.
|
2017-07-17 03:50:03 +00:00
|
|
|
sprintf(cmd, "osascript -e 'activate' -e 'do shell script \"sudo \\\"%s\\\" --privileged %d\" with administrator privileges'", pathToSelf, activeAppPID);
|
2016-12-21 14:08:36 +00:00
|
|
|
err = callPosixSpawn(cmd, true);
|
2012-06-16 15:03:11 +00:00
|
|
|
}
|
2007-06-08 11:16:48 +00:00
|
|
|
|
2016-12-21 14:08:36 +00:00
|
|
|
if (cancelled || (err != noErr)) {
|
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;
|
|
|
|
}
|
|
|
|
|
2016-12-21 14:08:36 +00:00
|
|
|
CFStringRef CFBOINCDataPath, CFUserPrefsPath;
|
|
|
|
char BOINCDataPath[MAXPATHLEN], temp[MAXPATHLEN], PathToPrefs[MAXPATHLEN];
|
|
|
|
Boolean success = false;
|
|
|
|
|
|
|
|
CFURLRef urlref = CFURLCreateWithFileSystemPath(NULL, CFSTR("/Library"),
|
|
|
|
kCFURLPOSIXPathStyle, true);
|
|
|
|
success = CFURLCopyResourcePropertyForKey(urlref, kCFURLLocalizedNameKey,
|
|
|
|
&CFBOINCDataPath, NULL);
|
|
|
|
CFRelease(urlref);
|
|
|
|
if (success) {
|
|
|
|
success = CFStringGetCString(CFBOINCDataPath, temp,
|
|
|
|
sizeof(temp), kCFStringEncodingUTF8);
|
|
|
|
CFRelease(CFBOINCDataPath);
|
|
|
|
}
|
2013-06-20 11:06:24 +00:00
|
|
|
|
2016-12-21 14:08:36 +00:00
|
|
|
if (success) {
|
|
|
|
success = false;
|
|
|
|
strlcpy(BOINCDataPath, "/", sizeof(BOINCDataPath));
|
|
|
|
strlcat(BOINCDataPath, temp, sizeof(BOINCDataPath));
|
|
|
|
strlcat(BOINCDataPath, "/", sizeof(BOINCDataPath));
|
2007-06-06 12:52:37 +00:00
|
|
|
|
2016-12-21 14:08:36 +00:00
|
|
|
urlref = CFURLCreateWithFileSystemPath(NULL, CFSTR("/Library/Application Support"),
|
|
|
|
kCFURLPOSIXPathStyle, true);
|
|
|
|
success = CFURLCopyResourcePropertyForKey(urlref, kCFURLLocalizedNameKey,
|
|
|
|
&CFBOINCDataPath, NULL);
|
|
|
|
CFRelease(urlref);
|
|
|
|
}
|
|
|
|
if (success) {
|
|
|
|
success = CFStringGetCString(CFBOINCDataPath, temp,
|
|
|
|
sizeof(temp), kCFStringEncodingUTF8);
|
|
|
|
CFRelease(CFBOINCDataPath);
|
|
|
|
}
|
|
|
|
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;
|
|
|
|
|
|
|
|
urlref = CFURLCreateWithFileSystemPath(NULL, CFSTR("/Users"),
|
|
|
|
kCFURLPOSIXPathStyle, true);
|
|
|
|
success = CFURLCopyResourcePropertyForKey(urlref, kCFURLLocalizedNameKey,
|
|
|
|
&CFUserPrefsPath, NULL);
|
|
|
|
CFRelease(urlref);
|
|
|
|
if (success) {
|
|
|
|
success = CFStringGetCString(CFUserPrefsPath, temp, sizeof(temp),
|
|
|
|
kCFStringEncodingUTF8);
|
|
|
|
CFRelease(CFUserPrefsPath);
|
|
|
|
}
|
|
|
|
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));
|
2013-06-20 11:06:24 +00:00
|
|
|
|
2016-12-21 14:08:36 +00:00
|
|
|
sprintf(temp, "/Users/%s/Library", loginName);
|
|
|
|
CFUserPrefsPath = CFStringCreateWithCString(kCFAllocatorDefault, temp,
|
|
|
|
kCFStringEncodingUTF8);
|
|
|
|
|
|
|
|
urlref = CFURLCreateWithFileSystemPath(NULL, CFUserPrefsPath,
|
|
|
|
kCFURLPOSIXPathStyle, true);
|
|
|
|
CFRelease(CFUserPrefsPath);
|
|
|
|
success = CFURLCopyResourcePropertyForKey(urlref, kCFURLLocalizedNameKey,
|
|
|
|
&CFUserPrefsPath, NULL);
|
|
|
|
CFRelease(urlref);
|
|
|
|
}
|
|
|
|
if (success) {
|
|
|
|
success = CFStringGetCString(CFUserPrefsPath, temp, sizeof(temp),
|
|
|
|
kCFStringEncodingUTF8);
|
|
|
|
CFRelease(CFUserPrefsPath);
|
|
|
|
}
|
|
|
|
if (success) {
|
2013-06-20 11:06:24 +00:00
|
|
|
success = false;
|
2016-12-21 14:08:36 +00:00
|
|
|
strlcat(PathToPrefs, temp, sizeof(PathToPrefs));
|
|
|
|
strlcat(PathToPrefs, "/", sizeof(PathToPrefs));
|
|
|
|
|
|
|
|
sprintf(temp, "/Users/%s/Library/Preferences", loginName);
|
|
|
|
CFUserPrefsPath = CFStringCreateWithCString(kCFAllocatorDefault, temp,
|
|
|
|
kCFStringEncodingUTF8);
|
|
|
|
urlref = CFURLCreateWithFileSystemPath(NULL, CFUserPrefsPath,
|
|
|
|
kCFURLPOSIXPathStyle, true);
|
|
|
|
CFRelease(CFUserPrefsPath);
|
|
|
|
success = CFURLCopyResourcePropertyForKey(urlref, kCFURLLocalizedNameKey,
|
|
|
|
&CFUserPrefsPath, NULL);
|
|
|
|
CFRelease(urlref);
|
|
|
|
}
|
|
|
|
if (success) {
|
|
|
|
success = CFStringGetCString(CFUserPrefsPath, temp, sizeof(temp),
|
|
|
|
kCFStringEncodingUTF8);
|
|
|
|
CFRelease(CFUserPrefsPath);
|
|
|
|
}
|
|
|
|
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));
|
|
|
|
}
|
2013-06-20 11:06:24 +00:00
|
|
|
|
2016-12-21 14:08:36 +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) {
|
|
|
|
if (KillOneProcess("VirtualBox")) {
|
|
|
|
sleep(5);
|
2014-01-21 12:20:53 +00:00
|
|
|
}
|
2016-12-21 14:08:36 +00:00
|
|
|
// List of processes to kill taken from my_processes
|
|
|
|
// array in VirtualBox_Uninstall.tool script:
|
|
|
|
KillOneProcess("VirtualBox-amd64");
|
|
|
|
KillOneProcess("VirtualBox-x86");
|
|
|
|
KillOneProcess("VirtualBoxVM");
|
|
|
|
KillOneProcess("VirtualBoxVM-amd64");
|
|
|
|
KillOneProcess("VirtualBoxVM-x86");
|
|
|
|
KillOneProcess("VBoxManage");
|
|
|
|
KillOneProcess("VBoxManage-amd64");
|
|
|
|
KillOneProcess("VBoxManage-x86");
|
|
|
|
KillOneProcess("VBoxHeadless");
|
|
|
|
KillOneProcess("VBoxHeadless-amd64");
|
|
|
|
KillOneProcess("VBoxHeadless-x86");
|
|
|
|
KillOneProcess("vboxwebsrv");
|
|
|
|
KillOneProcess("vboxwebsrv-amd64");
|
|
|
|
KillOneProcess("vboxwebsrv-x86");
|
|
|
|
KillOneProcess("VBoxXPCOMIPCD");
|
|
|
|
KillOneProcess("VBoxXPCOMIPCD-amd64");
|
|
|
|
KillOneProcess("VBoxXPCOMIPCD-x86");
|
|
|
|
KillOneProcess("VBoxSVC");
|
|
|
|
KillOneProcess("VBoxSVC-amd64");
|
|
|
|
KillOneProcess("VBoxSVC-x86");
|
|
|
|
KillOneProcess("VBoxNetDHCP");
|
|
|
|
KillOneProcess("VBoxNetDHCP-amd64");
|
|
|
|
KillOneProcess("VBoxNetDHCP-x86");
|
|
|
|
sleep(2);
|
|
|
|
|
|
|
|
snprintf(cmd, sizeof(cmd), "source \"%s\" --unattended", pathToVBoxUninstallTool);
|
|
|
|
callPosixSpawn(cmd);
|
2014-01-21 12:20:53 +00:00
|
|
|
}
|
2013-06-20 11:06:24 +00:00
|
|
|
}
|
|
|
|
|
2016-12-21 14:08:36 +00:00
|
|
|
ShowMessage(false, false, false, (char *)_("Removal completed.\n\n You may want to remove the following remaining items using the Finder: \n"
|
|
|
|
"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) {
|
2018-06-27 12:37:53 +00:00
|
|
|
FILE *f;
|
2007-06-06 12:52:37 +00:00
|
|
|
pid_t coreClientPID = 0;
|
2018-06-26 13:38:51 +00:00
|
|
|
int i;
|
2009-11-19 10:41:47 +00:00
|
|
|
char cmd[1024];
|
|
|
|
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/";
|
2017-02-27 14:32:17 +00:00
|
|
|
CFStringRef cfPath;
|
|
|
|
CFURLRef appURL;
|
2018-06-26 13:38:51 +00:00
|
|
|
int pathOffset;
|
2012-05-03 11:40:55 +00:00
|
|
|
#endif
|
2007-06-06 12:52:37 +00:00
|
|
|
|
|
|
|
#if TESTING
|
2018-06-27 12:37:53 +00:00
|
|
|
showDebugMsg("Permission OK after relaunch");
|
2007-06-06 12:52:37 +00:00
|
|
|
#endif
|
|
|
|
|
2018-06-27 12:37:53 +00:00
|
|
|
f = fopen("/tmp/UninstallBOINC/loginName", "r");
|
|
|
|
if (f) {
|
|
|
|
fgets(loginName, sizeof(loginName), f);
|
|
|
|
fclose(f);
|
2018-05-23 15:10:02 +00:00
|
|
|
}
|
2018-06-27 12:37:53 +00:00
|
|
|
|
|
|
|
// With fast user switching, each logged in user can be running
|
2018-07-31 02:33:51 +00:00
|
|
|
// a separate copy of the Manager; killall terminates all of them
|
2018-06-27 12:37:53 +00:00
|
|
|
for (i=0; i<NUMBRANDS; ++i) {
|
|
|
|
#if TESTING
|
|
|
|
showDebugMsg("killing any running instances of %s", appName[i]);
|
|
|
|
#endif
|
2018-07-31 02:33:51 +00:00
|
|
|
snprintf(cmd, sizeof(cmd), "killall \"%s\"", appName[i]);
|
2018-06-27 12:37:53 +00:00
|
|
|
callPosixSpawn(cmd);
|
|
|
|
}
|
|
|
|
|
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
|
2017-02-27 14:32:17 +00:00
|
|
|
// WARNING -- SEARCHFORALLBOINCMANAGERS CODE HAS NOT BEEN TESTED
|
|
|
|
|
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);
|
|
|
|
|
2017-02-27 14:32:17 +00:00
|
|
|
err = GetPathToAppFromID('BNC!', CFSTR("edu.berkeley.boinc"), myRmCommand+pathOffset, MAXPATHLEN);
|
|
|
|
if (err) {
|
2007-06-07 12:24:29 +00:00
|
|
|
break;
|
2017-02-27 14:32:17 +00:00
|
|
|
}
|
2007-06-07 12:24:29 +00:00
|
|
|
|
|
|
|
strlcat(myRmCommand, "\"", sizeof(myRmCommand));
|
|
|
|
|
|
|
|
#if TESTING
|
2018-06-27 12:37:53 +00:00
|
|
|
showDebugMsg("manager: %s", myRmCommand);
|
2007-06-07 12:24:29 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
p = strstr(myRmCommand, notBoot);
|
|
|
|
|
|
|
|
if (p == myRmCommand+pathOffset) {
|
|
|
|
#if TESTING
|
2018-06-27 12:37:53 +00:00
|
|
|
showDebugMsg("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
|
2017-02-27 14:32:17 +00:00
|
|
|
// LaunchServices Database; otherwise GetPathToAppFromID might return
|
|
|
|
// this application again after it's been deleted.
|
2007-06-07 12:24:29 +00:00
|
|
|
strlcpy(plistRmCommand, myRmCommand, sizeof(plistRmCommand));
|
|
|
|
strlcat(plistRmCommand, "/Contents/info.plist", sizeof(plistRmCommand));
|
|
|
|
#if TESTING
|
2018-06-27 12:37:53 +00:00
|
|
|
showDebugMsg("Deleting info.plist: %s", plistRmCommand);
|
2007-06-07 12:24:29 +00:00
|
|
|
#endif
|
2016-12-21 14:08:36 +00:00
|
|
|
callPosixSpawn(plistRmCommand);
|
2017-02-27 14:32:17 +00:00
|
|
|
cfPath = CFStringCreateWithCString(NULL, myRmCommand+pathOffset, kCFStringEncodingUTF8);
|
|
|
|
appURL = CFURLCreateWithFileSystemPath(NULL, CFStringRef filePath, kCFURLPOSIXPathStyle, true);
|
|
|
|
if (cfPath) {
|
|
|
|
CFRelease(cfPath);
|
|
|
|
}
|
|
|
|
if (appURL) {
|
|
|
|
CFRelease(appURL);
|
|
|
|
}
|
|
|
|
|
|
|
|
err = LSRegisterURL, true);
|
2007-06-07 12:24:29 +00:00
|
|
|
#if TESTING
|
|
|
|
if (err)
|
2018-06-27 12:37:53 +00:00
|
|
|
showDebugMsg("LSRegisterFSRef returned error %d", err);
|
2007-06-07 12:24:29 +00:00
|
|
|
#endif
|
2016-12-21 14:08:36 +00:00
|
|
|
callPosixSpawn(myRmCommand);
|
2007-06-07 12:24:29 +00:00
|
|
|
}
|
|
|
|
}
|
2016-12-21 14:08:36 +00:00
|
|
|
#endif // SEARCHFORALLBOINCMANAGERS
|
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
|
2018-06-26 13:38:51 +00:00
|
|
|
// Remove everything we may have installed, though the above 2 calls already deleted some
|
2014-03-07 12:28:32 +00:00
|
|
|
|
2018-06-26 13:38:51 +00:00
|
|
|
for (i=0; i<NUMBRANDS; ++i) {
|
|
|
|
sprintf(cmd, "rm -rf \"%s\"", appPath[i]);
|
|
|
|
callPosixSpawn(cmd);
|
|
|
|
sprintf(cmd, "rm -rf \"/Library/Screen Savers/%s.saver\"", saverName[i]);
|
|
|
|
callPosixSpawn(cmd);
|
|
|
|
}
|
2011-02-15 11:02:40 +00:00
|
|
|
|
2018-06-26 13:38:51 +00:00
|
|
|
for (i=0; i<NUMBRANDS; ++i) {
|
|
|
|
// NOTE: the following work for older versions of OS X, but newer versions
|
|
|
|
// of OS X store the receipts elsewhere. However, this step is probably
|
|
|
|
// not needed to allow installing older versions of BOINC over newer ones
|
|
|
|
// with more recent versions of OS X.
|
|
|
|
// Delete any receipt from a very old BOINC Installer
|
|
|
|
sprintf(cmd, "rm -rf \"/Library/Receipts/%s\".pkg", brandName[i]);
|
|
|
|
callPosixSpawn(cmd);
|
|
|
|
|
|
|
|
// Delete any receipt from a newer BOINC installer (which has
|
|
|
|
// a wrapper application around the installer package.)
|
|
|
|
sprintf(cmd, "rm -rf \"%s\"", receiptName[i]);
|
|
|
|
callPosixSpawn(cmd);
|
|
|
|
}
|
|
|
|
|
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
|
2016-12-21 14:08:36 +00:00
|
|
|
// callPosixSpawn ("rm -rf \"/Library/Application Support/BOINC Data\"");
|
2018-06-27 12:37:53 +00:00
|
|
|
pw = getpwnam(loginName);
|
2009-11-19 10:41:47 +00:00
|
|
|
sprintf(cmd, "chown -R %d:%d \"/Library/Application Support/BOINC Data\"", pw->pw_uid, pw->pw_gid);
|
2016-12-21 14:08:36 +00:00
|
|
|
callPosixSpawn (cmd);
|
|
|
|
callPosixSpawn("chmod -R u+rw-s,g+r-w-s,o+r-w \"/Library/Application Support/BOINC Data\"");
|
|
|
|
callPosixSpawn("chmod 600 \"/Library/Application Support/BOINC Data/gui_rpc_auth.cfg\"");
|
2009-11-19 10:41:47 +00:00
|
|
|
|
|
|
|
// Phase 6: step through all users and do user-specific cleanup
|
2007-06-06 12:52:37 +00:00
|
|
|
CleanupAllVisibleUsers();
|
|
|
|
|
2016-12-21 14:08:36 +00:00
|
|
|
callPosixSpawn ("dscl . -delete /users/boinc_master");
|
|
|
|
callPosixSpawn ("dscl . -delete /groups/boinc_master");
|
|
|
|
callPosixSpawn ("dscl . -delete /users/boinc_project");
|
|
|
|
callPosixSpawn ("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
|
2018-06-27 12:37:53 +00:00
|
|
|
showDebugMsg("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
|
2018-06-27 12:37:53 +00:00
|
|
|
showDebugMsg("Bundles: %s", myRmCommand);
|
2007-06-07 12:24:29 +00:00
|
|
|
#endif
|
|
|
|
|
2016-12-21 14:08:36 +00:00
|
|
|
callPosixSpawn(myRmCommand);
|
2007-06-07 12:24:29 +00:00
|
|
|
} else {
|
|
|
|
#if TESTING
|
2018-06-27 12:37:53 +00:00
|
|
|
// showDebugMsg("Bundles: Not deleting %s", myRmCommand+pathOffset);
|
2007-06-07 12:24:29 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
} // if (thisID)
|
|
|
|
#if TESTING
|
|
|
|
else
|
2018-06-27 12:37:53 +00:00
|
|
|
showDebugMsg("CFBundleGetIdentifier failed for index %d", index);
|
2007-06-07 12:24:29 +00:00
|
|
|
#endif
|
|
|
|
CFRelease(thisBundle);
|
|
|
|
} //if (thisBundle)
|
|
|
|
#if TESTING
|
|
|
|
else
|
2018-06-27 12:37:53 +00:00
|
|
|
showDebugMsg("CFBundleCreate failed for index %d", index);
|
2007-06-07 12:24:29 +00:00
|
|
|
#endif
|
|
|
|
CFRelease(bundleURLRef);
|
|
|
|
} // if (bundleURLRef)
|
|
|
|
#if TESTING
|
|
|
|
else
|
2018-06-27 12:37:53 +00:00
|
|
|
showDebugMsg("CFURLCreateWithFileSystemPath failed");
|
2007-06-07 12:24:29 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
CFRelease(urlStringRef);
|
|
|
|
} // if (urlStringRef)
|
|
|
|
#if TESTING
|
|
|
|
else
|
2018-06-27 12:37:53 +00:00
|
|
|
showDebugMsg("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'
|
|
|
|
};
|
|
|
|
|
2016-12-21 14:08:36 +00:00
|
|
|
CFStringRef kSystemEventsBundleID = CFSTR("com.apple.systemevents");
|
|
|
|
char *systemEventsAppName = "System Events";
|
2012-05-03 11:33:03 +00:00
|
|
|
|
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
|
|
|
{
|
2018-06-26 13:38:51 +00:00
|
|
|
long brandID = 0;
|
|
|
|
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];
|
|
|
|
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();
|
|
|
|
|
2016-12-21 14:08:36 +00:00
|
|
|
err = noErr;
|
2018-06-26 13:38:51 +00:00
|
|
|
brandID = GetBrandID("/Library/Application Support/BOINC Data/Branding");
|
2017-02-27 14:32:17 +00:00
|
|
|
|
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
|
2018-06-27 12:37:53 +00:00
|
|
|
showDebugMsg("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) {
|
2018-06-26 13:38:51 +00:00
|
|
|
if (strstr(p, "/var/empty") != NULL) {
|
|
|
|
flag = 1;
|
|
|
|
break;
|
|
|
|
}
|
2012-03-29 09:42:32 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
pclose(f);
|
|
|
|
}
|
|
|
|
|
2018-06-26 13:38:51 +00:00
|
|
|
if (flag) {
|
|
|
|
sprintf(s, "dscl . -read \"/Users/%s\" UserShell", human_user_name);
|
|
|
|
f = popen(s, "r");
|
|
|
|
if (f) {
|
|
|
|
while (PersistentFGets(buf, sizeof(buf), f)) {
|
|
|
|
p = strrchr(buf, ' ');
|
|
|
|
if (p) {
|
|
|
|
if (strstr(p, "/usr/bin/false") != NULL) flag |= 2;
|
|
|
|
}
|
2012-03-29 09:42:32 +00:00
|
|
|
}
|
2018-06-26 13:38:51 +00:00
|
|
|
pclose(f);
|
2012-03-29 09:42:32 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
// Skip all non-human (non-login) users
|
|
|
|
if (flag == 3) { // if (Home Directory == "/var/empty") && (UserShell == "/usr/bin/false")
|
|
|
|
#if TESTING
|
2018-06-27 12:37:53 +00:00
|
|
|
showDebugMsg("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
|
2018-06-27 12:37:53 +00:00
|
|
|
showDebugMsg("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
|
2018-06-27 12:37:53 +00:00
|
|
|
sprintf(s, "dscl . -delete /groups/boinc_master users \"%s\"", pw->pw_name);
|
2016-12-21 14:08:36 +00:00
|
|
|
callPosixSpawn (s);
|
2007-06-06 12:52:37 +00:00
|
|
|
|
2018-06-27 12:37:53 +00:00
|
|
|
sprintf(s, "dscl . -delete /groups/boinc_project users \"%s\"", pw->pw_name);
|
2016-12-21 14:08:36 +00:00
|
|
|
callPosixSpawn (s);
|
2007-06-06 12:52:37 +00:00
|
|
|
|
2018-06-26 13:38:51 +00:00
|
|
|
// Set login item for this user
|
|
|
|
bool useOSASript = false;
|
|
|
|
|
|
|
|
if ((compareOSVersionTo(10, 13) < 0)
|
|
|
|
|| (strcmp(loginName, human_user_name) == 0)
|
|
|
|
|| (strcmp(loginName, pw->pw_name) == 0)
|
|
|
|
|| (strcmp(loginName, pw->pw_gecos) == 0)) {
|
|
|
|
useOSASript = true;
|
|
|
|
}
|
|
|
|
#if USE_OSASCRIPT_FOR_ALL_LOGGED_IN_USERS
|
|
|
|
if (! useOSASript) {
|
|
|
|
useOSASript = IsUserLoggedIn(pw->pw_name);
|
|
|
|
}
|
2012-05-03 11:33:03 +00:00
|
|
|
#endif
|
2018-06-26 13:38:51 +00:00
|
|
|
if (useOSASript) {
|
|
|
|
snprintf(s, sizeof(s), "/Users/%s/Library/LaunchAgents/edu.berkeley.boinc.plist", pw->pw_name);
|
|
|
|
boinc_delete_file(s);
|
2012-05-03 11:33:03 +00:00
|
|
|
#if TESTING
|
2018-06-27 12:37:53 +00:00
|
|
|
showDebugMsg("calling DeleteLoginItemOSAScript for user %s, euid = %d\n",
|
2018-06-26 13:38:51 +00:00
|
|
|
pw->pw_name, geteuid());
|
2012-05-06 08:22:37 +00:00
|
|
|
#endif
|
2018-06-26 13:38:51 +00:00
|
|
|
DeleteLoginItemOSAScript(pw->pw_name);
|
|
|
|
} else {
|
2012-05-06 08:22:37 +00:00
|
|
|
#if TESTING
|
2018-06-27 12:37:53 +00:00
|
|
|
showDebugMsg("calling DeleteLoginItemLaunchAgent for user %s, euid = %d\n",
|
2018-06-26 13:38:51 +00:00
|
|
|
pw->pw_name, geteuid());
|
2012-05-03 11:33:03 +00:00
|
|
|
#endif
|
2018-06-26 13:38:51 +00:00
|
|
|
DeleteLoginItemLaunchAgent(brandID, pw);
|
2011-09-24 12:43:19 +00:00
|
|
|
}
|
2016-12-21 14:08:36 +00:00
|
|
|
|
2019-11-08 11:40:22 +00:00
|
|
|
#if TESTING
|
2019-12-06 13:32:28 +00:00
|
|
|
showDebugMsg("calling DeleteScreenSaverLaunchAgent for user %s, euid = %d\n",
|
2019-11-08 11:40:22 +00:00
|
|
|
pw->pw_name);
|
|
|
|
#endif
|
2019-12-06 13:32:28 +00:00
|
|
|
DeleteScreenSaverLaunchAgent(pw);
|
2019-11-08 11:40:22 +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);
|
2016-12-21 14:08:36 +00:00
|
|
|
// callPosixSpawn (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);
|
2016-12-21 14:08:36 +00:00
|
|
|
callPosixSpawn (s);
|
2014-03-07 12:28:32 +00:00
|
|
|
|
2018-06-27 12:37:53 +00:00
|
|
|
// Set screensaver to "Flurry" screensaver only
|
|
|
|
// if it was BOINC unbranded or branded screensaver.
|
2007-06-06 12:52:37 +00:00
|
|
|
changeSaver = false;
|
2018-05-23 15:10:02 +00:00
|
|
|
|
2018-06-26 13:38:51 +00:00
|
|
|
err = GetCurrentScreenSaverSelection(pw, s, sizeof(s) -1);
|
|
|
|
if (err == noErr) {
|
|
|
|
for (i=0; i<NUMBRANDS; ++i) {
|
|
|
|
if (strcmp(s, saverName[i]) == 0) {
|
2018-05-23 15:10:02 +00:00
|
|
|
changeSaver = true;
|
|
|
|
}
|
2009-12-16 12:50:40 +00:00
|
|
|
}
|
2018-06-27 12:37:53 +00:00
|
|
|
#if TESTING
|
|
|
|
showDebugMsg("Current screensaver selection for user %s is %s\n", pw->pw_name, s);
|
|
|
|
#endif
|
2007-06-06 12:52:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (changeSaver) {
|
|
|
|
#if TESTING
|
2018-06-27 12:37:53 +00:00
|
|
|
showDebugMsg("Setting screensaver for user %s to Flurry\n", pw->pw_name);
|
2007-06-06 12:52:37 +00:00
|
|
|
#endif
|
2018-06-27 12:37:53 +00:00
|
|
|
seteuid(pw->pw_uid); // Temporarily set effective uid to this user
|
|
|
|
err = SetScreenSaverSelection("Flurry", "/System/Library/Screen Savers/Flurry.saver", 0);
|
|
|
|
seteuid(saved_euid); // Set effective uid back to privileged user
|
2018-06-26 13:38:51 +00:00
|
|
|
// This seems to work also:
|
|
|
|
// sprintf(s, "su -l \"%s\" -c 'defaults -currentHost write com.apple.screensaver moduleDict -dict moduleName \"Computer Name\" path \"/System/Library/Frameworks/ScreenSaver.framework/Resources/Computer Name.saver"\" type 0'");
|
|
|
|
// callPosixSpawn(s);
|
2018-06-27 12:37:53 +00:00
|
|
|
#if TESTING
|
|
|
|
// showDebugMsg("After seteuid(%d) for user %s, euid = %d, saved_uid = %d", pw->pw_uid, human_user_name, geteuid(), saved_uid);
|
|
|
|
#endif
|
2018-06-26 13:38:51 +00:00
|
|
|
}
|
2012-06-16 15:03:11 +00:00
|
|
|
} // End userIndex loop
|
|
|
|
|
|
|
|
sleep(1);
|
2012-05-03 11:33:03 +00:00
|
|
|
|
2007-06-06 12:52:37 +00:00
|
|
|
return noErr;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-06-26 13:38:51 +00:00
|
|
|
static void DeleteLoginItemOSAScript(char *userName)
|
2007-06-06 12:52:37 +00:00
|
|
|
{
|
2018-06-26 13:38:51 +00:00
|
|
|
int i, j;
|
2011-08-11 10:20:25 +00:00
|
|
|
char cmd[2048];
|
2018-06-26 13:38:51 +00:00
|
|
|
char systemEventsPath[1024];
|
|
|
|
pid_t systemEventsPID;
|
|
|
|
OSErr err, err2;
|
|
|
|
#if USE_OSASCRIPT_FOR_ALL_LOGGED_IN_USERS
|
|
|
|
Boolean isHighSierraOrLater = (compareOSVersionTo(10, 13) >= 0);
|
|
|
|
// NOTE: It may not be necessary to kill and relaunch the
|
|
|
|
// System Events application for each logged in user under High Sierra
|
|
|
|
#endif
|
2007-06-06 12:52:37 +00:00
|
|
|
|
2012-05-03 11:33:03 +00:00
|
|
|
#if TESTING
|
2018-06-27 12:37:53 +00:00
|
|
|
showDebugMsg("Adjusting login items for user %s\n", userName);
|
2018-06-26 13:38:51 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
// We must launch the System Events application for the target user
|
|
|
|
err = noErr;
|
|
|
|
systemEventsPath[0] = '\0';
|
|
|
|
|
|
|
|
err = GetPathToAppFromID(kSystemEventsCreator, kSystemEventsBundleID, systemEventsPath, sizeof(systemEventsPath));
|
|
|
|
|
|
|
|
#if TESTING
|
|
|
|
if (err == noErr) {
|
2018-06-27 12:37:53 +00:00
|
|
|
showDebugMsg("SystemEvents is at %s\n", systemEventsPath);
|
2018-06-26 13:38:51 +00:00
|
|
|
} else {
|
2018-06-27 12:37:53 +00:00
|
|
|
showDebugMsg("GetPathToAppFromID(kSystemEventsCreator, kSystemEventsBundleID) returned error %d ", (int) err);
|
2007-06-06 12:52:37 +00:00
|
|
|
}
|
2012-05-03 11:33:03 +00:00
|
|
|
#endif
|
2018-06-26 13:38:51 +00:00
|
|
|
|
|
|
|
if (err == noErr) {
|
|
|
|
// Find SystemEvents process. If found, quit it in case
|
|
|
|
// it is running under a different user.
|
|
|
|
#if TESTING
|
2018-06-27 12:37:53 +00:00
|
|
|
showDebugMsg("Telling System Events to quit (at start of DeleteLoginItemOSAScript)\n");
|
2018-06-26 13:38:51 +00:00
|
|
|
#endif
|
|
|
|
systemEventsPID = FindProcessPID(systemEventsAppName, 0);
|
|
|
|
if (systemEventsPID != 0) {
|
|
|
|
err = kill(systemEventsPID, SIGKILL);
|
|
|
|
}
|
|
|
|
#if TESTING
|
|
|
|
if (err != noErr) {
|
2018-06-27 12:37:53 +00:00
|
|
|
showDebugMsg("(systemEventsPID, SIGKILL) returned error %d \n", (int) err);
|
2018-06-26 13:38:51 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
// Wait for the process to be gone
|
|
|
|
for (i=0; i<50; ++i) { // 5 seconds max delay
|
|
|
|
SleepSeconds(0.1); // 1/10 second
|
|
|
|
systemEventsPID = FindProcessPID(systemEventsAppName, 0);
|
|
|
|
if (systemEventsPID == 0) break;
|
|
|
|
}
|
|
|
|
if (i >= 50) {
|
|
|
|
#if TESTING
|
2018-06-27 12:37:53 +00:00
|
|
|
showDebugMsg("Failed to make System Events quit\n");
|
2018-06-26 13:38:51 +00:00
|
|
|
#endif
|
|
|
|
err = noErr;
|
|
|
|
goto cleanupSystemEvents;
|
|
|
|
}
|
|
|
|
sleep(4);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (systemEventsPath[0] != '\0') {
|
|
|
|
#if TESTING
|
2018-06-27 12:37:53 +00:00
|
|
|
showDebugMsg("Launching SystemEvents for user %s\n", userName);
|
2018-06-26 13:38:51 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
for (j=0; j<5; ++j) {
|
|
|
|
sprintf(cmd, "sudo -u \"%s\" -b \"%s/Contents/MacOS/System Events\" &", userName, systemEventsPath);
|
|
|
|
err = callPosixSpawn(cmd);
|
|
|
|
if (err) {
|
|
|
|
#if TESTING
|
2018-06-27 12:37:53 +00:00
|
|
|
showDebugMsg("Command: %s returned error %d (try %d of 5)\n", cmd, (int) err, j);
|
2018-06-26 13:38:51 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
// Wait for the process to start
|
|
|
|
for (i=0; i<50; ++i) { // 5 seconds max delay
|
|
|
|
SleepSeconds(0.1); // 1/10 second
|
|
|
|
systemEventsPID = FindProcessPID(systemEventsAppName, 0);
|
|
|
|
if (systemEventsPID != 0) break;
|
|
|
|
}
|
|
|
|
if (i < 50) break; // Exit j loop on success
|
|
|
|
}
|
|
|
|
if (j >= 5) {
|
|
|
|
#if TESTING
|
2018-06-27 12:37:53 +00:00
|
|
|
showDebugMsg("Failed to launch System Events for user %s\n", userName);
|
2018-06-26 13:38:51 +00:00
|
|
|
#endif
|
|
|
|
err = noErr;
|
|
|
|
goto cleanupSystemEvents;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
sleep(2);
|
2011-09-24 12:43:19 +00:00
|
|
|
|
2018-06-26 13:38:51 +00:00
|
|
|
for (i=0; i<NUMBRANDS; i++) {
|
2018-06-27 12:37:53 +00:00
|
|
|
#if TESTING
|
|
|
|
showDebugMsg("Deleting any login items containing %s for user %s\n", appName[i], userName);
|
|
|
|
#endif
|
2018-06-26 13:38:51 +00:00
|
|
|
#if USE_OSASCRIPT_FOR_ALL_LOGGED_IN_USERS
|
|
|
|
if (isHighSierraOrLater) {
|
2018-06-27 12:37:53 +00:00
|
|
|
sprintf(cmd, "su -l \"%s\" -c 'osascript -e \"tell application \\\"System Events\\\" to delete login item \\\"%s\\\"\"'", userName, appName[i]);
|
2018-06-26 13:38:51 +00:00
|
|
|
} else
|
|
|
|
#endif
|
|
|
|
{
|
2018-06-27 12:37:53 +00:00
|
|
|
sprintf(cmd, "sudo -u \"%s\" osascript -e 'tell application \"System Events\" to delete login item \"%s\"'", userName, appName[i]);
|
2018-06-26 13:38:51 +00:00
|
|
|
}
|
|
|
|
err = callPosixSpawn(cmd);
|
|
|
|
#if TESTING
|
|
|
|
if (err) {
|
2018-06-27 12:37:53 +00:00
|
|
|
showDebugMsg("Command: %s\n", cmd);
|
|
|
|
showDebugMsg("Delete login item containing %s returned error %d\n", appName[i], err);
|
2018-06-26 13:38:51 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
2012-06-18 11:11:44 +00:00
|
|
|
|
2018-06-26 13:38:51 +00:00
|
|
|
cleanupSystemEvents:
|
|
|
|
// Clean up in case this was our last user
|
2018-06-27 12:37:53 +00:00
|
|
|
fprintf(stdout, "Telling System Events to quit (at end of DeleteLoginItemOSAScript)\n");
|
2018-06-26 13:38:51 +00:00
|
|
|
fflush(stdout);
|
|
|
|
systemEventsPID = FindProcessPID(systemEventsAppName, 0);
|
|
|
|
err2 = noErr;
|
|
|
|
if (systemEventsPID != 0) {
|
|
|
|
err2 = kill(systemEventsPID, SIGKILL);
|
|
|
|
}
|
|
|
|
if (err2 != noErr) {
|
|
|
|
#if TESTING
|
2018-06-27 12:37:53 +00:00
|
|
|
showDebugMsg("kill(systemEventsPID, SIGKILL) returned error %d \n", (int) err2);
|
2018-06-26 13:38:51 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
// Wait for the process to be gone
|
|
|
|
for (i=0; i<50; ++i) { // 5 seconds max delay
|
|
|
|
SleepSeconds(0.1); // 1/10 second
|
|
|
|
systemEventsPID = FindProcessPID(systemEventsAppName, 0);
|
|
|
|
if (systemEventsPID == 0) break;
|
|
|
|
}
|
|
|
|
if (i >= 50) {
|
|
|
|
#if TESTING
|
2018-06-27 12:37:53 +00:00
|
|
|
showDebugMsg("Failed to make System Events quit\n");
|
2018-06-26 13:38:51 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
sleep(4);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Under OS 10.13 High Sierra, telling System Events to modify Login Items for
|
|
|
|
// users who are not currently logged in no longer works, even when System Events
|
|
|
|
// is running as that user.
|
|
|
|
// So we create a LaunchAgent for that user. The next time that user logs in, the
|
|
|
|
// LaunchAgent will make the desired changes to that user's Login Items, launch
|
|
|
|
// BOINC Manager if appropriate, and delete itself.
|
|
|
|
//
|
|
|
|
// While we could just use a LaunchAgent to launch BOINC Manager on every login
|
|
|
|
// instead of using it to create a Login Item, I prefer Login Items because:
|
|
|
|
// * they are more readily visible to a less technically aware user through
|
|
|
|
// System Preferences, and
|
|
|
|
// * they are more easily added or removed through System Preferences, and
|
|
|
|
// * continuing to use them is consistent with older versions of BOINC Manager.
|
|
|
|
//
|
|
|
|
Boolean DeleteLoginItemLaunchAgent(long brandID, passwd *pw)
|
2012-06-18 11:11:44 +00:00
|
|
|
{
|
2018-10-08 10:45:36 +00:00
|
|
|
static bool alreadyCopied = false;
|
2018-06-26 13:38:51 +00:00
|
|
|
struct stat sbuf;
|
2018-10-08 10:45:36 +00:00
|
|
|
char path[MAXPATHLEN];
|
2018-06-26 13:38:51 +00:00
|
|
|
char s[2048];
|
2018-10-08 10:45:36 +00:00
|
|
|
OSErr err;
|
|
|
|
|
|
|
|
if (!alreadyCopied) {
|
|
|
|
getPathToThisApp(path, sizeof(path));
|
2020-05-06 12:34:56 +00:00
|
|
|
strncat(path, "/Contents/Resources/boinc_finish_install", sizeof(path)-1);
|
2018-10-09 12:08:45 +00:00
|
|
|
snprintf(s, sizeof(s), "cp -f \"%s\" \"/Library/Application Support/BOINC Data/%s_Finish_Uninstall\"", path, appName[brandID]);
|
2018-10-08 10:45:36 +00:00
|
|
|
err = callPosixSpawn(s);
|
|
|
|
if (err) {
|
|
|
|
printf("[2] Command %s returned error %d\n", s, err);
|
|
|
|
fflush(stdout);
|
|
|
|
} else {
|
|
|
|
alreadyCopied = true;
|
|
|
|
}
|
|
|
|
|
2018-10-09 13:49:33 +00:00
|
|
|
snprintf(s, sizeof(s), "/Library/Application Support/BOINC Data/%s_Finish_Install\"</string>\n", appName[brandID]);
|
2018-10-08 10:45:36 +00:00
|
|
|
chmod(s, 0755);
|
|
|
|
chown(s, pw->pw_uid, pw->pw_gid);
|
|
|
|
}
|
2018-06-26 13:38:51 +00:00
|
|
|
|
|
|
|
// Create a LaunchAgent for the specified user, replacing any LaunchAgent created
|
2018-10-08 10:45:36 +00:00
|
|
|
// previously (such as by Installer or by installing a differently branded BOINC.)
|
2018-06-27 12:37:53 +00:00
|
|
|
|
|
|
|
// Create LaunchAgents directory for this user if it does not yet exist
|
2018-06-26 13:38:51 +00:00
|
|
|
snprintf(s, sizeof(s), "/Users/%s/Library/LaunchAgents", pw->pw_name);
|
|
|
|
if (stat(s, &sbuf) != 0) {
|
|
|
|
mkdir(s, 0755);
|
|
|
|
chown(s, pw->pw_uid, pw->pw_gid);
|
|
|
|
}
|
2012-06-18 11:11:44 +00:00
|
|
|
|
2018-06-26 13:38:51 +00:00
|
|
|
snprintf(s, sizeof(s), "/Users/%s/Library/LaunchAgents/edu.berkeley.boinc.plist", pw->pw_name);
|
|
|
|
FILE* f = fopen(s, "w");
|
|
|
|
if (!f) return false;
|
|
|
|
fprintf(f, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
|
|
|
|
fprintf(f, "<!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">\n");
|
|
|
|
fprintf(f, "<plist version=\"1.0\">\n");
|
|
|
|
fprintf(f, "<dict>\n");
|
|
|
|
fprintf(f, "\t<key>Label</key>\n");
|
2018-10-08 10:45:36 +00:00
|
|
|
fprintf(f, "\t<string>edu.berkeley.fix_login_items</string>\n");
|
2018-06-26 13:38:51 +00:00
|
|
|
fprintf(f, "\t<key>ProgramArguments</key>\n");
|
|
|
|
fprintf(f, "\t<array>\n");
|
2018-10-09 12:08:45 +00:00
|
|
|
fprintf(f, "\t\t<string>/Library/Application Support/BOINC Data/%s_Finish_Uninstall</string>\n", appName[brandID]);
|
2018-06-26 13:38:51 +00:00
|
|
|
// If this user was previously authorized to run the Manager, there
|
|
|
|
// may still be a Login Item for this user, and the Login Item may
|
|
|
|
// launch the Manager before the LaunchAgent deletes the Login Item.
|
|
|
|
// To guard against this, we have the LaunchAgent kill the Manager
|
|
|
|
// (for this user only) if it is running.
|
|
|
|
//
|
2018-10-08 10:45:36 +00:00
|
|
|
// Actually, the uninstaller should have deleted the Manager before
|
|
|
|
// that could happen, so this step is probably unnecessary.
|
|
|
|
//
|
2018-10-09 12:08:45 +00:00
|
|
|
fprintf(f, "\t\t<string>-d</string>\n");
|
|
|
|
fprintf(f, "\t\t<string>%s</string>\n", appName[brandID]);
|
2018-06-26 13:38:51 +00:00
|
|
|
fprintf(f, "\t</array>\n");
|
|
|
|
fprintf(f, "\t<key>RunAtLoad</key>\n");
|
|
|
|
fprintf(f, "\t<true/>\n");
|
|
|
|
fprintf(f, "</dict>\n");
|
|
|
|
fprintf(f, "</plist>\n");
|
|
|
|
fclose(f);
|
2012-06-18 11:11:44 +00:00
|
|
|
|
2018-06-26 13:38:51 +00:00
|
|
|
chmod(s, 0644);
|
|
|
|
chown(s, pw->pw_uid, pw->pw_gid);
|
|
|
|
|
2019-12-06 13:32:28 +00:00
|
|
|
if (IsUserLoggedIn(pw->pw_name)) {
|
|
|
|
sprintf(s, "su -l \"%s\" -c 'launchctl unload /Users/%s/Library/LaunchAgents/edu.berkeley.boinc.plist'", pw->pw_name, pw->pw_name);
|
|
|
|
callPosixSpawn(s);
|
|
|
|
sprintf(s, "su -l \"%s\" -c 'launchctl load /Users/%s/Library/LaunchAgents/edu.berkeley.boinc.plist'", pw->pw_name, pw->pw_name);
|
|
|
|
callPosixSpawn(s);
|
|
|
|
}
|
|
|
|
|
2018-06-26 13:38:51 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-04-23 14:18:54 +00:00
|
|
|
// Some older versions of BOINC installed a Screensaver LaunchAgent for each user.
|
|
|
|
// Even though we no longer do this, delete it if it exists, for backward compatibility
|
2019-11-08 11:40:22 +00:00
|
|
|
void DeleteScreenSaverLaunchAgent(passwd *pw) {
|
|
|
|
char cmd[MAXPATHLEN];
|
|
|
|
|
2019-12-06 13:32:28 +00:00
|
|
|
sprintf(cmd, "/Users/%s/Library/LaunchAgents/edu.berkeley.boinc-sshelper.plist", pw->pw_name);
|
|
|
|
if (boinc_file_exists(cmd)) {
|
|
|
|
sprintf(cmd, "su -l \"%s\" -c 'launchctl unload /Users/%s/Library/LaunchAgents/edu.berkeley.boinc-sshelper.plist'", pw->pw_name, pw->pw_name);
|
|
|
|
callPosixSpawn(cmd);
|
2019-11-08 11:40:22 +00:00
|
|
|
|
2019-12-06 13:32:28 +00:00
|
|
|
snprintf(cmd, sizeof(cmd),
|
|
|
|
"/Users/%s/Library/LaunchAgents/edu.berkeley.boinc-sshelper.plist",
|
|
|
|
pw->pw_name);
|
|
|
|
boinc_delete_file(cmd);
|
|
|
|
}
|
2019-11-08 11:40:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-06-26 13:38:51 +00:00
|
|
|
|
|
|
|
long GetBrandID(char *path)
|
|
|
|
{
|
|
|
|
long iBrandId;
|
|
|
|
|
|
|
|
iBrandId = 0; // Default value
|
2012-06-18 11:11:44 +00:00
|
|
|
|
2018-06-26 13:38:51 +00:00
|
|
|
FILE *f = fopen(path, "r");
|
|
|
|
if (f) {
|
|
|
|
fscanf(f, "BrandId=%ld\n", &iBrandId);
|
|
|
|
fclose(f);
|
2011-09-24 12:43:19 +00:00
|
|
|
}
|
2018-07-11 10:59:34 +00:00
|
|
|
if ((iBrandId < 0) || (iBrandId > (NUMBRANDS-1))) {
|
|
|
|
iBrandId = 0;
|
|
|
|
}
|
2018-06-26 13:38:51 +00:00
|
|
|
return iBrandId;
|
2011-09-24 12:43:19 +00:00
|
|
|
}
|
2007-06-06 12:52:37 +00:00
|
|
|
|
|
|
|
|
2019-12-06 13:32:28 +00:00
|
|
|
static Boolean IsUserLoggedIn(const char *userName){
|
|
|
|
char s[1024];
|
|
|
|
|
|
|
|
sprintf(s, "w -h \"%s\"", userName);
|
|
|
|
FILE *f = popen(s, "r");
|
|
|
|
if (f) {
|
|
|
|
if (PersistentFGets(s, sizeof(s), f) != NULL) {
|
|
|
|
pclose (f);
|
|
|
|
printf("User %s is currently logged in\n", userName);
|
|
|
|
return true; // this user is logged in (perhaps via fast user switching)
|
|
|
|
}
|
|
|
|
pclose (f);
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-06-26 13:38:51 +00:00
|
|
|
OSErr GetCurrentScreenSaverSelection(passwd *pw, char *moduleName, size_t maxLen) {
|
|
|
|
char buf[1024];
|
|
|
|
FILE *f;
|
|
|
|
char *p, *q;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
*moduleName = '\0';
|
|
|
|
sprintf(buf, "su -l \"%s\" -c 'defaults -currentHost read com.apple.screensaver moduleDict'", pw->pw_name);
|
|
|
|
f = popen(buf, "r");
|
|
|
|
if (f == NULL) {
|
|
|
|
#if TESTING
|
2018-06-27 12:37:53 +00:00
|
|
|
showDebugMsg("Could not get current screensaver selection for user %s\n", pw->pw_name);
|
2018-06-26 13:38:51 +00:00
|
|
|
#endif
|
|
|
|
return fnfErr;
|
2012-06-16 15:03:11 +00:00
|
|
|
}
|
|
|
|
|
2018-06-26 13:38:51 +00:00
|
|
|
while (PersistentFGets(buf, sizeof(buf), f))
|
|
|
|
{
|
|
|
|
p = strstr(buf, "moduleName = ");
|
|
|
|
if (p) {
|
|
|
|
p += 13; // Point past "moduleName = "
|
|
|
|
q = moduleName;
|
|
|
|
for (i=0; i<maxLen-1; ++i) {
|
|
|
|
if (*p == '"') {
|
|
|
|
++p;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (*p == ';') break;
|
|
|
|
*q++ = *p++;
|
|
|
|
}
|
|
|
|
*q = '\0';
|
|
|
|
pclose(f);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
2012-06-16 15:03:11 +00:00
|
|
|
|
2018-06-26 13:38:51 +00:00
|
|
|
pclose(f);
|
|
|
|
return fnfErr;
|
2012-06-16 15:03:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-12-21 14:08:36 +00:00
|
|
|
// Kill a process if it exists
|
|
|
|
static int KillOneProcess(char* name) {
|
|
|
|
pid_t thePid;
|
|
|
|
char cmd[MAXPATHLEN+10];
|
2007-06-06 12:52:37 +00:00
|
|
|
|
2016-12-21 14:08:36 +00:00
|
|
|
thePid = FindProcessPID(name, 0);
|
|
|
|
if (thePid <= 0) return 0; // No such process
|
2007-06-06 12:52:37 +00:00
|
|
|
|
2016-12-21 14:08:36 +00:00
|
|
|
kill(thePid, SIGQUIT);
|
|
|
|
for (int i=0; i<20; ++i) {
|
|
|
|
SleepSeconds(0.1);
|
|
|
|
if (!FindProcessPID(NULL, thePid)) {
|
|
|
|
return 0;
|
2007-06-06 12:52:37 +00:00
|
|
|
}
|
|
|
|
}
|
2016-12-21 14:08:36 +00:00
|
|
|
kill(thePid, SIGKILL);
|
|
|
|
for (int i=0; i<20; ++i) {
|
|
|
|
SleepSeconds(0.1);
|
|
|
|
if (!FindProcessPID(NULL, thePid)) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
sprintf(cmd, "killall %s", name);
|
|
|
|
return callPosixSpawn(cmd);
|
2007-06-06 12:52:37 +00:00
|
|
|
}
|
|
|
|
|
2012-05-06 08:22:37 +00:00
|
|
|
|
2016-12-21 14:08:36 +00:00
|
|
|
// return time of day (seconds since 1970) as a double
|
|
|
|
//
|
|
|
|
static double dtime(void) {
|
|
|
|
struct timeval tv;
|
|
|
|
gettimeofday(&tv, 0);
|
|
|
|
return tv.tv_sec + (tv.tv_usec/1.e6);
|
2014-01-21 12:20:53 +00:00
|
|
|
}
|
|
|
|
|
2007-06-06 12:52:37 +00:00
|
|
|
// Uses usleep to sleep for full duration even if a signal is received
|
2016-12-21 14:08:36 +00:00
|
|
|
static void SleepSeconds(double seconds) {
|
|
|
|
double end_time = dtime() + seconds - 0.01;
|
|
|
|
// sleep() and usleep() can be interrupted by SIGALRM,
|
|
|
|
// so we may need multiple calls
|
|
|
|
//
|
|
|
|
while (1) {
|
|
|
|
if (seconds >= 1) {
|
|
|
|
sleep((unsigned int) seconds);
|
|
|
|
} else {
|
|
|
|
usleep((int)fmod(seconds*1000000, 1000000));
|
|
|
|
}
|
|
|
|
seconds = end_time - dtime();
|
|
|
|
if (seconds <= 0) break;
|
|
|
|
}
|
2007-06-06 12:52:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
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
|
2018-06-27 12:37:53 +00:00
|
|
|
f = fopen("/tmp/UninstallBOINC/BOINC_preferred_languages", "w");
|
2013-06-18 11:03:24 +00:00
|
|
|
|
|
|
|
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);
|
2016-12-21 14:08:36 +00:00
|
|
|
if (language == NULL) {
|
|
|
|
if (CFStringGetCString(aLanguage, shortLanguage, sizeof(shortLanguage), kCFStringEncodingMacRoman)) {
|
|
|
|
language = shortLanguage;
|
|
|
|
}
|
|
|
|
}
|
2013-06-18 11:03:24 +00:00
|
|
|
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
|
2018-06-27 12:37:53 +00:00
|
|
|
f = fopen("/tmp/UninstallBOINC/BOINC_preferred_languages", "r");
|
2013-06-18 11:03:24 +00:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-06-27 12:37:53 +00:00
|
|
|
static void showDebugMsg(const char *format, ...) {
|
|
|
|
va_list args;
|
|
|
|
char s[1024];
|
|
|
|
|
|
|
|
va_start(args, format);
|
|
|
|
vsprintf(s, format, args);
|
|
|
|
va_end(args);
|
|
|
|
|
|
|
|
#if DEBUG_PRINT
|
|
|
|
print_to_log_file(s);
|
|
|
|
#else
|
|
|
|
ShowMessage(false, false, false, s);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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;
|
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
|
|
|
|
2016-12-21 14:08:36 +00:00
|
|
|
BringAppToFront();
|
2007-06-06 12:52:37 +00:00
|
|
|
|
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
|
|
|
|
|
|
|
|
2016-12-21 14:08:36 +00:00
|
|
|
#define NOT_IN_TOKEN 0
|
|
|
|
#define IN_SINGLE_QUOTED_TOKEN 1
|
|
|
|
#define IN_DOUBLE_QUOTED_TOKEN 2
|
|
|
|
#define IN_UNQUOTED_TOKEN 3
|
|
|
|
|
|
|
|
int parse_command_line(char* p, char** argv) {
|
|
|
|
int state = NOT_IN_TOKEN;
|
|
|
|
int argc=0;
|
|
|
|
|
|
|
|
while (*p) {
|
|
|
|
switch(state) {
|
|
|
|
case NOT_IN_TOKEN:
|
|
|
|
if (isspace(*p)) {
|
|
|
|
} else if (*p == '\'') {
|
|
|
|
p++;
|
|
|
|
argv[argc++] = p;
|
|
|
|
state = IN_SINGLE_QUOTED_TOKEN;
|
|
|
|
break;
|
|
|
|
} else if (*p == '\"') {
|
|
|
|
p++;
|
|
|
|
argv[argc++] = p;
|
|
|
|
state = IN_DOUBLE_QUOTED_TOKEN;
|
|
|
|
break;
|
|
|
|
} else {
|
|
|
|
argv[argc++] = p;
|
|
|
|
state = IN_UNQUOTED_TOKEN;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case IN_SINGLE_QUOTED_TOKEN:
|
|
|
|
if (*p == '\'') {
|
|
|
|
if (*(p-1) == '\\') break;
|
|
|
|
*p = 0;
|
|
|
|
state = NOT_IN_TOKEN;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case IN_DOUBLE_QUOTED_TOKEN:
|
|
|
|
if (*p == '\"') {
|
|
|
|
if (*(p-1) == '\\') break;
|
|
|
|
*p = 0;
|
|
|
|
state = NOT_IN_TOKEN;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case IN_UNQUOTED_TOKEN:
|
|
|
|
if (isspace(*p)) {
|
|
|
|
*p = 0;
|
|
|
|
state = NOT_IN_TOKEN;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
p++;
|
|
|
|
}
|
|
|
|
argv[argc] = 0;
|
|
|
|
return argc;
|
|
|
|
}
|
|
|
|
|
|
|
|
#include <spawn.h>
|
|
|
|
|
|
|
|
int callPosixSpawn(const char *cmdline, bool delayForResult) {
|
|
|
|
char command[1024];
|
|
|
|
char progName[1024];
|
|
|
|
char progPath[MAXPATHLEN];
|
|
|
|
char* argv[100];
|
|
|
|
int argc = 0;
|
|
|
|
char *p;
|
|
|
|
pid_t thePid = 0;
|
|
|
|
int result = 0;
|
|
|
|
int status = 0;
|
|
|
|
extern char **environ;
|
2013-11-15 13:02:04 +00:00
|
|
|
|
2016-12-21 14:08:36 +00:00
|
|
|
// Make a copy of cmdline because parse_command_line modifies it
|
|
|
|
strlcpy(command, cmdline, sizeof(command));
|
|
|
|
argc = parse_command_line(const_cast<char*>(command), argv);
|
|
|
|
strlcpy(progPath, argv[0], sizeof(progPath));
|
|
|
|
strlcpy(progName, argv[0], sizeof(progName));
|
|
|
|
p = strrchr(progName, '/');
|
|
|
|
if (p) {
|
|
|
|
argv[0] = p+1;
|
|
|
|
} else {
|
|
|
|
argv[0] = progName;
|
2013-11-15 13:02:04 +00:00
|
|
|
}
|
2016-12-21 14:08:36 +00:00
|
|
|
|
|
|
|
#if VERBOSE_TEST
|
|
|
|
print_to_log_file("***********");
|
|
|
|
for (int i=0; i<argc; ++i) {
|
|
|
|
print_to_log_file("argv[%d]=%s", i, argv[i]);
|
2013-11-15 13:02:04 +00:00
|
|
|
}
|
2016-12-21 14:08:36 +00:00
|
|
|
print_to_log_file("***********\n");
|
|
|
|
#endif
|
|
|
|
|
|
|
|
errno = 0;
|
|
|
|
|
|
|
|
result = posix_spawnp(&thePid, progPath, NULL, NULL, argv, environ);
|
|
|
|
#if VERBOSE_TEST
|
|
|
|
print_to_log_file("callPosixSpawn command: %s", cmdline);
|
|
|
|
print_to_log_file("callPosixSpawn: posix_spawnp returned %d: %s", result, strerror(result));
|
|
|
|
#endif
|
|
|
|
if (result) {
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
// CAF int val =
|
|
|
|
waitpid(thePid, &status, WUNTRACED);
|
|
|
|
// CAF if (val < 0) printf("first waitpid returned %d\n", val);
|
|
|
|
if (delayForResult) {
|
|
|
|
// For unknow reason, we don't get the error immediately if user cancelled authorization dialog.
|
|
|
|
SleepSeconds(0.5);
|
|
|
|
// CAF val =
|
|
|
|
waitpid(thePid, &status, WUNTRACED);
|
|
|
|
// CAF if (val < 0) printf("delayed waitpid returned %d\n", val);
|
|
|
|
}
|
|
|
|
if (status != 0) {
|
|
|
|
#if VERBOSE_TEST
|
|
|
|
print_to_log_file("waitpid() returned status=%d", status);
|
|
|
|
#endif
|
|
|
|
result = status;
|
|
|
|
} else {
|
|
|
|
if (WIFEXITED(status)) {
|
|
|
|
result = WEXITSTATUS(status);
|
|
|
|
if (result == 1) {
|
|
|
|
#if VERBOSE_TEST
|
|
|
|
print_to_log_file("WEXITSTATUS(status) returned 1, errno=%d: %s", errno, strerror(errno));
|
|
|
|
#endif
|
|
|
|
result = errno;
|
|
|
|
}
|
|
|
|
#if VERBOSE_TEST
|
|
|
|
else if (result) {
|
|
|
|
print_to_log_file("WEXITSTATUS(status) returned %d", result);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
} // end if (WIFEXITED(status)) else
|
|
|
|
} // end if waitpid returned 0 sstaus else
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
2017-01-06 09:53:47 +00:00
|
|
|
|
|
|
|
|
2018-06-27 12:37:53 +00:00
|
|
|
#if VERBOSE_TEST || TESTING
|
|
|
|
static void strip_cr(char *buf)
|
2016-12-21 14:08:36 +00:00
|
|
|
{
|
|
|
|
char *theCR;
|
|
|
|
|
|
|
|
theCR = strrchr(buf, '\n');
|
|
|
|
if (theCR)
|
|
|
|
*theCR = '\0';
|
|
|
|
theCR = strrchr(buf, '\r');
|
|
|
|
if (theCR)
|
|
|
|
*theCR = '\0';
|
|
|
|
}
|
|
|
|
#endif // VERBOSE_TEST
|
|
|
|
|
|
|
|
|
|
|
|
// For debugging
|
2018-06-27 12:37:53 +00:00
|
|
|
static void print_to_log_file(const char *format, ...) {
|
|
|
|
#if VERBOSE_TEST || TESTING
|
2016-12-21 14:08:36 +00:00
|
|
|
FILE *f;
|
|
|
|
va_list args;
|
|
|
|
char buf[256];
|
|
|
|
time_t t;
|
2018-06-27 12:37:53 +00:00
|
|
|
sprintf(buf, "/Users/%s/Documents/test_log.txt", loginName);
|
2016-12-21 14:08:36 +00:00
|
|
|
f = fopen(buf, "a");
|
|
|
|
if (!f) return;
|
2018-06-27 12:37:53 +00:00
|
|
|
|
|
|
|
// File will be owned by root, so make it world readable & writable
|
|
|
|
chmod(buf, 0666);
|
2016-12-21 14:08:36 +00:00
|
|
|
|
|
|
|
// freopen(buf, "a", stdout);
|
|
|
|
// freopen(buf, "a", stderr);
|
|
|
|
|
|
|
|
time(&t);
|
|
|
|
strlcpy(buf, asctime(localtime(&t)), sizeof(buf));
|
|
|
|
strip_cr(buf);
|
|
|
|
|
|
|
|
fputs(buf, f);
|
|
|
|
fputs(" ", f);
|
|
|
|
|
|
|
|
va_start(args, format);
|
|
|
|
vfprintf(f, format, args);
|
|
|
|
va_end(args);
|
|
|
|
|
|
|
|
fputs("\n", f);
|
|
|
|
fflush(f);
|
|
|
|
fclose(f);
|
|
|
|
#endif
|
2013-11-15 13:02:04 +00:00
|
|
|
}
|