Fork me on GitHub

root/kernel/syscalls/setreuid.c

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

DEFINITIONS

This source file includes following definitions.
  1. sys_setreuid

   1 /*
   2  * fiwix/kernel/syscalls/setreuid.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_setreuid(__uid_t uid, __uid_t euid)
  17 {
  18 #ifdef __DEBUG__
  19         printk("(pid %d) sys_setreuid(%d, %d) -> ", current->pid, uid, euid);
  20 #endif /*__DEBUG__ */
  21 
  22         if(IS_SUPERUSER) {
  23                 if(euid != (__uid_t)-1) {
  24                         if(uid != (__uid_t)-1 || (current->euid >= 0 && current->uid != euid)) {
  25                                 current->suid = euid;
  26                         }
  27                         current->euid = euid;
  28                 }
  29                 if(uid != (__uid_t)-1) {
  30                         current->uid = uid;
  31                 }
  32         } else {
  33                 if(euid != (__uid_t)-1 && (current->uid == euid || current->euid == euid || current->suid == euid)) {
  34                         if(uid != (__uid_t)-1 || (current->euid >= 0 && current->uid != euid)) {
  35                                 current->suid = euid;
  36                         }
  37                         current->euid = euid;
  38                 } else {
  39                         return -EPERM;
  40                 }
  41                 if(uid != (__uid_t)-1 && (current->uid == uid || current->euid == uid)) {
  42                         current->uid = uid;
  43                 } else {
  44                         return -EPERM;
  45                 }
  46         }
  47 
  48 #ifdef __DEBUG__
  49         printk(" 0\n");
  50 #endif /*__DEBUG__ */
  51 
  52         return 0;
  53 }

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