Fork me on GitHub

root/kernel/syscalls/setgid.c

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

DEFINITIONS

This source file includes following definitions.
  1. sys_setgid

   1 /*
   2  * fiwix/kernel/syscalls/setgid.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_setgid(__gid_t gid)
  17 {
  18 #ifdef __DEBUG__
  19         printk("(pid %d) sys_setgid(%d)\n", current->pid, gid);
  20 #endif /*__DEBUG__ */
  21 
  22         if(IS_SUPERUSER) {
  23                 current->gid = current->egid = current->sgid = gid;
  24         } else {
  25                 if((current->gid == gid) || (current->sgid == gid)) {
  26                         current->egid = gid;
  27                 } else {
  28                         return -EPERM;
  29                 }
  30         }
  31         return 0;
  32 }

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