2 * Copyright (c) 1982, 1986, 1989, 1990, 1991, 1993
3 * The Regents of the University of California. All rights reserved.
4 * (c) UNIX System Laboratories, Inc.
5 * All or some portions of this file are derived from material licensed
6 * to the University of California by American Telephone and Telegraph
7 * Co. or Unix System Laboratories, Inc. and are reproduced herein with
8 * the permission of UNIX System Laboratories, Inc.
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 3. All advertising materials mentioning features or use of this software
19 * must display the following acknowledgement:
20 * This product includes software developed by the University of
21 * California, Berkeley and its contributors.
22 * 4. Neither the name of the University nor the names of its contributors
23 * may be used to endorse or promote products derived from this software
24 * without specific prior written permission.
26 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
27 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
29 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
30 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
31 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
32 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
33 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
35 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
38 * @(#)kern_prot.c 8.6 (Berkeley) 1/21/94
39 * $FreeBSD: src/sys/kern/kern_prot.c,v 1.53.2.9 2002/03/09 05:20:26 dd Exp $
40 * $DragonFly: src/sys/kern/kern_prot.c,v 1.2 2003/06/17 04:28:41 dillon Exp $
44 * System calls related to processes and protection
47 #include "opt_compat.h"
49 #include <sys/param.h>
51 #include <sys/systm.h>
52 #include <sys/sysproto.h>
53 #include <sys/kernel.h>
55 #include <sys/malloc.h>
56 #include <sys/pioctl.h>
57 #include <sys/resourcevar.h>
59 static MALLOC_DEFINE(M_CRED, "cred", "credentials");
61 #ifndef _SYS_SYSPROTO_H_
68 * NOT MP SAFE due to p_pptr access
74 struct getpid_args *uap;
77 p->p_retval[0] = p->p_pid;
78 #if defined(COMPAT_43) || defined(COMPAT_SUNOS)
79 p->p_retval[1] = p->p_pptr->p_pid;
84 #ifndef _SYS_SYSPROTO_H_
93 struct getppid_args *uap;
96 p->p_retval[0] = p->p_pptr->p_pid;
101 * Get process group ID; note that POSIX getpgrp takes no parameter
105 #ifndef _SYS_SYSPROTO_H_
106 struct getpgrp_args {
114 struct getpgrp_args *uap;
117 p->p_retval[0] = p->p_pgrp->pg_id;
121 /* Get an arbitary pid's process group id */
122 #ifndef _SYS_SYSPROTO_H_
123 struct getpgid_args {
131 struct getpgid_args *uap;
139 if ((pt = pfind(uap->pid)) == 0)
142 p->p_retval[0] = pt->p_pgrp->pg_id;
147 * Get an arbitary pid's session id.
149 #ifndef _SYS_SYSPROTO_H_
158 struct getsid_args *uap;
166 if ((pt = pfind(uap->pid)) == 0)
169 p->p_retval[0] = pt->p_session->s_sid;
177 #ifndef _SYS_SYSPROTO_H_
187 struct getuid_args *uap;
190 p->p_retval[0] = p->p_cred->p_ruid;
191 #if defined(COMPAT_43) || defined(COMPAT_SUNOS)
192 p->p_retval[1] = p->p_ucred->cr_uid;
198 * geteuid() - MP SAFE
200 #ifndef _SYS_SYSPROTO_H_
201 struct geteuid_args {
210 struct geteuid_args *uap;
213 p->p_retval[0] = p->p_ucred->cr_uid;
220 #ifndef _SYS_SYSPROTO_H_
230 struct getgid_args *uap;
233 p->p_retval[0] = p->p_cred->p_rgid;
234 #if defined(COMPAT_43) || defined(COMPAT_SUNOS)
235 p->p_retval[1] = p->p_ucred->cr_groups[0];
241 * Get effective group ID. The "egid" is groups[0], and could be obtained
242 * via getgroups. This syscall exists because it is somewhat painful to do
243 * correctly in a library function.
245 #ifndef _SYS_SYSPROTO_H_
246 struct getegid_args {
255 struct getegid_args *uap;
258 p->p_retval[0] = p->p_ucred->cr_groups[0];
262 #ifndef _SYS_SYSPROTO_H_
263 struct getgroups_args {
271 register struct getgroups_args *uap;
273 register struct pcred *pc = p->p_cred;
277 if ((ngrp = uap->gidsetsize) == 0) {
278 p->p_retval[0] = pc->pc_ucred->cr_ngroups;
281 if (ngrp < pc->pc_ucred->cr_ngroups)
283 ngrp = pc->pc_ucred->cr_ngroups;
284 if ((error = copyout((caddr_t)pc->pc_ucred->cr_groups,
285 (caddr_t)uap->gidset, ngrp * sizeof(gid_t))))
287 p->p_retval[0] = ngrp;
291 #ifndef _SYS_SYSPROTO_H_
300 register struct proc *p;
301 struct setsid_args *uap;
304 if (p->p_pgid == p->p_pid || pgfind(p->p_pid)) {
307 (void)enterpgrp(p, p->p_pid, 1);
308 p->p_retval[0] = p->p_pid;
314 * set process group (setpgid/old setpgrp)
316 * caller does setpgid(targpid, targpgid)
318 * pid must be caller or child of caller (ESRCH)
320 * pid must be in same session (EPERM)
321 * pid can't have done an exec (EACCES)
323 * there must exist some pid in same session having pgid (EPERM)
324 * pid must not be session leader (EPERM)
326 #ifndef _SYS_SYSPROTO_H_
327 struct setpgid_args {
328 int pid; /* target process id */
329 int pgid; /* target pgrp id */
336 register struct setpgid_args *uap;
338 register struct proc *targp; /* target process */
339 register struct pgrp *pgrp; /* target pgrp */
343 if (uap->pid != 0 && uap->pid != curp->p_pid) {
344 if ((targp = pfind(uap->pid)) == 0 || !inferior(targp))
346 if (targp->p_pgrp == NULL || targp->p_session != curp->p_session)
348 if (targp->p_flag & P_EXEC)
352 if (SESS_LEADER(targp))
355 uap->pgid = targp->p_pid;
356 else if (uap->pgid != targp->p_pid)
357 if ((pgrp = pgfind(uap->pgid)) == 0 ||
358 pgrp->pg_session != curp->p_session)
360 return (enterpgrp(targp, uap->pgid, 0));
364 * Use the clause in B.4.2.2 that allows setuid/setgid to be 4.2/4.3BSD
365 * compatable. It says that setting the uid/gid to euid/egid is a special
366 * case of "appropriate privilege". Once the rules are expanded out, this
367 * basically means that setuid(nnn) sets all three id's, in all permitted
368 * cases unless _POSIX_SAVED_IDS is enabled. In that case, setuid(getuid())
369 * does not set the saved id - this is dangerous for traditional BSD
370 * programs. For this reason, we *really* do not want to set
371 * _POSIX_SAVED_IDS and do not want to clear POSIX_APPENDIX_B_4_2_2.
373 #define POSIX_APPENDIX_B_4_2_2
375 #ifndef _SYS_SYSPROTO_H_
384 struct setuid_args *uap;
386 register struct pcred *pc = p->p_cred;
391 * See if we have "permission" by POSIX 1003.1 rules.
393 * Note that setuid(geteuid()) is a special case of
394 * "appropriate privileges" in appendix B.4.2.2. We need
395 * to use this clause to be compatable with traditional BSD
396 * semantics. Basically, it means that "setuid(xx)" sets all
397 * three id's (assuming you have privs).
399 * Notes on the logic. We do things in three steps.
400 * 1: We determine if the euid is going to change, and do EPERM
401 * right away. We unconditionally change the euid later if this
402 * test is satisfied, simplifying that part of the logic.
403 * 2: We determine if the real and/or saved uid's are going to
404 * change. Determined by compile options.
405 * 3: Change euid last. (after tests in #2 for "appropriate privs")
408 if (uid != pc->p_ruid && /* allow setuid(getuid()) */
409 #ifdef _POSIX_SAVED_IDS
410 uid != pc->p_svuid && /* allow setuid(saved gid) */
412 #ifdef POSIX_APPENDIX_B_4_2_2 /* Use BSD-compat clause from B.4.2.2 */
413 uid != pc->pc_ucred->cr_uid && /* allow setuid(geteuid()) */
415 (error = suser_xxx(0, p, PRISON_ROOT)))
418 #ifdef _POSIX_SAVED_IDS
420 * Do we have "appropriate privileges" (are we root or uid == euid)
421 * If so, we are changing the real uid and/or saved uid.
424 #ifdef POSIX_APPENDIX_B_4_2_2 /* Use the clause from B.4.2.2 */
425 uid == pc->pc_ucred->cr_uid ||
427 suser_xxx(0, p, PRISON_ROOT) == 0) /* we are using privs */
431 * Set the real uid and transfer proc count to new user.
433 if (uid != pc->p_ruid) {
440 * XXX always set saved uid even if not _POSIX_SAVED_IDS, as
441 * the security of seteuid() depends on it. B.4.2.2 says it
442 * is important that we should do this.
444 if (pc->p_svuid != uid) {
451 * In all permitted cases, we are changing the euid.
452 * Copy credentials so other references do not see our changes.
454 if (pc->pc_ucred->cr_uid != uid) {
461 #ifndef _SYS_SYSPROTO_H_
462 struct seteuid_args {
470 struct seteuid_args *uap;
472 register struct pcred *pc = p->p_cred;
477 if (euid != pc->p_ruid && /* allow seteuid(getuid()) */
478 euid != pc->p_svuid && /* allow seteuid(saved uid) */
479 (error = suser_xxx(0, p, PRISON_ROOT)))
482 * Everything's okay, do it. Copy credentials so other references do
483 * not see our changes.
485 if (pc->pc_ucred->cr_uid != euid) {
486 change_euid(p, euid);
492 #ifndef _SYS_SYSPROTO_H_
501 struct setgid_args *uap;
503 register struct pcred *pc = p->p_cred;
508 * See if we have "permission" by POSIX 1003.1 rules.
510 * Note that setgid(getegid()) is a special case of
511 * "appropriate privileges" in appendix B.4.2.2. We need
512 * to use this clause to be compatable with traditional BSD
513 * semantics. Basically, it means that "setgid(xx)" sets all
514 * three id's (assuming you have privs).
516 * For notes on the logic here, see setuid() above.
519 if (gid != pc->p_rgid && /* allow setgid(getgid()) */
520 #ifdef _POSIX_SAVED_IDS
521 gid != pc->p_svgid && /* allow setgid(saved gid) */
523 #ifdef POSIX_APPENDIX_B_4_2_2 /* Use BSD-compat clause from B.4.2.2 */
524 gid != pc->pc_ucred->cr_groups[0] && /* allow setgid(getegid()) */
526 (error = suser_xxx(0, p, PRISON_ROOT)))
529 #ifdef _POSIX_SAVED_IDS
531 * Do we have "appropriate privileges" (are we root or gid == egid)
532 * If so, we are changing the real uid and saved gid.
535 #ifdef POSIX_APPENDIX_B_4_2_2 /* use the clause from B.4.2.2 */
536 gid == pc->pc_ucred->cr_groups[0] ||
538 suser_xxx(0, p, PRISON_ROOT) == 0) /* we are using privs */
544 if (pc->p_rgid != gid) {
551 * XXX always set saved gid even if not _POSIX_SAVED_IDS, as
552 * the security of setegid() depends on it. B.4.2.2 says it
553 * is important that we should do this.
555 if (pc->p_svgid != gid) {
561 * In all cases permitted cases, we are changing the egid.
562 * Copy credentials so other references do not see our changes.
564 if (pc->pc_ucred->cr_groups[0] != gid) {
565 pc->pc_ucred = crcopy(pc->pc_ucred);
566 pc->pc_ucred->cr_groups[0] = gid;
572 #ifndef _SYS_SYSPROTO_H_
573 struct setegid_args {
581 struct setegid_args *uap;
583 register struct pcred *pc = p->p_cred;
588 if (egid != pc->p_rgid && /* allow setegid(getgid()) */
589 egid != pc->p_svgid && /* allow setegid(saved gid) */
590 (error = suser_xxx(0, p, PRISON_ROOT)))
592 if (pc->pc_ucred->cr_groups[0] != egid) {
593 pc->pc_ucred = crcopy(pc->pc_ucred);
594 pc->pc_ucred->cr_groups[0] = egid;
600 #ifndef _SYS_SYSPROTO_H_
601 struct setgroups_args {
610 struct setgroups_args *uap;
612 register struct pcred *pc = p->p_cred;
616 if ((error = suser_xxx(0, p, PRISON_ROOT)))
618 ngrp = uap->gidsetsize;
622 * XXX A little bit lazy here. We could test if anything has
623 * changed before crcopy() and setting P_SUGID.
625 pc->pc_ucred = crcopy(pc->pc_ucred);
628 * setgroups(0, NULL) is a legitimate way of clearing the
629 * groups vector on non-BSD systems (which generally do not
630 * have the egid in the groups[0]). We risk security holes
631 * when running non-BSD software if we do not do the same.
633 pc->pc_ucred->cr_ngroups = 1;
635 if ((error = copyin((caddr_t)uap->gidset,
636 (caddr_t)pc->pc_ucred->cr_groups, ngrp * sizeof(gid_t))))
638 pc->pc_ucred->cr_ngroups = ngrp;
644 #ifndef _SYS_SYSPROTO_H_
645 struct setreuid_args {
653 register struct proc *p;
654 struct setreuid_args *uap;
656 register struct pcred *pc = p->p_cred;
657 register uid_t ruid, euid;
662 if (((ruid != (uid_t)-1 && ruid != pc->p_ruid && ruid != pc->p_svuid) ||
663 (euid != (uid_t)-1 && euid != pc->pc_ucred->cr_uid &&
664 euid != pc->p_ruid && euid != pc->p_svuid)) &&
665 (error = suser_xxx(0, p, PRISON_ROOT)) != 0)
668 if (euid != (uid_t)-1 && pc->pc_ucred->cr_uid != euid) {
669 change_euid(p, euid);
672 if (ruid != (uid_t)-1 && pc->p_ruid != ruid) {
673 change_ruid(p, ruid);
676 if ((ruid != (uid_t)-1 || pc->pc_ucred->cr_uid != pc->p_ruid) &&
677 pc->p_svuid != pc->pc_ucred->cr_uid) {
678 pc->p_svuid = pc->pc_ucred->cr_uid;
684 #ifndef _SYS_SYSPROTO_H_
685 struct setregid_args {
693 register struct proc *p;
694 struct setregid_args *uap;
696 register struct pcred *pc = p->p_cred;
697 register gid_t rgid, egid;
702 if (((rgid != (gid_t)-1 && rgid != pc->p_rgid && rgid != pc->p_svgid) ||
703 (egid != (gid_t)-1 && egid != pc->pc_ucred->cr_groups[0] &&
704 egid != pc->p_rgid && egid != pc->p_svgid)) &&
705 (error = suser_xxx(0, p, PRISON_ROOT)) != 0)
708 if (egid != (gid_t)-1 && pc->pc_ucred->cr_groups[0] != egid) {
709 pc->pc_ucred = crcopy(pc->pc_ucred);
710 pc->pc_ucred->cr_groups[0] = egid;
713 if (rgid != (gid_t)-1 && pc->p_rgid != rgid) {
717 if ((rgid != (gid_t)-1 || pc->pc_ucred->cr_groups[0] != pc->p_rgid) &&
718 pc->p_svgid != pc->pc_ucred->cr_groups[0]) {
719 pc->p_svgid = pc->pc_ucred->cr_groups[0];
726 * setresuid(ruid, euid, suid) is like setreuid except control over the
727 * saved uid is explicit.
730 #ifndef _SYS_SYSPROTO_H_
731 struct setresuid_args {
740 register struct proc *p;
741 struct setresuid_args *uap;
743 register struct pcred *pc = p->p_cred;
744 register uid_t ruid, euid, suid;
750 if (((ruid != (uid_t)-1 && ruid != pc->p_ruid && ruid != pc->p_svuid &&
751 ruid != pc->pc_ucred->cr_uid) ||
752 (euid != (uid_t)-1 && euid != pc->p_ruid && euid != pc->p_svuid &&
753 euid != pc->pc_ucred->cr_uid) ||
754 (suid != (uid_t)-1 && suid != pc->p_ruid && suid != pc->p_svuid &&
755 suid != pc->pc_ucred->cr_uid)) &&
756 (error = suser_xxx(0, p, PRISON_ROOT)) != 0)
758 if (euid != (uid_t)-1 && pc->pc_ucred->cr_uid != euid) {
759 change_euid(p, euid);
762 if (ruid != (uid_t)-1 && pc->p_ruid != ruid) {
763 change_ruid(p, ruid);
766 if (suid != (uid_t)-1 && pc->p_svuid != suid) {
774 * setresgid(rgid, egid, sgid) is like setregid except control over the
775 * saved gid is explicit.
778 #ifndef _SYS_SYSPROTO_H_
779 struct setresgid_args {
788 register struct proc *p;
789 struct setresgid_args *uap;
791 register struct pcred *pc = p->p_cred;
792 register gid_t rgid, egid, sgid;
798 if (((rgid != (gid_t)-1 && rgid != pc->p_rgid && rgid != pc->p_svgid &&
799 rgid != pc->pc_ucred->cr_groups[0]) ||
800 (egid != (gid_t)-1 && egid != pc->p_rgid && egid != pc->p_svgid &&
801 egid != pc->pc_ucred->cr_groups[0]) ||
802 (sgid != (gid_t)-1 && sgid != pc->p_rgid && sgid != pc->p_svgid &&
803 sgid != pc->pc_ucred->cr_groups[0])) &&
804 (error = suser_xxx(0, p, PRISON_ROOT)) != 0)
807 if (egid != (gid_t)-1 && pc->pc_ucred->cr_groups[0] != egid) {
808 pc->pc_ucred = crcopy(pc->pc_ucred);
809 pc->pc_ucred->cr_groups[0] = egid;
812 if (rgid != (gid_t)-1 && pc->p_rgid != rgid) {
816 if (sgid != (gid_t)-1 && pc->p_svgid != sgid) {
823 #ifndef _SYS_SYSPROTO_H_
824 struct getresuid_args {
833 register struct proc *p;
834 struct getresuid_args *uap;
836 struct pcred *pc = p->p_cred;
837 int error1 = 0, error2 = 0, error3 = 0;
840 error1 = copyout((caddr_t)&pc->p_ruid,
841 (caddr_t)uap->ruid, sizeof(pc->p_ruid));
843 error2 = copyout((caddr_t)&pc->pc_ucred->cr_uid,
844 (caddr_t)uap->euid, sizeof(pc->pc_ucred->cr_uid));
846 error3 = copyout((caddr_t)&pc->p_svuid,
847 (caddr_t)uap->suid, sizeof(pc->p_svuid));
848 return error1 ? error1 : (error2 ? error2 : error3);
851 #ifndef _SYS_SYSPROTO_H_
852 struct getresgid_args {
861 register struct proc *p;
862 struct getresgid_args *uap;
864 struct pcred *pc = p->p_cred;
865 int error1 = 0, error2 = 0, error3 = 0;
868 error1 = copyout((caddr_t)&pc->p_rgid,
869 (caddr_t)uap->rgid, sizeof(pc->p_rgid));
871 error2 = copyout((caddr_t)&pc->pc_ucred->cr_groups[0],
872 (caddr_t)uap->egid, sizeof(pc->pc_ucred->cr_groups[0]));
874 error3 = copyout((caddr_t)&pc->p_svgid,
875 (caddr_t)uap->sgid, sizeof(pc->p_svgid));
876 return error1 ? error1 : (error2 ? error2 : error3);
880 #ifndef _SYS_SYSPROTO_H_
881 struct issetugid_args {
888 register struct proc *p;
889 struct issetugid_args *uap;
892 * Note: OpenBSD sets a P_SUGIDEXEC flag set at execve() time,
893 * we use P_SUGID because we consider changing the owners as
894 * "tainting" as well.
895 * This is significant for procs that start as root and "become"
896 * a user without an exec - programs cannot know *everything*
897 * that libc *might* have put in their data segment.
899 p->p_retval[0] = (p->p_flag & P_SUGID) ? 1 : 0;
904 * Check if gid is a member of the group set.
907 groupmember(gid, cred)
909 register struct ucred *cred;
914 egp = &(cred->cr_groups[cred->cr_ngroups]);
915 for (gp = cred->cr_groups; gp < egp; gp++)
922 * Test whether the specified credentials imply "super-user"
923 * privilege; if so, and we have accounting info, set the flag
924 * indicating use of super-powers.
925 * Returns 0 or error.
931 return suser_xxx(0, p, 0);
935 suser_xxx(cred, proc, flag)
940 if (!cred && !proc) {
941 printf("suser_xxx(): THINK!\n");
945 cred = proc->p_ucred;
946 if (cred->cr_uid != 0)
948 if (proc && proc->p_prison && !(flag & PRISON_ROOT))
951 proc->p_acflag |= ASU;
956 * Return zero if p1 can fondle p2, return errno (EPERM/ESRCH) otherwise.
960 p_trespass(struct proc *p1, struct proc *p2)
965 if (!PRISON_CHECK(p1, p2))
967 if (p1->p_cred->p_ruid == p2->p_cred->p_ruid)
969 if (p1->p_ucred->cr_uid == p2->p_cred->p_ruid)
971 if (p1->p_cred->p_ruid == p2->p_ucred->cr_uid)
973 if (p1->p_ucred->cr_uid == p2->p_ucred->cr_uid)
975 if (!suser_xxx(0, p1, PRISON_ROOT))
981 * Allocate a zeroed cred structure.
986 register struct ucred *cr;
988 MALLOC(cr, struct ucred *, sizeof(*cr), M_CRED, M_WAITOK);
989 bzero((caddr_t)cr, sizeof(*cr));
995 * Claim another reference to a ucred structure
1005 * Free a cred structure.
1006 * Throws away space when ref count gets to 0.
1012 if (cr->cr_ref == 0)
1013 panic("Freeing already free credential! %p", cr);
1015 if (--cr->cr_ref == 0) {
1017 * Some callers of crget(), such as nfs_statfs(),
1018 * allocate a temporary credential, but don't
1019 * allocate a uidinfo structure.
1021 if (cr->cr_uidinfo != NULL)
1022 uifree(cr->cr_uidinfo);
1023 FREE((caddr_t)cr, M_CRED);
1028 * Copy cred structure to a new one and free the old one.
1034 struct ucred *newcr;
1036 if (cr->cr_ref == 1)
1040 uihold(newcr->cr_uidinfo);
1047 * Dup cred struct to a new held one.
1053 struct ucred *newcr;
1057 uihold(newcr->cr_uidinfo);
1063 * Fill in a struct xucred based on a struct ucred.
1071 bzero(xcr, sizeof(*xcr));
1072 xcr->cr_version = XUCRED_VERSION;
1073 xcr->cr_uid = cr->cr_uid;
1074 xcr->cr_ngroups = cr->cr_ngroups;
1075 bcopy(cr->cr_groups, xcr->cr_groups, sizeof(cr->cr_groups));
1079 * Get login name, if available.
1081 #ifndef _SYS_SYSPROTO_H_
1082 struct getlogin_args {
1091 struct getlogin_args *uap;
1094 if (uap->namelen > MAXLOGNAME)
1095 uap->namelen = MAXLOGNAME;
1096 return (copyout((caddr_t) p->p_pgrp->pg_session->s_login,
1097 (caddr_t) uap->namebuf, uap->namelen));
1103 #ifndef _SYS_SYSPROTO_H_
1104 struct setlogin_args {
1112 struct setlogin_args *uap;
1115 char logintmp[MAXLOGNAME];
1117 if ((error = suser_xxx(0, p, PRISON_ROOT)))
1119 error = copyinstr((caddr_t) uap->namebuf, (caddr_t) logintmp,
1120 sizeof(logintmp), (size_t *)0);
1121 if (error == ENAMETOOLONG)
1124 (void) memcpy(p->p_pgrp->pg_session->s_login, logintmp,
1133 p->p_flag |= P_SUGID;
1134 if (!(p->p_pfsflags & PF_ISUGID))
1139 * Helper function to change the effective uid of a process
1142 change_euid(p, euid)
1147 struct uidinfo *uip;
1151 * crcopy is essentially a NOP if ucred has a reference count
1152 * of 1, which is true if it has already been copied.
1154 pc->pc_ucred = crcopy(pc->pc_ucred);
1155 uip = pc->pc_ucred->cr_uidinfo;
1156 pc->pc_ucred->cr_uid = euid;
1157 pc->pc_ucred->cr_uidinfo = uifind(euid);
1162 * Helper function to change the real uid of a process
1164 * The per-uid process count for this process is transfered from
1165 * the old uid to the new uid.
1168 change_ruid(p, ruid)
1173 struct uidinfo *uip;
1176 (void)chgproccnt(pc->p_uidinfo, -1, 0);
1177 uip = pc->p_uidinfo;
1178 /* It is assumed that pcred is not shared between processes */
1180 pc->p_uidinfo = uifind(ruid);
1181 (void)chgproccnt(pc->p_uidinfo, 1, 0);