taskid_t pr_settaskid(struct ps_prochandle *Pr, projid_t project, int flags) { sysret_t rval; argdes_t argd[3]; argdes_t *adp; int error; if (Pr == NULL) /* No subject process */ return (settaskid(project, flags)); adp = &argd[0]; adp->arg_value = 0; /* switch for settaskid in tasksys */ adp->arg_object = NULL; adp->arg_type = AT_BYVAL; adp->arg_inout = AI_INPUT; adp->arg_size = 0; adp++; adp->arg_value = project; adp->arg_object = NULL; adp->arg_type = AT_BYVAL; adp->arg_inout = AI_INPUT; adp->arg_size = sizeof (project); adp++; adp->arg_value = flags; adp->arg_object = NULL; adp->arg_type = AT_BYVAL; adp->arg_inout = AI_INPUT; adp->arg_size = 0; error = Psyscall(Pr, &rval, SYS_tasksys, 3, &argd[0]); if (error) { errno = (error > 0) ? error : ENOSYS; return (-1); } return (rval.sys_rval1); }
static void dtlogin_process(struct dmuser *user, int user_logged_in) { struct project proj; char proj_buf[PROJECT_BUFSZ]; struct passwd *ppasswd; const char *auth_file = NULL; auth_file = GetAuthFilename(); if (auth_file) { if (chown(auth_file, user->uid, user->gid) < 0) DtloginError("Error in changing owner to %d", user->uid); } /* This gid dance is necessary in order to make sure our "saved-set-gid" is 0 so that we can regain gid 0 when necessary for priocntl & power management. The first step sets rgid to the user's gid and makes the egid & saved-gid be 0. The second then sets the egid to the users gid, but leaves the saved-gid as 0. */ if (user->gid != (gid_t) -1) { DtloginInfo("Setting gid to %d\n", user->gid); if (setregid(user->gid, 0) < 0) DtloginError("Error in setting regid to %d\n", user->gid); if (setegid(user->gid) < 0) DtloginError("Error in setting egid to %d\n", user->gid); } if (user->groupid_cnt >= 0) { if (setgroups(user->groupid_cnt, user->groupids) < 0) DtloginError("Error in setting supplemental (%d) groups", user->groupid_cnt); } /* * BUG: 4462531: Set project ID for Xserver * Get user name and default project. * Set before the uid value is set. */ if (user->projid != (uid_t) -1) { if (settaskid(user->projid, TASK_NORMAL) == (taskid_t) -1) { DtloginError("Error in setting project id to %d", user->projid); } } else if (user->uid != (uid_t) -1) { ppasswd = getpwuid(user->uid); if (ppasswd == NULL) { DtloginError("Error in getting user name for %d", user->uid); } else { if (getdefaultproj(ppasswd->pw_name, &proj, (void *)&proj_buf, PROJECT_BUFSZ) == NULL) { DtloginError("Error in getting project id for %s", ppasswd->pw_name); } else { DtloginInfo("Setting project to %s\n", proj.pj_name); if (setproject(proj.pj_name, ppasswd->pw_name, TASK_NORMAL) == -1) { DtloginError("Error in setting project to %s", proj.pj_name); } } } } if (user->uid != (uid_t) -1) { DtloginInfo("Setting uid to %d\n", user->uid); if (setreuid(user->uid, -1) < 0) DtloginError("Error in setting ruid to %d", user->uid); if (setreuid(-1, user->uid) < 0) DtloginError("Error in setting euid to %d", user->uid); /* Wrap closeScreen to allow resetting uid on closedown */ if ((user->uid != 0) && (user != &originalUser)) { int i; if (dixRegisterPrivateKey(dmScreenKey, PRIVATE_SCREEN, 0)) { for (i = 0; i < screenInfo.numScreens; i++) { ScreenPtr pScreen = screenInfo.screens[i]; struct dmScreenPriv *pScreenPriv = calloc(1, sizeof(struct dmScreenPriv)); dixSetPrivate(&pScreen->devPrivates, dmScreenKey, pScreenPriv); if (pScreenPriv != NULL) { pScreenPriv->CloseScreen = pScreen->CloseScreen; pScreen->CloseScreen = DtloginCloseScreen; } else { DtloginError("Failed to allocate %d bytes" " for uid reset info", sizeof(struct dmScreenPriv)); } } } else { DtloginError("Failed to register screen private %s", "for uid reset info"); } } } if (user->homedir != NULL) { char *env_str = Xprintf("HOME=%s", user->homedir); if (env_str == NULL) { DtloginError("Not enough memory to setenv HOME=%s", user->homedir); } else { DtloginInfo("Setting %s\n",env_str); if (putenv(env_str) < 0) DtloginError("Failed to setenv %s", env_str); } if (chdir(user->homedir) < 0) DtloginError("Error in changing working directory to %s", user->homedir); } /* Inform the kernel whether a user has logged in on this VT device */ if (xf86ConsoleFd != -1) ioctl(xf86ConsoleFd, VT_SETDISPLOGIN, user_logged_in); }