2008-08-06 18:36:30 +00:00
|
|
|
// This file is part of BOINC.
|
2005-04-27 12:59:53 +00:00
|
|
|
// http://boinc.berkeley.edu
|
2009-11-18 10:19:14 +00:00
|
|
|
// Copyright (C) 2009 University of California
|
2005-04-27 12:59:53 +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.
|
2005-04-27 12:59:53 +00:00
|
|
|
//
|
2008-08-06 18:36:30 +00:00
|
|
|
// BOINC is distributed in the hope that it will be useful,
|
2005-04-27 12:59:53 +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/>.
|
2005-04-27 12:59:53 +00:00
|
|
|
|
2006-06-27 12:56:11 +00:00
|
|
|
/* PostInstall.cpp */
|
2005-04-27 12:59:53 +00:00
|
|
|
|
2005-05-05 14:31:51 +00:00
|
|
|
#define CREATE_LOG 1 /* for debugging */
|
|
|
|
|
2005-04-27 12:59:53 +00:00
|
|
|
#include <Carbon/Carbon.h>
|
2005-07-07 10:44:57 +00:00
|
|
|
#include <grp.h>
|
2005-04-27 12:59:53 +00:00
|
|
|
|
|
|
|
#include <unistd.h> // getlogin
|
|
|
|
#include <sys/types.h> // getpwname, getpwuid, getuid
|
|
|
|
#include <pwd.h> // getpwname, getpwuid, getuid
|
2007-05-19 11:56:01 +00:00
|
|
|
#include <grp.h> // getgrnam
|
2005-04-27 12:59:53 +00:00
|
|
|
#include <sys/wait.h> // waitpid
|
2006-06-20 11:25:23 +00:00
|
|
|
#include <dirent.h>
|
2006-06-27 12:56:11 +00:00
|
|
|
#include <sys/param.h> // for MAXPATHLEN
|
2006-07-19 09:25:25 +00:00
|
|
|
#include <sys/stat.h> // for chmod
|
|
|
|
#include <sys/socket.h>
|
|
|
|
#include <netinet/in.h>
|
|
|
|
#include <cerrno>
|
2010-02-05 04:34:43 +00:00
|
|
|
#include <time.h> // for time()
|
2006-07-19 09:25:25 +00:00
|
|
|
|
2006-06-07 05:54:55 +00:00
|
|
|
#include "LoginItemAPI.h" //please take a look at LoginItemAPI.h for an explanation of the routines available to you.
|
|
|
|
|
|
|
|
#include "SetupSecurity.h"
|
2005-04-27 12:59:53 +00:00
|
|
|
|
2009-11-26 10:46:20 +00:00
|
|
|
|
|
|
|
#define boinc_master_user_name "boinc_master"
|
|
|
|
#define boinc_master_group_name "boinc_master"
|
|
|
|
#define boinc_project_user_name "boinc_project"
|
|
|
|
#define boinc_project_group_name "boinc_project"
|
|
|
|
|
2005-04-27 12:59:53 +00:00
|
|
|
void Initialize(void); /* function prototypes */
|
2010-02-05 04:34:43 +00:00
|
|
|
Boolean myFilterProc(DialogRef theDialog, EventRecord *theEvent, DialogItemIndex *itemHit);
|
2006-06-23 04:20:32 +00:00
|
|
|
int DeleteReceipt(void);
|
2006-07-20 02:17:39 +00:00
|
|
|
OSStatus CheckLogoutRequirement(int *finalAction);
|
2009-11-26 10:46:20 +00:00
|
|
|
void CheckUserAndGroupConflicts();
|
2009-11-18 10:19:14 +00:00
|
|
|
Boolean SetLoginItem(long brandID, Boolean deleteLogInItem);
|
2007-05-19 23:08:22 +00:00
|
|
|
void SetSkinInUserPrefs(char *userName, char *skinName);
|
2006-07-22 09:05:08 +00:00
|
|
|
Boolean CheckDeleteFile(char *name);
|
2009-11-18 10:19:14 +00:00
|
|
|
void SetEUIDBackToUser (void);
|
|
|
|
static char * PersistentFGets(char *buf, size_t buflen, FILE *f);
|
2006-06-20 11:25:23 +00:00
|
|
|
OSErr UpdateAllVisibleUsers(long brandID);
|
2006-01-20 11:57:52 +00:00
|
|
|
long GetBrandID(void);
|
2006-07-19 09:25:25 +00:00
|
|
|
int TestRPCBind(void);
|
2009-11-18 10:19:14 +00:00
|
|
|
static OSStatus ResynchSystem(void);
|
2005-05-06 04:30:41 +00:00
|
|
|
OSErr FindProcess (OSType typeToFind, OSType creatorToFind, ProcessSerialNumberPtr processSN);
|
2005-07-26 02:40:47 +00:00
|
|
|
pid_t FindProcessPID(char* name, pid_t thePID);
|
2007-05-19 11:56:01 +00:00
|
|
|
int FindSkinName(char *name, size_t len);
|
2005-05-17 12:56:07 +00:00
|
|
|
static OSErr QuitBOINCManager(OSType signature);
|
2005-05-05 14:31:51 +00:00
|
|
|
static OSErr QuitAppleEventHandler(const AppleEvent *appleEvt, AppleEvent* reply, UInt32 refcon);
|
|
|
|
void print_to_log_file(const char *format, ...);
|
|
|
|
void strip_cr(char *buf);
|
2005-04-27 12:59:53 +00:00
|
|
|
|
2006-08-01 12:36:19 +00:00
|
|
|
extern int check_security(char *bundlePath, char *dataPath, int use_sandbox, int isManager);
|
2006-06-21 12:41:06 +00:00
|
|
|
|
2009-06-10 10:49:46 +00:00
|
|
|
#define NUMBRANDS 3
|
2006-06-21 12:41:06 +00:00
|
|
|
|
2009-12-05 11:01:03 +00:00
|
|
|
/* globals */
|
|
|
|
static Boolean gQuitFlag = false;
|
|
|
|
static Boolean currentUserCanRunBOINC = false;
|
|
|
|
static char loginName[256];
|
|
|
|
static long OSVersion = 0;
|
2010-02-05 04:34:43 +00:00
|
|
|
static time_t waitPermissionsStartTime;
|
2009-07-07 09:05:27 +00:00
|
|
|
|
2009-07-08 08:21:00 +00:00
|
|
|
static char *saverName[NUMBRANDS];
|
2009-07-07 09:31:07 +00:00
|
|
|
static char *saverNameEscaped[NUMBRANDS];
|
2009-06-10 10:49:46 +00:00
|
|
|
static char *brandName[NUMBRANDS];
|
|
|
|
static char *appName[NUMBRANDS];
|
|
|
|
static char *appNameEscaped[NUMBRANDS];
|
2009-06-11 01:57:35 +00:00
|
|
|
static char *receiptNameEscaped[NUMBRANDS];
|
2006-07-20 02:17:39 +00:00
|
|
|
|
|
|
|
enum { launchWhenDone,
|
|
|
|
logoutRequired,
|
2009-11-18 10:19:14 +00:00
|
|
|
restartRequired,
|
|
|
|
nothingrequired
|
2006-07-20 02:17:39 +00:00
|
|
|
};
|
2005-04-27 12:59:53 +00:00
|
|
|
|
2007-06-12 10:25:48 +00:00
|
|
|
/******************************************************************
|
|
|
|
*** ***
|
|
|
|
*** NOTE: ***
|
|
|
|
*** ***
|
|
|
|
*** On entry, the postinstall or postupgrade script has set the ***
|
|
|
|
*** current directory to the top level of our installer package ***
|
|
|
|
*** ***
|
|
|
|
******************************************************************/
|
|
|
|
|
2005-04-27 12:59:53 +00:00
|
|
|
int main(int argc, char *argv[])
|
|
|
|
{
|
2006-06-07 05:54:55 +00:00
|
|
|
Boolean Success;
|
|
|
|
ProcessSerialNumber ourProcess, installerPSN;
|
|
|
|
short itemHit;
|
|
|
|
long brandID = 0;
|
2006-06-20 11:25:23 +00:00
|
|
|
int i;
|
2009-11-18 10:19:14 +00:00
|
|
|
pid_t installerPID = 0, coreClientPID = 0, waitPermissionsPID = 0;
|
2006-06-07 05:54:55 +00:00
|
|
|
FSRef fileRef;
|
|
|
|
OSStatus err, err_fsref;
|
2007-06-12 10:25:48 +00:00
|
|
|
FILE *f;
|
2009-06-10 10:49:46 +00:00
|
|
|
char s[256];
|
2009-11-18 10:19:14 +00:00
|
|
|
char *q;
|
2006-08-02 00:43:27 +00:00
|
|
|
#ifdef SANDBOX
|
2009-11-18 10:19:14 +00:00
|
|
|
uid_t saved_euid, saved_uid, b_m_uid;
|
2006-07-19 09:25:25 +00:00
|
|
|
passwd *pw;
|
2006-07-20 02:17:39 +00:00
|
|
|
int finalInstallAction;
|
2010-02-05 04:34:43 +00:00
|
|
|
DialogRef theWin;
|
|
|
|
|
2009-11-26 10:46:20 +00:00
|
|
|
#else // SANDBOX
|
2006-06-20 11:25:23 +00:00
|
|
|
group *grp;
|
2009-11-26 10:46:20 +00:00
|
|
|
#endif // SANDBOX
|
2009-11-18 10:19:14 +00:00
|
|
|
|
2009-06-10 10:49:46 +00:00
|
|
|
appName[0] = "/Applications/BOINCManager.app";
|
|
|
|
appNameEscaped[0] = "/Applications/BOINCManager.app";
|
|
|
|
brandName[0] = "BOINC";
|
2009-07-08 08:21:00 +00:00
|
|
|
saverName[0] = "BOINCSaver";
|
2009-07-07 09:31:07 +00:00
|
|
|
saverNameEscaped[0] = "BOINCSaver";
|
2009-06-11 01:57:35 +00:00
|
|
|
receiptNameEscaped[0] = "/Library/Receipts/BOINC.pkg";
|
2009-06-10 10:49:46 +00:00
|
|
|
|
|
|
|
appName[1] = "/Applications/GridRepublic Desktop.app";
|
|
|
|
appNameEscaped[1] = "/Applications/GridRepublic\\ Desktop.app";
|
|
|
|
brandName[1] = "GridRepublic";
|
2009-07-08 08:21:00 +00:00
|
|
|
saverName[1] = "GridRepublic";
|
2009-07-07 09:31:07 +00:00
|
|
|
saverNameEscaped[1] = "GridRepublic";
|
2010-02-10 11:17:05 +00:00
|
|
|
receiptNameEscaped[1] = "/Library/Receipts/GridRepublic.pkg";
|
2009-06-10 10:49:46 +00:00
|
|
|
|
2009-06-11 00:36:15 +00:00
|
|
|
appName[2] = "/Applications/Progress Thru Processors Desktop.app";
|
|
|
|
appNameEscaped[2] = "/Applications/Progress\\ Thru\\ Processors\\ Desktop.app";
|
|
|
|
brandName[2] = "Progress Thru Processors";
|
2009-07-08 08:21:00 +00:00
|
|
|
saverName[2] = "Progress Thru Processors";
|
2009-07-07 09:31:07 +00:00
|
|
|
saverNameEscaped[2] = "Progress\\ Thru\\ Processors";
|
2009-06-11 01:57:35 +00:00
|
|
|
receiptNameEscaped[2] = "/Library/Receipts/Progress\\ Thru\\ Processors.pkg";
|
2009-06-10 10:49:46 +00:00
|
|
|
|
2009-12-05 11:01:03 +00:00
|
|
|
::GetCurrentProcess (&ourProcess);
|
|
|
|
|
|
|
|
// getlogin() gives unreliable results under OS 10.6.2, so use environment
|
|
|
|
strncpy(loginName, getenv("USER"), sizeof(loginName)-1);
|
|
|
|
|
|
|
|
err = Gestalt(gestaltSystemVersion, &OSVersion);
|
|
|
|
if (err != noErr)
|
|
|
|
return err;
|
|
|
|
|
2006-06-21 13:09:19 +00:00
|
|
|
for (i=0; i<argc; i++) {
|
2006-06-27 12:56:11 +00:00
|
|
|
if (strcmp(argv[i], "-part2") == 0)
|
2006-06-23 04:20:32 +00:00
|
|
|
return DeleteReceipt();
|
2006-06-21 13:09:19 +00:00
|
|
|
}
|
2009-11-18 10:19:14 +00:00
|
|
|
|
2005-04-27 12:59:53 +00:00
|
|
|
Initialize();
|
|
|
|
|
2005-07-26 02:40:47 +00:00
|
|
|
QuitBOINCManager('BNC!'); // Quit any old instance of BOINC manager
|
|
|
|
sleep(2);
|
2006-06-07 05:54:55 +00:00
|
|
|
|
2005-07-26 02:40:47 +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
|
|
|
|
|
2005-05-06 04:30:41 +00:00
|
|
|
err = FindProcess ('APPL', 'xins', &installerPSN);
|
|
|
|
if (err == noErr)
|
|
|
|
err = GetProcessPID(&installerPSN , &installerPID);
|
|
|
|
|
2006-01-21 12:42:04 +00:00
|
|
|
brandID = GetBrandID();
|
2009-06-10 10:49:46 +00:00
|
|
|
|
2009-06-13 00:54:29 +00:00
|
|
|
if ((brandID < 0) || (brandID >= NUMBRANDS)) { // Safety check
|
|
|
|
brandID = 0;
|
|
|
|
}
|
|
|
|
|
2009-12-05 11:01:03 +00:00
|
|
|
if (OSVersion < 0x1040) {
|
2005-05-05 14:31:51 +00:00
|
|
|
::SetFrontProcess(&ourProcess);
|
2006-01-21 12:42:04 +00:00
|
|
|
// Remove everything we've installed
|
2009-12-05 11:01:03 +00:00
|
|
|
// "\pSorry, this version of GridRepublic requires system 10.4.0 or higher."
|
|
|
|
s[0] = sprintf(s+1, "Sorry, this version of %s requires system 10.4.0 or higher.", brandName[brandID]);
|
2009-06-10 10:49:46 +00:00
|
|
|
StandardAlert (kAlertStopAlert, (StringPtr)s, NULL, NULL, &itemHit);
|
2005-05-05 14:31:51 +00:00
|
|
|
|
2009-06-10 10:49:46 +00:00
|
|
|
// "rm -rf /Applications/GridRepublic\\ Desktop.app"
|
|
|
|
sprintf(s, "rm -rf %s", appNameEscaped[brandID]);
|
|
|
|
system (s);
|
|
|
|
|
|
|
|
// "rm -rf /Library/Screen\\ Savers/GridRepublic.saver"
|
2009-07-07 09:31:07 +00:00
|
|
|
sprintf(s, "rm -rf /Library/Screen\\ Savers/%s.saver", saverNameEscaped[brandID]);
|
2009-06-10 10:49:46 +00:00
|
|
|
system (s);
|
|
|
|
|
|
|
|
// "rm -rf /Library/Receipts/GridRepublic.pkg"
|
2009-06-11 01:57:35 +00:00
|
|
|
sprintf(s, "rm -rf %s", receiptNameEscaped[brandID]);
|
2009-06-10 10:49:46 +00:00
|
|
|
system (s);
|
|
|
|
|
|
|
|
// We don't customize BOINC Data directory name for branding
|
2006-04-17 07:58:19 +00:00
|
|
|
system ("rm -rf /Library/Application\\ Support/BOINC\\ Data");
|
|
|
|
|
2005-05-22 11:12:16 +00:00
|
|
|
err = kill(installerPID, SIGKILL);
|
|
|
|
|
2005-05-05 14:31:51 +00:00
|
|
|
ExitToShell();
|
2006-01-20 11:57:52 +00:00
|
|
|
}
|
|
|
|
|
2006-07-19 09:25:25 +00:00
|
|
|
sleep (2);
|
2007-06-12 10:25:48 +00:00
|
|
|
|
|
|
|
// Install all_projects_list.xml file, but only if one doesn't
|
|
|
|
// already exist, since a pre-existing one is probably newer.
|
|
|
|
f = fopen("/Library/Application Support/BOINC Data/all_projects_list.xml", "r");
|
|
|
|
if (f) {
|
|
|
|
fclose(f); // Already exists
|
|
|
|
} else {
|
|
|
|
system ("cp -fp Contents/Resources/all_projects_list.xml /Library/Application\\ Support/BOINC\\ Data/");
|
|
|
|
system ("chmod a-x /Library/Application\\ Support/BOINC\\ Data/all_projects_list.xml");
|
|
|
|
}
|
2006-07-19 09:25:25 +00:00
|
|
|
|
2005-07-07 10:44:57 +00:00
|
|
|
Success = false;
|
|
|
|
|
2006-06-20 11:25:23 +00:00
|
|
|
#ifdef SANDBOX
|
|
|
|
|
2009-11-26 10:46:20 +00:00
|
|
|
CheckUserAndGroupConflicts();
|
|
|
|
|
2006-06-21 12:41:06 +00:00
|
|
|
for (i=0; i<5; ++i) {
|
|
|
|
err = CreateBOINCUsersAndGroups();
|
2006-06-21 13:09:19 +00:00
|
|
|
if (err != noErr) {
|
2006-06-22 10:10:51 +00:00
|
|
|
// print_to_log_file("CreateBOINCUsersAndGroups returned %d (repetition=%d)", err, i);
|
2006-06-21 12:41:06 +00:00
|
|
|
continue;
|
2006-06-21 13:09:19 +00:00
|
|
|
}
|
2006-06-21 12:41:06 +00:00
|
|
|
|
2009-06-10 10:49:46 +00:00
|
|
|
// err = SetBOINCAppOwnersGroupsAndPermissions("/Applications/GridRepublic Desktop.app");
|
|
|
|
err = SetBOINCAppOwnersGroupsAndPermissions(appName[brandID]);
|
2006-06-20 11:25:23 +00:00
|
|
|
|
2006-06-21 13:09:19 +00:00
|
|
|
if (err != noErr) {
|
2006-06-22 10:10:51 +00:00
|
|
|
// print_to_log_file("SetBOINCAppOwnersGroupsAndPermissions returned %d (repetition=%d)", err, i);
|
2006-06-21 12:41:06 +00:00
|
|
|
continue;
|
2006-06-21 13:09:19 +00:00
|
|
|
}
|
2006-06-21 12:41:06 +00:00
|
|
|
|
|
|
|
err = SetBOINCDataOwnersGroupsAndPermissions();
|
2006-06-21 13:09:19 +00:00
|
|
|
if (err != noErr) {
|
2006-06-22 10:10:51 +00:00
|
|
|
// print_to_log_file("SetBOINCDataOwnersGroupsAndPermissions returned %d (repetition=%d)", err, i);
|
2006-06-21 12:41:06 +00:00
|
|
|
continue;
|
2006-06-21 13:09:19 +00:00
|
|
|
}
|
2006-06-21 12:41:06 +00:00
|
|
|
|
2009-06-10 10:49:46 +00:00
|
|
|
err = check_security(appName[brandID], "/Library/Application Support/BOINC Data", true, false);
|
2006-06-22 10:10:51 +00:00
|
|
|
if (err == noErr)
|
|
|
|
break;
|
|
|
|
// print_to_log_file("check_security returned %d (repetition=%d)", err, i);
|
2006-06-21 12:41:06 +00:00
|
|
|
}
|
|
|
|
|
2006-06-20 11:25:23 +00:00
|
|
|
#else // ! defined(SANDBOX)
|
|
|
|
|
2005-07-07 10:44:57 +00:00
|
|
|
// The BOINC Manager and Core Client have the set-user-ID-on-execution
|
|
|
|
// flag set, so their ownership is important and must match the
|
|
|
|
// ownership of the BOINC Data directory.
|
|
|
|
|
|
|
|
// Find an appropriate admin user to set as owner of installed files
|
|
|
|
// First, try the user currently logged in
|
|
|
|
grp = getgrnam("admin");
|
|
|
|
i = 0;
|
|
|
|
while ((p = grp->gr_mem[i]) != NULL) { // Step through all users in group admin
|
2009-12-05 11:01:03 +00:00
|
|
|
if (strcmp(p, loginName) == 0) {
|
2005-07-07 10:44:57 +00:00
|
|
|
Success = true; // Logged in user is a member of group admin
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
++i;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If currently logged in user is not admin, use first non-root admin user
|
|
|
|
if (!Success) {
|
|
|
|
i = 0;
|
|
|
|
while ((p = grp->gr_mem[i]) != NULL) { // Step through all users in group admin
|
|
|
|
if (strcmp(p, "root") != 0)
|
|
|
|
break;
|
|
|
|
++i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-06-10 10:49:46 +00:00
|
|
|
// Set owner of branded BOINCManager and contents, including core client
|
|
|
|
// "chown -Rf username /Applications/GridRepublic\\ Desktop.app"
|
|
|
|
sprintf(s, "chown -Rf %s %s", p, appNameEscaped[brandID]);
|
|
|
|
system (s);
|
2005-07-07 10:44:57 +00:00
|
|
|
|
2009-06-10 10:49:46 +00:00
|
|
|
// Set owner of BOINC Screen Saver
|
|
|
|
// "chown -Rf username /Library/Screen\\ Savers/GridRepublic.saver"
|
2009-07-07 09:31:07 +00:00
|
|
|
sprintf(s, "chown -Rf %s /Library/Screen\\ Savers/%s.saver", p, saverNameEscaped[brandID]);
|
2009-06-10 10:49:46 +00:00
|
|
|
system (s);
|
2005-07-07 10:44:57 +00:00
|
|
|
|
2009-06-10 10:49:46 +00:00
|
|
|
// We don't customize BOINC Data directory name for branding
|
|
|
|
// "chown -Rf username /Library/Application\\ Support/BOINC\\ Data"
|
|
|
|
sprintf(s, "chown -Rf %s /Library/Application\\ Support/BOINC\\ Data", p);
|
|
|
|
system (s);
|
2005-07-07 10:44:57 +00:00
|
|
|
|
2009-06-10 10:49:46 +00:00
|
|
|
// "chmod -R a+s /Applications/GridRepublic\\ Desktop.app"
|
|
|
|
sprintf(s, "chmod -R a+s %s", appNameEscaped[brandID]);
|
|
|
|
system (s);
|
2006-01-21 12:42:04 +00:00
|
|
|
|
2009-06-10 10:49:46 +00:00
|
|
|
#endif // ! defined(SANDBOX)
|
2006-01-21 12:42:04 +00:00
|
|
|
|
2009-06-10 10:49:46 +00:00
|
|
|
// Remove any branded versions of BOINC other than ours (i.e., old versions)
|
|
|
|
for (i=0; i< NUMBRANDS; i++) {
|
|
|
|
if (i == brandID) continue;
|
|
|
|
|
|
|
|
// "rm -rf /Applications/GridRepublic\\ Desktop.app"
|
|
|
|
sprintf(s, "rm -rf %s", appNameEscaped[i]);
|
|
|
|
system (s);
|
|
|
|
|
|
|
|
// "rm -rf /Library/Screen\\ Savers/GridRepublic.saver"
|
2009-07-08 07:30:42 +00:00
|
|
|
sprintf(s, "rm -rf /Library/Screen\\ Savers/%s.saver", saverNameEscaped[i]);
|
2006-01-21 12:42:04 +00:00
|
|
|
system (s);
|
2006-06-20 11:25:23 +00:00
|
|
|
}
|
2009-06-10 10:49:46 +00:00
|
|
|
|
|
|
|
if (brandID == 0) { // Installing generic BOINC
|
|
|
|
system ("rm -f /Library/Application\\ Support/BOINC\\ Data/Branding");
|
2006-01-21 12:42:04 +00:00
|
|
|
}
|
2006-01-20 14:04:06 +00:00
|
|
|
|
2009-06-10 10:49:46 +00:00
|
|
|
// err_fsref = FSPathMakeRef((StringPtr)"/Applications/GridRepublic Desktop.app", &fileRef, NULL);
|
|
|
|
err_fsref = FSPathMakeRef((StringPtr)appName[brandID], &fileRef, NULL);
|
|
|
|
|
2006-01-21 12:42:04 +00:00
|
|
|
if (err_fsref == noErr)
|
2006-01-23 13:16:28 +00:00
|
|
|
err = LSRegisterFSRef(&fileRef, true);
|
2006-01-21 12:42:04 +00:00
|
|
|
|
2006-06-20 11:25:23 +00:00
|
|
|
err = UpdateAllVisibleUsers(brandID);
|
|
|
|
if (err != noErr)
|
|
|
|
return err;
|
2006-06-21 13:09:19 +00:00
|
|
|
|
2009-11-18 10:19:14 +00:00
|
|
|
#ifdef SANDBOX
|
|
|
|
err = CheckLogoutRequirement(&finalInstallAction);
|
|
|
|
|
|
|
|
if (finalInstallAction == launchWhenDone) {
|
|
|
|
// Wait for BOINC's RPC socket address to become available to user boinc_master, in
|
|
|
|
// case we are upgrading from a version which did not run as user boinc_master.
|
|
|
|
saved_uid = getuid();
|
|
|
|
saved_euid = geteuid();
|
|
|
|
|
|
|
|
pw = getpwnam("boinc_master");
|
|
|
|
b_m_uid = pw->pw_uid;
|
|
|
|
seteuid(b_m_uid);
|
|
|
|
|
|
|
|
for (i=0; i<120; i++) {
|
|
|
|
err = TestRPCBind();
|
|
|
|
if (err == noErr)
|
|
|
|
break;
|
|
|
|
|
|
|
|
sleep(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
seteuid(saved_euid);
|
|
|
|
|
|
|
|
ProcessSerialNumber ourPSN;
|
|
|
|
ProcessInfoRec pInfo;
|
|
|
|
FSRef ourFSRef, theFSRef;
|
|
|
|
char thePath[MAXPATHLEN];
|
|
|
|
|
|
|
|
// Get the full path to this PostInstall application's bundle
|
|
|
|
err = GetCurrentProcess (&ourPSN);
|
|
|
|
if (err)
|
|
|
|
return -1000; // Should never happen
|
|
|
|
|
|
|
|
memset(&pInfo, 0, sizeof(pInfo));
|
|
|
|
pInfo.processInfoLength = sizeof( ProcessInfoRec );
|
|
|
|
err = GetProcessInformation(&ourPSN, &pInfo);
|
|
|
|
if (err)
|
|
|
|
return -1001; // Should never happen
|
|
|
|
|
|
|
|
err = GetProcessBundleLocation(&ourPSN, &ourFSRef);
|
|
|
|
if (err)
|
|
|
|
return -1002; // Should never happen
|
|
|
|
|
|
|
|
err = FSRefMakePath (&ourFSRef, (UInt8*)thePath, sizeof(thePath));
|
|
|
|
if (err)
|
|
|
|
return -1003; // Should never happen
|
|
|
|
|
|
|
|
q = strrchr(thePath, '/');
|
|
|
|
if (q == NULL)
|
|
|
|
return -1004; // Should never happen
|
|
|
|
|
|
|
|
*++q = '\0';
|
|
|
|
strlcat(thePath, "WaitPermissions.app", sizeof(thePath));
|
|
|
|
err = FSPathMakeRef((StringPtr)thePath, &theFSRef, NULL);
|
|
|
|
|
|
|
|
// When we first create the boinc_master group and add the current user to the
|
|
|
|
// new group, there is a delay before the new group membership is recognized.
|
|
|
|
// If we launch the BOINC Manager too soon, it will fail with a -1037 permissions
|
|
|
|
// error, so we wait until the current user can access the switcher application.
|
|
|
|
// Apparently, in order to get the changed permissions / group membership, we must
|
|
|
|
// launch a new process belonging to the user. It may also need to be in a new
|
|
|
|
// process group or new session. Neither system() nor popen() works, even after
|
|
|
|
// setting the uid and euid back to the logged in user, but LSOpenFSRef() does.
|
|
|
|
// The WaitPermissions application loops until it can access the switcher
|
|
|
|
// application.
|
|
|
|
err = LSOpenFSRef(&theFSRef, NULL);
|
|
|
|
|
2010-02-05 04:34:43 +00:00
|
|
|
waitPermissionsStartTime = time(NULL);
|
|
|
|
for (i=0; i<15; i++) { // Show "Please wait..." alert after 15 seconds
|
2009-11-18 10:19:14 +00:00
|
|
|
waitPermissionsPID = FindProcessPID("WaitPermissions", 0);
|
|
|
|
if (waitPermissionsPID == 0) {
|
2010-02-05 04:34:43 +00:00
|
|
|
return 0;
|
2009-11-18 10:19:14 +00:00
|
|
|
}
|
|
|
|
sleep(1);
|
|
|
|
}
|
2010-02-05 04:34:43 +00:00
|
|
|
|
|
|
|
CreateStandardAlert(kAlertNoteAlert, CFSTR("Finishing install. Please wait ..."), CFSTR("This may take a few more minutes."), NULL, &theWin);
|
|
|
|
HideDialogItem(theWin, kStdOkItemIndex);
|
|
|
|
RemoveDialogItems(theWin, kStdOkItemIndex, 1, false);
|
|
|
|
RunStandardAlert(theWin, &myFilterProc, &itemHit);
|
|
|
|
|
2009-11-18 10:19:14 +00:00
|
|
|
}
|
|
|
|
#endif // SANDBOX
|
|
|
|
|
2006-06-21 13:09:19 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2006-06-20 11:25:23 +00:00
|
|
|
|
2006-06-21 13:09:19 +00:00
|
|
|
|
2010-02-05 04:34:43 +00:00
|
|
|
Boolean myFilterProc(DialogRef theDialog, EventRecord *theEvent, DialogItemIndex *itemHit) {
|
|
|
|
static time_t lastCheckTime = 0;
|
|
|
|
time_t now = time(NULL);
|
|
|
|
pid_t waitPermissionsPID = 0;
|
|
|
|
|
|
|
|
if (now != lastCheckTime) {
|
|
|
|
waitPermissionsPID = FindProcessPID("WaitPermissions", 0);
|
|
|
|
if (waitPermissionsPID == 0) {
|
|
|
|
*itemHit = kStdOkItemIndex;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
lastCheckTime = now;
|
|
|
|
// Limit delay to 3 minutes
|
|
|
|
if ((now - waitPermissionsStartTime) > 180) {
|
|
|
|
*itemHit = kStdOkItemIndex;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-06-27 12:56:11 +00:00
|
|
|
// After installation has completed, delete the installer receipt.
|
|
|
|
// If we don't need to logout the user, also launch BOINC Manager.
|
2006-06-23 04:20:32 +00:00
|
|
|
int DeleteReceipt()
|
2006-06-21 13:09:19 +00:00
|
|
|
{
|
|
|
|
ProcessSerialNumber installerPSN;
|
|
|
|
long brandID = 0;
|
|
|
|
int i;
|
|
|
|
pid_t installerPID = 0;
|
2006-06-23 04:20:32 +00:00
|
|
|
OSStatus err;
|
2006-07-20 02:17:39 +00:00
|
|
|
int finalInstallAction;
|
2006-06-27 12:56:11 +00:00
|
|
|
FSRef fileRef;
|
2009-06-10 10:49:46 +00:00
|
|
|
char s[256];
|
2009-11-18 10:19:14 +00:00
|
|
|
struct stat sbuf;
|
2006-06-27 12:56:11 +00:00
|
|
|
OSStatus err_fsref;
|
2006-06-21 13:09:19 +00:00
|
|
|
|
|
|
|
Initialize();
|
2006-07-20 02:17:39 +00:00
|
|
|
err = CheckLogoutRequirement(&finalInstallAction);
|
|
|
|
|
2006-06-21 13:09:19 +00:00
|
|
|
err = FindProcess ('APPL', 'xins', &installerPSN);
|
|
|
|
if (err == noErr)
|
|
|
|
err = GetProcessPID(&installerPSN , &installerPID);
|
|
|
|
|
|
|
|
// Launch BOINC Manager when user closes installer or after 15 seconds
|
2006-06-20 11:25:23 +00:00
|
|
|
for (i=0; i<15; i++) { // Wait 15 seconds max for installer to quit
|
|
|
|
sleep (1);
|
2006-06-21 13:09:19 +00:00
|
|
|
if (err == noErr)
|
|
|
|
if (FindProcessPID(NULL, installerPID) == 0)
|
|
|
|
break;
|
2006-06-20 11:25:23 +00:00
|
|
|
}
|
|
|
|
|
2006-06-21 13:09:19 +00:00
|
|
|
brandID = GetBrandID();
|
2006-06-20 11:25:23 +00:00
|
|
|
|
|
|
|
// Remove installer package receipt so we can run installer again if needed to fix permissions
|
2009-06-10 10:49:46 +00:00
|
|
|
// "rm -rf /Library/Receipts/GridRepublic.pkg"
|
2009-06-11 01:57:35 +00:00
|
|
|
sprintf(s, "rm -rf %s", receiptNameEscaped[brandID]);
|
2009-06-10 10:49:46 +00:00
|
|
|
system (s);
|
|
|
|
|
|
|
|
// err_fsref = FSPathMakeRef((StringPtr)"/Applications/GridRepublic Desktop.app", &fileRef, NULL);
|
|
|
|
err_fsref = FSPathMakeRef((StringPtr)appName[brandID], &fileRef, NULL);
|
2006-06-27 12:56:11 +00:00
|
|
|
|
2008-01-07 03:47:56 +00:00
|
|
|
if (finalInstallAction == launchWhenDone) {
|
2009-11-18 10:19:14 +00:00
|
|
|
// If system is set up to run BOINC Client as a daemon using launchd, launch it
|
|
|
|
// as a daemon and allow time for client to start before launching BOINC Manager.
|
2010-01-17 00:44:01 +00:00
|
|
|
err = stat("/Library/LaunchDaemons/edu.berkeley.boinc.plist", &sbuf);
|
2009-11-18 10:19:14 +00:00
|
|
|
if (err == noErr) {
|
2008-01-07 03:47:56 +00:00
|
|
|
system("launchctl unload /Library/LaunchDaemons/edu.berkeley.boinc.plist");
|
|
|
|
i = system("launchctl load /Library/LaunchDaemons/edu.berkeley.boinc.plist");
|
|
|
|
if (i == 0) sleep (2);
|
|
|
|
}
|
2009-11-18 10:19:14 +00:00
|
|
|
err = LSOpenFSRef(&fileRef, NULL);
|
2008-01-07 03:47:56 +00:00
|
|
|
}
|
2006-06-20 11:25:23 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-07-20 02:17:39 +00:00
|
|
|
OSStatus CheckLogoutRequirement(int *finalAction)
|
2006-06-27 12:56:11 +00:00
|
|
|
{
|
|
|
|
char path[MAXPATHLEN];
|
|
|
|
FSRef infoPlistFileRef;
|
|
|
|
Boolean isDirectory, result;
|
|
|
|
CFURLRef xmlURL = NULL;
|
|
|
|
CFDataRef xmlDataIn = NULL;
|
|
|
|
CFPropertyListRef propertyListRef = NULL;
|
|
|
|
CFStringRef restartKey = CFSTR("IFPkgFlagRestartAction");
|
|
|
|
CFStringRef currentValue = NULL;
|
2006-07-20 02:17:39 +00:00
|
|
|
// CFStringRef valueRestartRequired = CFSTR("RequiredRestart");
|
|
|
|
CFStringRef valueLogoutRequired = CFSTR("RequiredLogout");
|
2006-06-27 12:56:11 +00:00
|
|
|
CFStringRef valueNoRestart = CFSTR("NoRestart");
|
|
|
|
CFStringRef errorString = NULL;
|
|
|
|
OSStatus err = noErr;
|
2009-11-18 10:19:14 +00:00
|
|
|
#ifdef SANDBOX
|
2009-12-05 11:01:03 +00:00
|
|
|
char *p;
|
2009-11-18 10:19:14 +00:00
|
|
|
group *grp = NULL;
|
|
|
|
int i;
|
|
|
|
Boolean isMember = false;
|
2009-11-26 10:46:20 +00:00
|
|
|
#endif // SANDBOX
|
2006-07-20 02:17:39 +00:00
|
|
|
|
|
|
|
*finalAction = restartRequired;
|
2009-11-18 10:19:14 +00:00
|
|
|
|
2009-12-05 11:01:03 +00:00
|
|
|
if (OSVersion < 0x1040) {
|
2009-12-07 08:42:09 +00:00
|
|
|
return noErr; // Always require restart on OS 10.3.9
|
2009-12-05 11:01:03 +00:00
|
|
|
}
|
|
|
|
|
2009-11-18 10:19:14 +00:00
|
|
|
#ifdef SANDBOX
|
|
|
|
grp = getgrnam("boinc_master");
|
|
|
|
if (loginName && grp) {
|
|
|
|
i = 0;
|
|
|
|
while ((p = grp->gr_mem[i]) != NULL) { // Step through all users in group boinc_master
|
|
|
|
if (strcmp(p, loginName) == 0) {
|
|
|
|
isMember = true; // Logged in user is a member of group boinc_master
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
++i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-12-05 11:01:03 +00:00
|
|
|
if (!isMember && !currentUserCanRunBOINC) {
|
2009-11-18 10:19:14 +00:00
|
|
|
*finalAction = nothingrequired;
|
|
|
|
return noErr;
|
|
|
|
}
|
2009-11-26 10:46:20 +00:00
|
|
|
#endif // SANDBOX
|
2006-06-27 12:56:11 +00:00
|
|
|
|
|
|
|
getcwd(path, sizeof(path));
|
|
|
|
strlcat(path, "/Contents/Info.plist", sizeof(path));
|
|
|
|
|
|
|
|
err = FSPathMakeRef((UInt8*)path, &infoPlistFileRef, &isDirectory);
|
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
|
|
|
|
xmlURL = CFURLCreateFromFSRef(NULL, &infoPlistFileRef);
|
|
|
|
if (xmlURL == NULL)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
// Read XML Data from file
|
|
|
|
result = CFURLCreateDataAndPropertiesFromResource(NULL, xmlURL, &xmlDataIn, NULL, NULL, &err);
|
|
|
|
if (err == noErr)
|
|
|
|
if (!result)
|
|
|
|
err = coreFoundationUnknownErr;
|
|
|
|
|
|
|
|
if (err == noErr) { // Convert XML Data to internal CFPropertyListRef / CFDictionaryRef format
|
|
|
|
propertyListRef = CFPropertyListCreateFromXMLData(NULL, xmlDataIn, kCFPropertyListMutableContainersAndLeaves, &errorString);
|
|
|
|
if (propertyListRef == NULL)
|
|
|
|
err = coreFoundationUnknownErr;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (err == noErr) { // Get current value for our key
|
|
|
|
currentValue = (CFStringRef)CFDictionaryGetValue((CFDictionaryRef)propertyListRef, restartKey);
|
|
|
|
if (currentValue == NULL)
|
|
|
|
err = coreFoundationUnknownErr;
|
|
|
|
}
|
|
|
|
|
2006-07-20 02:17:39 +00:00
|
|
|
if (err == noErr) {
|
|
|
|
if (CFStringCompare(currentValue, valueLogoutRequired, 0) == kCFCompareEqualTo)
|
|
|
|
*finalAction = logoutRequired;
|
|
|
|
else if (CFStringCompare(currentValue, valueNoRestart, 0) == kCFCompareEqualTo)
|
|
|
|
*finalAction = launchWhenDone;
|
|
|
|
}
|
2006-06-27 12:56:11 +00:00
|
|
|
|
|
|
|
if (xmlURL)
|
|
|
|
CFRelease(xmlURL);
|
|
|
|
if (xmlDataIn)
|
|
|
|
CFRelease(xmlDataIn);
|
|
|
|
if (propertyListRef)
|
|
|
|
CFRelease(propertyListRef);
|
|
|
|
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-11-26 10:46:20 +00:00
|
|
|
// Some newer versions of the OS define users and groups which may conflict with
|
|
|
|
// our previously created boinc_master or boinc_project user or group. This could
|
|
|
|
// also happen when the user installs new software. So we must check for such
|
|
|
|
// duplicate UserIDs and groupIDs; if found, we delete our user or group so that
|
|
|
|
// the PostInstall application will cerate a new one that does not conflict.
|
|
|
|
|
|
|
|
// NOTE: getgrnam and getgrgid use one static memory area to return their results,
|
|
|
|
// so each call to getgrnam or getgrgid overwrites the data from any previous calls.
|
|
|
|
void CheckUserAndGroupConflicts()
|
|
|
|
{
|
|
|
|
#ifdef SANDBOX
|
|
|
|
passwd *pw = NULL;
|
|
|
|
group *grp = NULL;
|
|
|
|
gid_t boinc_master_gid = 0, boinc_project_gid = 0;
|
|
|
|
uid_t boinc_master_uid = 0, boinc_project_uid = 0;
|
|
|
|
|
|
|
|
FILE *f;
|
|
|
|
char cmd[256], buf[256];
|
|
|
|
int entryCount;
|
|
|
|
|
|
|
|
entryCount = 0;
|
|
|
|
grp = getgrnam(boinc_master_group_name);
|
|
|
|
if (grp) {
|
|
|
|
boinc_master_gid = grp->gr_gid;
|
|
|
|
sprintf(cmd, "dscl . -search /Groups PrimaryGroupID %d", boinc_master_gid);
|
|
|
|
f = popen(cmd, "r");
|
|
|
|
if (f) {
|
|
|
|
while (PersistentFGets(buf, sizeof(buf), f)) {
|
|
|
|
if (strstr(buf, "PrimaryGroupID")) {
|
|
|
|
++entryCount;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
pclose(f);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (entryCount > 1) {
|
|
|
|
system ("dscl . -delete /groups/boinc_master");
|
|
|
|
// User boinc_master must have group boinc_master as its primary group.
|
|
|
|
// Since this group no longer exists, delete the user as well.
|
|
|
|
system ("dscl . -delete /users/boinc_master");
|
|
|
|
ResynchSystem();
|
|
|
|
}
|
|
|
|
|
|
|
|
entryCount = 0;
|
|
|
|
grp = getgrnam(boinc_project_group_name);
|
|
|
|
if (grp) {
|
|
|
|
boinc_project_gid = grp->gr_gid;
|
|
|
|
sprintf(cmd, "dscl . -search /Groups PrimaryGroupID %d", boinc_project_gid);
|
|
|
|
f = popen(cmd, "r");
|
|
|
|
if (f) {
|
|
|
|
while (PersistentFGets(buf, sizeof(buf), f)) {
|
|
|
|
if (strstr(buf, "PrimaryGroupID")) {
|
|
|
|
++entryCount;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
pclose(f);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (entryCount > 1) {
|
2009-12-05 11:01:03 +00:00
|
|
|
system ("dscl . -delete /groups/boinc_project");
|
2009-11-26 10:46:20 +00:00
|
|
|
// User boinc_project must have group boinc_project as its primary group.
|
|
|
|
// Since this group no longer exists, delete the user as well.
|
|
|
|
system ("dscl . -delete /users/boinc_project");
|
|
|
|
ResynchSystem();
|
|
|
|
}
|
|
|
|
|
|
|
|
entryCount = 0;
|
|
|
|
pw = getpwnam(boinc_master_user_name);
|
|
|
|
if (pw) {
|
|
|
|
boinc_master_uid = pw->pw_uid;
|
|
|
|
sprintf(cmd, "dscl . -search /Users UniqueID %d", boinc_master_uid);
|
|
|
|
f = popen(cmd, "r");
|
|
|
|
if (f) {
|
|
|
|
while (PersistentFGets(buf, sizeof(buf), f)) {
|
|
|
|
if (strstr(buf, "UniqueID")) {
|
|
|
|
++entryCount;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
pclose(f);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (entryCount > 1) {
|
|
|
|
system ("dscl . -delete /users/boinc_master");
|
|
|
|
ResynchSystem();
|
|
|
|
}
|
|
|
|
|
|
|
|
entryCount = 0;
|
|
|
|
pw = getpwnam(boinc_project_user_name);
|
|
|
|
if (pw) {
|
|
|
|
boinc_project_uid = pw->pw_uid;
|
|
|
|
sprintf(cmd, "dscl . -search /Users UniqueID %d", boinc_project_uid);
|
|
|
|
f = popen(cmd, "r");
|
|
|
|
if (f) {
|
|
|
|
while (PersistentFGets(buf, sizeof(buf), f)) {
|
|
|
|
if (strstr(buf, "UniqueID")) {
|
|
|
|
++entryCount;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
pclose(f);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (entryCount > 1) {
|
|
|
|
system ("dscl . -delete /users/boinc_project");
|
|
|
|
ResynchSystem();
|
|
|
|
}
|
|
|
|
#endif // SANDBOX
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-11-18 10:19:14 +00:00
|
|
|
Boolean SetLoginItem(long brandID, Boolean deleteLogInItem)
|
2006-06-20 11:25:23 +00:00
|
|
|
{
|
|
|
|
Boolean Success;
|
|
|
|
int NumberOfLoginItems, Counter;
|
|
|
|
char *p, *q;
|
2009-06-10 10:49:46 +00:00
|
|
|
char s[256];
|
|
|
|
int i;
|
2005-04-27 12:59:53 +00:00
|
|
|
|
2005-07-07 10:44:57 +00:00
|
|
|
Success = false;
|
2009-06-10 10:49:46 +00:00
|
|
|
|
2005-04-27 12:59:53 +00:00
|
|
|
NumberOfLoginItems = GetCountOfLoginItems(kCurrentUser);
|
|
|
|
|
|
|
|
// Search existing login items in reverse order, deleting any duplicates of ours
|
|
|
|
for (Counter = NumberOfLoginItems ; Counter > 0 ; Counter--)
|
|
|
|
{
|
|
|
|
p = ReturnLoginItemPropertyAtIndex(kCurrentUser, kApplicationNameInfo, Counter-1);
|
|
|
|
q = p;
|
|
|
|
while (*q)
|
|
|
|
{
|
|
|
|
// It is OK to modify the returned string because we "own" it
|
|
|
|
*q = toupper(*q); // Make it case-insensitive
|
|
|
|
q++;
|
|
|
|
}
|
2009-06-10 10:49:46 +00:00
|
|
|
|
|
|
|
for (i=0; i<NUMBRANDS; i++) {
|
|
|
|
q = strrchr(appName[i], '/');
|
|
|
|
if (!q) continue; // Should never happen
|
|
|
|
strncpy(s, q+1, sizeof(s)-1);
|
|
|
|
q = s;
|
|
|
|
while (*q) {
|
|
|
|
*q = toupper(*q);
|
|
|
|
q++;
|
|
|
|
}
|
|
|
|
|
|
|
|
// if (strcmp(p, "BOINCMANAGER.APP") == 0)
|
|
|
|
// if (strcmp(p, "GRIDREPUBLIC DESKTOP.APP") == 0)
|
2009-06-11 00:36:15 +00:00
|
|
|
// if (strcmp(p, "PROGRESS THRU PROCESSORS DESKTOP.APP") == 0)
|
2009-06-10 10:49:46 +00:00
|
|
|
if (strcmp(p, s) == 0) {
|
|
|
|
Success = RemoveLoginItemAtIndex(kCurrentUser, Counter-1);
|
|
|
|
}
|
|
|
|
}
|
2005-04-27 12:59:53 +00:00
|
|
|
}
|
|
|
|
|
2006-07-22 09:05:08 +00:00
|
|
|
if (deleteLogInItem)
|
2009-11-18 10:19:14 +00:00
|
|
|
return false;
|
2006-07-22 09:05:08 +00:00
|
|
|
|
2009-06-10 10:49:46 +00:00
|
|
|
Success = AddLoginItemWithPropertiesToUser(kCurrentUser, appName[brandID], kHideOnLaunch);
|
2009-11-18 10:19:14 +00:00
|
|
|
|
|
|
|
return Success;
|
2005-04-27 12:59:53 +00:00
|
|
|
}
|
|
|
|
|
2009-06-10 10:49:46 +00:00
|
|
|
// Sets the skin selection in the specified user's preferences to the specified skin
|
2007-05-19 23:08:22 +00:00
|
|
|
void SetSkinInUserPrefs(char *userName, char *skinName)
|
|
|
|
{
|
|
|
|
passwd *pw;
|
|
|
|
FILE *oldPrefs, *newPrefs;
|
|
|
|
char oldFileName[MAXPATHLEN], tempFilename[MAXPATHLEN];
|
|
|
|
char buf[1024];
|
|
|
|
int wroteSkinName;
|
|
|
|
struct stat sbuf;
|
|
|
|
group *grp;
|
|
|
|
OSStatus statErr;
|
|
|
|
|
|
|
|
if (skinName[0]) {
|
|
|
|
sprintf(oldFileName, "/Users/%s/Library/Preferences/BOINC Manager Preferences", userName);
|
|
|
|
sprintf(tempFilename, "/Users/%s/Library/Preferences/BOINC Manager NewPrefs", userName);
|
|
|
|
newPrefs = fopen(tempFilename, "w");
|
|
|
|
if (newPrefs) {
|
|
|
|
wroteSkinName = 0;
|
|
|
|
statErr = stat(oldFileName, &sbuf);
|
|
|
|
|
|
|
|
oldPrefs = fopen(oldFileName, "r");
|
|
|
|
if (oldPrefs) {
|
|
|
|
while (fgets(buf, sizeof(buf), oldPrefs)) {
|
|
|
|
if (strstr(buf, "Skin=")) {
|
|
|
|
fprintf(newPrefs, "Skin=%s\n", skinName);
|
|
|
|
wroteSkinName = 1;
|
|
|
|
} else {
|
|
|
|
fputs(buf, newPrefs);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
fclose(oldPrefs);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (! wroteSkinName)
|
|
|
|
fprintf(newPrefs, "Skin=%s\n", skinName);
|
|
|
|
|
|
|
|
fclose(newPrefs);
|
|
|
|
rename(tempFilename, oldFileName); // Deletes old file
|
|
|
|
if (! statErr) {
|
|
|
|
chown(oldFileName, sbuf.st_uid, sbuf.st_gid);
|
|
|
|
chmod(oldFileName, sbuf.st_mode);
|
|
|
|
} else {
|
|
|
|
chmod(oldFileName, 0664);
|
|
|
|
pw = getpwnam(userName);
|
|
|
|
grp = getgrnam(userName);
|
|
|
|
if (pw && grp)
|
|
|
|
chown(oldFileName, pw->pw_uid, grp->gr_gid);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-07-22 09:05:08 +00:00
|
|
|
// Returns true if the user name is in the nologinitems.txt, else false
|
|
|
|
Boolean CheckDeleteFile(char *name)
|
|
|
|
{
|
|
|
|
FILE *f;
|
|
|
|
char buf[64];
|
|
|
|
size_t len;
|
|
|
|
|
|
|
|
f = fopen("/Library/Application Support/BOINC Data/nologinitems.txt", "r");
|
|
|
|
if (!f)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
while (true) {
|
|
|
|
*buf = '\0';
|
|
|
|
len = sizeof(buf);
|
|
|
|
fgets(buf, len, f);
|
|
|
|
if (feof(f)) break;
|
|
|
|
strip_cr(buf);
|
|
|
|
if (strcmp(buf, name) == 0) {
|
|
|
|
fclose(f);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fclose(f);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2009-11-18 10:19:14 +00:00
|
|
|
void SetEUIDBackToUser (void)
|
2005-04-27 12:59:53 +00:00
|
|
|
{
|
|
|
|
uid_t login_uid;
|
|
|
|
passwd *pw;
|
|
|
|
|
2009-12-05 11:01:03 +00:00
|
|
|
pw = getpwnam(loginName);
|
2005-04-27 12:59:53 +00:00
|
|
|
login_uid = pw->pw_uid;
|
|
|
|
|
|
|
|
setuid(login_uid);
|
2009-11-18 10:19:14 +00:00
|
|
|
seteuid(login_uid);
|
2005-04-27 12:59:53 +00:00
|
|
|
}
|
|
|
|
|
2009-07-08 08:21:00 +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);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static Boolean ShowMessage(Boolean allowCancel, const char *format, ...) {
|
|
|
|
va_list args;
|
|
|
|
char s[1024];
|
|
|
|
short itemHit;
|
|
|
|
AlertStdAlertParamRec alertParams;
|
|
|
|
|
|
|
|
ProcessSerialNumber ourProcess;
|
|
|
|
|
|
|
|
va_start(args, format);
|
|
|
|
s[0] = vsprintf(s+1, format, args);
|
|
|
|
va_end(args);
|
|
|
|
|
|
|
|
alertParams.movable = true;
|
|
|
|
alertParams.helpButton = false;
|
|
|
|
alertParams.filterProc = NULL;
|
|
|
|
alertParams.defaultText = (StringPtr)"\pYes";
|
|
|
|
alertParams.cancelText = allowCancel ? (StringPtr)"\pNo" : NULL;
|
|
|
|
alertParams.otherText = NULL;
|
|
|
|
alertParams.defaultButton = kAlertStdAlertOKButton;
|
|
|
|
alertParams.cancelButton = allowCancel ? kAlertStdAlertCancelButton : 0;
|
|
|
|
alertParams.position = kWindowDefaultPosition;
|
|
|
|
|
|
|
|
::GetCurrentProcess (&ourProcess);
|
|
|
|
::SetFrontProcess(&ourProcess);
|
|
|
|
|
|
|
|
StandardAlert (kAlertNoteAlert, (StringPtr)s, NULL, &alertParams, &itemHit);
|
|
|
|
|
|
|
|
return (itemHit == kAlertStdAlertOKButton);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-09-16 09:57:11 +00:00
|
|
|
// Find all visible users.
|
2006-06-20 11:25:23 +00:00
|
|
|
// If user is a member of group admin, add user to groups boinc_master and boinc_project.
|
2009-09-16 09:57:11 +00:00
|
|
|
// Optionally add non-admin users to group boinc_master but not to group boinc_project.
|
|
|
|
// Set login item for all members of group boinc_master to launch BOINC Manager.
|
|
|
|
// If our install package included a skin, set those user's preferences to use that skin.
|
|
|
|
// Optionally set BOINC as screensaver for all users running BOINC.
|
2006-06-20 11:25:23 +00:00
|
|
|
OSErr UpdateAllVisibleUsers(long brandID)
|
|
|
|
{
|
|
|
|
DIR *dirp;
|
|
|
|
dirent *dp;
|
|
|
|
passwd *pw;
|
|
|
|
uid_t saved_uid;
|
2006-07-22 09:05:08 +00:00
|
|
|
Boolean deleteLoginItem;
|
2007-05-19 11:56:01 +00:00
|
|
|
char skinName[256];
|
2009-07-08 08:21:00 +00:00
|
|
|
char s[256];
|
2009-09-02 02:11:03 +00:00
|
|
|
group grpAdmin, *grpAdminPtr;
|
|
|
|
char adminBuf[32768];
|
|
|
|
group grpBOINC_master, *grpBOINC_masterPtr;
|
|
|
|
char bmBuf[32768];
|
2009-09-16 09:57:11 +00:00
|
|
|
Boolean saverAlreadySetForAll = true;
|
|
|
|
Boolean setSaverForAllUsers = false;
|
|
|
|
Boolean allNonAdminUsersAreSet = true;
|
|
|
|
Boolean allowNonAdminUsersToRunBOINC = false;
|
2009-09-01 03:51:03 +00:00
|
|
|
Boolean found = false;
|
2009-07-08 08:21:00 +00:00
|
|
|
FILE *f;
|
2007-05-19 23:08:22 +00:00
|
|
|
OSStatus err;
|
2009-09-02 02:11:03 +00:00
|
|
|
Boolean isGroupMember;
|
2006-08-02 00:43:27 +00:00
|
|
|
#ifdef SANDBOX
|
|
|
|
char *p;
|
|
|
|
short i;
|
2006-06-20 11:25:23 +00:00
|
|
|
|
2009-09-02 02:11:03 +00:00
|
|
|
err = getgrnam_r("admin", &grpAdmin, adminBuf, sizeof(adminBuf), &grpAdminPtr);
|
|
|
|
if (err) { // Should never happen unless buffer too small
|
2006-06-20 11:25:23 +00:00
|
|
|
puts("getgrnam(\"admin\") failed\n");
|
|
|
|
return -1;
|
|
|
|
}
|
2009-09-02 02:11:03 +00:00
|
|
|
|
|
|
|
err = getgrnam_r("boinc_master", &grpBOINC_master, bmBuf, sizeof(bmBuf), &grpBOINC_masterPtr);
|
|
|
|
if (err) { // Should never happen unless buffer too small
|
|
|
|
puts("getgrnam(\"boinc_master\") failed\n");
|
|
|
|
return -1;
|
|
|
|
}
|
2009-11-26 10:46:20 +00:00
|
|
|
#endif // SANDBOX
|
2006-07-22 09:05:08 +00:00
|
|
|
|
2007-05-19 11:56:01 +00:00
|
|
|
FindSkinName(skinName, sizeof(skinName));
|
|
|
|
|
2006-06-20 11:25:23 +00:00
|
|
|
dirp = opendir("/Users");
|
|
|
|
if (dirp == NULL) { // Should never happen
|
|
|
|
puts("opendir(\"/Users\") failed\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2009-09-16 09:57:11 +00:00
|
|
|
// Step through all users
|
2006-06-20 11:25:23 +00:00
|
|
|
while (true) {
|
|
|
|
dp = readdir(dirp);
|
|
|
|
if (dp == NULL)
|
|
|
|
break; // End of list
|
|
|
|
|
|
|
|
if (dp->d_name[0] == '.')
|
|
|
|
continue; // Ignore names beginning with '.'
|
|
|
|
|
|
|
|
pw = getpwnam(dp->d_name);
|
|
|
|
if (pw == NULL) // "Deleted Users", "Shared", etc.
|
|
|
|
continue;
|
|
|
|
|
2006-07-22 09:05:08 +00:00
|
|
|
#ifdef SANDBOX
|
2009-09-02 02:11:03 +00:00
|
|
|
isGroupMember = false;
|
2006-06-20 11:25:23 +00:00
|
|
|
i = 0;
|
2009-09-02 02:11:03 +00:00
|
|
|
while ((p = grpAdmin.gr_mem[i]) != NULL) { // Step through all users in group admin
|
2006-06-20 11:25:23 +00:00
|
|
|
if (strcmp(p, dp->d_name) == 0) {
|
|
|
|
// User is a member of group admin, so add user to groups boinc_master and boinc_project
|
|
|
|
err = AddAdminUserToGroups(p);
|
|
|
|
if (err != noErr)
|
|
|
|
return err;
|
2009-09-02 02:11:03 +00:00
|
|
|
isGroupMember = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
++i;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!isGroupMember) {
|
|
|
|
i = 0;
|
|
|
|
while ((p = grpBOINC_master.gr_mem[i]) != NULL) { // Step through all users in group boinc_master
|
|
|
|
if (strcmp(p, dp->d_name) == 0) {
|
|
|
|
// User is a member of group boinc_master
|
|
|
|
isGroupMember = true;
|
2009-09-16 09:57:11 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
++i;
|
2006-06-20 11:25:23 +00:00
|
|
|
}
|
|
|
|
}
|
2009-09-16 09:57:11 +00:00
|
|
|
if (!isGroupMember) {
|
|
|
|
allNonAdminUsersAreSet = false;
|
2009-09-02 02:11:03 +00:00
|
|
|
}
|
2009-11-26 10:46:20 +00:00
|
|
|
#else // SANDBOX
|
2009-09-02 02:11:03 +00:00
|
|
|
isGroupMember = true;
|
2009-11-26 10:46:20 +00:00
|
|
|
#endif // SANDBOX
|
2006-06-20 11:25:23 +00:00
|
|
|
|
2009-09-02 02:11:03 +00:00
|
|
|
if (isGroupMember) {
|
2009-12-05 11:01:03 +00:00
|
|
|
if (strcmp(loginName, dp->d_name) == 0) {
|
|
|
|
currentUserCanRunBOINC = true;
|
|
|
|
}
|
|
|
|
|
2009-09-16 09:57:11 +00:00
|
|
|
saved_uid = geteuid();
|
|
|
|
seteuid(pw->pw_uid); // Temporarily set effective uid to this user
|
|
|
|
|
|
|
|
if (OSVersion < 0x1060) {
|
|
|
|
f = popen("defaults -currentHost read com.apple.screensaver moduleName", "r");
|
|
|
|
} else {
|
|
|
|
sprintf(s, "sudo -u %s defaults -currentHost read com.apple.screensaver moduleDict -dict",
|
|
|
|
dp->d_name);
|
|
|
|
f = popen(s, "r");
|
2009-09-01 03:51:03 +00:00
|
|
|
}
|
2009-09-16 09:57:11 +00:00
|
|
|
|
|
|
|
if (f) {
|
|
|
|
found = false;
|
|
|
|
while (PersistentFGets(s, sizeof(s), f)) {
|
|
|
|
if (strstr(s, saverName[brandID])) {
|
|
|
|
found = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
pclose(f);
|
|
|
|
if (!found) {
|
|
|
|
saverAlreadySetForAll = false;
|
2009-09-02 02:11:03 +00:00
|
|
|
}
|
2009-09-01 03:51:03 +00:00
|
|
|
}
|
2009-09-16 09:57:11 +00:00
|
|
|
|
|
|
|
seteuid(saved_uid); // Set effective uid back to privileged user
|
|
|
|
} // End if (isGroupMember)
|
|
|
|
} // End while (true)
|
2006-06-20 11:25:23 +00:00
|
|
|
|
|
|
|
closedir(dirp);
|
2009-09-16 09:57:11 +00:00
|
|
|
|
2009-11-18 10:19:14 +00:00
|
|
|
ResynchSystem();
|
|
|
|
|
2009-09-16 09:57:11 +00:00
|
|
|
if (! allNonAdminUsersAreSet) {
|
|
|
|
if (ShowMessage(true,
|
|
|
|
"Users who are permitted to administer this computer will automatically be allowed to "
|
|
|
|
"run and control %s.\n\n"
|
|
|
|
"Do you also want non-administrative users to be able to run and control %s on this Mac?",
|
|
|
|
brandName[brandID], brandName[brandID])
|
|
|
|
) {
|
|
|
|
allowNonAdminUsersToRunBOINC = true;
|
2009-12-05 11:01:03 +00:00
|
|
|
currentUserCanRunBOINC = true;
|
2009-09-16 09:57:11 +00:00
|
|
|
saverAlreadySetForAll = false;
|
|
|
|
}
|
2009-07-08 08:21:00 +00:00
|
|
|
}
|
|
|
|
|
2009-09-16 09:57:11 +00:00
|
|
|
if (! saverAlreadySetForAll) {
|
|
|
|
setSaverForAllUsers = ShowMessage(true,
|
|
|
|
"Do you want to set %s as the screensaver for all %s users on this Mac?",
|
|
|
|
brandName[brandID], brandName[brandID]);
|
2009-07-08 08:21:00 +00:00
|
|
|
}
|
2009-09-16 09:57:11 +00:00
|
|
|
|
|
|
|
// Step through all users a second time, setting non-admin users and / or our screensaver
|
2009-07-08 08:21:00 +00:00
|
|
|
dirp = opendir("/Users");
|
|
|
|
if (dirp == NULL) { // Should never happen
|
|
|
|
puts("opendir(\"/Users\") failed\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
while (true) {
|
|
|
|
dp = readdir(dirp);
|
|
|
|
if (dp == NULL)
|
|
|
|
break; // End of list
|
|
|
|
|
|
|
|
if (dp->d_name[0] == '.')
|
|
|
|
continue; // Ignore names beginning with '.'
|
|
|
|
|
|
|
|
pw = getpwnam(dp->d_name);
|
|
|
|
if (pw == NULL) // "Deleted Users", "Shared", etc.
|
|
|
|
continue;
|
|
|
|
|
2009-09-02 02:11:03 +00:00
|
|
|
#ifdef SANDBOX
|
|
|
|
isGroupMember = false;
|
|
|
|
|
|
|
|
i = 0;
|
2010-02-05 04:34:43 +00:00
|
|
|
while ((p = grpAdmin.gr_mem[i]) != NULL) { // Step through all users in group admin
|
2009-09-02 02:11:03 +00:00
|
|
|
if (strcmp(p, dp->d_name) == 0) {
|
2010-02-05 04:34:43 +00:00
|
|
|
// User is a member of group admin
|
2009-09-02 02:11:03 +00:00
|
|
|
isGroupMember = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
++i;
|
|
|
|
}
|
|
|
|
|
2010-02-05 04:34:43 +00:00
|
|
|
// If allNonAdminUsersAreSet, some older versions added non-admin users only to
|
|
|
|
// group boinc_master; make sure they are also members of group boinc_project
|
2009-09-16 09:57:11 +00:00
|
|
|
if (! isGroupMember) {
|
2010-02-05 04:34:43 +00:00
|
|
|
if (allowNonAdminUsersToRunBOINC || allNonAdminUsersAreSet) {
|
2009-09-16 09:57:11 +00:00
|
|
|
// Add to group boinc_master but not group boinc_project
|
2010-02-05 04:34:43 +00:00
|
|
|
err = AddAdminUserToGroups(dp->d_name);
|
2009-09-16 09:57:11 +00:00
|
|
|
isGroupMember = true;
|
|
|
|
}
|
2009-09-02 02:11:03 +00:00
|
|
|
}
|
2009-11-26 10:46:20 +00:00
|
|
|
#else // SANDBOX
|
2009-09-16 09:57:11 +00:00
|
|
|
isGroupMember = true;
|
2009-11-26 10:46:20 +00:00
|
|
|
#endif // SANDBOX
|
2009-09-02 02:11:03 +00:00
|
|
|
|
2009-07-08 08:21:00 +00:00
|
|
|
saved_uid = geteuid();
|
|
|
|
seteuid(pw->pw_uid); // Temporarily set effective uid to this user
|
2009-09-16 09:57:11 +00:00
|
|
|
deleteLoginItem = CheckDeleteFile(dp->d_name);
|
|
|
|
if (!isGroupMember) {
|
|
|
|
deleteLoginItem = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
SetLoginItem(brandID, deleteLoginItem); // Set login item for this user
|
2009-07-08 08:21:00 +00:00
|
|
|
|
2009-09-16 09:57:11 +00:00
|
|
|
if (isGroupMember) {
|
|
|
|
SetSkinInUserPrefs(dp->d_name, skinName);
|
|
|
|
|
|
|
|
if (setSaverForAllUsers) {
|
|
|
|
if (OSVersion < 0x1060) {
|
|
|
|
sprintf(s, "defaults -currentHost write com.apple.screensaver moduleName %s", saverNameEscaped[brandID]);
|
|
|
|
system (s);
|
|
|
|
sprintf(s, "defaults -currentHost write com.apple.screensaver modulePath /Library/Screen\\ Savers/%s.saver",
|
|
|
|
saverNameEscaped[brandID]);
|
|
|
|
} else {
|
|
|
|
sprintf(s, "sudo -u %s defaults -currentHost write com.apple.screensaver moduleDict -dict moduleName %s path /Library/Screen\\ Savers/%s.saver",
|
|
|
|
dp->d_name, saverNameEscaped[brandID], saverNameEscaped[brandID]);
|
|
|
|
}
|
|
|
|
system (s);
|
|
|
|
}
|
2009-09-01 02:02:35 +00:00
|
|
|
}
|
2009-07-08 08:21:00 +00:00
|
|
|
|
|
|
|
seteuid(saved_uid); // Set effective uid back to privileged user
|
|
|
|
}
|
|
|
|
|
|
|
|
closedir(dirp);
|
|
|
|
|
2009-11-18 10:19:14 +00:00
|
|
|
ResynchSystem();
|
|
|
|
|
2006-06-20 11:25:23 +00:00
|
|
|
return noErr;
|
|
|
|
}
|
|
|
|
|
2005-04-27 12:59:53 +00:00
|
|
|
|
|
|
|
void Initialize() /* Initialize some managers */
|
|
|
|
{
|
|
|
|
OSErr err;
|
|
|
|
|
|
|
|
InitCursor();
|
|
|
|
|
|
|
|
err = AEInstallEventHandler( kCoreEventClass, kAEQuitApplication, NewAEEventHandlerUPP((AEEventHandlerProcPtr)QuitAppleEventHandler), 0, false );
|
|
|
|
if (err != noErr)
|
|
|
|
ExitToShell();
|
|
|
|
}
|
|
|
|
|
2006-01-20 11:57:52 +00:00
|
|
|
|
|
|
|
long GetBrandID()
|
|
|
|
{
|
|
|
|
long iBrandId;
|
|
|
|
|
|
|
|
iBrandId = 0; // Default value
|
|
|
|
|
2006-01-20 14:04:06 +00:00
|
|
|
FILE *f = fopen("Contents/Resources/Branding", "r");
|
2006-01-20 11:57:52 +00:00
|
|
|
if (f) {
|
|
|
|
fscanf(f, "BrandId=%ld\n", &iBrandId);
|
|
|
|
fclose(f);
|
|
|
|
}
|
|
|
|
|
|
|
|
return iBrandId;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-07-19 09:25:25 +00:00
|
|
|
int TestRPCBind()
|
|
|
|
{
|
|
|
|
sockaddr_in addr;
|
|
|
|
int lsock;
|
|
|
|
int retval;
|
|
|
|
|
|
|
|
lsock = (int)socket(AF_INET, SOCK_STREAM, 0);
|
|
|
|
if (lsock < 0)
|
|
|
|
return -153;
|
|
|
|
|
|
|
|
memset(&addr, 0, sizeof(addr));
|
|
|
|
addr.sin_family = AF_INET;
|
|
|
|
addr.sin_port = htons(31416);
|
|
|
|
addr.sin_addr.s_addr = htonl(INADDR_ANY);
|
|
|
|
|
|
|
|
int one = 1;
|
|
|
|
retval = setsockopt(lsock, SOL_SOCKET, SO_REUSEADDR, (char*)&one, 4);
|
|
|
|
|
|
|
|
if (! retval)
|
|
|
|
retval = bind(lsock, (const sockaddr*)(&addr), (socklen_t)sizeof(addr));
|
|
|
|
|
|
|
|
if (! retval)
|
|
|
|
retval = listen(lsock, 999);
|
|
|
|
|
|
|
|
close(lsock);
|
|
|
|
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-11-18 10:19:14 +00:00
|
|
|
static OSStatus ResynchSystem() {
|
|
|
|
OSStatus err = noErr;
|
|
|
|
|
2009-12-05 11:01:03 +00:00
|
|
|
if (OSVersion >= 0x1050) {
|
2009-11-18 10:19:14 +00:00
|
|
|
// OS 10.5
|
|
|
|
err = system("dscacheutil -flushcache");
|
|
|
|
err = system("dsmemberutil flushcache");
|
|
|
|
return noErr;
|
|
|
|
}
|
|
|
|
|
|
|
|
err = system("lookupd -flushcache");
|
|
|
|
|
2009-12-05 11:01:03 +00:00
|
|
|
if (OSVersion >= 0x1040)
|
2009-11-18 10:19:14 +00:00
|
|
|
err = system("memberd -r"); // Available only in OS 10.4
|
|
|
|
|
|
|
|
return noErr;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-05-06 04:30:41 +00:00
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
/* This runs through the process list looking for the indicated application */
|
|
|
|
/* Searches for process by file type and signature (creator code) */
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
OSErr FindProcess (OSType typeToFind, OSType creatorToFind, ProcessSerialNumberPtr processSN)
|
2005-04-27 12:59:53 +00:00
|
|
|
{
|
2005-05-06 04:30:41 +00:00
|
|
|
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);
|
2005-04-27 12:59:53 +00:00
|
|
|
}
|
2005-05-05 14:31:51 +00:00
|
|
|
|
|
|
|
|
2007-05-19 11:56:01 +00:00
|
|
|
int FindSkinName(char *name, size_t len)
|
|
|
|
{
|
|
|
|
FILE *f;
|
|
|
|
char buf[MAXPATHLEN];
|
|
|
|
char *pattern = "/BOINC Data/skins/";
|
|
|
|
char *p, *q;
|
|
|
|
|
|
|
|
name[0] = '\0';
|
|
|
|
|
2008-10-22 03:12:52 +00:00
|
|
|
f = popen("lsbom -d -s ./Contents/Archive.bom", "r");
|
2007-05-19 11:56:01 +00:00
|
|
|
if (f == NULL)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
while (PersistentFGets(buf, sizeof(buf), f)) {
|
|
|
|
p = strstr(buf, pattern);
|
|
|
|
if (p) {
|
|
|
|
p += strlen(pattern);
|
|
|
|
q = strchr(p, '/');
|
|
|
|
if (q) *q = 0;
|
|
|
|
q = strchr(p, '\n');
|
|
|
|
if (q) *q = 0;
|
|
|
|
|
|
|
|
if (strlen(p) > (len-1))
|
|
|
|
return 0;
|
|
|
|
strlcpy(name, p, len);
|
|
|
|
pclose(f);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
pclose(f);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2005-07-26 02:40:47 +00:00
|
|
|
pid_t FindProcessPID(char* name, pid_t thePID)
|
2005-05-05 14:31:51 +00:00
|
|
|
{
|
2005-05-06 04:30:41 +00:00
|
|
|
FILE *f;
|
|
|
|
char buf[1024];
|
2005-07-26 02:40:47 +00:00
|
|
|
size_t n = 0;
|
2005-05-06 04:30:41 +00:00
|
|
|
pid_t aPID;
|
2005-07-26 02:40:47 +00:00
|
|
|
|
|
|
|
if (name != NULL) // Search ny name
|
|
|
|
n = strlen(name);
|
|
|
|
|
2005-05-06 04:30:41 +00:00
|
|
|
f = popen("ps -a -x -c -o command,pid", "r");
|
|
|
|
if (f == NULL)
|
|
|
|
return 0;
|
|
|
|
|
2005-09-20 00:45:00 +00:00
|
|
|
while (PersistentFGets(buf, sizeof(buf), f))
|
2005-07-26 02:40:47 +00:00
|
|
|
{
|
2009-11-18 10:19:14 +00:00
|
|
|
if (name != NULL) { // Search by name
|
2005-07-26 02:40:47 +00:00
|
|
|
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;
|
|
|
|
}
|
2005-05-06 04:30:41 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
pclose(f);
|
|
|
|
return 0;
|
|
|
|
}
|
2005-05-05 14:31:51 +00:00
|
|
|
|
|
|
|
|
2005-05-17 12:56:07 +00:00
|
|
|
static OSErr QuitBOINCManager(OSType signature) {
|
|
|
|
bool done = false;
|
|
|
|
ProcessSerialNumber thisPSN;
|
|
|
|
ProcessInfoRec thisPIR;
|
|
|
|
OSErr err = noErr;
|
|
|
|
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)
|
|
|
|
done = true; // apparently the demo app isn't running. Odd but not impossible
|
|
|
|
else {
|
|
|
|
err = GetProcessInformation(&thisPSN,&thisPIR);
|
|
|
|
if (err != noErr)
|
|
|
|
goto bail;
|
|
|
|
|
|
|
|
if (thisPIR.processSignature == signature) { // is it or target process?
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-05-06 04:30:41 +00:00
|
|
|
static OSErr QuitAppleEventHandler( const AppleEvent *appleEvt, AppleEvent* reply, UInt32 refcon )
|
|
|
|
{
|
|
|
|
gQuitFlag = true;
|
|
|
|
|
|
|
|
return noErr;
|
2005-05-05 14:31:51 +00:00
|
|
|
}
|
|
|
|
|
2006-07-22 09:05:08 +00:00
|
|
|
void strip_cr(char *buf)
|
|
|
|
{
|
|
|
|
char *theCR;
|
|
|
|
|
|
|
|
theCR = strrchr(buf, '\n');
|
|
|
|
if (theCR)
|
|
|
|
*theCR = '\0';
|
|
|
|
theCR = strrchr(buf, '\r');
|
|
|
|
if (theCR)
|
|
|
|
*theCR = '\0';
|
|
|
|
}
|
2005-05-05 14:31:51 +00:00
|
|
|
|
|
|
|
// For debugging
|
|
|
|
void print_to_log_file(const char *format, ...) {
|
|
|
|
#if CREATE_LOG
|
|
|
|
FILE *f;
|
|
|
|
va_list args;
|
2006-07-19 09:25:25 +00:00
|
|
|
char path[256], buf[256];
|
2005-05-05 14:31:51 +00:00
|
|
|
time_t t;
|
2006-07-19 09:25:25 +00:00
|
|
|
strcpy(path, "/Users/Shared/test_log.txt");
|
|
|
|
// strcpy(path, "/Users/");
|
|
|
|
// strcat(path, getlogin());
|
|
|
|
// strcat(path, "/Documents/test_log.txt");
|
|
|
|
f = fopen(path, "a");
|
2005-05-05 14:31:51 +00:00
|
|
|
if (!f) return;
|
|
|
|
|
|
|
|
// freopen(buf, "a", stdout);
|
|
|
|
// freopen(buf, "a", stderr);
|
|
|
|
|
|
|
|
time(&t);
|
|
|
|
strcpy(buf, asctime(localtime(&t)));
|
|
|
|
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);
|
2006-07-19 09:25:25 +00:00
|
|
|
chmod(path, S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH);
|
|
|
|
|
2005-05-05 14:31:51 +00:00
|
|
|
#endif
|
|
|
|
}
|
2005-09-13 09:01:56 +00:00
|
|
|
const char *BOINC_RCSID_c7abe0490e="$Id$";
|