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>
16 /*===========================================================================*
18 *===========================================================================*/
21 /* Handle GETUID, GETGID, GETGROUPS, GETGROUPS_O, GETPID, GETPGRP, GETSID,
25 register struct mproc
*rmp
= mp
;
28 char sgroups
[NGROUPS_MAX
]; /* XXX: Temp storage for GETGROUPS_O */
32 ngroups
= m_in
.grp_no
;
33 if (ngroups
> NGROUPS_MAX
|| ngroups
< 0)
41 if (ngroups
< rmp
->mp_ngroups
)
42 /* Asking for less groups than available */
45 for (i
= 0; i
< ngroups
; i
++)
46 sgroups
[i
] = (char) rmp
->mp_sgroups
[i
];
48 r
= sys_datacopy(SELF
, (vir_bytes
) &sgroups
, who_e
,
49 (vir_bytes
) m_in
.groupsp
, ngroups
* sizeof(char));
57 ngroups
= m_in
.grp_no
;
58 if (ngroups
> NGROUPS_MAX
|| ngroups
< 0)
66 if (ngroups
< rmp
->mp_ngroups
)
67 /* Asking for less groups than available */
70 r
= sys_datacopy(SELF
, (vir_bytes
) rmp
->mp_sgroups
, who_e
,
71 (vir_bytes
) m_in
.groupsp
, ngroups
* sizeof(gid_t
));
80 rmp
->mp_reply
.reply_res2
= rmp
->mp_effuid
;
85 rmp
->mp_reply
.reply_res2
= rmp
->mp_effgid
;
89 r
= mproc
[who_p
].mp_pid
;
90 rmp
->mp_reply
.reply_res2
= mproc
[rmp
->mp_parent
].mp_pid
;
100 pid_t p
= m_in
.PM_GETSID_PID
;
101 target
= p
? find_proc(p
) : &mproc
[who_p
];
104 r
= target
->mp_procgrp
;
108 r
= !!(rmp
->mp_flags
& TAINTED
);
118 /*===========================================================================*
120 *===========================================================================*/
123 /* Handle SETUID, SETEUID, SETGID, SETEGID, SETSID. These calls have in common
124 * that, if successful, they will be forwarded to VFS as well.
126 register struct mproc
*rmp
= mp
;
130 char sgroups
[NGROUPS_MAX
]; /* XXX: Temp storage for SETGROUPS_O */
136 if (rmp
->mp_realuid
!= (uid_t
) m_in
.usr_id
&&
137 rmp
->mp_effuid
!= SUPER_USER
)
139 if(call_nr
== SETUID
) rmp
->mp_realuid
= (uid_t
) m_in
.usr_id
;
140 rmp
->mp_effuid
= (uid_t
) m_in
.usr_id
;
142 m
.m_type
= PM_SETUID
;
143 m
.PM_PROC
= rmp
->mp_endpoint
;
144 m
.PM_EID
= rmp
->mp_effuid
;
145 m
.PM_RID
= rmp
->mp_realuid
;
151 if (rmp
->mp_realgid
!= (gid_t
) m_in
.grp_id
&&
152 rmp
->mp_effuid
!= SUPER_USER
)
154 if(call_nr
== SETGID
) rmp
->mp_realgid
= (gid_t
) m_in
.grp_id
;
155 rmp
->mp_effgid
= (gid_t
) m_in
.grp_id
;
157 m
.m_type
= PM_SETGID
;
158 m
.PM_PROC
= rmp
->mp_endpoint
;
159 m
.PM_EID
= rmp
->mp_effgid
;
160 m
.PM_RID
= rmp
->mp_realgid
;
164 if (rmp
->mp_effuid
!= SUPER_USER
)
167 ngroups
= m_in
.grp_no
;
169 if (ngroups
> NGROUPS_MAX
|| ngroups
< 0)
172 if (m_in
.groupsp
== NULL
)
175 r
= sys_datacopy(who_e
, (vir_bytes
) m_in
.groupsp
, SELF
,
176 (vir_bytes
) rmp
->mp_sgroups
,
177 ngroups
* sizeof(gid_t
));
181 for (i
= 0; i
< ngroups
; i
++) {
182 if (rmp
->mp_sgroups
[i
] > GID_MAX
)
185 for (i
= ngroups
; i
< NGROUPS_MAX
; i
++) {
186 rmp
->mp_sgroups
[i
] = 0;
188 rmp
->mp_ngroups
= ngroups
;
190 m
.m_type
= PM_SETGROUPS
;
191 m
.PM_PROC
= rmp
->mp_endpoint
;
192 m
.PM_GROUP_NO
= rmp
->mp_ngroups
;
193 m
.PM_GROUP_ADDR
= (char *) rmp
->mp_sgroups
;
197 if (rmp
->mp_effuid
!= SUPER_USER
)
200 ngroups
= m_in
.grp_no
;
202 if (ngroups
> NGROUPS_MAX
|| ngroups
< 0)
205 if (m_in
.groupsp
== NULL
)
208 r
= sys_datacopy(who_e
, (vir_bytes
) m_in
.groupsp
, SELF
,
209 (vir_bytes
) &sgroups
, ngroups
* sizeof(char));
213 for (i
= 0; i
< ngroups
; i
++)
214 rmp
->mp_sgroups
[i
] = (gid_t
) sgroups
[i
];
215 for (i
= ngroups
; i
< NGROUPS_MAX
; i
++)
216 rmp
->mp_sgroups
[i
] = 0;
217 rmp
->mp_ngroups
= ngroups
;
219 m
.m_type
= PM_SETGROUPS
;
220 m
.PM_PROC
= rmp
->mp_endpoint
;
221 m
.PM_GROUP_NO
= rmp
->mp_ngroups
;
222 m
.PM_GROUP_ADDR
= (char *) rmp
->mp_sgroups
;
226 if (rmp
->mp_procgrp
== rmp
->mp_pid
) return(EPERM
);
227 rmp
->mp_procgrp
= rmp
->mp_pid
;
229 m
.m_type
= PM_SETSID
;
230 m
.PM_PROC
= rmp
->mp_endpoint
;
238 /* Send the request to VFS */
241 /* Do not reply until VFS has processed the request */