diff options
author | Arthur de Jong <arthur@arthurdejong.org> | 2010-10-15 13:22:47 +0200 |
---|---|---|
committer | Arthur de Jong <arthur@arthurdejong.org> | 2010-10-15 13:22:47 +0200 |
commit | 4ea9ad10160da3dcb572527c7ea9dcaa8182bc6a (patch) | |
tree | 370d24c1eeb32723b800f2507e5c010598cafc49 /nss | |
parent | 1fab81db27cbe228d576ce5bda756d3af42e3817 (diff) |
switch to using SETs to follow the netgroups
git-svn-id: http://arthurdejong.org/svn/nss-pam-ldapd/nss-pam-ldapd-solaris@1281 ef36b2f9-881f-0410-afb5-c4e39611909c
Diffstat (limited to 'nss')
-rw-r--r-- | nss/Makefile.am | 3 | ||||
-rw-r--r-- | nss/common.c | 91 | ||||
-rw-r--r-- | nss/common.h | 12 | ||||
-rw-r--r-- | nss/netgroup.c | 61 |
4 files changed, 23 insertions, 144 deletions
diff --git a/nss/Makefile.am b/nss/Makefile.am index 4c790bd..d16eba6 100644 --- a/nss/Makefile.am +++ b/nss/Makefile.am @@ -33,6 +33,9 @@ EXTRA_nss_ldap_so_SOURCES = aliases.c ethers.c group.c hosts.c netgroup.c \ shadow.c nss_ldap_so_DEPENDENCIES = $(NSS_MODULE_OBJS) nss_ldap_so_LDADD = $(NSS_MODULE_OBJS) ../common/libtio.a ../common/libprot.a +if NSS_FLAVOUR_SOLARIS +nss_ldap_so_LDADD += ../common/libdict.a +endif EXTRA_DIST = exports.glibc exports.solaris diff --git a/nss/common.c b/nss/common.c index c3c0616..20a3136 100644 --- a/nss/common.c +++ b/nss/common.c @@ -1,8 +1,7 @@ /* - common.c - common functions for NSS lookups + common.c - common definitions Copyright (C) 2010 Arthur de Jong - Copyright (C) 2010 Symas Corporation This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public @@ -20,92 +19,4 @@ 02110-1301 USA */ -#include "config.h" - -#ifdef HAVE_STDINT_H -#include <stdint.h> -#endif /* HAVE_STDINT_H */ -#include <unistd.h> -#include <stdio.h> -#include <sys/socket.h> -#include <sys/un.h> -#include <sys/types.h> -#include <sys/stat.h> -#include <errno.h> -#ifdef HAVE_NSS_H -#include <nss.h> -#endif /* HAVE_NSS_H */ -#include <string.h> - -#include "nslcd.h" -#include "common.h" -#include "common/tio.h" - -/* flag used to disable NSS lookups using this module */ int _nss_ldap_enablelookups=1; - -#ifdef NSS_FLAVOUR_SOLARIS -/* Adapted from PADL */ - -/* add a nested netgroup or group to the namelist */ -nss_status_t _nss_ldap_namelist_push(struct name_list **head,const char *name) -{ - struct name_list *nl; - nl=(struct name_list *)malloc(sizeof(*nl)); - if (nl==NULL) - return NSS_STATUS_TRYAGAIN; - nl->name=strdup(name); - if (nl->name==NULL) - { - free(nl); - return NSS_STATUS_TRYAGAIN; - } - nl->next=*head; - *head=nl; - return NSS_STATUS_SUCCESS; -} - -/* remove last nested netgroup or group from the namelist */ -void _nss_ldap_namelist_pop(struct name_list **head) -{ - struct name_list *nl; - nl=*head; - *head=nl->next; - free(nl->name); - free(nl); -} - -/* cleanup nested netgroup or group namelist */ -void _nss_ldap_namelist_destroy(struct name_list **head) -{ - struct name_list *p,*next; - for (p=*head;p!=NULL;p=next) - { - next=p->next; - if (p->name!=NULL) - free(p->name); - free(p); - } - *head=NULL; -} - -/* - *Check whether we have already seen a netgroup or group, - *to avoid loops in nested netgroup traversal - */ -int _nss_ldap_namelist_find(struct name_list *head,const char *netgroup) -{ - struct name_list *p; - int found=0; - for (p=head;p!=NULL;p=p->next) - { - if (strcasecmp(p->name,netgroup)==0) - { - found++; - break; - } - } - return found; -} - -#endif /* NSS_FLAVOUR_SOLARIS */ diff --git a/nss/common.h b/nss/common.h index ffb718f..f1bd73e 100644 --- a/nss/common.h +++ b/nss/common.h @@ -31,18 +31,6 @@ #include "compat/attrs.h" #include "compat/nss_compat.h" -/* Adapted from PADL */ -/* Routines for managing namelists */ -struct name_list -{ - char *name; - struct name_list *next; -}; -nss_status_t _nss_ldap_namelist_push(struct name_list **head,const char *name); -void _nss_ldap_namelist_pop(struct name_list **head); -int _nss_ldap_namelist_find(struct name_list *head,const char *netgroup); -void _nss_ldap_namelist_destroy(struct name_list **head); - /* These are macros for handling read and write problems, they are NSS specific due to the return code so are defined here. They genrally close the open file, set an error code and return with diff --git a/nss/netgroup.c b/nss/netgroup.c index 4ad50e7..1531cc4 100644 --- a/nss/netgroup.c +++ b/nss/netgroup.c @@ -30,6 +30,7 @@ #include "prototypes.h" #include "common.h" #include "compat/attrs.h" +#include "common/set.h" /* we redefine this here because we need to return NSS_STATUS_RETURN instead of NSS_STATUS_NOTFOUND */ @@ -146,8 +147,8 @@ struct nss_ldap_netgr_backend nss_backend_op_t *ops; int n_ops; ent_context_t *state; - struct name_list *known_groups; /* netgroups seen, for loop detection */ - struct name_list *needed_groups; /* nested netgroups to chase */ + SET *known_groups; /* netgroups seen, for loop detection */ + SET *needed_groups; /* nested netgroups to chase */ }; typedef struct nss_ldap_netgr_backend nss_ldap_netgr_backend_t; @@ -157,35 +158,20 @@ static nss_status_t _xnss_ldap_setnetgrent(nss_backend_t UNUSED(*be),void UNUSED } /* find a netgroup that has not been traversed */ -static char *_nss_ldap_chase_netgroup(nss_ldap_netgr_backend_t *ngbe) +static char *find_unseen_netgroup(nss_ldap_netgr_backend_t *ngbe) { - nss_status_t status; - char *group=NULL; - int found=0; - if (!ngbe->needed_groups) - { - /* exhausted all netgroups */ - return NULL; - } - while (ngbe->needed_groups&&!found) + char *group; + while (1) { - if (_nss_ldap_namelist_find(ngbe->known_groups, - ngbe->needed_groups->name)) + group=set_pop(ngbe->needed_groups); + if (group==NULL) + return NULL; + if (set_contains(ngbe->known_groups,group)) { - /* netgroup seen before,ignore it */ - _nss_ldap_namelist_pop(&ngbe->needed_groups); + set_add(ngbe->known_groups,group); + return group; } - else - found=1; - } - if (found) - { - group=strdup(ngbe->needed_groups->name); - status=_nss_ldap_namelist_push(&ngbe->known_groups, - ngbe->needed_groups->name); - _nss_ldap_namelist_pop(&ngbe->needed_groups); } - return group; } /* thread-local file pointer to an ongoing request */ @@ -236,7 +222,7 @@ static nss_status_t _xnss_ldap_getnetgrent_r(nss_backend_t *_be,void *_args) while (!found) { /* find a nested netgroup to pursue further */ - group=_nss_ldap_chase_netgroup(ngbe); + group=find_unseen_netgroup(ngbe); if (!group) { /* no more netgroup */ @@ -263,11 +249,7 @@ static nss_status_t _xnss_ldap_getnetgrent_r(nss_backend_t *_be,void *_args) if (result.type==group_val) { /* a netgroup nested within the current netgroup */ - rc=_nss_ldap_namelist_push(&ngbe->needed_groups,result.val.group); - if (rc!=NSS_STATUS_SUCCESS) - { - /* unable to push the group name for later netgroup */ - } + set_add(ngbe->needed_groups,result.val.group); } else if (result.type==triple_val) { @@ -298,8 +280,8 @@ static nss_status_t destructor(nss_backend_t *be,void UNUSED(*args)) { nss_ldap_netgr_backend_t *ngbe=(nss_ldap_netgr_backend_t *)be; /* free list of nested netgroups */ - _nss_ldap_namelist_destroy(&ngbe->known_groups); - _nss_ldap_namelist_destroy(&ngbe->needed_groups); + set_free(ngbe->known_groups); + set_free(ngbe->needed_groups); free(ngbe); return NSS_STATUS_SUCCESS; } @@ -338,12 +320,7 @@ static nss_status_t _xnss_ldap_netgr_set(nss_backend_t *be,void *_args) return stat; } /* place the group name in known list */ - stat=_nss_ldap_namelist_push(&ngbe->known_groups,args->netgroup); - if (stat!=NSS_STATUS_SUCCESS) - { - destructor((nss_backend_t *)ngbe,NULL); - return stat; - } + set_add(ngbe->known_groups,args->netgroup); args->iterator=(nss_backend_t *)ngbe; return stat; } @@ -356,8 +333,8 @@ nss_backend_t *_nss_ldap_netgroup_constr(const char UNUSED(*db_name), return NULL; be->ops=netgroup_ops; be->n_ops=sizeof(netgroup_ops)/sizeof(nss_backend_op_t); - be->known_groups=NULL; - be->needed_groups=NULL; + be->known_groups=set_new(); + be->needed_groups=set_new(); return (nss_backend_t *)be; } |