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 <minix/endpoint.h>
|
---|
10 | #include <signal.h>
|
---|
11 | #include "mproc.h"
|
---|
12 | #include "param.h"
|
---|
13 |
|
---|
14 | /*===========================================================================*
|
---|
15 | * do_getset *
|
---|
16 | *===========================================================================*/
|
---|
17 | PUBLIC int do_getset()
|
---|
18 | {
|
---|
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.
|
---|
23 | */
|
---|
24 |
|
---|
25 | register struct mproc *rmp = mp;
|
---|
26 | int r, proc;
|
---|
27 |
|
---|
28 | switch(call_nr) {
|
---|
29 | case GETUID:
|
---|
30 | r = rmp->mp_realuid;
|
---|
31 | rmp->mp_reply.reply_res2 = rmp->mp_effuid;
|
---|
32 | break;
|
---|
33 |
|
---|
34 | case GETGID:
|
---|
35 | r = rmp->mp_realgid;
|
---|
36 | rmp->mp_reply.reply_res2 = rmp->mp_effgid;
|
---|
37 | break;
|
---|
38 |
|
---|
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;
|
---|
45 |
|
---|
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;
|
---|
53 | tell_fs(SETUID, who_e, rmp->mp_realuid, rmp->mp_effuid);
|
---|
54 | r = OK;
|
---|
55 | break;
|
---|
56 |
|
---|
57 | case SETEGID:
|
---|
58 | case SETGID:
|
---|
59 | if (rmp->mp_realgid != (gid_t) m_in.grp_id &&
|
---|
60 | rmp->mp_effuid != SUPER_USER)
|
---|
61 | return(EPERM);
|
---|
62 | if(call_nr == SETGID) rmp->mp_realgid = (gid_t) m_in.grp_id;
|
---|
63 | rmp->mp_effgid = (gid_t) m_in.grp_id;
|
---|
64 | tell_fs(SETGID, who_e, rmp->mp_realgid, rmp->mp_effgid);
|
---|
65 | r = OK;
|
---|
66 | break;
|
---|
67 |
|
---|
68 | case SETSID:
|
---|
69 | if (rmp->mp_procgrp == rmp->mp_pid) return(EPERM);
|
---|
70 | rmp->mp_procgrp = rmp->mp_pid;
|
---|
71 | tell_fs(SETSID, who_e, 0, 0);
|
---|
72 | /* fall through */
|
---|
73 |
|
---|
74 | case GETPGRP:
|
---|
75 | r = rmp->mp_procgrp;
|
---|
76 | break;
|
---|
77 |
|
---|
78 | default:
|
---|
79 | r = EINVAL;
|
---|
80 | break;
|
---|
81 | }
|
---|
82 | return(r);
|
---|
83 | }
|
---|