1 /* This file handles the 6 system calls that get and set uids and gids.
2 * It also handles getpid(), setsid(), and getpgrp(). The code for each
3 * one is so tiny that it hardly seemed worthwhile to make each a separate
8 #include <minix/callnr.h>
9 #include <minix/endpoint.h>
11 #include <minix/com.h>
15 /*===========================================================================*
17 *===========================================================================*/
20 /* Handle PM_GETUID, PM_GETGID, PM_GETGROUPS, PM_GETPID, PM_GETPGRP, PM_GETSID,
23 register struct mproc
*rmp
= mp
;
29 ngroups
= m_in
.m_lc_pm_groups
.num
;
30 if (ngroups
> NGROUPS_MAX
|| ngroups
< 0)
38 if (ngroups
< rmp
->mp_ngroups
)
39 /* Asking for less groups than available */
42 r
= sys_datacopy(SELF
, (vir_bytes
) rmp
->mp_sgroups
, who_e
,
43 m_in
.m_lc_pm_groups
.ptr
, ngroups
* sizeof(gid_t
));
52 rmp
->mp_reply
.m_pm_lc_getuid
.euid
= rmp
->mp_effuid
;
57 rmp
->mp_reply
.m_pm_lc_getgid
.egid
= rmp
->mp_effgid
;
61 r
= mproc
[who_p
].mp_pid
;
62 rmp
->mp_reply
.m_pm_lc_getpid
.parent_pid
= mproc
[rmp
->mp_parent
].mp_pid
;
72 pid_t p
= m_in
.m_lc_pm_getsid
.pid
;
73 target
= p
? find_proc(p
) : &mproc
[who_p
];
76 r
= target
->mp_procgrp
;
80 r
= !!(rmp
->mp_flags
& TAINTED
);
90 /*===========================================================================*
92 *===========================================================================*/
95 /* Handle PM_SETUID, PM_SETEUID, PM_SETGID, PM_SETGROUPS, PM_SETEGID, and
96 * SETSID. These calls have in common that, if successful, they will be
97 * forwarded to VFS as well.
99 register struct mproc
*rmp
= mp
;
106 memset(&m
, 0, sizeof(m
));
111 uid
= m_in
.m_lc_pm_setuid
.uid
;
112 if (rmp
->mp_realuid
!= uid
&& rmp
->mp_effuid
!= SUPER_USER
)
114 if(call_nr
== PM_SETUID
) rmp
->mp_realuid
= uid
;
115 rmp
->mp_effuid
= uid
;
117 m
.m_type
= VFS_PM_SETUID
;
118 m
.VFS_PM_ENDPT
= rmp
->mp_endpoint
;
119 m
.VFS_PM_EID
= rmp
->mp_effuid
;
120 m
.VFS_PM_RID
= rmp
->mp_realuid
;
126 gid
= m_in
.m_lc_pm_setgid
.gid
;
127 if (rmp
->mp_realgid
!= gid
&& rmp
->mp_effuid
!= SUPER_USER
)
129 if(call_nr
== PM_SETGID
) rmp
->mp_realgid
= gid
;
130 rmp
->mp_effgid
= gid
;
132 m
.m_type
= VFS_PM_SETGID
;
133 m
.VFS_PM_ENDPT
= rmp
->mp_endpoint
;
134 m
.VFS_PM_EID
= rmp
->mp_effgid
;
135 m
.VFS_PM_RID
= rmp
->mp_realgid
;
139 if (rmp
->mp_effuid
!= SUPER_USER
)
142 ngroups
= m_in
.m_lc_pm_groups
.num
;
144 if (ngroups
> NGROUPS_MAX
|| ngroups
< 0)
147 if (ngroups
> 0 && m_in
.m_lc_pm_groups
.ptr
== 0)
150 r
= sys_datacopy(who_e
, m_in
.m_lc_pm_groups
.ptr
, SELF
,
151 (vir_bytes
) rmp
->mp_sgroups
,
152 ngroups
* sizeof(gid_t
));
156 for (i
= 0; i
< ngroups
; i
++) {
157 if (rmp
->mp_sgroups
[i
] > GID_MAX
)
160 for (i
= ngroups
; i
< NGROUPS_MAX
; i
++) {
161 rmp
->mp_sgroups
[i
] = 0;
163 rmp
->mp_ngroups
= ngroups
;
165 m
.m_type
= VFS_PM_SETGROUPS
;
166 m
.VFS_PM_ENDPT
= rmp
->mp_endpoint
;
167 m
.VFS_PM_GROUP_NO
= rmp
->mp_ngroups
;
168 m
.VFS_PM_GROUP_ADDR
= (char *) rmp
->mp_sgroups
;
172 if (rmp
->mp_procgrp
== rmp
->mp_pid
) return(EPERM
);
173 rmp
->mp_procgrp
= rmp
->mp_pid
;
175 m
.m_type
= VFS_PM_SETSID
;
176 m
.VFS_PM_ENDPT
= rmp
->mp_endpoint
;
184 /* Send the request to VFS */
187 /* Do not reply until VFS has processed the request */