Welcome to The Fiwix Project
A UNIX-like kernel for the i386 architecture
1 /* 2 * fiwix/kernel/syscalls/setgroups.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/fs.h> 10 #include <fiwix/process.h> 11 #include <fiwix/errno.h> 12 13 #ifdef __DEBUG__ 14 #include <fiwix/stdio.h> 15 #endif /*__DEBUG__ */ 16 17 int sys_setgroups(__ssize_t size, const __gid_t *list) 18 { 19 int n, errno; 20 21 #ifdef __DEBUG__ 22 printk("(pid %d) sys_setgroups(%d, 0x%08x)\n", current->pid, size, (unsigned int)list); 23 #endif /*__DEBUG__ */ 24 25 if((errno = check_user_area(VERIFY_READ, list, sizeof(__gid_t)))) { 26 return errno; 27 } 28 if(!IS_SUPERUSER) { 29 return -EPERM; 30 } 31 if(size > NGROUPS_MAX) { 32 return -EINVAL; 33 } 34 for(n = 0; n < NGROUPS_MAX; n++) { 35 current->groups[n] = -1; 36 if(n < size) { 37 current->groups[n] = list[n]; 38 } 39 } 40 return 0; 41 }