📄 getset.c
字号:
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
src/mm/getset.c
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
18500 /* This file handles the 4 system calls that get and set uids and gids.
18501 * It also handles getpid(), setsid(), and getpgrp(). The code for each
18502 * one is so tiny that it hardly seemed worthwhile to make each a separate
18503 * function.
18504 */
18505
18506 #include "mm.h"
18507 #include <minix/callnr.h>
18508 #include <signal.h>
18509 #include "mproc.h"
18510 #include "param.h"
18511
18512 /*===========================================================================*
18513 * do_getset *
18514 *===========================================================================*/
18515 PUBLIC int do_getset()
18516 {
18517 /* Handle GETUID, GETGID, GETPID, GETPGRP, SETUID, SETGID, SETSID. The four
18518 * GETs and SETSID return their primary results in 'r'. GETUID, GETGID, and
18519 * GETPID also return secondary results (the effective IDs, or the parent
18520 * process ID) in 'result2', which is returned to the user.
18521 */
18522
18523 register struct mproc *rmp = mp;
18524 register int r;
18525
18526 switch(mm_call) {
18527 case GETUID:
18528 r = rmp->mp_realuid;
18529 result2 = rmp->mp_effuid;
18530 break;
18531
18532 case GETGID:
18533 r = rmp->mp_realgid;
18534 result2 = rmp->mp_effgid;
18535 break;
18536
18537 case GETPID:
18538 r = mproc[who].mp_pid;
18539 result2 = mproc[rmp->mp_parent].mp_pid;
18540 break;
18541
18542 case SETUID:
18543 if (rmp->mp_realuid != usr_id && rmp->mp_effuid != SUPER_USER)
18544 return(EPERM);
18545 rmp->mp_realuid = usr_id;
18546 rmp->mp_effuid = usr_id;
18547 tell_fs(SETUID, who, usr_id, usr_id);
18548 r = OK;
18549 break;
18550
18551 case SETGID:
18552 if (rmp->mp_realgid != grpid && rmp->mp_effuid != SUPER_USER)
18553 return(EPERM);
18554 rmp->mp_realgid = grpid;
18555 rmp->mp_effgid = grpid;
18556 tell_fs(SETGID, who, grpid, grpid);
18557 r = OK;
18558 break;
18559
18560 case SETSID:
18561 if (rmp->mp_procgrp == rmp->mp_pid) return(EPERM);
18562 rmp->mp_procgrp = rmp->mp_pid;
18563 tell_fs(SETSID, who, 0, 0);
18564 /*FALL THROUGH*/
18565
18566 case GETPGRP:
18567 r = rmp->mp_procgrp;
18568 break;
18569
18570 default:
18571 r = EINVAL;
18572 break;
18573 }
18574 return(r);
18575 }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -