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.7 2003/07/26 18:12:44 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>
60 static MALLOC_DEFINE(M_CRED, "cred", "credentials");
63 * NOT MP SAFE due to p_pptr access
67 getpid(struct getpid_args *uap)
69 struct proc *p = curproc;
71 uap->lmsg.u.ms_fds[0] = p->p_pid;
72 #if defined(COMPAT_43) || defined(COMPAT_SUNOS)
73 uap->lmsg.u.ms_fds[1] = p->p_pptr->p_pid;
80 getppid(struct getppid_args *uap)
82 struct proc *p = curproc;
84 uap->lmsg.u.ms_result = p->p_pptr->p_pid;
89 * Get process group ID; note that POSIX getpgrp takes no parameter
94 getpgrp(struct getpgrp_args *uap)
96 struct proc *p = curproc;
98 uap->lmsg.u.ms_result = p->p_pgrp->pg_id;
103 * Get an arbitary pid's process group id
106 getpgid(struct getpgid_args *uap)
108 struct proc *p = curproc;
115 if ((pt = pfind(uap->pid)) == 0)
118 uap->lmsg.u.ms_result = pt->p_pgrp->pg_id;
123 * Get an arbitary pid's session id.
126 getsid(struct getsid_args *uap)
128 struct proc *p = curproc;
135 if ((pt = pfind(uap->pid)) == 0)
138 uap->lmsg.u.ms_result = pt->p_session->s_sid;
148 getuid(struct getuid_args *uap)
150 struct proc *p = curproc;
152 uap->lmsg.u.ms_fds[0] = p->p_ucred->cr_ruid;
153 #if defined(COMPAT_43) || defined(COMPAT_SUNOS)
154 uap->lmsg.u.ms_fds[1] = p->p_ucred->cr_uid;
160 * geteuid() - MP SAFE
164 geteuid(struct geteuid_args *uap)
166 struct proc *p = curproc;
168 uap->lmsg.u.ms_result = p->p_ucred->cr_uid;
177 getgid(struct getgid_args *uap)
179 struct proc *p = curproc;
181 uap->lmsg.u.ms_fds[0] = p->p_ucred->cr_rgid;
182 #if defined(COMPAT_43) || defined(COMPAT_SUNOS)
183 uap->lmsg.u.ms_fds[1] = p->p_ucred->cr_groups[0];
189 * Get effective group ID. The "egid" is groups[0], and could be obtained
190 * via getgroups. This syscall exists because it is somewhat painful to do
191 * correctly in a library function.
195 getegid(struct getegid_args *uap)
197 struct proc *p = curproc;
199 uap->lmsg.u.ms_result = p->p_ucred->cr_groups[0];
204 getgroups(struct getgroups_args *uap)
206 struct proc *p = curproc;
211 if (p == NULL) /* API enforcement */
215 if ((ngrp = uap->gidsetsize) == 0) {
216 uap->lmsg.u.ms_result = cr->cr_ngroups;
219 if (ngrp < cr->cr_ngroups)
221 ngrp = cr->cr_ngroups;
222 if ((error = copyout((caddr_t)cr->cr_groups,
223 (caddr_t)uap->gidset, ngrp * sizeof(gid_t))))
225 uap->lmsg.u.ms_result = ngrp;
231 setsid(struct setsid_args *uap)
233 struct proc *p = curproc;
235 if (p->p_pgid == p->p_pid || pgfind(p->p_pid)) {
238 (void)enterpgrp(p, p->p_pid, 1);
239 uap->lmsg.u.ms_result = p->p_pid;
245 * set process group (setpgid/old setpgrp)
247 * caller does setpgid(targpid, targpgid)
249 * pid must be caller or child of caller (ESRCH)
251 * pid must be in same session (EPERM)
252 * pid can't have done an exec (EACCES)
254 * there must exist some pid in same session having pgid (EPERM)
255 * pid must not be session leader (EPERM)
259 setpgid(struct setpgid_args *uap)
261 struct proc *curp = curproc;
262 struct proc *targp; /* target process */
263 struct pgrp *pgrp; /* target pgrp */
267 if (uap->pid != 0 && uap->pid != curp->p_pid) {
268 if ((targp = pfind(uap->pid)) == 0 || !inferior(targp))
270 if (targp->p_pgrp == NULL || targp->p_session != curp->p_session)
272 if (targp->p_flag & P_EXEC)
276 if (SESS_LEADER(targp))
279 uap->pgid = targp->p_pid;
280 else if (uap->pgid != targp->p_pid)
281 if ((pgrp = pgfind(uap->pgid)) == 0 ||
282 pgrp->pg_session != curp->p_session)
284 return (enterpgrp(targp, uap->pgid, 0));
288 * Use the clause in B.4.2.2 that allows setuid/setgid to be 4.2/4.3BSD
289 * compatable. It says that setting the uid/gid to euid/egid is a special
290 * case of "appropriate privilege". Once the rules are expanded out, this
291 * basically means that setuid(nnn) sets all three id's, in all permitted
292 * cases unless _POSIX_SAVED_IDS is enabled. In that case, setuid(getuid())
293 * does not set the saved id - this is dangerous for traditional BSD
294 * programs. For this reason, we *really* do not want to set
295 * _POSIX_SAVED_IDS and do not want to clear POSIX_APPENDIX_B_4_2_2.
297 #define POSIX_APPENDIX_B_4_2_2
301 setuid(struct setuid_args *uap)
303 struct proc *p = curproc;
308 if (p == NULL) /* API enforcement */
313 * See if we have "permission" by POSIX 1003.1 rules.
315 * Note that setuid(geteuid()) is a special case of
316 * "appropriate privileges" in appendix B.4.2.2. We need
317 * to use this clause to be compatable with traditional BSD
318 * semantics. Basically, it means that "setuid(xx)" sets all
319 * three id's (assuming you have privs).
321 * Notes on the logic. We do things in three steps.
322 * 1: We determine if the euid is going to change, and do EPERM
323 * right away. We unconditionally change the euid later if this
324 * test is satisfied, simplifying that part of the logic.
325 * 2: We determine if the real and/or saved uid's are going to
326 * change. Determined by compile options.
327 * 3: Change euid last. (after tests in #2 for "appropriate privs")
330 if (uid != cr->cr_ruid && /* allow setuid(getuid()) */
331 #ifdef _POSIX_SAVED_IDS
332 uid != crc->cr_svuid && /* allow setuid(saved gid) */
334 #ifdef POSIX_APPENDIX_B_4_2_2 /* Use BSD-compat clause from B.4.2.2 */
335 uid != cr->cr_uid && /* allow setuid(geteuid()) */
337 (error = suser_cred(cr, PRISON_ROOT)))
340 #ifdef _POSIX_SAVED_IDS
342 * Do we have "appropriate privileges" (are we root or uid == euid)
343 * If so, we are changing the real uid and/or saved uid.
346 #ifdef POSIX_APPENDIX_B_4_2_2 /* Use the clause from B.4.2.2 */
349 suser_cred(cr, PRISON_ROOT) == 0) /* we are using privs */
353 * Set the real uid and transfer proc count to new user.
355 if (uid != cr->cr_ruid) {
362 * XXX always set saved uid even if not _POSIX_SAVED_IDS, as
363 * the security of seteuid() depends on it. B.4.2.2 says it
364 * is important that we should do this.
366 if (cr->cr_svuid != uid) {
373 * In all permitted cases, we are changing the euid.
374 * Copy credentials so other references do not see our changes.
376 if (cr->cr_uid != uid) {
385 seteuid(struct seteuid_args *uap)
387 struct proc *p = curproc;
392 if (p == NULL) /* API enforcement */
397 if (euid != cr->cr_ruid && /* allow seteuid(getuid()) */
398 euid != cr->cr_svuid && /* allow seteuid(saved uid) */
399 (error = suser_cred(cr, PRISON_ROOT)))
402 * Everything's okay, do it. Copy credentials so other references do
403 * not see our changes.
405 if (cr->cr_uid != euid) {
414 setgid(struct setgid_args *uap)
416 struct proc *p = curproc;
421 if (p == NULL) /* API enforcement */
426 * See if we have "permission" by POSIX 1003.1 rules.
428 * Note that setgid(getegid()) is a special case of
429 * "appropriate privileges" in appendix B.4.2.2. We need
430 * to use this clause to be compatable with traditional BSD
431 * semantics. Basically, it means that "setgid(xx)" sets all
432 * three id's (assuming you have privs).
434 * For notes on the logic here, see setuid() above.
437 if (gid != cr->cr_rgid && /* allow setgid(getgid()) */
438 #ifdef _POSIX_SAVED_IDS
439 gid != cr->cr_svgid && /* allow setgid(saved gid) */
441 #ifdef POSIX_APPENDIX_B_4_2_2 /* Use BSD-compat clause from B.4.2.2 */
442 gid != cr->cr_groups[0] && /* allow setgid(getegid()) */
444 (error = suser_cred(cr, PRISON_ROOT)))
447 #ifdef _POSIX_SAVED_IDS
449 * Do we have "appropriate privileges" (are we root or gid == egid)
450 * If so, we are changing the real uid and saved gid.
453 #ifdef POSIX_APPENDIX_B_4_2_2 /* use the clause from B.4.2.2 */
454 gid == cr->cr_groups[0] ||
456 suser_cred(cr, PRISON_ROOT) == 0) /* we are using privs */
462 if (cr->cr_rgid != gid) {
469 * XXX always set saved gid even if not _POSIX_SAVED_IDS, as
470 * the security of setegid() depends on it. B.4.2.2 says it
471 * is important that we should do this.
473 if (cr->cr_svgid != gid) {
479 * In all cases permitted cases, we are changing the egid.
480 * Copy credentials so other references do not see our changes.
482 if (cr->cr_groups[0] != gid) {
483 cr = cratom(&p->p_ucred);
484 cr->cr_groups[0] = gid;
492 setegid(struct setegid_args *uap)
494 struct proc *p = curproc;
499 if (p == NULL) /* API enforcement */
504 if (egid != cr->cr_rgid && /* allow setegid(getgid()) */
505 egid != cr->cr_svgid && /* allow setegid(saved gid) */
506 (error = suser_cred(cr, PRISON_ROOT)))
508 if (cr->cr_groups[0] != egid) {
509 cr = cratom(&p->p_ucred);
510 cr->cr_groups[0] = egid;
518 setgroups(struct setgroups_args *uap)
520 struct proc *p = curproc;
525 if (p == NULL) /* API enforcement */
529 if ((error = suser_cred(cr, PRISON_ROOT)))
531 ngrp = uap->gidsetsize;
535 * XXX A little bit lazy here. We could test if anything has
536 * changed before cratom() and setting P_SUGID.
538 cr = cratom(&p->p_ucred);
541 * setgroups(0, NULL) is a legitimate way of clearing the
542 * groups vector on non-BSD systems (which generally do not
543 * have the egid in the groups[0]). We risk security holes
544 * when running non-BSD software if we do not do the same.
548 if ((error = copyin((caddr_t)uap->gidset,
549 (caddr_t)cr->cr_groups, ngrp * sizeof(gid_t))))
551 cr->cr_ngroups = ngrp;
559 setreuid(struct setreuid_args *uap)
561 struct proc *p = curproc;
566 if (p == NULL) /* API enforcement */
572 if (((ruid != (uid_t)-1 && ruid != cr->cr_ruid && ruid != cr->cr_svuid) ||
573 (euid != (uid_t)-1 && euid != cr->cr_uid &&
574 euid != cr->cr_ruid && euid != cr->cr_svuid)) &&
575 (error = suser_cred(cr, PRISON_ROOT)) != 0)
578 if (euid != (uid_t)-1 && cr->cr_uid != euid) {
582 if (ruid != (uid_t)-1 && cr->cr_ruid != ruid) {
586 if ((ruid != (uid_t)-1 || cr->cr_uid != cr->cr_ruid) &&
587 cr->cr_svuid != cr->cr_uid) {
588 cr = cratom(&p->p_ucred);
589 cr->cr_svuid = cr->cr_uid;
597 setregid(struct setregid_args *uap)
599 struct proc *p = curproc;
604 if (p == NULL) /* API enforcement */
610 if (((rgid != (gid_t)-1 && rgid != cr->cr_rgid && rgid != cr->cr_svgid) ||
611 (egid != (gid_t)-1 && egid != cr->cr_groups[0] &&
612 egid != cr->cr_rgid && egid != cr->cr_svgid)) &&
613 (error = suser_cred(cr, PRISON_ROOT)) != 0)
616 if (egid != (gid_t)-1 && cr->cr_groups[0] != egid) {
617 cr = cratom(&p->p_ucred);
618 cr->cr_groups[0] = egid;
621 if (rgid != (gid_t)-1 && cr->cr_rgid != rgid) {
622 cr = cratom(&p->p_ucred);
626 if ((rgid != (gid_t)-1 || cr->cr_groups[0] != cr->cr_rgid) &&
627 cr->cr_svgid != cr->cr_groups[0]) {
628 cr = cratom(&p->p_ucred);
629 cr->cr_svgid = cr->cr_groups[0];
636 * setresuid(ruid, euid, suid) is like setreuid except control over the
637 * saved uid is explicit.
642 setresuid(struct setresuid_args *uap)
644 struct proc *p = curproc;
646 uid_t ruid, euid, suid;
653 if (((ruid != (uid_t)-1 && ruid != cr->cr_ruid && ruid != cr->cr_svuid &&
654 ruid != cr->cr_uid) ||
655 (euid != (uid_t)-1 && euid != cr->cr_ruid && euid != cr->cr_svuid &&
656 euid != cr->cr_uid) ||
657 (suid != (uid_t)-1 && suid != cr->cr_ruid && suid != cr->cr_svuid &&
658 suid != cr->cr_uid)) &&
659 (error = suser_cred(cr, PRISON_ROOT)) != 0)
661 if (euid != (uid_t)-1 && cr->cr_uid != euid) {
665 if (ruid != (uid_t)-1 && cr->cr_ruid != ruid) {
669 if (suid != (uid_t)-1 && cr->cr_svuid != suid) {
670 cr = cratom(&p->p_ucred);
678 * setresgid(rgid, egid, sgid) is like setregid except control over the
679 * saved gid is explicit.
684 setresgid(struct setresgid_args *uap)
686 struct proc *p = curproc;
688 gid_t rgid, egid, sgid;
695 if (((rgid != (gid_t)-1 && rgid != cr->cr_rgid && rgid != cr->cr_svgid &&
696 rgid != cr->cr_groups[0]) ||
697 (egid != (gid_t)-1 && egid != cr->cr_rgid && egid != cr->cr_svgid &&
698 egid != cr->cr_groups[0]) ||
699 (sgid != (gid_t)-1 && sgid != cr->cr_rgid && sgid != cr->cr_svgid &&
700 sgid != cr->cr_groups[0])) &&
701 (error = suser_cred(cr, PRISON_ROOT)) != 0)
704 if (egid != (gid_t)-1 && cr->cr_groups[0] != egid) {
705 cr = cratom(&p->p_ucred);
706 cr->cr_groups[0] = egid;
709 if (rgid != (gid_t)-1 && cr->cr_rgid != rgid) {
710 cr = cratom(&p->p_ucred);
714 if (sgid != (gid_t)-1 && cr->cr_svgid != sgid) {
715 cr = cratom(&p->p_ucred);
724 getresuid(struct getresuid_args *uap)
726 struct proc *p = curproc;
727 struct ucred *cr = p->p_ucred;
728 int error1 = 0, error2 = 0, error3 = 0;
731 error1 = copyout((caddr_t)&cr->cr_ruid,
732 (caddr_t)uap->ruid, sizeof(cr->cr_ruid));
734 error2 = copyout((caddr_t)&cr->cr_uid,
735 (caddr_t)uap->euid, sizeof(cr->cr_uid));
737 error3 = copyout((caddr_t)&cr->cr_svuid,
738 (caddr_t)uap->suid, sizeof(cr->cr_svuid));
739 return error1 ? error1 : (error2 ? error2 : error3);
744 getresgid(struct getresgid_args *uap)
746 struct proc *p = curproc;
747 struct ucred *cr = p->p_ucred;
748 int error1 = 0, error2 = 0, error3 = 0;
751 error1 = copyout((caddr_t)&cr->cr_rgid,
752 (caddr_t)uap->rgid, sizeof(cr->cr_rgid));
754 error2 = copyout((caddr_t)&cr->cr_groups[0],
755 (caddr_t)uap->egid, sizeof(cr->cr_groups[0]));
757 error3 = copyout((caddr_t)&cr->cr_svgid,
758 (caddr_t)uap->sgid, sizeof(cr->cr_svgid));
759 return error1 ? error1 : (error2 ? error2 : error3);
765 issetugid(struct issetugid_args *uap)
767 struct proc *p = curproc;
769 * Note: OpenBSD sets a P_SUGIDEXEC flag set at execve() time,
770 * we use P_SUGID because we consider changing the owners as
771 * "tainting" as well.
772 * This is significant for procs that start as root and "become"
773 * a user without an exec - programs cannot know *everything*
774 * that libc *might* have put in their data segment.
776 uap->lmsg.u.ms_result = (p->p_flag & P_SUGID) ? 1 : 0;
781 * Check if gid is a member of the group set.
784 groupmember(gid_t gid, struct ucred *cred)
789 egp = &(cred->cr_groups[cred->cr_ngroups]);
790 for (gp = cred->cr_groups; gp < egp; gp++)
797 * Test whether the specified credentials imply "super-user"
798 * privilege; if so, and we have accounting info, set the flag
799 * indicating use of super-powers. A kernel thread without a process
800 * context is assumed to have super user capabilities. In situations
801 * where the caller always expect a cred to exist, the cred should be
802 * passed separately and suser_cred()should be used instead of suser().
804 * Returns 0 or error.
807 suser(struct thread *td)
809 struct proc *p = td->td_proc;
812 return suser_cred(p->p_ucred, 0);
819 suser_cred(struct ucred *cred, int flag)
821 KASSERT(cred != NULL, ("suser_cred: NULL cred!"));
823 if (cred->cr_uid != 0)
825 if (cred->cr_prison && !(flag & PRISON_ROOT))
827 /* NOTE: accounting for suser access (p_acflag/ASU) removed */
832 * Return zero if p1 can fondle p2, return errno (EPERM/ESRCH) otherwise.
835 p_trespass(struct ucred *cr1, struct ucred *cr2)
839 if (!PRISON_CHECK(cr1, cr2))
841 if (cr1->cr_ruid == cr2->cr_ruid)
843 if (cr1->cr_uid == cr2->cr_ruid)
845 if (cr1->cr_ruid == cr2->cr_uid)
847 if (cr1->cr_uid == cr2->cr_uid)
849 if (suser_cred(cr1, PRISON_ROOT) == 0)
855 * Allocate a zeroed cred structure.
860 register struct ucred *cr;
862 MALLOC(cr, struct ucred *, sizeof(*cr), M_CRED, M_WAITOK);
863 bzero((caddr_t)cr, sizeof(*cr));
869 * Claim another reference to a ucred structure. Can be used with special
873 crhold(struct ucred *cr)
875 if (cr != NOCRED && cr != FSCRED)
881 * Free a cred structure.
882 * Throws away space when ref count gets to 0.
885 crfree(struct ucred *cr)
888 panic("Freeing already free credential! %p", cr);
890 if (--cr->cr_ref == 0) {
892 * Some callers of crget(), such as nfs_statfs(),
893 * allocate a temporary credential, but don't
894 * allocate a uidinfo structure.
896 if (cr->cr_uidinfo != NULL)
897 uifree(cr->cr_uidinfo);
898 if (cr->cr_ruidinfo != NULL)
899 uifree(cr->cr_ruidinfo);
902 * Destroy empty prisons
904 if (cr->cr_prison && !--cr->cr_prison->pr_ref) {
905 if (cr->cr_prison->pr_linux != NULL)
906 FREE(cr->cr_prison->pr_linux, M_PRISON);
907 FREE(cr->cr_prison, M_PRISON);
909 cr->cr_prison = NULL; /* safety */
911 FREE((caddr_t)cr, M_CRED);
916 * Atomize a cred structure so it can be modified without polluting
917 * other references to it.
920 cratom(struct ucred **pcr)
926 if (oldcr->cr_ref == 1)
930 if (newcr->cr_uidinfo)
931 uihold(newcr->cr_uidinfo);
932 if (newcr->cr_ruidinfo)
933 uihold(newcr->cr_ruidinfo);
934 if (newcr->cr_prison)
935 ++newcr->cr_prison->pr_ref;
942 #if 0 /* no longer used but keep around for a little while */
944 * Copy cred structure to a new one and free the old one.
947 crcopy(struct ucred *cr)
955 if (newcr->cr_uidinfo)
956 uihold(newcr->cr_uidinfo);
957 if (newcr->cr_ruidinfo)
958 uihold(newcr->cr_ruidinfo);
959 if (newcr->cr_prison)
960 ++newcr->cr_prison->pr_ref;
968 * Dup cred struct to a new held one.
978 if (newcr->cr_uidinfo)
979 uihold(newcr->cr_uidinfo);
980 if (newcr->cr_ruidinfo)
981 uihold(newcr->cr_ruidinfo);
982 if (newcr->cr_prison)
983 ++newcr->cr_prison->pr_ref;
989 * Fill in a struct xucred based on a struct ucred.
997 bzero(xcr, sizeof(*xcr));
998 xcr->cr_version = XUCRED_VERSION;
999 xcr->cr_uid = cr->cr_uid;
1000 xcr->cr_ngroups = cr->cr_ngroups;
1001 bcopy(cr->cr_groups, xcr->cr_groups, sizeof(cr->cr_groups));
1005 * Get login name, if available.
1009 getlogin(struct getlogin_args *uap)
1011 struct proc *p = curproc;
1013 if (uap->namelen > MAXLOGNAME)
1014 uap->namelen = MAXLOGNAME;
1015 return (copyout((caddr_t) p->p_pgrp->pg_session->s_login,
1016 (caddr_t) uap->namebuf, uap->namelen));
1024 setlogin(struct setlogin_args *uap)
1026 struct proc *p = curproc;
1028 char logintmp[MAXLOGNAME];
1030 KKASSERT(p != NULL);
1031 if ((error = suser_cred(p->p_ucred, PRISON_ROOT)))
1033 error = copyinstr((caddr_t) uap->namebuf, (caddr_t) logintmp,
1034 sizeof(logintmp), (size_t *)0);
1035 if (error == ENAMETOOLONG)
1038 (void) memcpy(p->p_pgrp->pg_session->s_login, logintmp,
1046 struct proc *p = curproc;
1048 KKASSERT(p != NULL);
1049 p->p_flag |= P_SUGID;
1050 if (!(p->p_pfsflags & PF_ISUGID))
1055 * Helper function to change the effective uid of a process
1058 change_euid(uid_t euid)
1060 struct proc *p = curproc;
1062 struct uidinfo *uip;
1064 KKASSERT(p != NULL);
1066 cr = cratom(&p->p_ucred);
1067 uip = cr->cr_uidinfo;
1069 cr->cr_uidinfo = uifind(euid);
1074 * Helper function to change the real uid of a process
1076 * The per-uid process count for this process is transfered from
1077 * the old uid to the new uid.
1080 change_ruid(uid_t ruid)
1082 struct proc *p = curproc;
1084 struct uidinfo *uip;
1086 KKASSERT(p != NULL);
1088 cr = cratom(&p->p_ucred);
1089 (void)chgproccnt(cr->cr_ruidinfo, -1, 0);
1090 uip = cr->cr_ruidinfo;
1091 /* It is assumed that pcred is not shared between processes */
1093 cr->cr_ruidinfo = uifind(ruid);
1094 (void)chgproccnt(cr->cr_ruidinfo, 1, 0);