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 */
6
7 #include "pm.h"
8 #include <minix/callnr.h>
9 #include <signal.h>
10 #include "mproc.h"
11 #include "param.h"
12
13 /*===========================================================================*
14 * do_getset *
15 *===========================================================================*/
16 PUBLIC int do_getset()
17 {
18 /* Handle GETUID, GETGID, GETPID, GETPGRP, SETUID, SETGID, SETSID. The four
19 * GETs and SETSID return their primary results in 'r'. GETUID, GETGID, and
20 * GETPID also return secondary results (the effective IDs, or the parent
21 * process ID) in 'reply_res2', which is returned to the user.
22 */
23
24 register struct mproc *rmp = mp;
25 register int r;
26
27 switch(call_nr) {
28 case GETUID:
29 r = rmp->mp_realuid;
30 rmp->mp_reply.reply_res2 = rmp->mp_effuid;
31 break;
32
33 case GETGID:
34 r = rmp->mp_realgid;
35 rmp->mp_reply.reply_res2 = rmp->mp_effgid;
36 break;
37
38 case GETPID:
39 r = mproc[who].mp_pid;
40 rmp->mp_reply.reply_res2 = mproc[rmp->mp_parent].mp_pid;
41 if (m_in.procnr >= 0 && m_in.procnr < NR_PROCS)
42 rmp->mp_reply.reply_res3 = mproc[m_in.procnr].mp_pid;
43 break;
44
45 case SETUID:
46 if (rmp->mp_realuid != (uid_t) m_in.usr_id &&
47 rmp->mp_effuid != SUPER_USER)
48 return(EPERM);
49 rmp->mp_realuid = (uid_t) m_in.usr_id;
50 rmp->mp_effuid = (uid_t) m_in.usr_id;
51 tell_fs(SETUID, who, rmp->mp_realuid, rmp->mp_effuid);
52 r = OK;
53 break;
54
55 case SETGID:
56 if (rmp->mp_realgid != (gid_t) m_in.grp_id &&
57 rmp->mp_effuid != SUPER_USER)
58 return(EPERM);
59 rmp->mp_realgid = (gid_t) m_in.grp_id;
60 rmp->mp_effgid = (gid_t) m_in.grp_id;
61 tell_fs(SETGID, who, rmp->mp_realgid, rmp->mp_effgid);
62 r = OK;
63 break;
64
65 case SETSID:
66 if (rmp->mp_procgrp == rmp->mp_pid) return(EPERM);
67 rmp->mp_procgrp = rmp->mp_pid;
68 tell_fs(SETSID, who, 0, 0);
69 /* fall through */
70
71 case GETPGRP:
72 r = rmp->mp_procgrp;
73 break;
74
75 default:
76 r = EINVAL;
77 break;
78 }
79 return(r);
80 }
Cache object: 8ca8f842405c904f4e4a43af4a9dd2c5
|