source: branches/minix3-book/servers/pm/getset.c@ 26

Last change on this file since 26 was 4, checked in by Mattia Monga, 14 years ago

Importazione sorgenti libro

File size: 2.0 KB
Line 
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 *===========================================================================*/
16PUBLIC 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 break;
42
43 case SETUID:
44 if (rmp->mp_realuid != (uid_t) m_in.usr_id &&
45 rmp->mp_effuid != SUPER_USER)
46 return(EPERM);
47 rmp->mp_realuid = (uid_t) m_in.usr_id;
48 rmp->mp_effuid = (uid_t) m_in.usr_id;
49 tell_fs(SETUID, who, rmp->mp_realuid, rmp->mp_effuid);
50 r = OK;
51 break;
52
53 case SETGID:
54 if (rmp->mp_realgid != (gid_t) m_in.grp_id &&
55 rmp->mp_effuid != SUPER_USER)
56 return(EPERM);
57 rmp->mp_realgid = (gid_t) m_in.grp_id;
58 rmp->mp_effgid = (gid_t) m_in.grp_id;
59 tell_fs(SETGID, who, rmp->mp_realgid, rmp->mp_effgid);
60 r = OK;
61 break;
62
63 case SETSID:
64 if (rmp->mp_procgrp == rmp->mp_pid) return(EPERM);
65 rmp->mp_procgrp = rmp->mp_pid;
66 tell_fs(SETSID, who, 0, 0);
67 /* fall through */
68
69 case GETPGRP:
70 r = rmp->mp_procgrp;
71 break;
72
73 default:
74 r = EINVAL;
75 break;
76 }
77 return(r);
78}
Note: See TracBrowser for help on using the repository browser.