guile-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: setgroups


From: Paul Jarc
Subject: Re: setgroups
Date: Fri, 18 Apr 2003 11:37:22 -0400
User-agent: Gnus/5.090019 (Oort Gnus v0.19) Emacs/21.3 (gnu/linux)

Marius Vollmer <address@hidden> wrote:
> However, just assuming that the vector holds inums is not OK, I'd say.
> You need to use scm_num2ulong and then check that it fits in a gid_t.

I agree that it would be good to check that it fits in gid_t, but
set[ug]id already fail do that, and I wouldn't know exactly what to do
in the case where it didn't fit.  So here's a version that's in line
with the way set[ug]id currently work.  If you explain how to throw
the appropriate error, I'll work on a patch to fix all such functions
I can find in posix.c.

There's another opportunity for overflow in this code; see the comment
below.

Index: configure.in
===================================================================
RCS file: /cvsroot/guile/guile/guile-core/configure.in,v
retrieving revision 1.213
diff -u -r1.213 configure.in
--- configure.in        7 Apr 2003 17:31:02 -0000       1.213
+++ configure.in        18 Apr 2003 15:19:32 -0000
@@ -583,7 +583,7 @@
     [Define if the system supports Unix-domain (file-domain) sockets.])
 fi
 
-AC_CHECK_FUNCS(socketpair getgroups setpwent pause tzset)
+AC_CHECK_FUNCS(socketpair getgroups setgroups setpwent pause tzset)
 
 AC_CHECK_FUNCS(sethostent   gethostent   endhostent   dnl
                setnetent    getnetent    endnetent    dnl
Index: libguile/posix.c
===================================================================
RCS file: /cvsroot/guile/guile/guile-core/libguile/posix.c,v
retrieving revision 1.112
diff -u -r1.112 posix.c
--- libguile/posix.c    5 Apr 2003 19:10:22 -0000       1.112
+++ libguile/posix.c    18 Apr 2003 15:19:32 -0000
@@ -228,6 +228,41 @@
 #undef FUNC_NAME  
 #endif
 
+#ifdef HAVE_SETGROUPS
+SCM_DEFINE (scm_setgroups, "setgroups", 1, 0, 0,
+            (SCM group_vec),
+           "Set the supplementary group IDs to those found in the vector\n"
+            "argument.")
+#define FUNC_NAME s_scm_setgroups
+{
+  size_t ngroups;
+  size_t size;
+  size_t i;
+  int result;
+  GETGROUPS_T *groups;
+
+  SCM_VALIDATE_VECTOR (0, group_vec);
+
+  ngroups = SCM_VECTOR_LENGTH (group_vec);
+  size = ngroups * sizeof (GETGROUPS_T);
+  /* XXX - if (ngroups / sizeof (GETGROUPS_T) != size) out-of-range */
+  groups = scm_malloc (size);
+  for(i = ngroups; i >= 0; i--)
+    {
+      SCM gid = SCM_VECTOR_REF (group_vec, i);
+      SCM_VALIDATE_INUM (0, gid);
+      groups [i] = SCM_INUM (gid);
+    }
+
+  result = setgroups (ngroups, groups);
+  free (groups);
+  if (result < 0)
+    SCM_SYSERROR;
+  return SCM_UNSPECIFIED;
+}
+#undef FUNC_NAME
+#endif
+
 #ifdef HAVE_GETPWENT
 SCM_DEFINE (scm_getpwuid, "getpw", 0, 1, 0,
             (SCM user),


paul




reply via email to

[Prev in Thread] Current Thread [Next in Thread]