// Berkeley Open Infrastructure for Network Computing // http://boinc.berkeley.edu // Copyright (C) 2005 University of California // // This 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 2.1 of the License, or (at your option) any later version. // // This software is distributed in the hope that it will be useful, // 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. // // To view the GNU Lesser General Public License visit // http://www.gnu.org/copyleft/lesser.html // or write to the Free Software Foundation, Inc., // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA // gfx_switcher.C // // Used by screensaver to: // - launch graphics application at given slot number as user & owner boinc_project // - kill graphics application with given process ID #include #include #include #include #include // for MAXPATHLEN #include // getpwuid #include #include "boinc_api.h" #include "common_defs.h" #define CREATE_LOG 0 #ifdef __cplusplus extern "C" { #endif static void print_to_log_file(const char *format, ...); #ifdef __cplusplus } static void strip_cr(char *buf); #endif int main(int argc, char** argv) { passwd *pw; group *grp; char user_name[256], group_name[256]; char gfx_app_path[MAXPATHLEN], resolved_path[MAXPATHLEN]; char *BOINCDatSlotsPath = "/Library/Application Support/BOINC Data/slots/"; int retval; int pid; strlcpy(user_name, "boinc_project", sizeof(user_name)); strlcpy(group_name, "boinc_project", sizeof(group_name)); #if 0 // For debugging only char current_dir[MAXPATHLEN]; getcwd( current_dir, sizeof(current_dir)); print_to_log_file( "current directory = %s", current_dir); for (int i=0; ipw_name, sizeof(user_name)); grp = getgrgid(getgid()); if (grp) strlcpy(group_name, grp->gr_gid, sizeof(group_name)); #endif // We are running setuid root, so setgid() sets real group ID, // effective group ID and saved set_group-ID for this process grp = getgrnam(group_name); if (grp) setgid(grp->gr_gid); // We are running setuid root, so setuid() sets real user ID, // effective user ID and saved set_user-ID for this process pw = getpwnam(user_name); if (pw) setuid(pw->pw_uid); if (argc < 2) return EINVAL; if (strcmp(argv[1], "-launch_gfx") == 0) { strlcpy(gfx_app_path, BOINCDatSlotsPath, sizeof(gfx_app_path)); strlcat(gfx_app_path, argv[2], sizeof(gfx_app_path)); strlcat(gfx_app_path, "/", sizeof(gfx_app_path)); strlcat(gfx_app_path, GRAPHICS_APP_FILENAME, sizeof(gfx_app_path)); retval = boinc_resolve_filename(gfx_app_path, resolved_path, sizeof(resolved_path)); if (retval) return retval; argv[2] = resolved_path; #if 0 // For debugging only for (int i=2; i