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
.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 (vir_bytes
) m_in
.PM_GROUPS_PTR
,
44 ngroups
* sizeof(gid_t
));
53 rmp
->mp_reply
.PM_GETUID_EUID
= rmp
->mp_effuid
;
58 rmp
->mp_reply
.PM_GETGID_EGID
= rmp
->mp_effgid
;
62 r
= mproc
[who_p
].mp_pid
;
63 rmp
->mp_reply
.PM_GETPID_PARENT
= mproc
[rmp
->mp_parent
].mp_pid
;
73 pid_t p
= m_in
.PM_GETSID_PID
;
74 target
= p
? find_proc(p
) : &mproc
[who_p
];
77 r
= target
->mp_procgrp
;
81 r
= !!(rmp
->mp_flags
& TAINTED
);
91 /*===========================================================================*
93 *===========================================================================*/
96 /* Handle PM_SETUID, PM_SETEUID, PM_SETGID, PM_SETGROUPS, PM_SETEGID, and
97 * SETSID. These calls have in common that, if successful, they will be
98 * forwarded to VFS as well.
100 register struct mproc
*rmp
= mp
;
107 memset(&m
, 0, sizeof(m
));
112 uid
= (uid_t
) m_in
.PM_SETUID_UID
;
113 if (rmp
->mp_realuid
!= uid
&& rmp
->mp_effuid
!= SUPER_USER
)
115 if(call_nr
== PM_SETUID
) rmp
->mp_realuid
= uid
;
116 rmp
->mp_effuid
= uid
;
118 m
.m_type
= VFS_PM_SETUID
;
119 m
.VFS_PM_ENDPT
= rmp
->mp_endpoint
;
120 m
.VFS_PM_EID
= rmp
->mp_effuid
;
121 m
.VFS_PM_RID
= rmp
->mp_realuid
;
127 gid
= (gid_t
) m_in
.PM_SETGID_GID
;
128 if (rmp
->mp_realgid
!= gid
&& rmp
->mp_effuid
!= SUPER_USER
)
130 if(call_nr
== PM_SETGID
) rmp
->mp_realgid
= gid
;
131 rmp
->mp_effgid
= gid
;
133 m
.m_type
= VFS_PM_SETGID
;
134 m
.VFS_PM_ENDPT
= rmp
->mp_endpoint
;
135 m
.VFS_PM_EID
= rmp
->mp_effgid
;
136 m
.VFS_PM_RID
= rmp
->mp_realgid
;
140 if (rmp
->mp_effuid
!= SUPER_USER
)
143 ngroups
= m_in
.PM_GROUPS_NUM
;
145 if (ngroups
> NGROUPS_MAX
|| ngroups
< 0)
148 if (ngroups
> 0 && m_in
.PM_GROUPS_PTR
== NULL
)
151 r
= sys_datacopy(who_e
, (vir_bytes
) m_in
.PM_GROUPS_PTR
, SELF
,
152 (vir_bytes
) rmp
->mp_sgroups
,
153 ngroups
* sizeof(gid_t
));
157 for (i
= 0; i
< ngroups
; i
++) {
158 if (rmp
->mp_sgroups
[i
] > GID_MAX
)
161 for (i
= ngroups
; i
< NGROUPS_MAX
; i
++) {
162 rmp
->mp_sgroups
[i
] = 0;
164 rmp
->mp_ngroups
= ngroups
;
166 m
.m_type
= VFS_PM_SETGROUPS
;
167 m
.VFS_PM_ENDPT
= rmp
->mp_endpoint
;
168 m
.VFS_PM_GROUP_NO
= rmp
->mp_ngroups
;
169 m
.VFS_PM_GROUP_ADDR
= (char *) rmp
->mp_sgroups
;
173 if (rmp
->mp_procgrp
== rmp
->mp_pid
) return(EPERM
);
174 rmp
->mp_procgrp
= rmp
->mp_pid
;
176 m
.m_type
= VFS_PM_SETSID
;
177 m
.VFS_PM_ENDPT
= rmp
->mp_endpoint
;
185 /* Send the request to VFS */
188 /* Do not reply until VFS has processed the request */