diff options
author | scheidell <scheidell@FreeBSD.org> | 2011-12-04 02:45:42 +0800 |
---|---|---|
committer | scheidell <scheidell@FreeBSD.org> | 2011-12-04 02:45:42 +0800 |
commit | 32b823af8b1c633fce716a177d8b2bd5eb263c19 (patch) | |
tree | 3c9f2cd0f333a87f7f895378ef2298ba9a73de9c /net/nss_ldap | |
parent | 01fb9eebc1d62ea1a186b6ae2ab905664910fc52 (diff) | |
download | freebsd-ports-gnome-32b823af8b1c633fce716a177d8b2bd5eb263c19.tar.gz freebsd-ports-gnome-32b823af8b1c633fce716a177d8b2bd5eb263c19.tar.zst freebsd-ports-gnome-32b823af8b1c633fce716a177d8b2bd5eb263c19.zip |
-Fix nss_initgroups_ignoreusers (add patch to bsdnss.c)
PR: 152982
Submitted by: kmenshikov@peterhost.ru
Approved by: mentor (timeout), gabor (mentor)
Obtained from: http://lists.freebsd.org/pipermail/freebsd-current/2007-July/075131.html
Feature safe: yes
Diffstat (limited to 'net/nss_ldap')
-rw-r--r-- | net/nss_ldap/Makefile | 2 | ||||
-rw-r--r-- | net/nss_ldap/files/bsdnss.c | 61 |
2 files changed, 62 insertions, 1 deletions
diff --git a/net/nss_ldap/Makefile b/net/nss_ldap/Makefile index 306c16b4d9d0..f0fa322a6203 100644 --- a/net/nss_ldap/Makefile +++ b/net/nss_ldap/Makefile @@ -7,7 +7,7 @@ PORTNAME= nss_ldap PORTVERSION= 1.${NSS_LDAP_VERSION} -PORTREVISION= 6 +PORTREVISION= 7 CATEGORIES= net MASTER_SITES= http://www.padl.com/download/ \ LOCAL/martymac diff --git a/net/nss_ldap/files/bsdnss.c b/net/nss_ldap/files/bsdnss.c index f1ccde3a03d8..8b1601454ac1 100644 --- a/net/nss_ldap/files/bsdnss.c +++ b/net/nss_ldap/files/bsdnss.c @@ -1,9 +1,11 @@ #include <errno.h> +#include <stdlib.h> #include <sys/param.h> #include <netinet/in.h> #include <pwd.h> #include <grp.h> #include <nss.h> +#include <nsswitch.h> #include <netdb.h> extern enum nss_status _nss_ldap_getgrent_r(struct group *, char *, size_t, @@ -14,6 +16,8 @@ extern enum nss_status _nss_ldap_getgrgid_r(gid_t gid, struct group *, char *, size_t, int *); extern enum nss_status _nss_ldap_setgrent(void); extern enum nss_status _nss_ldap_endgrent(void); +extern enum nss_status _nss_ldap_initgroups_dyn(const char *, gid_t, long int *, + long int *, gid_t **, long int, int *); extern enum nss_status _nss_ldap_getpwent_r(struct passwd *, char *, size_t, int *); @@ -40,6 +44,7 @@ NSS_METHOD_PROTOTYPE(__nss_compat_getgrgid_r); NSS_METHOD_PROTOTYPE(__nss_compat_getgrent_r); NSS_METHOD_PROTOTYPE(__nss_compat_setgrent); NSS_METHOD_PROTOTYPE(__nss_compat_endgrent); +static NSS_METHOD_PROTOTYPE(__freebsd_getgroupmembership); NSS_METHOD_PROTOTYPE(__nss_compat_getpwnam_r); NSS_METHOD_PROTOTYPE(__nss_compat_getpwuid_r); @@ -57,6 +62,7 @@ static ns_mtab methods[] = { { NSDB_GROUP, "getgrent_r", __nss_compat_getgrent_r, _nss_ldap_getgrent_r }, { NSDB_GROUP, "setgrent", __nss_compat_setgrent, _nss_ldap_setgrent }, { NSDB_GROUP, "endgrent", __nss_compat_endgrent, _nss_ldap_endgrent }, +{ NSDB_GROUP, "getgroupmembership", __freebsd_getgroupmembership, NULL }, { NSDB_PASSWD, "getpwnam_r", __nss_compat_getpwnam_r, _nss_ldap_getpwnam_r }, { NSDB_PASSWD, "getpwuid_r", __nss_compat_getpwuid_r, _nss_ldap_getpwuid_r }, @@ -156,3 +162,58 @@ int __nss_compat_gethostbyaddr(void *retval, void *mdata, va_list ap) h_errno = h_errnop; return (status); } + +static int +__gr_addgid(gid_t gid, gid_t *groups, int maxgrp, int *groupc) +{ + int ret, dupc; + + /* skip duplicates */ + for (dupc = 0; dupc < MIN(maxgrp, *groupc); dupc++) { + if (groups[dupc] == gid) + return 1; + } + + ret = 1; + if (*groupc < maxgrp) /* add this gid */ + groups[*groupc] = gid; + else + ret = 0; + (*groupc)++; + return ret; +} + +static int __freebsd_getgroupmembership(void *retval, void *mdata, va_list ap) +{ + int err; + enum nss_status s; + const char *user = va_arg(ap, const char *); + gid_t group = va_arg(ap, gid_t); + gid_t *groups = va_arg(ap, gid_t *); + int limit = va_arg(ap, int); + int *size = va_arg(ap, int*); + gid_t *tmpgroups; + long int lstart, lsize; + int i; + + tmpgroups = malloc(limit * sizeof(gid_t)); + if (tmpgroups == NULL) + return NS_TRYAGAIN; + + /* insert primary membership */ + __gr_addgid(group, groups, limit, size); + + lstart = 0; + lsize = limit; + s = _nss_ldap_initgroups_dyn(user, group, &lstart, &lsize, + &tmpgroups, 0, &err); + if (s == NSS_STATUS_SUCCESS) { + for (i = 0; i < lstart; i++) + __gr_addgid(tmpgroups[i], groups, limit, size); + s = NSS_STATUS_NOTFOUND; + } + + free(tmpgroups); + + return __nss_compat_result(s, err); +} |