"Fossies" - the Fresh Open Source Software Archive

Member "nss_ldap-265/irs-grp.c" (6 Nov 2009, 2974 Bytes) of package /linux/privat/old/nss_ldap-265.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

    1 /* Copyright (C) 1997-2005 Luke Howard.
    2    This file is part of the nss_ldap library.
    3    Contributed by Luke Howard, <lukeh@padl.com>, 1997.
    4 
    5    The nss_ldap library is free software; you can redistribute it and/or
    6    modify it under the terms of the GNU Library General Public License as
    7    published by the Free Software Foundation; either version 2 of the
    8    License, or (at your option) any later version.
    9 
   10    The nss_ldap library is distributed in the hope that it will be useful,
   11    but WITHOUT ANY WARRANTY; without even the implied warranty of
   12    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   13    Library General Public License for more details.
   14 
   15    You should have received a copy of the GNU Library General Public
   16    License along with the nss_ldap library; see the file COPYING.LIB.  If not,
   17    write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
   18    Boston, MA 02111-1307, USA.
   19  */
   20 
   21 #ifdef HAVE_IRS_H
   22 
   23 #include <errno.h>
   24 #include "irs-nss.h"
   25 
   26 /* $Id: irs-grp.c,v 2.26 2005/05/20 05:30:39 lukeh Exp $ */
   27 
   28 #ifdef HAVE_USERSEC_H
   29 void *gr_pvtinit (void);
   30 #endif
   31 IRS_EXPORT void gr_close (struct irs_gr *);
   32 IRS_EXPORT struct group *gr_next (struct irs_gr *);
   33 IRS_EXPORT struct group *gr_byname (struct irs_gr *, const char *);
   34 IRS_EXPORT struct group *gr_bygid (struct irs_gr *, gid_t);
   35 IRS_EXPORT void gr_rewind (struct irs_gr *);
   36 IRS_EXPORT void gr_minimize (struct irs_gr *);
   37 
   38 struct pvt
   39 {
   40   struct group result;
   41   char buffer[NSS_BUFLEN_GROUP];
   42   ent_context_t *state;
   43 };
   44 
   45 IRS_EXPORT struct group *
   46 gr_byname (struct irs_gr *this, const char *name)
   47 {
   48   LOOKUP_NAME (name, this, _nss_ldap_filt_getgrnam, LM_GROUP,
   49            _nss_ldap_parse_gr, NSS_BUFLEN_GROUP);
   50 }
   51 
   52 IRS_EXPORT struct group *
   53 gr_bygid (struct irs_gr *this, gid_t gid)
   54 {
   55   LOOKUP_NUMBER (gid, this, _nss_ldap_filt_getgrgid, LM_GROUP,
   56          _nss_ldap_parse_gr, NSS_BUFLEN_GROUP);
   57 }
   58 
   59 IRS_EXPORT void
   60 gr_close (struct irs_gr *this)
   61 {
   62   LOOKUP_ENDENT (this);
   63 #ifdef HAVE_USERSEC_H
   64   free (this->private);
   65   free (this);
   66 #endif
   67 }
   68 
   69 IRS_EXPORT struct group *
   70 gr_next (struct irs_gr *this)
   71 {
   72   LOOKUP_GETENT (this, _nss_ldap_filt_getgrent, LM_GROUP, _nss_ldap_parse_gr,
   73          NSS_BUFLEN_GROUP);
   74 }
   75 
   76 IRS_EXPORT void
   77 gr_rewind (struct irs_gr *this)
   78 {
   79   LOOKUP_SETENT (this);
   80 }
   81 
   82 IRS_EXPORT void
   83 gr_minimize (struct irs_gr *this)
   84 {
   85 }
   86 
   87 #ifdef HAVE_USERSEC_H
   88 void *
   89 gr_pvtinit (void)
   90 #else
   91 struct irs_gr *
   92 irs_ldap_gr (struct irs_acc *this)
   93 #endif
   94 {
   95   struct irs_gr *gr;
   96   struct pvt *pvt;
   97 
   98   gr = calloc (1, sizeof (*gr));
   99   if (gr == NULL)
  100     return NULL;
  101 
  102   pvt = calloc (1, sizeof (*pvt));
  103   if (pvt == NULL)
  104     {
  105       free (gr);
  106       return NULL;
  107     }
  108 
  109   pvt->state = NULL;
  110   gr->private = pvt;
  111   gr->close = gr_close;
  112   gr->next = gr_next;
  113   gr->byname = gr_byname;
  114   gr->bygid = gr_bygid;
  115 #ifndef HAVE_USERSEC_H
  116   gr->list = make_group_list;
  117 #else
  118   gr->list = NULL;
  119 #endif
  120   gr->rewind = gr_rewind;
  121   gr->minimize = gr_minimize;
  122   return gr;
  123 }
  124 
  125 #endif /* HAVE_IRS_H */