]> andersk Git - openssh.git/commitdiff
- (dtucker) [configure.ac openbsd-compat/port-aix.{c,h}] Bug #1081: Implement
authordtucker <dtucker>
Thu, 28 Feb 2008 12:16:04 +0000 (12:16 +0000)
committerdtucker <dtucker>
Thu, 28 Feb 2008 12:16:04 +0000 (12:16 +0000)
   getgrouplist via getgrset on AIX, rather than iterating over getgrent.
   This allows, eg, Match and AllowGroups directives to work with NIS and
   LDAP groups.

ChangeLog
configure.ac
openbsd-compat/port-aix.c
openbsd-compat/port-aix.h

index b2007e877f139baeaa2e58b6de1c6e190623027b..376d8a827ab906c15316b81f4648fba0ffae52ef 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -7,6 +7,10 @@
    SSLeay_add_all_algorithms as a macro already.
  - (dtucker) [key.c defines.h openbsd-compat/openssl-compat.h] Move old OpenSSL
    compat glue into openssl-compat.h.
+ - (dtucker) [configure.ac openbsd-compat/port-aix.{c,h}] Bug #1081: Implement
+   getgrouplist via getgrset on AIX, rather than iterating over getgrent.
+   This allows, eg, Match and AllowGroups directives to work with NIS and
+   LDAP groups.
 
 20080225
  - (dtucker) [openbsd-compat/fake-rfc2553.h] rename ssh_gai_strerror hack
index 2f6c7ebb1853616d89e612daac10c9ca79aa3720..8b2d152dedd90162f009772b677420327426a948 100644 (file)
@@ -357,7 +357,7 @@ int main(void) { exit(0); }
                [],
                [#include <usersec.h>]
        )
-       AC_CHECK_FUNCS(setauthdb)
+       AC_CHECK_FUNCS(getgrset setauthdb)
        AC_CHECK_DECL(F_CLOSEM,
            AC_DEFINE(HAVE_FCNTL_CLOSEM, 1, [Use F_CLOSEM fcntl for closefrom]),
            [],
index 94faec6703571de07fa2f558872791f199eae295..b19d2296e74ec3fbea2d9ed0b2b0e2745a5858ae 100644 (file)
@@ -1,7 +1,7 @@
 /*
  *
  * Copyright (c) 2001 Gert Doering.  All rights reserved.
- * Copyright (c) 2003,2004,2005 Darren Tucker.  All rights reserved.
+ * Copyright (c) 2003,2004,2005,2006 Darren Tucker.  All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -394,4 +394,58 @@ sshaix_getnameinfo(const struct sockaddr *sa, size_t salen, char *host,
 }
 # endif /* AIX_GETNAMEINFO_HACK */
 
+# if defined(USE_GETGRSET)
+#  include <stdlib.h>
+int
+getgrouplist(const char *user, gid_t pgid, gid_t *groups, int *grpcnt)
+{
+       char *cp, *grplist, *grp;
+       gid_t gid;
+       int ret = 0, ngroups = 0, maxgroups;
+       long l;
+
+       maxgroups = *grpcnt;
+
+       if ((cp = grplist = getgrset(user)) == NULL)
+               return -1;
+
+       /* handle zero-length case */
+       if (maxgroups <= 0) {
+               *grpcnt = 0;
+               return -1;
+       }
+
+       /* copy primary group */
+       groups[ngroups++] = pgid;
+
+       /* copy each entry from getgrset into group list */
+       while ((grp = strsep(&grplist, ",")) != NULL) {
+               l = strtol(grp, NULL, 10);
+               if (ngroups >= maxgroups || l == LONG_MIN || l == LONG_MAX) {
+                       ret = -1;
+                       goto out;
+               }
+               gid = (gid_t)l;
+               if (gid == pgid)
+                       continue;       /* we have already added primary gid */
+               groups[ngroups++] = gid;
+       }
+out:
+       free(cp);
+       *grpcnt = ngroups;
+       return ret;
+}
+
+int
+ssh_initgroups(const char *user, gid_t group)
+{
+       gid_t grps[NGROUPS_MAX];
+       int grpcnt = NGROUPS_MAX;
+
+       if (getgrouplist(user, group, grps, &grpcnt) == -1)
+               return -1;
+       return setgroups(grpcnt, grps);
+}
+# endif        /* USE_GETGRSET */
+
 #endif /* _AIX */
index eae82a9e0858549faec39a3021f16002e6fb1bb9..cd1c2c2ec5b311b44724f14226e44c3bc111fa19 100644 (file)
@@ -3,7 +3,7 @@
 /*
  *
  * Copyright (c) 2001 Gert Doering.  All rights reserved.
- * Copyright (c) 2004, 2005 Darren Tucker.  All rights reserved.
+ * Copyright (c) 2004,2005,2006 Darren Tucker.  All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -103,4 +103,16 @@ int sshaix_getnameinfo(const struct sockaddr *, size_t, char *, size_t,
 # define getnameinfo(a,b,c,d,e,f,g) (sshaix_getnameinfo(a,b,c,d,e,f,g))
 #endif
 
+/*
+ * We use getgrset in preference to multiple getgrent calls for efficiency
+ * plus it supports NIS and LDAP groups.
+ */
+#if !defined(HAVE_GETGROUPLIST) && defined(HAVE_GETGRSET)
+# define HAVE_GETGROUPLIST
+# define USE_GETGRSET
+int getgrouplist(const char *, gid_t, gid_t *, int *);
+int ssh_initgroups(const char *, gid_t);
+# define initgroups(a, b) ssh_initgroups((a), (b))
+#endif
+
 #endif /* _AIX */
This page took 4.030457 seconds and 5 git commands to generate.