Back to index

glibc  2.9
nsswitch.h
Go to the documentation of this file.
00001 /* Copyright (C) 1996-1999,2001,2002,2003,2004,2007
00002    Free Software Foundation, Inc.
00003    This file is part of the GNU C Library.
00004 
00005    The GNU C Library is free software; you can redistribute it and/or
00006    modify it under the terms of the GNU Lesser General Public
00007    License as published by the Free Software Foundation; either
00008    version 2.1 of the License, or (at your option) any later version.
00009 
00010    The GNU C Library is distributed in the hope that it will be useful,
00011    but WITHOUT ANY WARRANTY; without even the implied warranty of
00012    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013    Lesser General Public License for more details.
00014 
00015    You should have received a copy of the GNU Lesser General Public
00016    License along with the GNU C Library; if not, write to the Free
00017    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
00018    02111-1307 USA.  */
00019 
00020 #ifndef _NSSWITCH_H
00021 #define _NSSWITCH_H  1
00022 
00023 /* This is an *internal* header.  */
00024 
00025 #include <arpa/nameser.h>
00026 #include <netinet/in.h>
00027 #include <nss.h>
00028 #include <resolv.h>
00029 #include <search.h>
00030 #include <dlfcn.h>
00031 
00032 /* Actions performed after lookup finished.  */
00033 typedef enum
00034 {
00035   NSS_ACTION_CONTINUE,
00036   NSS_ACTION_RETURN
00037 } lookup_actions;
00038 
00039 
00040 typedef struct service_library
00041 {
00042   /* Name of service (`files', `dns', `nis', ...).  */
00043   const char *name;
00044   /* Pointer to the loaded shared library.  */
00045   void *lib_handle;
00046   /* And the link to the next entry.  */
00047   struct service_library *next;
00048 } service_library;
00049 
00050 
00051 /* For mapping a function name to a function pointer.  It is known in
00052    nsswitch.c:nss_lookup_function that a string pointer for the lookup key
00053    is the first member.  */
00054 typedef struct
00055 {
00056   const char *fct_name;
00057   void *fct_ptr;
00058 } known_function;
00059 
00060 
00061 typedef struct service_user
00062 {
00063   /* And the link to the next entry.  */
00064   struct service_user *next;
00065   /* Action according to result.  */
00066   lookup_actions actions[5];
00067   /* Link to the underlying library object.  */
00068   service_library *library;
00069   /* Collection of known functions.  */
00070   void *known;
00071   /* Name of the service (`files', `dns', `nis', ...).  */
00072   char name[0];
00073 } service_user;
00074 
00075 /* To access the action based on the status value use this macro.  */
00076 #define nss_next_action(ni, status) ((ni)->actions[2 + status])
00077 
00078 
00079 typedef struct name_database_entry
00080 {
00081   /* And the link to the next entry.  */
00082   struct name_database_entry *next;
00083   /* List of service to be used.  */
00084   service_user *service;
00085   /* Name of the database.  */
00086   char name[0];
00087 } name_database_entry;
00088 
00089 
00090 typedef struct name_database
00091 {
00092   /* List of all known databases.  */
00093   name_database_entry *entry;
00094   /* List of libraries with service implementation.  */
00095   service_library *library;
00096 } name_database;
00097 
00098 
00099 /* Interface functions for NSS.  */
00100 
00101 /* Get the data structure representing the specified database.
00102    If there is no configuration for this database in the file,
00103    parse a service list from DEFCONFIG and use that.  More
00104    than one function can use the database.  */
00105 extern int __nss_database_lookup (const char *database,
00106                               const char *alternative_name,
00107                               const char *defconfig, service_user **ni);
00108 libc_hidden_proto (__nss_database_lookup)
00109 
00110 /* Put first function with name FCT_NAME for SERVICE in FCTP.  The
00111    position is remembered in NI.  The function returns a value < 0 if
00112    an error occurred or no such function exists.  */
00113 extern int __nss_lookup (service_user **ni, const char *fct_name,
00114                       const char *fct2_name, void **fctp) attribute_hidden;
00115 
00116 /* Determine the next step in the lookup process according to the
00117    result STATUS of the call to the last function returned by
00118    `__nss_lookup' or `__nss_next'.  NI specifies the last function
00119    examined.  The function return a value > 0 if the process should
00120    stop with the last result of the last function call to be the
00121    result of the entire lookup.  The returned value is 0 if there is
00122    another function to use and < 0 if an error occurred.
00123 
00124    If ALL_VALUES is nonzero, the return value will not be > 0 as long as
00125    there is a possibility the lookup process can ever use following
00126    services.  In other words, only if all four lookup results have
00127    the action RETURN associated the lookup process stops before the
00128    natural end.  */
00129 extern int __nss_next2 (service_user **ni, const char *fct_name,
00130                      const char *fct2_name, void **fctp, int status,
00131                      int all_values) attribute_hidden;
00132 libc_hidden_proto (__nss_next2)
00133 extern int __nss_next (service_user **ni, const char *fct_name, void **fctp,
00134                      int status, int all_values);
00135 
00136 /* Search for the service described in NI for a function named FCT_NAME
00137    and return a pointer to this function if successful.  */
00138 extern void *__nss_lookup_function (service_user *ni, const char *fct_name);
00139 libc_hidden_proto (__nss_lookup_function)
00140 
00141 
00142 /* Called by NSCD to disable recursive calls.  */
00143 extern void __nss_disable_nscd (void);
00144 
00145 
00146 typedef int (*db_lookup_function) (service_user **, const char *, const char *,
00147                                void **)
00148      internal_function;
00149 typedef enum nss_status (*setent_function) (int);
00150 typedef enum nss_status (*endent_function) (void);
00151 typedef enum nss_status (*getent_function) (void *, char *, size_t,
00152                                        int *, int *);
00153 typedef int (*getent_r_function) (void *, char *, size_t,
00154                               void **result, int *);
00155 
00156 extern void __nss_setent (const char *func_name,
00157                        db_lookup_function lookup_fct,
00158                        service_user **nip, service_user **startp,
00159                        service_user **last_nip, int stayon,
00160                        int *stayon_tmp, int res);
00161 extern void __nss_endent (const char *func_name,
00162                        db_lookup_function lookup_fct,
00163                        service_user **nip, service_user **startp,
00164                        service_user **last_nip, int res);
00165 extern int __nss_getent_r (const char *getent_func_name,
00166                         const char *setent_func_name,
00167                         db_lookup_function lookup_fct,
00168                         service_user **nip, service_user **startp,
00169                         service_user **last_nip, int *stayon_tmp,
00170                         int res,
00171                         void *resbuf, char *buffer, size_t buflen,
00172                         void **result, int *h_errnop);
00173 extern void *__nss_getent (getent_r_function func,
00174                         void **resbuf, char **buffer, size_t buflen,
00175                         size_t *buffer_size, int *h_errnop);
00176 struct hostent;
00177 extern int __nss_hostname_digits_dots (const char *name,
00178                                    struct hostent *resbuf, char **buffer,
00179                                    size_t *buffer_size, size_t buflen,
00180                                    struct hostent **result,
00181                                    enum nss_status *status, int af,
00182                                    int *h_errnop);
00183 libc_hidden_proto (__nss_hostname_digits_dots)
00184 
00185 #endif /* nsswitch.h */