"Fossies" - the Fresh Open Source Software Archive

Member "nss_ldap-265/ldap-proto.c" (6 Nov 2009, 5733 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    $Id: ldap-proto.c,v 2.30 2006/01/11 18:03:49 lukeh Exp $
   21  */
   22 
   23 /*
   24    Determine the canonical name of the RPC with _nss_ldap_getrdnvalue(),
   25    and assign any values of "cn" which do NOT match this canonical name
   26    as aliases.
   27  */
   28 
   29 
   30 static char rcsId[] =
   31   "$Id: ldap-proto.c,v 2.30 2006/01/11 18:03:49 lukeh Exp $";
   32 
   33 #include "config.h"
   34 
   35 #ifdef HAVE_PORT_BEFORE_H
   36 #include <port_before.h>
   37 #endif
   38 
   39 #if defined(HAVE_THREAD_H) && !defined(_AIX)
   40 #include <thread.h>
   41 #elif defined(HAVE_PTHREAD_H)
   42 #include <pthread.h>
   43 #endif
   44 
   45 #include <stdio.h>
   46 #include <stdlib.h>
   47 #include <string.h>
   48 #include <netdb.h>
   49 
   50 #ifdef HAVE_LBER_H
   51 #include <lber.h>
   52 #endif
   53 #ifdef HAVE_LDAP_H
   54 #include <ldap.h>
   55 #endif
   56 
   57 #include "ldap-nss.h"
   58 #include "ldap-proto.h"
   59 #include "util.h"
   60 
   61 #ifdef HAVE_PORT_AFTER_H
   62 #include <port_after.h>
   63 #endif
   64 
   65 #ifdef HAVE_NSS_H
   66 static ent_context_t *proto_context = NULL;
   67 #endif
   68 
   69 static NSS_STATUS
   70 _nss_ldap_parse_proto (LDAPMessage * e,
   71                ldap_state_t * pvt,
   72                void *result, char *buffer, size_t buflen)
   73 {
   74 
   75   struct protoent *proto = (struct protoent *) result;
   76   char *number;
   77   NSS_STATUS stat;
   78 
   79   stat =
   80     _nss_ldap_getrdnvalue (e, ATM (LM_PROTOCOLS, cn), &proto->p_name,
   81                            &buffer, &buflen);
   82   if (stat != NSS_SUCCESS)
   83     return stat;
   84 
   85   stat =
   86     _nss_ldap_assign_attrval (e, AT (ipProtocolNumber), &number, &buffer,
   87                   &buflen);
   88   if (stat != NSS_SUCCESS)
   89     return stat;
   90 
   91   proto->p_proto = atoi (number);
   92 
   93   stat =
   94     _nss_ldap_assign_attrvals (e, ATM (LM_PROTOCOLS, cn), proto->p_name,
   95                    &proto->p_aliases, &buffer, &buflen, NULL);
   96   if (stat != NSS_SUCCESS)
   97     return stat;
   98 
   99   return NSS_SUCCESS;
  100 }
  101 
  102 #ifdef HAVE_NSSWITCH_H
  103 static NSS_STATUS
  104 _nss_ldap_getprotobyname_r (nss_backend_t * be, void *args)
  105 {
  106   LOOKUP_NAME (args, _nss_ldap_filt_getprotobyname, LM_PROTOCOLS,
  107            _nss_ldap_parse_proto, LDAP_NSS_BUFLEN_DEFAULT);
  108 }
  109 #elif defined(HAVE_NSS_H)
  110 NSS_STATUS
  111 _nss_ldap_getprotobyname_r (const char *name, struct protoent *result,
  112                 char *buffer, size_t buflen, int *errnop)
  113 {
  114   LOOKUP_NAME (name, result, buffer, buflen, errnop,
  115            _nss_ldap_filt_getprotobyname, LM_PROTOCOLS,
  116            _nss_ldap_parse_proto, LDAP_NSS_BUFLEN_DEFAULT);
  117 }
  118 #endif
  119 
  120 #ifdef HAVE_NSSWITCH_H
  121 static NSS_STATUS
  122 _nss_ldap_getprotobynumber_r (nss_backend_t * be, void *args)
  123 {
  124   LOOKUP_NUMBER (args, key.number, _nss_ldap_filt_getprotobynumber,
  125          LM_PROTOCOLS, _nss_ldap_parse_proto, LDAP_NSS_BUFLEN_DEFAULT);
  126 }
  127 #elif defined(HAVE_NSS_H)
  128 NSS_STATUS
  129 _nss_ldap_getprotobynumber_r (int number, struct protoent *result,
  130                   char *buffer, size_t buflen, int *errnop)
  131 {
  132   LOOKUP_NUMBER (number, result, buffer, buflen, errnop,
  133          _nss_ldap_filt_getprotobynumber, LM_PROTOCOLS,
  134          _nss_ldap_parse_proto, LDAP_NSS_BUFLEN_DEFAULT);
  135 }
  136 #endif
  137 
  138 #ifdef HAVE_NSSWITCH_H
  139 static NSS_STATUS
  140 _nss_ldap_setprotoent_r (nss_backend_t * proto_context, void *fakeargs)
  141 #elif defined(HAVE_NSS_H)
  142      NSS_STATUS _nss_ldap_setprotoent (void)
  143 #endif
  144 #if defined(HAVE_NSS_H) || defined(HAVE_NSSWITCH_H)
  145 {
  146   LOOKUP_SETENT (proto_context);
  147 }
  148 #endif
  149 
  150 #ifdef HAVE_NSSWITCH_H
  151 static NSS_STATUS
  152 _nss_ldap_endprotoent_r (nss_backend_t * proto_context, void *fakeargs)
  153 #elif defined(HAVE_NSS_H)
  154      NSS_STATUS _nss_ldap_endprotoent (void)
  155 #endif
  156 #if defined(HAVE_NSS_H) || defined(HAVE_NSSWITCH_H)
  157 {
  158   LOOKUP_ENDENT (proto_context);
  159 }
  160 #endif
  161 
  162 #ifdef HAVE_NSSWITCH_H
  163 static NSS_STATUS
  164 _nss_ldap_getprotoent_r (nss_backend_t * proto_context, void *args)
  165 {
  166   LOOKUP_GETENT (args, proto_context, _nss_ldap_filt_getprotoent,
  167          LM_PROTOCOLS, _nss_ldap_parse_proto, LDAP_NSS_BUFLEN_DEFAULT);
  168 }
  169 #elif defined(HAVE_NSS_H)
  170 NSS_STATUS
  171 _nss_ldap_getprotoent_r (struct protoent *result, char *buffer, size_t buflen,
  172              int *errnop)
  173 {
  174   LOOKUP_GETENT (proto_context, result, buffer, buflen, errnop,
  175          _nss_ldap_filt_getprotoent, LM_PROTOCOLS,
  176          _nss_ldap_parse_proto, LDAP_NSS_BUFLEN_DEFAULT);
  177 }
  178 #endif
  179 
  180 #ifdef HAVE_NSSWITCH_H
  181 static NSS_STATUS
  182 _nss_ldap_protocols_destr (nss_backend_t * proto_context, void *args)
  183 {
  184   return _nss_ldap_default_destr (proto_context, args);
  185 }
  186 
  187 static nss_backend_op_t proto_ops[] = {
  188   _nss_ldap_protocols_destr,
  189   _nss_ldap_endprotoent_r,
  190   _nss_ldap_setprotoent_r,
  191   _nss_ldap_getprotoent_r,
  192   _nss_ldap_getprotobyname_r,
  193   _nss_ldap_getprotobynumber_r
  194 };
  195 
  196 nss_backend_t *
  197 _nss_ldap_protocols_constr (const char *db_name,
  198                 const char *src_name, const char *cfg_args)
  199 {
  200   nss_ldap_backend_t *be;
  201 
  202   if (!(be = (nss_ldap_backend_t *) malloc (sizeof (*be))))
  203     return NULL;
  204 
  205   be->ops = proto_ops;
  206   be->n_ops = sizeof (proto_ops) / sizeof (nss_backend_op_t);
  207 
  208   if (_nss_ldap_default_constr (be) != NSS_SUCCESS)
  209     return NULL;
  210 
  211   return (nss_backend_t *) be;
  212 }
  213 
  214 #endif /* !HAVE_NSS_H */
  215 
  216 #ifdef HAVE_IRS_H
  217 #include "irs-proto.c"
  218 #endif