"Fossies" - the Fresh Open Source Software Archive

Member "nss_ldap-265/ldap-rpc.c" (6 Nov 2009, 5737 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-rpc.c,v 2.30 2008/10/30 20:49:47 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-rpc.c,v 2.30 2008/10/30 20:49:47 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 
   49 #ifdef HAVE_RPC_RPCENT_H
   50 #include <rpc/rpcent.h>
   51 #else
   52 #include <netdb.h>
   53 #endif
   54 
   55 #ifdef HAVE_LBER_H
   56 #include <lber.h>
   57 #endif
   58 #ifdef HAVE_LDAP_H
   59 #include <ldap.h>
   60 #endif
   61 
   62 #include "ldap-nss.h"
   63 #include "ldap-rpc.h"
   64 #include "util.h"
   65 
   66 #ifdef HAVE_PORT_AFTER_H
   67 #include <port_after.h>
   68 #endif
   69 
   70 #if defined(HAVE_NSSWITCH_H) || defined(HAVE_NSS_H)
   71 
   72 #ifdef HAVE_NSS_H
   73 static ent_context_t *rpc_context = NULL;
   74 #endif
   75 
   76 static NSS_STATUS
   77 _nss_ldap_parse_rpc (LDAPMessage * e,
   78              ldap_state_t * pvt,
   79              void *result, char *buffer, size_t buflen)
   80 {
   81 
   82   struct rpcent *rpc = (struct rpcent *) result;
   83   char *number;
   84   NSS_STATUS stat;
   85 
   86   stat =
   87     _nss_ldap_getrdnvalue (e, ATM (LM_RPC, cn), &rpc->r_name, &buffer,
   88                            &buflen);
   89   if (stat != NSS_SUCCESS)
   90     return stat;
   91 
   92   stat =
   93     _nss_ldap_assign_attrval (e, AT (oncRpcNumber), &number, &buffer,
   94                   &buflen);
   95   if (stat != NSS_SUCCESS)
   96     return stat;
   97 
   98   stat =
   99     _nss_ldap_parse_int (number, 0, &rpc->r_number);
  100   if (stat != NSS_SUCCESS)
  101     return stat;
  102 
  103   stat =
  104     _nss_ldap_assign_attrvals (e, ATM (LM_RPC, cn), rpc->r_name,
  105                                &rpc->r_aliases, &buffer, &buflen, NULL);
  106   if (stat != NSS_SUCCESS)
  107     return stat;
  108 
  109   return NSS_SUCCESS;
  110 }
  111 
  112 #ifdef HAVE_NSSWITCH_H
  113 static NSS_STATUS
  114 _nss_ldap_getrpcbyname_r (nss_backend_t * be, void *args)
  115 {
  116   LOOKUP_NAME (args, _nss_ldap_filt_getrpcbyname, LM_RPC,
  117            _nss_ldap_parse_rpc, LDAP_NSS_BUFLEN_DEFAULT);
  118 }
  119 #elif defined(HAVE_NSS_H)
  120 NSS_STATUS
  121 _nss_ldap_getrpcbyname_r (const char *name, struct rpcent *result,
  122               char *buffer, size_t buflen, int *errnop)
  123 {
  124   LOOKUP_NAME (name, result, buffer, buflen, errnop,
  125            _nss_ldap_filt_getrpcbyname, LM_RPC, _nss_ldap_parse_rpc,
  126            LDAP_NSS_BUFLEN_DEFAULT);
  127 }
  128 #endif
  129 
  130 #ifdef HAVE_NSSWITCH_H
  131 static NSS_STATUS
  132 _nss_ldap_getrpcbynumber_r (nss_backend_t * be, void *args)
  133 {
  134   LOOKUP_NUMBER (args, key.number, _nss_ldap_filt_getrpcbynumber, LM_RPC,
  135          _nss_ldap_parse_rpc, LDAP_NSS_BUFLEN_DEFAULT);
  136 }
  137 #elif defined(HAVE_NSS_H)
  138 NSS_STATUS
  139 _nss_ldap_getrpcbynumber_r (int number, struct rpcent *result,
  140                 char *buffer, size_t buflen, int *errnop)
  141 {
  142   LOOKUP_NUMBER (number, result, buffer, buflen, errnop,
  143          _nss_ldap_filt_getrpcbynumber, LM_RPC, _nss_ldap_parse_rpc,
  144          LDAP_NSS_BUFLEN_DEFAULT);
  145 }
  146 #endif
  147 
  148 #ifdef HAVE_NSSWITCH_H
  149 static NSS_STATUS
  150 _nss_ldap_setrpcent_r (nss_backend_t * rpc_context, void *args)
  151 #elif defined(HAVE_NSS_H)
  152      NSS_STATUS _nss_ldap_setrpcent (void)
  153 #endif
  154 #if defined(HAVE_NSSWITCH_H) || defined(HAVE_NSS_H)
  155 {
  156   LOOKUP_SETENT (rpc_context);
  157 }
  158 #endif
  159 
  160 #ifdef HAVE_NSSWITCH_H
  161 static NSS_STATUS
  162 _nss_ldap_endrpcent_r (nss_backend_t * rpc_context, void *args)
  163 #elif defined(HAVE_NSS_H)
  164      NSS_STATUS _nss_ldap_endrpcent (void)
  165 #endif
  166 #if defined(HAVE_NSSWITCH_H) || defined(HAVE_NSS_H)
  167 {
  168   LOOKUP_ENDENT (rpc_context);
  169 }
  170 #endif
  171 
  172 #ifdef HAVE_NSSWITCH_H
  173 static NSS_STATUS
  174 _nss_ldap_getrpcent_r (nss_backend_t * rpc_context, void *args)
  175 {
  176   LOOKUP_GETENT (args, rpc_context, _nss_ldap_filt_getrpcent, LM_RPC,
  177          _nss_ldap_parse_rpc, LDAP_NSS_BUFLEN_DEFAULT);
  178 }
  179 #elif defined(HAVE_NSS_H)
  180 NSS_STATUS
  181 _nss_ldap_getrpcent_r (struct rpcent *result, char *buffer, size_t buflen,
  182                int *errnop)
  183 {
  184   LOOKUP_GETENT (rpc_context, result, buffer, buflen, errnop,
  185          _nss_ldap_filt_getrpcent, LM_RPC, _nss_ldap_parse_rpc,
  186          LDAP_NSS_BUFLEN_DEFAULT);
  187 }
  188 #endif
  189 
  190 #ifdef HAVE_NSSWITCH_H
  191 static NSS_STATUS
  192 _nss_ldap_rpc_destr (nss_backend_t * rpc_context, void *args)
  193 {
  194   return _nss_ldap_default_destr (rpc_context, args);
  195 }
  196 
  197 static nss_backend_op_t rpc_ops[] = {
  198   _nss_ldap_rpc_destr,
  199   _nss_ldap_endrpcent_r,
  200   _nss_ldap_setrpcent_r,
  201   _nss_ldap_getrpcent_r,
  202   _nss_ldap_getrpcbyname_r,
  203   _nss_ldap_getrpcbynumber_r
  204 };
  205 
  206 nss_backend_t *
  207 _nss_ldap_rpc_constr (const char *db_name,
  208               const char *src_name, const char *cfg_args)
  209 {
  210   nss_ldap_backend_t *be;
  211 
  212   if (!(be = (nss_ldap_backend_t *) malloc (sizeof (*be))))
  213     return NULL;
  214 
  215   be->ops = rpc_ops;
  216   be->n_ops = sizeof (rpc_ops) / sizeof (nss_backend_op_t);
  217 
  218   if (_nss_ldap_default_constr (be) != NSS_SUCCESS)
  219     return NULL;
  220 
  221   return (nss_backend_t *) be;
  222 }
  223 #endif /* HAVE_NSSWITCH_H */
  224 
  225 #endif /* !HAVE_IRS_H */