From 61b3a42219dc8f575923346b59162f81186b7425 Mon Sep 17 00:00:00 2001 From: Eric Blake Date: Thu, 12 Nov 2009 09:53:14 -0700 Subject: [PATCH] getgroups, getugroups: provide stubs for mingw Avoid link failure on mingw, which lacks getgroups and anything else related to gid_t management (stat.st_gid is always 0). * lib/getgroups.c (getgroups): Provide ENOSYS stub for mingw. * lib/getugroups.c (getugroups): Likewise. * m4/getgroups.m4 (gl_FUNC_GETGROUPS): Check for missing function. Modernize replacement scheme. (gl_PREREQ_GETGROUPS): Delete. * m4/getugroups.m4 (gl_GETUGROUPS): Check for . * modules/getgroups (configure.ac): Declare witness. * m4/unistd_h.m4 (gl_UNISTD_H_DEFAULTS): Add default. * modules/unistd (Depends-on): Substitute witness. * lib/unistd.in.h (getgroups): Declare replacement. Signed-off-by: Eric Blake --- ChangeLog | 12 ++++++++++++ lib/getgroups.c | 17 ++++++++++++++++- lib/getugroups.c | 29 ++++++++++++++++++++--------- lib/unistd.in.h | 22 ++++++++++++++++++++++ m4/getgroups.m4 | 19 ++++++++----------- m4/getugroups.m4 | 6 ++++-- m4/unistd_h.m4 | 5 ++++- modules/getgroups | 1 + modules/unistd | 3 +++ 9 files changed, 90 insertions(+), 24 deletions(-) diff --git a/ChangeLog b/ChangeLog index 86e3bf83a..26aa6437e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,17 @@ 2009-11-13 Eric Blake + getgroups, getugroups: provide stubs for mingw + * lib/getgroups.c (getgroups): Provide ENOSYS stub for mingw. + * lib/getugroups.c (getugroups): Likewise. + * m4/getgroups.m4 (gl_FUNC_GETGROUPS): Check for missing + function. Modernize replacement scheme. + (gl_PREREQ_GETGROUPS): Delete. + * m4/getugroups.m4 (gl_GETUGROUPS): Check for . + * modules/getgroups (configure.ac): Declare witness. + * m4/unistd_h.m4 (gl_UNISTD_H_DEFAULTS): Add default. + * modules/unistd (Depends-on): Substitute witness. + * lib/unistd.in.h (getgroups): Declare replacement. + getgroups: avoid calling exit * modules/getgroups (Depends-on): Add malloc-posix and unistd, drop xalloc. diff --git a/lib/getgroups.c b/lib/getgroups.c index e764d732f..bad676ea5 100644 --- a/lib/getgroups.c +++ b/lib/getgroups.c @@ -25,7 +25,20 @@ #include #include -#undef getgroups +#if !HAVE_GETGROUPS + +/* Provide a stub that fails with ENOSYS, since there is no group + information available on mingw. */ +int +getgroups (int n _UNUSED_PARAMETER_, GETGROUPS_T *groups _UNUSED_PARAMETER_) +{ + errno = ENOSYS; + return -1; +} + +#else /* HAVE_GETGROUPS */ + +# undef getgroups /* On at least Ultrix 4.3 and NextStep 3.2, getgroups (0, NULL) always fails. On other systems, it returns the number of supplemental @@ -66,3 +79,5 @@ rpl_getgroups (int n, GETGROUPS_T *group) return n_groups; } + +#endif /* HAVE_GETGROUPS */ diff --git a/lib/getugroups.c b/lib/getugroups.c index 2207b85a1..a614ec7be 100644 --- a/lib/getugroups.c +++ b/lib/getugroups.c @@ -21,22 +21,31 @@ #include "getugroups.h" +#include #include #include /* grp.h on alpha OSF1 V2.0 uses "FILE *". */ -#include - +#include #include -#include +#if !HAVE_GRP_H -/* Some old header files might not declare setgrent, getgrent, and endgrent. - If you don't have them at all, we can't implement this function. - You lose! */ -struct group *getgrent (void); +/* Mingw lacks all things related to group management. The best we + can do is fail with ENOSYS. */ -#include +int +getugroups (int maxcount _UNUSED_PARAMETER_, + gid_t *grouplist _UNUSED_PARAMETER_, + char const *username _UNUSED_PARAMETER_, + gid_t gid _UNUSED_PARAMETER_) +{ + errno = ENOSYS; + return -1; +} -#define STREQ(s1, s2) (strcmp (s1, s2) == 0) +#else /* HAVE_GRP_H */ +# include + +# define STREQ(s1, s2) (strcmp (s1, s2) == 0) /* Like `getgroups', but for user USERNAME instead of for the current process. Store at most MAXCOUNT group IDs in the GROUPLIST array. @@ -112,3 +121,5 @@ getugroups (int maxcount, GETGROUPS_T *grouplist, char const *username, return count; } + +#endif /* HAVE_GRP_H */ diff --git a/lib/unistd.in.h b/lib/unistd.in.h index b6d2fa06b..90494e4d1 100644 --- a/lib/unistd.in.h +++ b/lib/unistd.in.h @@ -406,6 +406,28 @@ extern int getdtablesize (void); #endif +#if @GNULIB_GETGROUPS@ +# if @REPLACE_GETGROUPS@ +# undef getgroups +# define getgroups rpl_getgroups +# endif +# if !@HAVE_GETGROUPS@ || @REPLACE_GETGROUPS@ +/* Return the supplemental groups that the current process belongs to. + It is unspecified whether the effective group id is in the list. + If N is 0, return the group count; otherwise, N describes how many + entries are available in GROUPS. Return -1 and set errno if N is + not 0 and not large enough. Fails with ENOSYS on some systems. */ +int getgroups (int n, GETGROUPS_T *groups); +# endif +#elif defined GNULIB_POSIXCHECK +# undef getgroups +# define getgroups(n,g) \ + (GL_LINK_WARNING ("getgroups is unportable - " \ + "use gnulib module getgroups for portability"), \ + getgroups (n, g)) +#endif + + #if @GNULIB_GETHOSTNAME@ /* Return the standard host name of the machine. WARNING! The host name may or may not be fully qualified. diff --git a/m4/getgroups.m4 b/m4/getgroups.m4 index a7019fb66..1dd39eacc 100644 --- a/m4/getgroups.m4 +++ b/m4/getgroups.m4 @@ -1,4 +1,4 @@ -# serial 12 +# serial 13 dnl From Jim Meyering. dnl A wrapper around AC_FUNC_GETGROUPS. @@ -12,17 +12,14 @@ dnl A wrapper around AC_FUNC_GETGROUPS. AC_DEFUN([gl_FUNC_GETGROUPS], [ AC_REQUIRE([AC_FUNC_GETGROUPS]) - if test "$ac_cv_func_getgroups_works" != yes; then + AC_REQUIRE([AC_TYPE_GETGROUPS]) + AC_REQUIRE([gl_UNISTD_H_DEFAULTS]) + if test "$ac_cv_func_getgroups" != yes; then + AC_LIBOBJ([getgroups]) + HAVE_GETGROUPS=0 + elif test "$ac_cv_func_getgroups_works" != yes; then AC_LIBOBJ([getgroups]) - AC_DEFINE([getgroups], [rpl_getgroups], - [Define as rpl_getgroups if getgroups doesn't work right.]) - gl_PREREQ_GETGROUPS + REPLACE_GETGROUPS=1 fi test -n "$GETGROUPS_LIB" && LIBS="$GETGROUPS_LIB $LIBS" ]) - -# Prerequisites of lib/getgroups.c. -AC_DEFUN([gl_PREREQ_GETGROUPS], -[ - AC_REQUIRE([AC_TYPE_GETGROUPS]) -]) diff --git a/m4/getugroups.m4 b/m4/getugroups.m4 index 3c5e15eed..e437e1ba3 100644 --- a/m4/getugroups.m4 +++ b/m4/getugroups.m4 @@ -1,5 +1,6 @@ -# getugroups.m4 serial 6 -dnl Copyright (C) 2002, 2003, 2005, 2006 Free Software Foundation, Inc. +# getugroups.m4 serial 7 +dnl Copyright (C) 2002, 2003, 2005, 2006, 2009 Free Software +dnl Foundation, Inc. dnl This file is free software; the Free Software Foundation dnl gives unlimited permission to copy and/or distribute it, dnl with or without modifications, as long as this notice is preserved. @@ -7,6 +8,7 @@ dnl with or without modifications, as long as this notice is preserved. AC_DEFUN([gl_GETUGROUPS], [ AC_LIBOBJ([getugroups]) + AC_CHECK_HEADERS_ONCE([grp.h]) dnl Prerequisites of lib/getugroups.c. AC_TYPE_GETGROUPS diff --git a/m4/unistd_h.m4 b/m4/unistd_h.m4 index 5aa39aeda..5c94916eb 100644 --- a/m4/unistd_h.m4 +++ b/m4/unistd_h.m4 @@ -1,4 +1,4 @@ -# unistd_h.m4 serial 31 +# unistd_h.m4 serial 32 dnl Copyright (C) 2006-2009 Free Software Foundation, Inc. dnl This file is free software; the Free Software Foundation dnl gives unlimited permission to copy and/or distribute it, @@ -46,6 +46,7 @@ AC_DEFUN([gl_UNISTD_H_DEFAULTS], GNULIB_GETCWD=0; AC_SUBST([GNULIB_GETCWD]) GNULIB_GETDOMAINNAME=0; AC_SUBST([GNULIB_GETDOMAINNAME]) GNULIB_GETDTABLESIZE=0; AC_SUBST([GNULIB_GETDTABLESIZE]) + GNULIB_GETGROUPS=0; AC_SUBST([GNULIB_GETGROUPS]) GNULIB_GETHOSTNAME=0; AC_SUBST([GNULIB_GETHOSTNAME]) GNULIB_GETLOGIN_R=0; AC_SUBST([GNULIB_GETLOGIN_R]) GNULIB_GETPAGESIZE=0; AC_SUBST([GNULIB_GETPAGESIZE]) @@ -76,6 +77,7 @@ AC_DEFUN([gl_UNISTD_H_DEFAULTS], HAVE_FTRUNCATE=1; AC_SUBST([HAVE_FTRUNCATE]) HAVE_GETDOMAINNAME=1; AC_SUBST([HAVE_GETDOMAINNAME]) HAVE_GETDTABLESIZE=1; AC_SUBST([HAVE_GETDTABLESIZE]) + HAVE_GETGROUPS=1; AC_SUBST([HAVE_GETGROUPS]) HAVE_GETHOSTNAME=1; AC_SUBST([HAVE_GETHOSTNAME]) HAVE_GETPAGESIZE=1; AC_SUBST([HAVE_GETPAGESIZE]) HAVE_GETUSERSHELL=1; AC_SUBST([HAVE_GETUSERSHELL]) @@ -99,6 +101,7 @@ AC_DEFUN([gl_UNISTD_H_DEFAULTS], REPLACE_FCHDIR=0; AC_SUBST([REPLACE_FCHDIR]) REPLACE_FCHOWNAT=0; AC_SUBST([REPLACE_FCHOWNAT]) REPLACE_GETCWD=0; AC_SUBST([REPLACE_GETCWD]) + REPLACE_GETGROUPS=0; AC_SUBST([REPLACE_GETGROUPS]) REPLACE_GETPAGESIZE=0; AC_SUBST([REPLACE_GETPAGESIZE]) REPLACE_LCHOWN=0; AC_SUBST([REPLACE_LCHOWN]) REPLACE_LINK=0; AC_SUBST([REPLACE_LINK]) diff --git a/modules/getgroups b/modules/getgroups index 472d20e9c..8ecbbdd49 100644 --- a/modules/getgroups +++ b/modules/getgroups @@ -11,6 +11,7 @@ unistd configure.ac: gl_FUNC_GETGROUPS +gl_UNISTD_MODULE_INDICATOR([getgroups]) Makefile.am: diff --git a/modules/unistd b/modules/unistd index d299e4af0..48259ace9 100644 --- a/modules/unistd +++ b/modules/unistd @@ -39,6 +39,7 @@ unistd.h: unistd.in.h -e 's|@''GNULIB_GETCWD''@|$(GNULIB_GETCWD)|g' \ -e 's|@''GNULIB_GETDOMAINNAME''@|$(GNULIB_GETDOMAINNAME)|g' \ -e 's|@''GNULIB_GETDTABLESIZE''@|$(GNULIB_GETDTABLESIZE)|g' \ + -e 's|@''GNULIB_GETGROUPS''@|$(GNULIB_GETGROUPS)|g' \ -e 's|@''GNULIB_GETHOSTNAME''@|$(GNULIB_GETHOSTNAME)|g' \ -e 's|@''GNULIB_GETLOGIN_R''@|$(GNULIB_GETLOGIN_R)|g' \ -e 's|@''GNULIB_GETPAGESIZE''@|$(GNULIB_GETPAGESIZE)|g' \ @@ -68,6 +69,7 @@ unistd.h: unistd.in.h -e 's|@''HAVE_FTRUNCATE''@|$(HAVE_FTRUNCATE)|g' \ -e 's|@''HAVE_GETDOMAINNAME''@|$(HAVE_GETDOMAINNAME)|g' \ -e 's|@''HAVE_GETDTABLESIZE''@|$(HAVE_GETDTABLESIZE)|g' \ + -e 's|@''HAVE_GETGROUPS''@|$(HAVE_GETGROUPS)|g' \ -e 's|@''HAVE_GETHOSTNAME''@|$(HAVE_GETHOSTNAME)|g' \ -e 's|@''HAVE_GETPAGESIZE''@|$(HAVE_GETPAGESIZE)|g' \ -e 's|@''HAVE_GETUSERSHELL''@|$(HAVE_GETUSERSHELL)|g' \ @@ -91,6 +93,7 @@ unistd.h: unistd.in.h -e 's|@''REPLACE_FCHDIR''@|$(REPLACE_FCHDIR)|g' \ -e 's|@''REPLACE_FCHOWNAT''@|$(REPLACE_FCHOWNAT)|g' \ -e 's|@''REPLACE_GETCWD''@|$(REPLACE_GETCWD)|g' \ + -e 's|@''REPLACE_GETGROUPS''@|$(REPLACE_GETGROUPS)|g' \ -e 's|@''REPLACE_GETPAGESIZE''@|$(REPLACE_GETPAGESIZE)|g' \ -e 's|@''REPLACE_LCHOWN''@|$(REPLACE_LCHOWN)|g' \ -e 's|@''REPLACE_LINK''@|$(REPLACE_LINK)|g' \ -- 2.11.0