1 /* This file handles the 4 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>
14 /*===========================================================================*
16 *===========================================================================*/
17 PUBLIC
int do_getset()
19 /* Handle GETUID, GETGID, GETPID, GETPGRP, SETUID, SETGID, SETSID. The four
20 * GETs and SETSID return their primary results in 'r'. GETUID, GETGID, and
21 * GETPID also return secondary results (the effective IDs, or the parent
22 * process ID) in 'reply_res2', which is returned to the user.
25 register struct mproc
*rmp
= mp
;
31 rmp
->mp_reply
.reply_res2
= rmp
->mp_effuid
;
36 rmp
->mp_reply
.reply_res2
= rmp
->mp_effgid
;
40 r
= mproc
[who_p
].mp_pid
;
41 rmp
->mp_reply
.reply_res2
= mproc
[rmp
->mp_parent
].mp_pid
;
42 if(pm_isokendpt(m_in
.endpt
, &proc
) == OK
&& proc
>= 0)
43 rmp
->mp_reply
.reply_res3
= mproc
[proc
].mp_pid
;
48 if (rmp
->mp_realuid
!= (uid_t
) m_in
.usr_id
&&
49 rmp
->mp_effuid
!= SUPER_USER
)
51 if(call_nr
== SETUID
) rmp
->mp_realuid
= (uid_t
) m_in
.usr_id
;
52 rmp
->mp_effuid
= (uid_t
) m_in
.usr_id
;
54 if (rmp
->mp_fs_call
!= PM_IDLE
)
56 panic(__FILE__
, "do_getset: not idle",
59 rmp
->mp_fs_call
= PM_SETUID
;
60 r
= notify(FS_PROC_NR
);
62 panic(__FILE__
, "do_getset: unable to notify FS", r
);
64 /* Do not reply until FS is ready to process the setuid
72 if (rmp
->mp_realgid
!= (gid_t
) m_in
.grp_id
&&
73 rmp
->mp_effuid
!= SUPER_USER
)
75 if(call_nr
== SETGID
) rmp
->mp_realgid
= (gid_t
) m_in
.grp_id
;
76 rmp
->mp_effgid
= (gid_t
) m_in
.grp_id
;
78 if (rmp
->mp_fs_call
!= PM_IDLE
)
80 panic(__FILE__
, "do_getset: not idle",
83 rmp
->mp_fs_call
= PM_SETGID
;
84 r
= notify(FS_PROC_NR
);
86 panic(__FILE__
, "do_getset: unable to notify FS", r
);
88 /* Do not reply until FS is ready to process the setgid
95 if (rmp
->mp_procgrp
== rmp
->mp_pid
) return(EPERM
);
96 rmp
->mp_procgrp
= rmp
->mp_pid
;
98 if (rmp
->mp_fs_call
!= PM_IDLE
)
100 panic(__FILE__
, "do_getset: not idle",
103 rmp
->mp_fs_call
= PM_SETSID
;
104 r
= notify(FS_PROC_NR
);
106 panic(__FILE__
, "do_getset: unable to notify FS", r
);
108 /* Do not reply until FS is ready to process the setsid