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 "mm.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 'result2', which is returned to the user.
22 */
23
24 register struct mproc *rmp = mp;
25 register int r;
26
27 switch(mm_call) {
28 case GETUID:
29 r = rmp->mp_realuid;
30 result2 = rmp->mp_effuid;
31 break;
32
33 case GETGID:
34 r = rmp->mp_realgid;
35 result2 = rmp->mp_effgid;
36 break;
37
38 case GETPID:
39 r = mproc[who].mp_pid;
40 result2 = mproc[rmp->mp_parent].mp_pid;
41 break;
42
43 case SETUID:
44 if (rmp->mp_realuid != usr_id && rmp->mp_effuid != SUPER_USER)
45 return(EPERM);
46 rmp->mp_realuid = usr_id;
47 rmp->mp_effuid = usr_id;
48 tell_fs(SETUID, who, usr_id, usr_id);
49 r = OK;
50 break;
51
52 case SETGID:
53 if (rmp->mp_realgid != grpid && rmp->mp_effuid != SUPER_USER)
54 return(EPERM);
55 rmp->mp_realgid = grpid;
56 rmp->mp_effgid = grpid;
57 tell_fs(SETGID, who, grpid, grpid);
58 r = OK;
59 break;
60
61 case SETSID:
62 if (rmp->mp_procgrp == rmp->mp_pid) return(EPERM);
63 rmp->mp_procgrp = rmp->mp_pid;
64 tell_fs(SETSID, who, 0, 0);
65 /*FALL THROUGH*/
66
67 case GETPGRP:
68 r = rmp->mp_procgrp;
69 break;
70
71 default:
72 r = EINVAL;
73 break;
74 }
75 return(r);
76 }
77
This page was automatically generated by the
LXR engine.
Visit the LXR main site for more
information.