setgroups.c

Go to the documentation of this file.
00001 /*
00002 setgroups.c
00003 */
00004 
00005 #include <errno.h>
00006 #include <unistd.h>
00007 #include <string.h>
00008 #include <grp.h>
00009 
00010 int setgroups(int ngroups, const gid_t *gidset)
00011 {
00012         if(ngroups > 1) {
00013                 /* Supplementary groups not implemented */
00014                 errno= EINVAL;
00015                 return -1;
00016         }
00017 
00018         if(ngroups == 1)
00019                 return setgid(gidset[0]);
00020 
00021         return 0;
00022 }
00023 
00024 int initgroups(const char *name, gid_t basegid)
00025 {
00026         struct group *gr;
00027         int r, found = 0;
00028         if((r = setgid(basegid)) < 0)
00029                 return r;
00030 
00031         setgrent();
00032         while (!found && (gr = getgrent()) != NULL) {
00033                 char **mem;
00034                 for(mem = gr->gr_mem; mem && *mem; mem++) {
00035                         if(!strcmp(name, *mem)) {
00036                                 found = 1;
00037                                 break;
00038                         }
00039                 }
00040         }
00041         endgrent();
00042 
00043         /* Because supplemental groups aren't implemented, this call
00044          * should fail if the user is in any supplemental groups.
00045          */
00046         if(found) {
00047                 errno = EINVAL;
00048                 return -1;
00049         }
00050 
00051         return 0;
00052 }
00053 

Generated on Fri Apr 14 22:57:27 2006 for minix by  doxygen 1.4.6