2008-08-06 18:36:30 +00:00
|
|
|
// This file is part of BOINC.
|
2006-06-14 10:45:42 +00:00
|
|
|
// http://boinc.berkeley.edu
|
2008-08-06 18:36:30 +00:00
|
|
|
// Copyright (C) 2008 University of California
|
2006-06-14 10:45:42 +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.
|
2006-06-14 10:45:42 +00:00
|
|
|
//
|
2008-08-06 18:36:30 +00:00
|
|
|
// BOINC is distributed in the hope that it will be useful,
|
2006-06-14 10:45:42 +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/>.
|
2006-06-14 10:45:42 +00:00
|
|
|
|
|
|
|
// check_security.C
|
|
|
|
|
|
|
|
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <pwd.h> // getpwnam
|
|
|
|
#include <grp.h>
|
|
|
|
#include <sys/param.h> // for MAXPATHLEN
|
2006-07-01 05:32:02 +00:00
|
|
|
#include <dirent.h>
|
2006-08-02 00:43:27 +00:00
|
|
|
#include <cerrno>
|
2007-02-26 10:39:36 +00:00
|
|
|
|
|
|
|
#if (defined(__APPLE__) && defined(_DEBUG))
|
|
|
|
#include <Carbon/Carbon.h>
|
|
|
|
#endif
|
|
|
|
|
2006-06-14 10:45:42 +00:00
|
|
|
#include "util.h"
|
|
|
|
#include "error_numbers.h"
|
2006-06-15 11:11:41 +00:00
|
|
|
#include "file_names.h"
|
2006-06-17 00:20:46 +00:00
|
|
|
|
2006-08-01 12:36:19 +00:00
|
|
|
static int CheckNestedDirectories(char * basepath, int depth, int use_sandbox);
|
|
|
|
|
|
|
|
#if (! defined(__WXMAC__) && ! defined(_MAC_INSTALLER))
|
2006-08-02 00:43:27 +00:00
|
|
|
static char * PersistentFGets(char *buf, size_t buflen, FILE *f);
|
2006-08-01 12:36:19 +00:00
|
|
|
static void GetPathToThisProcess(char* outbuf, size_t maxLen);
|
|
|
|
#endif
|
2006-06-17 00:20:46 +00:00
|
|
|
|
2006-06-17 23:59:04 +00:00
|
|
|
#define REAL_BOINC_MASTER_NAME "boinc_master"
|
|
|
|
#define REAL_BOINC_PROJECT_NAME "boinc_project"
|
2006-06-15 11:11:41 +00:00
|
|
|
|
2006-07-01 05:32:02 +00:00
|
|
|
static char boinc_master_user_name[64];
|
|
|
|
static char boinc_master_group_name[64];
|
|
|
|
static char boinc_project_user_name[64];
|
|
|
|
static char boinc_project_group_name[64];
|
|
|
|
|
|
|
|
static gid_t boinc_master_gid, boinc_project_gid;
|
|
|
|
static uid_t boinc_master_uid, boinc_project_uid;
|
2006-06-14 10:45:42 +00:00
|
|
|
|
2006-06-21 12:41:06 +00:00
|
|
|
// Called from BOINC Manager, BOINC Client and Installer.
|
|
|
|
// The arguments are use only when called from the Installer
|
|
|
|
|
2006-06-14 10:45:42 +00:00
|
|
|
// Returns FALSE (0) if owners and permissions are OK, else TRUE (1)
|
2006-06-21 12:41:06 +00:00
|
|
|
int check_security(
|
|
|
|
#ifdef _MAC_INSTALLER
|
2006-08-01 12:36:19 +00:00
|
|
|
char *bundlePath, char *dataPath,
|
2006-06-21 12:41:06 +00:00
|
|
|
#endif
|
2006-08-01 12:36:19 +00:00
|
|
|
int use_sandbox, int isManager
|
2006-06-21 12:41:06 +00:00
|
|
|
) {
|
2006-06-14 10:45:42 +00:00
|
|
|
passwd *pw;
|
|
|
|
group *grp;
|
2006-07-01 05:32:02 +00:00
|
|
|
gid_t egid;
|
|
|
|
uid_t euid;
|
2006-06-15 11:11:41 +00:00
|
|
|
char dir_path[MAXPATHLEN], full_path[MAXPATHLEN];
|
2006-06-14 10:45:42 +00:00
|
|
|
struct stat sbuf;
|
|
|
|
int retval;
|
2006-08-01 12:36:19 +00:00
|
|
|
int useFakeProjectUserAndGroup = 0;
|
2007-02-26 10:39:36 +00:00
|
|
|
#if (defined(__APPLE__) && defined(_DEBUG))
|
|
|
|
long response;
|
|
|
|
OSStatus err = noErr;
|
|
|
|
#endif
|
2006-06-15 11:11:41 +00:00
|
|
|
#ifdef __WXMAC__ // If Mac BOINC Manager
|
2006-06-20 00:55:32 +00:00
|
|
|
ProcessSerialNumber ourPSN;
|
2006-06-17 11:51:48 +00:00
|
|
|
ProcessInfoRec pInfo;
|
2006-06-15 11:11:41 +00:00
|
|
|
FSRef ourFSRef;
|
2008-01-18 02:08:25 +00:00
|
|
|
char *p;
|
2006-06-15 11:11:41 +00:00
|
|
|
#endif
|
2008-01-18 02:08:25 +00:00
|
|
|
#ifdef _MAC_INSTALLER
|
2006-06-21 12:41:06 +00:00
|
|
|
char *p;
|
2008-01-18 02:08:25 +00:00
|
|
|
#endif
|
2006-08-01 12:36:19 +00:00
|
|
|
|
|
|
|
useFakeProjectUserAndGroup = ! use_sandbox;
|
2007-02-26 10:39:36 +00:00
|
|
|
#ifdef _DEBUG
|
|
|
|
#ifdef DEBUG_WITH_FAKE_PROJECT_USER_AND_GROUP
|
|
|
|
useFakeProjectUserAndGroup = 1;
|
2006-06-21 12:41:06 +00:00
|
|
|
#endif
|
2007-02-26 10:39:36 +00:00
|
|
|
#ifdef __APPLE__
|
|
|
|
err = Gestalt(gestaltSystemVersion, &response);
|
|
|
|
if ((err == noErr) && (response < 0x1040))
|
|
|
|
useFakeProjectUserAndGroup = 1;
|
|
|
|
#endif // __APPLE__
|
|
|
|
#endif // _DEBUG
|
2006-06-15 11:11:41 +00:00
|
|
|
|
|
|
|
// GDB can't attach to applications which are running as a diferent user or group so
|
|
|
|
// it ignores the S_ISUID and S_ISGID permisison bits when launching an application.
|
2006-06-20 00:55:32 +00:00
|
|
|
// To work around this, and to allow testing the uninstalled Deployment version, we
|
|
|
|
// assume that the BOINC Client has the correct user and group.
|
|
|
|
// We must get the BOINC Client's user and group differently depending on whether we
|
|
|
|
// were called from the Manager or from the Client
|
|
|
|
|
|
|
|
#ifdef __WXMAC__ // If Mac BOINC Manager
|
|
|
|
// Get the full path to BOINC Manager application's bundle
|
|
|
|
retval = GetCurrentProcess (&ourPSN);
|
|
|
|
if (retval)
|
2006-06-21 12:41:06 +00:00
|
|
|
return -1000; // Should never happen
|
2006-06-20 00:55:32 +00:00
|
|
|
|
|
|
|
memset(&pInfo, 0, sizeof(pInfo));
|
|
|
|
pInfo.processInfoLength = sizeof( ProcessInfoRec );
|
|
|
|
retval = GetProcessInformation(&ourPSN, &pInfo);
|
|
|
|
if (retval)
|
2006-06-21 12:41:06 +00:00
|
|
|
return -1001; // Should never happen
|
2006-06-20 00:55:32 +00:00
|
|
|
|
|
|
|
retval = GetProcessBundleLocation(&ourPSN, &ourFSRef);
|
|
|
|
if (retval)
|
2006-06-21 12:41:06 +00:00
|
|
|
return -1002; // Should never happen
|
2006-06-20 00:55:32 +00:00
|
|
|
|
|
|
|
retval = FSRefMakePath (&ourFSRef, (UInt8*)dir_path, sizeof(dir_path));
|
|
|
|
if (retval)
|
2006-06-21 12:41:06 +00:00
|
|
|
return -1003; // Should never happen
|
2006-08-01 12:36:19 +00:00
|
|
|
#elif defined (_MAC_INSTALLER)
|
2006-06-21 12:41:06 +00:00
|
|
|
strlcpy(dir_path, bundlePath, sizeof(dir_path));
|
|
|
|
#endif
|
2006-06-20 00:55:32 +00:00
|
|
|
|
2006-08-01 12:36:19 +00:00
|
|
|
if (use_sandbox) {
|
|
|
|
#if (defined(__WXMAC__) || defined(_MAC_INSTALLER)) // If called from Mac BOINC Manager or installer
|
|
|
|
// Get the full path to BOINC Client inside this application's bundle
|
|
|
|
strlcpy(full_path, dir_path, sizeof(full_path));
|
|
|
|
strlcat(full_path, "/Contents/Resources/boinc", sizeof(full_path));
|
|
|
|
#else
|
|
|
|
if (isManager) { // If called from BOINC Manager but not on Mac
|
|
|
|
getcwd(full_path, sizeof(full_path)); // Assume Client is in current directory
|
|
|
|
strlcat(full_path, "/boinc", sizeof(full_path));
|
|
|
|
} else // If called from BOINC Client
|
|
|
|
GetPathToThisProcess(full_path, sizeof(full_path));
|
|
|
|
#endif
|
2006-06-20 00:55:32 +00:00
|
|
|
|
2006-08-01 12:36:19 +00:00
|
|
|
retval = stat(full_path, &sbuf);
|
|
|
|
if (retval)
|
|
|
|
return -1004; // Should never happen
|
2006-06-20 00:55:32 +00:00
|
|
|
|
2006-08-01 12:36:19 +00:00
|
|
|
if ((sbuf.st_mode & (S_ISUID | S_ISGID)) != (S_ISUID | S_ISGID))
|
|
|
|
return -1005;
|
2006-06-20 00:55:32 +00:00
|
|
|
|
2006-08-18 02:51:27 +00:00
|
|
|
boinc_master_uid = sbuf.st_uid;
|
|
|
|
boinc_master_gid = sbuf.st_gid;
|
2006-08-01 12:36:19 +00:00
|
|
|
} else {
|
|
|
|
boinc_master_uid = geteuid();
|
|
|
|
boinc_master_gid = getegid();
|
2006-06-20 00:55:32 +00:00
|
|
|
|
2006-08-01 12:36:19 +00:00
|
|
|
}
|
2006-06-20 00:55:32 +00:00
|
|
|
|
2006-06-21 12:41:06 +00:00
|
|
|
#ifdef _MAC_INSTALLER
|
|
|
|
// Require absolute owner and group boinc_master:boinc_master
|
2006-06-17 23:59:04 +00:00
|
|
|
strlcpy(boinc_master_user_name, REAL_BOINC_MASTER_NAME, sizeof(boinc_master_user_name));
|
2006-06-15 11:11:41 +00:00
|
|
|
pw = getpwnam(boinc_master_user_name);
|
2006-06-14 10:45:42 +00:00
|
|
|
if (pw == NULL)
|
2006-06-21 12:41:06 +00:00
|
|
|
return -1006; // User boinc_master does not exist
|
2006-06-14 10:45:42 +00:00
|
|
|
boinc_master_uid = pw->pw_uid;
|
|
|
|
|
2006-06-17 23:59:04 +00:00
|
|
|
strlcpy(boinc_master_group_name, REAL_BOINC_MASTER_NAME, sizeof(boinc_master_group_name));
|
2006-06-15 11:11:41 +00:00
|
|
|
grp = getgrnam(boinc_master_group_name);
|
|
|
|
if (grp == NULL)
|
2006-06-21 12:41:06 +00:00
|
|
|
return -1007; // Group boinc_master does not exist
|
2006-06-15 11:11:41 +00:00
|
|
|
boinc_master_gid = grp->gr_gid;
|
2006-06-21 12:41:06 +00:00
|
|
|
|
|
|
|
#else // Use current user and group (see comment above)
|
|
|
|
|
|
|
|
pw = getpwuid(boinc_master_uid);
|
|
|
|
if (pw == NULL)
|
|
|
|
return -1008; // Should never happen
|
|
|
|
strlcpy(boinc_master_user_name, pw->pw_name, sizeof(boinc_master_user_name));
|
|
|
|
|
|
|
|
grp = getgrgid(boinc_master_gid);
|
|
|
|
if (grp == NULL)
|
|
|
|
return -1009;
|
|
|
|
strlcpy(boinc_master_group_name, grp->gr_name, sizeof(boinc_master_group_name));
|
|
|
|
|
2006-06-20 00:55:32 +00:00
|
|
|
#endif
|
2006-06-17 00:20:46 +00:00
|
|
|
|
2006-08-01 12:36:19 +00:00
|
|
|
if (useFakeProjectUserAndGroup) {
|
|
|
|
// For easier debugging of project applications
|
|
|
|
strlcpy(boinc_project_user_name, boinc_master_user_name, sizeof(boinc_project_user_name));
|
|
|
|
strlcpy(boinc_project_group_name, boinc_master_group_name, sizeof(boinc_project_group_name));
|
|
|
|
boinc_project_uid = boinc_master_uid;
|
|
|
|
boinc_project_gid = boinc_master_gid;
|
|
|
|
} else {
|
|
|
|
strlcpy(boinc_project_user_name, REAL_BOINC_PROJECT_NAME, sizeof(boinc_project_user_name));
|
|
|
|
pw = getpwnam(boinc_project_user_name);
|
|
|
|
if (pw == NULL)
|
|
|
|
return -1010; // User boinc_project does not exist
|
|
|
|
boinc_project_uid = pw->pw_uid;
|
|
|
|
|
|
|
|
strlcpy(boinc_project_group_name, REAL_BOINC_PROJECT_NAME, sizeof(boinc_project_group_name));
|
|
|
|
grp = getgrnam(boinc_project_group_name);
|
|
|
|
if (grp == NULL)
|
|
|
|
return -1011; // Group boinc_project does not exist
|
|
|
|
boinc_project_gid = grp->gr_gid;
|
|
|
|
}
|
2006-06-14 10:45:42 +00:00
|
|
|
|
2006-06-21 12:41:06 +00:00
|
|
|
#if (defined(__WXMAC__) || defined(_MAC_INSTALLER)) // If Mac BOINC Manager or installer
|
2006-06-17 11:51:48 +00:00
|
|
|
// Get the full path to BOINC Manager executable inside this application's bundle
|
|
|
|
strlcpy(full_path, dir_path, sizeof(full_path));
|
|
|
|
strlcat(full_path, "/Contents/MacOS/", sizeof(full_path));
|
|
|
|
// To allow for branding, assume name of executable inside bundle is same as name of bundle
|
|
|
|
p = strrchr(dir_path, '/'); // Assume name of executable inside bundle is same as name of bundle
|
|
|
|
if (p == NULL)
|
|
|
|
p = dir_path - 1;
|
|
|
|
strlcat(full_path, p+1, sizeof(full_path));
|
|
|
|
p = strrchr(full_path, '.'); // Strip off bundle extension (".app")
|
|
|
|
if (p)
|
|
|
|
*p = '\0';
|
|
|
|
|
2008-03-20 23:44:05 +00:00
|
|
|
retval = lstat(full_path, &sbuf);
|
2006-06-17 11:51:48 +00:00
|
|
|
if (retval)
|
2006-06-21 12:41:06 +00:00
|
|
|
return -1013; // Should never happen
|
2006-06-17 11:51:48 +00:00
|
|
|
|
|
|
|
if (sbuf.st_gid != boinc_master_gid)
|
2006-06-21 12:41:06 +00:00
|
|
|
return -1014;
|
2006-06-15 11:11:41 +00:00
|
|
|
|
2006-08-01 12:36:19 +00:00
|
|
|
if (use_sandbox) {
|
|
|
|
if ((sbuf.st_mode & S_ISGID) != S_ISGID)
|
|
|
|
return -1015;
|
|
|
|
}
|
2006-06-21 12:41:06 +00:00
|
|
|
#endif
|
2006-06-15 11:11:41 +00:00
|
|
|
|
2006-06-21 12:41:06 +00:00
|
|
|
#ifdef _MAC_INSTALLER
|
2006-06-20 11:25:23 +00:00
|
|
|
// Require absolute owner and group boinc_master:boinc_master
|
2006-08-01 12:36:19 +00:00
|
|
|
// Get the full path to BOINC Client inside this application's bundle
|
2006-06-17 11:51:48 +00:00
|
|
|
strlcpy(full_path, dir_path, sizeof(full_path));
|
|
|
|
strlcat(full_path, "/Contents/Resources/boinc", sizeof(full_path));
|
2006-06-15 11:11:41 +00:00
|
|
|
|
2006-06-17 11:51:48 +00:00
|
|
|
retval = stat(full_path, &sbuf);
|
|
|
|
if (retval)
|
2006-06-21 12:41:06 +00:00
|
|
|
return -1016; // Should never happen
|
2006-06-17 11:51:48 +00:00
|
|
|
|
|
|
|
if (sbuf.st_gid != boinc_master_gid)
|
2006-06-21 12:41:06 +00:00
|
|
|
return -1017;
|
2006-06-15 11:11:41 +00:00
|
|
|
|
2006-06-17 11:51:48 +00:00
|
|
|
if (sbuf.st_uid != boinc_master_uid)
|
2006-06-21 12:41:06 +00:00
|
|
|
return -1018;
|
2006-06-20 00:55:32 +00:00
|
|
|
#endif
|
2006-06-15 11:11:41 +00:00
|
|
|
|
2007-09-19 09:41:23 +00:00
|
|
|
#if (defined(__WXMAC__) || defined(_MAC_INSTALLER)) // If Mac BOINC Manager or installer
|
|
|
|
// Version 6 screensaver has its own embedded switcher application, but older versions don't.
|
2007-10-03 06:16:58 +00:00
|
|
|
// We don't allow unauthorized users to run the standard switcher application in the BOINC
|
|
|
|
// Data directory because they could use it to run as user & group boinc_project and damage
|
|
|
|
// project files. The screensaver's gfx_switcher application has very limited functionality
|
|
|
|
// to avoid this risk.
|
2007-09-19 09:41:23 +00:00
|
|
|
|
|
|
|
if (use_sandbox) {
|
2007-10-03 06:16:58 +00:00
|
|
|
// Does gfx_switcher exist in screensaver bundle?
|
|
|
|
strcpy(full_path, "/Library/Screen Savers/BOINCSaver.saver/Contents/Resources/gfx_switcher");
|
2007-09-19 09:41:23 +00:00
|
|
|
retval = stat(full_path, &sbuf);
|
|
|
|
if (! retval) {
|
|
|
|
#ifdef _DEBUG
|
|
|
|
if (sbuf.st_uid != boinc_master_uid)
|
2007-10-03 06:16:58 +00:00
|
|
|
return -1101;
|
2007-09-19 09:41:23 +00:00
|
|
|
|
|
|
|
if (sbuf.st_gid != boinc_master_gid)
|
2007-10-03 06:16:58 +00:00
|
|
|
return -1102;
|
2007-09-19 09:41:23 +00:00
|
|
|
|
|
|
|
if ((sbuf.st_mode & (S_ISUID | S_ISGID)) != 0)
|
2007-10-03 06:16:58 +00:00
|
|
|
return -1103;
|
2007-09-19 09:41:23 +00:00
|
|
|
#else
|
2007-10-03 06:16:58 +00:00
|
|
|
if (sbuf.st_uid != 0)
|
|
|
|
return -1101;
|
2007-09-19 09:41:23 +00:00
|
|
|
|
2007-10-03 06:16:58 +00:00
|
|
|
if (sbuf.st_gid != boinc_master_gid)
|
2007-09-19 09:41:23 +00:00
|
|
|
return -1102;
|
|
|
|
|
2007-10-03 06:16:58 +00:00
|
|
|
if ((sbuf.st_mode & (S_ISUID | S_ISGID)) != S_ISUID)
|
|
|
|
return -1103;
|
2007-09-19 09:41:23 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2006-06-15 11:11:41 +00:00
|
|
|
// rgid = getgid();
|
|
|
|
// ruid = getuid();
|
2006-06-14 10:45:42 +00:00
|
|
|
egid = getegid();
|
2006-06-15 11:11:41 +00:00
|
|
|
euid = geteuid();
|
2006-06-17 00:20:46 +00:00
|
|
|
|
2006-08-01 12:36:19 +00:00
|
|
|
#ifdef _MAC_INSTALLER
|
|
|
|
strlcpy(dir_path, dataPath, sizeof(dir_path)); // Installer
|
|
|
|
#else // _MAC_INSTALLER
|
|
|
|
getcwd(dir_path, sizeof(dir_path)); // Client or Manager
|
|
|
|
|
2006-06-14 10:45:42 +00:00
|
|
|
if (egid != boinc_master_gid)
|
2006-06-21 12:41:06 +00:00
|
|
|
return -1019; // Client or Manager should be running setgid boinc_master
|
2006-06-14 10:45:42 +00:00
|
|
|
|
2006-08-01 12:36:19 +00:00
|
|
|
if (! isManager) // If BOINC Client
|
|
|
|
if (euid != boinc_master_uid)
|
|
|
|
return -1020; // BOINC Client should be running setuid boinc_master
|
2006-06-15 11:11:41 +00:00
|
|
|
#endif
|
2006-06-14 10:45:42 +00:00
|
|
|
|
|
|
|
retval = stat(dir_path, &sbuf);
|
|
|
|
if (retval)
|
2006-06-21 12:41:06 +00:00
|
|
|
return -1021; // Should never happen
|
2006-08-01 12:36:19 +00:00
|
|
|
|
|
|
|
if (use_sandbox) {
|
|
|
|
|
|
|
|
// The top-level BOINC Data directory can have a different user if created by the Manager,
|
|
|
|
// but it should always have group boinc_master.
|
|
|
|
if (sbuf.st_gid != boinc_master_gid)
|
|
|
|
return -1022;
|
2006-06-14 10:45:42 +00:00
|
|
|
|
2008-01-16 10:38:21 +00:00
|
|
|
// The top-level BOINC Data directory should have permission 771 or 571
|
|
|
|
if ((sbuf.st_mode & 0577) != 0571)
|
2006-08-01 12:36:19 +00:00
|
|
|
return -1023;
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
if (sbuf.st_uid != boinc_master_uid)
|
|
|
|
return -1022;
|
|
|
|
|
|
|
|
}
|
2006-06-14 10:45:42 +00:00
|
|
|
|
2006-06-15 11:11:41 +00:00
|
|
|
strlcpy(full_path, dir_path, sizeof(full_path));
|
|
|
|
strlcat(full_path, "/", sizeof(full_path));
|
|
|
|
strlcat(full_path, PROJECTS_DIR, sizeof(full_path));
|
|
|
|
retval = stat(full_path, &sbuf);
|
2006-06-14 10:45:42 +00:00
|
|
|
if (! retval) { // Client can create projects directory if it does not yet exist.
|
2006-08-01 12:36:19 +00:00
|
|
|
if (use_sandbox) {
|
|
|
|
if (sbuf.st_gid != boinc_master_gid)
|
|
|
|
return -1024;
|
2006-06-14 10:45:42 +00:00
|
|
|
|
2006-06-16 13:40:30 +00:00
|
|
|
if ((sbuf.st_mode & 0777) != 0775)
|
2006-08-01 12:36:19 +00:00
|
|
|
return -1025;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (sbuf.st_uid != boinc_master_uid)
|
2006-06-21 12:41:06 +00:00
|
|
|
return -1026;
|
2006-07-01 05:32:02 +00:00
|
|
|
|
|
|
|
// Step through project directories
|
2006-08-01 12:36:19 +00:00
|
|
|
retval = CheckNestedDirectories(full_path, 1, use_sandbox);
|
2006-07-01 05:32:02 +00:00
|
|
|
if (retval)
|
|
|
|
return retval;
|
2006-06-14 10:45:42 +00:00
|
|
|
}
|
|
|
|
|
2006-06-15 11:11:41 +00:00
|
|
|
strlcpy(full_path, dir_path, sizeof(dir_path));
|
|
|
|
strlcat(full_path, "/", sizeof(full_path));
|
|
|
|
strlcat(full_path, SLOTS_DIR, sizeof(full_path));
|
|
|
|
retval = stat(full_path, &sbuf);
|
2006-06-14 10:45:42 +00:00
|
|
|
if (! retval) { // Client can create slots directory if it does not yet exist.
|
2006-08-01 12:36:19 +00:00
|
|
|
if (use_sandbox) {
|
|
|
|
if (sbuf.st_gid != boinc_master_gid)
|
|
|
|
return -1027;
|
2006-06-14 10:45:42 +00:00
|
|
|
|
2006-08-01 12:36:19 +00:00
|
|
|
if ((sbuf.st_mode & 0777) != 0775)
|
|
|
|
return -1028;
|
|
|
|
}
|
|
|
|
|
2006-06-14 10:45:42 +00:00
|
|
|
if (sbuf.st_uid != boinc_master_uid)
|
2006-06-21 12:41:06 +00:00
|
|
|
return -1029;
|
2006-07-01 05:32:02 +00:00
|
|
|
|
|
|
|
// Step through slot directories
|
2006-08-01 12:36:19 +00:00
|
|
|
retval = CheckNestedDirectories(full_path, 1, use_sandbox);
|
2006-07-01 05:32:02 +00:00
|
|
|
if (retval)
|
|
|
|
return retval;
|
2006-06-15 11:11:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
strlcpy(full_path, dir_path, sizeof(full_path));
|
|
|
|
strlcat(full_path, "/", sizeof(full_path));
|
|
|
|
strlcat(full_path, GUI_RPC_PASSWD_FILE, sizeof(full_path));
|
|
|
|
retval = stat(full_path, &sbuf);
|
|
|
|
if (! retval) { // Client can create RPC password file if it does not yet exist.
|
2006-08-01 12:36:19 +00:00
|
|
|
if (use_sandbox) {
|
|
|
|
if (sbuf.st_gid != boinc_master_gid)
|
|
|
|
return -1030;
|
2006-06-15 11:11:41 +00:00
|
|
|
|
2006-08-01 12:36:19 +00:00
|
|
|
if ((sbuf.st_mode & 0777) != 0660)
|
|
|
|
return -1032;
|
|
|
|
} else {
|
|
|
|
if ((sbuf.st_mode & 0717) != 0600)
|
|
|
|
return -1032;
|
|
|
|
}
|
|
|
|
|
2006-06-15 11:11:41 +00:00
|
|
|
if (sbuf.st_uid != boinc_master_uid)
|
2006-06-21 12:41:06 +00:00
|
|
|
return -1031;
|
2006-06-14 10:45:42 +00:00
|
|
|
}
|
|
|
|
|
2006-08-01 12:36:19 +00:00
|
|
|
if (use_sandbox) {
|
|
|
|
strlcpy(full_path, dir_path, sizeof(dir_path));
|
|
|
|
strlcat(full_path, "/", sizeof(full_path));
|
|
|
|
strlcat(full_path, SWITCHER_DIR, sizeof(full_path));
|
|
|
|
retval = stat(full_path, &sbuf);
|
|
|
|
if (retval)
|
|
|
|
return -1033;
|
|
|
|
|
|
|
|
if (sbuf.st_gid != boinc_master_gid)
|
|
|
|
return -1034;
|
2006-06-17 00:20:46 +00:00
|
|
|
|
2006-08-01 12:36:19 +00:00
|
|
|
if (sbuf.st_uid != boinc_master_uid)
|
|
|
|
return -1035;
|
2006-06-17 00:20:46 +00:00
|
|
|
|
2006-08-01 12:36:19 +00:00
|
|
|
if ((sbuf.st_mode & 0777) != 0550)
|
|
|
|
return -1036;
|
2006-06-17 00:20:46 +00:00
|
|
|
|
2006-08-01 12:36:19 +00:00
|
|
|
strlcat(full_path, "/", sizeof(full_path));
|
|
|
|
strlcat(full_path, SWITCHER_FILE_NAME, sizeof(full_path));
|
|
|
|
retval = stat(full_path, &sbuf);
|
|
|
|
if (retval)
|
|
|
|
return -1037;
|
|
|
|
|
2007-10-02 09:31:20 +00:00
|
|
|
if (sbuf.st_gid != boinc_master_gid)
|
2006-08-01 12:36:19 +00:00
|
|
|
return -1038;
|
2006-06-17 00:20:46 +00:00
|
|
|
|
2007-10-02 09:31:20 +00:00
|
|
|
if (sbuf.st_uid != 0) // root
|
2006-08-01 12:36:19 +00:00
|
|
|
return -1039;
|
2006-06-17 00:20:46 +00:00
|
|
|
|
2007-10-02 09:31:20 +00:00
|
|
|
if ((sbuf.st_mode & 07777) != 04050)
|
2006-08-01 12:36:19 +00:00
|
|
|
return -1040;
|
2006-07-01 05:32:02 +00:00
|
|
|
|
2006-08-01 12:36:19 +00:00
|
|
|
strlcpy(full_path, dir_path, sizeof(dir_path));
|
|
|
|
strlcat(full_path, "/", sizeof(full_path));
|
|
|
|
strlcat(full_path, SWITCHER_DIR, sizeof(full_path));
|
2006-07-01 05:32:02 +00:00
|
|
|
|
2006-08-01 12:36:19 +00:00
|
|
|
strlcat(full_path, "/", sizeof(full_path));
|
|
|
|
strlcat(full_path, SETPROJECTGRP_FILE_NAME, sizeof(full_path));
|
|
|
|
retval = stat(full_path, &sbuf);
|
|
|
|
if (retval)
|
|
|
|
return -1041;
|
|
|
|
|
|
|
|
if (sbuf.st_gid != boinc_project_gid)
|
|
|
|
return -1042;
|
2006-07-01 05:32:02 +00:00
|
|
|
|
2006-08-01 12:36:19 +00:00
|
|
|
if (sbuf.st_uid != boinc_master_uid)
|
|
|
|
return -1043;
|
2006-07-01 05:32:02 +00:00
|
|
|
|
2006-08-01 12:36:19 +00:00
|
|
|
if ((sbuf.st_mode & 07777) != 02500)
|
|
|
|
return -1044;
|
2006-09-25 10:49:39 +00:00
|
|
|
|
|
|
|
#ifdef __APPLE__
|
2007-02-20 01:39:26 +00:00
|
|
|
#if 0 // AppStats is deprecated as of version 5.8.15
|
2006-09-25 10:49:39 +00:00
|
|
|
strlcat(full_path, "/", sizeof(full_path));
|
|
|
|
strlcat(full_path, APP_STATS_FILE_NAME, sizeof(full_path));
|
|
|
|
retval = stat(full_path, &sbuf);
|
|
|
|
if (retval)
|
|
|
|
return -1045;
|
|
|
|
|
|
|
|
if (sbuf.st_gid != boinc_master_gid)
|
|
|
|
return -1046;
|
|
|
|
|
|
|
|
if (sbuf.st_uid != 0) // AppStats application must be setuid root
|
|
|
|
return -1047;
|
|
|
|
|
|
|
|
if ((sbuf.st_mode & 07777) != 04550)
|
|
|
|
return -1048;
|
2007-02-20 01:39:26 +00:00
|
|
|
#endif
|
2006-09-25 10:49:39 +00:00
|
|
|
#endif // __APPLE__
|
2009-02-05 01:21:24 +00:00
|
|
|
|
|
|
|
strlcpy(full_path, dir_path, sizeof(dir_path));
|
|
|
|
strlcat(full_path, "/", sizeof(full_path));
|
|
|
|
strlcat(full_path, SS_CONFIG_FILE, sizeof(full_path));
|
|
|
|
|
|
|
|
retval = stat(full_path, &sbuf);
|
|
|
|
if (!retval) {
|
|
|
|
if (sbuf.st_uid != boinc_master_uid)
|
|
|
|
return -1051;
|
|
|
|
|
|
|
|
if (sbuf.st_gid != boinc_master_gid)
|
|
|
|
return -1052;
|
|
|
|
|
|
|
|
if ((sbuf.st_mode & 0777) != 0664)
|
|
|
|
return -1053;
|
|
|
|
} // Screensaver config file ss_config.xml exists
|
|
|
|
|
|
|
|
strlcpy(full_path, dir_path, sizeof(dir_path));
|
|
|
|
strlcat(full_path, "/", sizeof(full_path));
|
|
|
|
strlcat(full_path, DEFAULT_SS_EXECUTABLE, sizeof(full_path));
|
|
|
|
|
|
|
|
retval = stat(full_path, &sbuf);
|
|
|
|
if (!retval) {
|
|
|
|
if (sbuf.st_uid != boinc_master_uid)
|
|
|
|
return -1055;
|
|
|
|
|
|
|
|
if (sbuf.st_gid != boinc_master_gid)
|
|
|
|
return -1056;
|
|
|
|
|
|
|
|
#ifdef _DEBUG
|
|
|
|
if ((sbuf.st_mode & 07777) != 06775)
|
|
|
|
return -1057;
|
|
|
|
#else
|
|
|
|
if ((sbuf.st_mode & 07777) != 06555)
|
|
|
|
return -1058;
|
|
|
|
#endif
|
|
|
|
} // Screensaver executable file boincscr exists
|
|
|
|
|
2007-02-20 01:39:26 +00:00
|
|
|
} // if (use_sandbox)
|
2006-08-01 12:36:19 +00:00
|
|
|
|
2006-06-14 10:45:42 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2006-07-01 05:32:02 +00:00
|
|
|
|
|
|
|
|
2006-08-01 12:36:19 +00:00
|
|
|
static int CheckNestedDirectories(char * basepath, int depth, int use_sandbox) {
|
2006-07-01 05:32:02 +00:00
|
|
|
int isDirectory;
|
|
|
|
char full_path[MAXPATHLEN];
|
|
|
|
struct stat sbuf;
|
|
|
|
int retval = 0;
|
|
|
|
DIR *dirp;
|
|
|
|
dirent *dp;
|
|
|
|
|
|
|
|
dirp = opendir(basepath);
|
|
|
|
if (dirp == NULL) // Should never happen
|
|
|
|
return -1200;
|
|
|
|
|
|
|
|
while (true) {
|
|
|
|
dp = readdir(dirp);
|
|
|
|
if (dp == NULL)
|
|
|
|
break; // End of list
|
|
|
|
|
|
|
|
if (dp->d_name[0] == '.')
|
|
|
|
continue; // Ignore names beginning with '.'
|
|
|
|
|
|
|
|
strlcpy(full_path, basepath, sizeof(full_path));
|
|
|
|
strlcat(full_path, "/", sizeof(full_path));
|
|
|
|
strlcat(full_path, dp->d_name, sizeof(full_path));
|
|
|
|
|
2008-03-20 23:44:05 +00:00
|
|
|
retval = lstat(full_path, &sbuf);
|
2006-07-01 05:32:02 +00:00
|
|
|
if (retval)
|
|
|
|
break; // Should never happen
|
|
|
|
|
|
|
|
isDirectory = S_ISDIR(sbuf.st_mode);
|
|
|
|
|
2008-03-21 11:55:12 +00:00
|
|
|
if (!S_ISLNK(sbuf.st_mode)) { // The system ignores ownership & permissions of symbolic links
|
2008-03-20 23:44:05 +00:00
|
|
|
if (depth > 1) {
|
|
|
|
// files and subdirectories created by projects may have owner boinc_master or boinc_project
|
|
|
|
if ( (sbuf.st_uid != boinc_master_uid) && (sbuf.st_uid != boinc_project_uid) ) {
|
|
|
|
retval = -1202;
|
2006-07-01 05:32:02 +00:00
|
|
|
break;
|
|
|
|
}
|
2008-03-20 23:44:05 +00:00
|
|
|
} else {
|
2006-08-01 12:36:19 +00:00
|
|
|
// project & slot directories (projects/setiathome.berkeley.edu, slots/0 etc.)
|
2008-03-20 23:44:05 +00:00
|
|
|
// must have owner boinc_master
|
|
|
|
if (sbuf.st_uid != boinc_master_uid) {
|
|
|
|
retval = -1202;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (use_sandbox) {
|
|
|
|
if (sbuf.st_gid != boinc_project_gid) {
|
|
|
|
retval = -1201;
|
2006-08-01 12:36:19 +00:00
|
|
|
break;
|
|
|
|
}
|
2008-03-20 23:44:05 +00:00
|
|
|
|
|
|
|
if (isDirectory) {
|
|
|
|
if (depth == 1) {
|
|
|
|
// project & slot directories (projects/setiathome.berkeley.edu, slots/0 etc.)
|
|
|
|
// must be readable & executable by other
|
|
|
|
if ((sbuf.st_mode & 0777) != 0775) {
|
|
|
|
retval = -1203;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
#if 0 // We may enforce permissions later for subdirectories written by project applications
|
|
|
|
} else {
|
|
|
|
// subdirectories created by projects may be executable by other or not
|
|
|
|
if ((sbuf.st_mode & 0770) != 0770) {
|
|
|
|
retval = -1203;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
#if 0 // We may enforce permissions later for files written by project applications
|
|
|
|
} else { // ! isDirectory
|
|
|
|
if ((sbuf.st_mode & 0666) != 0660) {
|
|
|
|
retval = -1204;
|
2006-08-01 12:36:19 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
2008-03-20 23:44:05 +00:00
|
|
|
} // if (use_sandbox)
|
|
|
|
} // if (!S_ISLNK(sbuf.st_mode))
|
|
|
|
|
|
|
|
if (isDirectory && !S_ISLNK(sbuf.st_mode)) {
|
2006-08-01 12:36:19 +00:00
|
|
|
if (use_sandbox && (depth > 1))
|
2006-07-06 11:04:46 +00:00
|
|
|
if ((sbuf.st_uid != boinc_master_uid) && (sbuf.st_gid != boinc_master_gid))
|
|
|
|
continue; // We can't check subdirectories owned by boinc_project
|
|
|
|
|
2006-08-01 12:36:19 +00:00
|
|
|
retval = CheckNestedDirectories(full_path, depth + 1, use_sandbox);
|
2006-07-01 05:32:02 +00:00
|
|
|
if (retval)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
} // End while (true)
|
|
|
|
|
|
|
|
closedir(dirp);
|
|
|
|
|
|
|
|
return retval;
|
|
|
|
}
|
2006-08-01 12:36:19 +00:00
|
|
|
|
|
|
|
|
|
|
|
#if (! defined(__WXMAC__) && ! defined(_MAC_INSTALLER))
|
2006-08-02 00:43:27 +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);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-08-01 12:36:19 +00:00
|
|
|
static void GetPathToThisProcess(char* outbuf, size_t maxLen) {
|
|
|
|
FILE *f;
|
|
|
|
char buf[256], *p, *q;
|
|
|
|
pid_t aPID = getpid();
|
|
|
|
|
|
|
|
*outbuf = '\0';
|
|
|
|
|
|
|
|
sprintf(buf, "ps -xwo command -p %d", (int)aPID);
|
|
|
|
f = popen(buf, "r");
|
|
|
|
if (f == NULL)
|
|
|
|
return;
|
|
|
|
|
2006-08-02 00:43:27 +00:00
|
|
|
PersistentFGets (outbuf, maxLen, f); // Discard header line
|
|
|
|
PersistentFGets (outbuf, maxLen, f);
|
2006-08-01 12:36:19 +00:00
|
|
|
pclose(f);
|
2006-08-02 00:43:27 +00:00
|
|
|
|
|
|
|
// Remove trailing newline if present
|
|
|
|
p = strchr(outbuf, '\n');
|
|
|
|
if (p)
|
|
|
|
*p = '\0';
|
2006-08-01 12:36:19 +00:00
|
|
|
|
|
|
|
// Strip off any arguments
|
|
|
|
p = strstr(outbuf, " -");
|
|
|
|
q = p;
|
|
|
|
if (p) {
|
|
|
|
while (*p == ' ') {
|
|
|
|
q = p;
|
|
|
|
if (--p < outbuf)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (q)
|
|
|
|
*q = '\0';
|
|
|
|
}
|
|
|
|
#endif
|