]> Zhao Yanbai Git Server - minix.git/commitdiff
Fake setgroups() and initgroups() implementation.
authorBen Gras <ben@minix3.org>
Mon, 13 Feb 2006 15:00:49 +0000 (15:00 +0000)
committerBen Gras <ben@minix3.org>
Mon, 13 Feb 2006 15:00:49 +0000 (15:00 +0000)
include/unistd.h
lib/other/setgroups.c

index 012e385d782ffff0b2d25b83e9c69e7dac1541e4..3e06537ecb017f4c63f7338df3ffbf75182b96a4 100755 (executable)
@@ -185,6 +185,7 @@ _PROTOTYPE( int devctl, (int ctl_req, int driver, int device, int style));
 /* For compatibility with other Unix systems */
 _PROTOTYPE( int getpagesize, (void)                                    );
 _PROTOTYPE( int setgroups, (int ngroups, const gid_t *gidset)          );
+_PROTOTYPE( int initgroups, (const char *name, gid_t basegid)          );
 
 #endif
 
index 23a364417725090cafc6b8b7556459ab707a3048..a1f199feb10318e5b22aabba4e255db6e64f8be0 100644 (file)
@@ -4,12 +4,48 @@ setgroups.c
 
 #include <errno.h>
 #include <unistd.h>
+#include <string.h>
+#include <grp.h>
 
 int setgroups(int ngroups, const gid_t *gidset)
 {
-       /* Not implemented */
+       if(!gidset || ngroups > 1) {
+               /* Supplementary groups not implemented */
+               errno= EINVAL;
+               return -1;
+       }
 
-       errno= ENOSYS;
-       return -1;
+       if(ngroups == 1)
+               return setgid(gidset[0]);
+
+       return 0;
+}
+
+int initgroups(const char *name, gid_t basegid)
+{
+       struct group *gr;
+       int r, found = 0;
+       if((r = setgid(basegid)) < 0)
+               return r;
+
+       setgrent();
+       while (!found && (gr = getgrent()) != NULL) {
+               char **mem;
+               for(mem = gr->gr_mem; mem && *mem; mem++) {
+                       if(!strcmp(name, *mem)) {
+                               found = 1;
+                               break;
+                       }
+               }
+       }
+       endgrent();
+
+       /* Because supplemental groups aren't implemented, this call
+        * should fail if the user is in any supplemental groups.
+        */
+       if(found)
+               return EINVAL;
+
+       return 0;
 }