Fork me on GitHub

root/kernel/syscalls/setregid.c

/* [previous][next][first][last][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. sys_setregid

   1 /*
   2  * fiwix/kernel/syscalls/setregid.c
   3  *
   4  * Copyright 2018, Jordi Sanfeliu. All rights reserved.
   5  * Distributed under the terms of the Fiwix License.
   6  */
   7 
   8 #include <fiwix/types.h>
   9 #include <fiwix/process.h>
  10 #include <fiwix/errno.h>
  11 
  12 #ifdef __DEBUG__
  13 #include <fiwix/stdio.h>
  14 #endif /*__DEBUG__ */
  15 
  16 int sys_setregid(__gid_t gid, __gid_t egid)
  17 {
  18 #ifdef __DEBUG__
  19         printk("(pid %d) sys_setregid(%d, %d) -> ", current->pid, gid, egid);
  20 #endif /*__DEBUG__ */
  21 
  22         if(IS_SUPERUSER) {
  23                 if(egid != (__uid_t)-1) {
  24                         if(gid != (__uid_t)-1 || (current->egid >= 0 && current->gid != egid)) {
  25                                 current->sgid = egid;
  26                         }
  27                         current->egid = egid;
  28                 }
  29                 if(gid != (__uid_t)-1) {
  30                         current->gid = gid;
  31                 }
  32         } else {
  33                 if(egid != (__uid_t)-1 && (current->gid == egid || current->egid == egid || current->sgid == egid)) {
  34                         if(gid != (__uid_t)-1 || (current->egid >= 0 && current->gid != egid)) {
  35                                 current->sgid = egid;
  36                         }
  37                         current->egid = egid;
  38                 } else {
  39                         return -EPERM;
  40                 }
  41                 if(gid != (__uid_t)-1 && (current->gid == gid || current->egid == gid)) {
  42                         current->gid = gid;
  43                 } else {
  44                         return -EPERM;
  45                 }
  46         }
  47 
  48         return 0;
  49 }

/* [previous][next][first][last][top][bottom][index][help] */