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, GETPID, GETPGRP.
24 register struct mproc
*rmp
= mp
;
30 ngroups
= m_in
.grp_no
;
31 if (ngroups
> NGROUPS_MAX
|| ngroups
< 0)
39 if (ngroups
< rmp
->mp_ngroups
)
40 /* Asking for less groups than available */
44 r
= sys_datacopy(SELF
, (vir_bytes
) rmp
->mp_sgroups
, who_e
,
45 (vir_bytes
) m_in
.groupsp
, ngroups
* sizeof(gid_t
));
54 rmp
->mp_reply
.reply_res2
= rmp
->mp_effuid
;
59 rmp
->mp_reply
.reply_res2
= rmp
->mp_effgid
;
63 r
= mproc
[who_p
].mp_pid
;
64 rmp
->mp_reply
.reply_res2
= mproc
[rmp
->mp_parent
].mp_pid
;
78 /*===========================================================================*
80 *===========================================================================*/
83 /* Handle SETUID, SETEUID, SETGID, SETEGID, SETSID. These calls have in common
84 * that, if successful, they will be forwarded to VFS as well.
86 register struct mproc
*rmp
= mp
;
94 if (rmp
->mp_realuid
!= (uid_t
) m_in
.usr_id
&&
95 rmp
->mp_effuid
!= SUPER_USER
)
97 if(call_nr
== SETUID
) rmp
->mp_realuid
= (uid_t
) m_in
.usr_id
;
98 rmp
->mp_effuid
= (uid_t
) m_in
.usr_id
;
100 m
.m_type
= PM_SETUID
;
101 m
.PM_PROC
= rmp
->mp_endpoint
;
102 m
.PM_EID
= rmp
->mp_effuid
;
103 m
.PM_RID
= rmp
->mp_realuid
;
109 if (rmp
->mp_realgid
!= (gid_t
) m_in
.grp_id
&&
110 rmp
->mp_effuid
!= SUPER_USER
)
112 if(call_nr
== SETGID
) rmp
->mp_realgid
= (gid_t
) m_in
.grp_id
;
113 rmp
->mp_effgid
= (gid_t
) m_in
.grp_id
;
115 m
.m_type
= PM_SETGID
;
116 m
.PM_PROC
= rmp
->mp_endpoint
;
117 m
.PM_EID
= rmp
->mp_effgid
;
118 m
.PM_RID
= rmp
->mp_realgid
;
122 if (rmp
->mp_effuid
!= SUPER_USER
)
125 ngroups
= m_in
.grp_no
;
127 if (ngroups
> NGROUPS_MAX
|| ngroups
< 0)
130 if (m_in
.groupsp
== NULL
)
133 r
= sys_datacopy(who_e
, (vir_bytes
) m_in
.groupsp
, SELF
,
134 (vir_bytes
) rmp
->mp_sgroups
,
135 ngroups
* sizeof(gid_t
));
139 for (i
= ngroups
; i
< NGROUPS_MAX
; i
++)
140 rmp
->mp_sgroups
[i
] = 0;
141 rmp
->mp_ngroups
= ngroups
;
143 m
.m_type
= PM_SETGROUPS
;
144 m
.PM_PROC
= rmp
->mp_endpoint
;
145 m
.PM_GROUP_NO
= rmp
->mp_ngroups
;
146 m
.PM_GROUP_ADDR
= rmp
->mp_sgroups
;
150 if (rmp
->mp_procgrp
== rmp
->mp_pid
) return(EPERM
);
151 rmp
->mp_procgrp
= rmp
->mp_pid
;
153 m
.m_type
= PM_SETSID
;
154 m
.PM_PROC
= rmp
->mp_endpoint
;
162 /* Send the request to FS */
165 /* Do not reply until FS has processed the request */