. service tells you which device it couldn't stat
[minix3.git] / servers / pm / getset.c
blobdd0868aec6fdafebced9d4d78933f9309e5a1abf
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
4 * function.
5 */
7 #include "pm.h"
8 #include <minix/callnr.h>
9 #include <minix/endpoint.h>
10 #include <signal.h>
11 #include "mproc.h"
12 #include "param.h"
14 /*===========================================================================*
15 * do_getset *
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;
26 int r, proc;
28 switch(call_nr) {
29 case GETUID:
30 r = rmp->mp_realuid;
31 rmp->mp_reply.reply_res2 = rmp->mp_effuid;
32 break;
34 case GETGID:
35 r = rmp->mp_realgid;
36 rmp->mp_reply.reply_res2 = rmp->mp_effgid;
37 break;
39 case GETPID:
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;
44 break;
46 case SETEUID:
47 case SETUID:
48 if (rmp->mp_realuid != (uid_t) m_in.usr_id &&
49 rmp->mp_effuid != SUPER_USER)
50 return(EPERM);
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",
57 rmp->mp_fs_call);
59 rmp->mp_fs_call= PM_SETUID;
60 r= notify(FS_PROC_NR);
61 if (r != OK)
62 panic(__FILE__, "do_getset: unable to notify FS", r);
64 /* Do not reply until FS is ready to process the setuid
65 * request
67 r= SUSPEND;
68 break;
70 case SETEGID:
71 case SETGID:
72 if (rmp->mp_realgid != (gid_t) m_in.grp_id &&
73 rmp->mp_effuid != SUPER_USER)
74 return(EPERM);
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",
81 rmp->mp_fs_call);
83 rmp->mp_fs_call= PM_SETGID;
84 r= notify(FS_PROC_NR);
85 if (r != OK)
86 panic(__FILE__, "do_getset: unable to notify FS", r);
88 /* Do not reply until FS is ready to process the setgid
89 * request
91 r= SUSPEND;
92 break;
94 case SETSID:
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",
101 rmp->mp_fs_call);
103 rmp->mp_fs_call= PM_SETSID;
104 r= notify(FS_PROC_NR);
105 if (r != OK)
106 panic(__FILE__, "do_getset: unable to notify FS", r);
108 /* Do not reply until FS is ready to process the setsid
109 * request
111 r= SUSPEND;
112 break;
114 case GETPGRP:
115 r = rmp->mp_procgrp;
116 break;
118 default:
119 r = EINVAL;
120 break;
122 return(r);