nss_db: Quash read implicit declaration warning
[platform/upstream/glibc.git] / nss / nsswitch.h
1 /* Copyright (C) 1996-1999,2001,2002,2003,2004,2007,2010
2    Free Software Foundation, Inc.
3    This file is part of the GNU C Library.
4
5    The GNU C Library is free software; you can redistribute it and/or
6    modify it under the terms of the GNU Lesser General Public
7    License as published by the Free Software Foundation; either
8    version 2.1 of the License, or (at your option) any later version.
9
10    The GNU C 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    Lesser General Public License for more details.
14
15    You should have received a copy of the GNU Lesser General Public
16    License along with the GNU C Library; if not, write to the Free
17    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
18    02111-1307 USA.  */
19
20 #ifndef _NSSWITCH_H
21 #define _NSSWITCH_H     1
22
23 /* This is an *internal* header.  */
24
25 #include <arpa/nameser.h>
26 #include <netinet/in.h>
27 #include <nss.h>
28 #include <resolv.h>
29 #include <search.h>
30 #include <dlfcn.h>
31 #include <stdbool.h>
32
33 /* Actions performed after lookup finished.  */
34 typedef enum
35 {
36   NSS_ACTION_CONTINUE,
37   NSS_ACTION_RETURN
38 } lookup_actions;
39
40
41 typedef struct service_library
42 {
43   /* Name of service (`files', `dns', `nis', ...).  */
44   const char *name;
45   /* Pointer to the loaded shared library.  */
46   void *lib_handle;
47   /* And the link to the next entry.  */
48   struct service_library *next;
49 } service_library;
50
51
52 /* For mapping a function name to a function pointer.  It is known in
53    nsswitch.c:nss_lookup_function that a string pointer for the lookup key
54    is the first member.  */
55 typedef struct
56 {
57   const char *fct_name;
58   void *fct_ptr;
59 } known_function;
60
61
62 typedef struct service_user
63 {
64   /* And the link to the next entry.  */
65   struct service_user *next;
66   /* Action according to result.  */
67   lookup_actions actions[5];
68   /* Link to the underlying library object.  */
69   service_library *library;
70   /* Collection of known functions.  */
71   void *known;
72   /* Name of the service (`files', `dns', `nis', ...).  */
73   char name[0];
74 } service_user;
75
76 /* To access the action based on the status value use this macro.  */
77 #define nss_next_action(ni, status) ((ni)->actions[2 + status])
78
79
80 typedef struct name_database_entry
81 {
82   /* And the link to the next entry.  */
83   struct name_database_entry *next;
84   /* List of service to be used.  */
85   service_user *service;
86   /* Name of the database.  */
87   char name[0];
88 } name_database_entry;
89
90
91 typedef struct name_database
92 {
93   /* List of all known databases.  */
94   name_database_entry *entry;
95   /* List of libraries with service implementation.  */
96   service_library *library;
97 } name_database;
98
99
100 /* Indices into DATABASES in nsswitch.c and __NSS_DATABASE_CUSTOM.  */
101 enum
102   {
103 #define DEFINE_DATABASE(arg) NSS_DBSIDX_##arg,
104 #include "databases.def"
105 #undef DEFINE_DATABASE
106     NSS_DBSIDX_max
107   };
108
109 /* Flags whether custom rules for database is set.  */
110 extern bool __nss_database_custom[NSS_DBSIDX_max];
111
112
113 /* Interface functions for NSS.  */
114
115 /* Get the data structure representing the specified database.
116    If there is no configuration for this database in the file,
117    parse a service list from DEFCONFIG and use that.  More
118    than one function can use the database.  */
119 extern int __nss_database_lookup (const char *database,
120                                   const char *alternative_name,
121                                   const char *defconfig, service_user **ni);
122 libc_hidden_proto (__nss_database_lookup)
123
124 /* Put first function with name FCT_NAME for SERVICE in FCTP.  The
125    position is remembered in NI.  The function returns a value < 0 if
126    an error occurred or no such function exists.  */
127 extern int __nss_lookup (service_user **ni, const char *fct_name,
128                          const char *fct2_name, void **fctp) attribute_hidden;
129
130 /* Determine the next step in the lookup process according to the
131    result STATUS of the call to the last function returned by
132    `__nss_lookup' or `__nss_next'.  NI specifies the last function
133    examined.  The function return a value > 0 if the process should
134    stop with the last result of the last function call to be the
135    result of the entire lookup.  The returned value is 0 if there is
136    another function to use and < 0 if an error occurred.
137
138    If ALL_VALUES is nonzero, the return value will not be > 0 as long as
139    there is a possibility the lookup process can ever use following
140    services.  In other words, only if all four lookup results have
141    the action RETURN associated the lookup process stops before the
142    natural end.  */
143 extern int __nss_next2 (service_user **ni, const char *fct_name,
144                         const char *fct2_name, void **fctp, int status,
145                         int all_values) attribute_hidden;
146 libc_hidden_proto (__nss_next2)
147 extern int __nss_next (service_user **ni, const char *fct_name, void **fctp,
148                        int status, int all_values);
149
150 /* Search for the service described in NI for a function named FCT_NAME
151    and return a pointer to this function if successful.  */
152 extern void *__nss_lookup_function (service_user *ni, const char *fct_name);
153 libc_hidden_proto (__nss_lookup_function)
154
155
156 /* Called by NSCD to disable recursive calls.  */
157 extern void __nss_disable_nscd (void);
158
159
160 typedef int (*db_lookup_function) (service_user **, const char *, const char *,
161                                    void **)
162      internal_function;
163 typedef enum nss_status (*setent_function) (int);
164 typedef enum nss_status (*endent_function) (void);
165 typedef enum nss_status (*getent_function) (void *, char *, size_t,
166                                             int *, int *);
167 typedef int (*getent_r_function) (void *, char *, size_t,
168                                   void **result, int *);
169
170 extern void __nss_setent (const char *func_name,
171                           db_lookup_function lookup_fct,
172                           service_user **nip, service_user **startp,
173                           service_user **last_nip, int stayon,
174                           int *stayon_tmp, int res);
175 extern void __nss_endent (const char *func_name,
176                           db_lookup_function lookup_fct,
177                           service_user **nip, service_user **startp,
178                           service_user **last_nip, int res);
179 extern int __nss_getent_r (const char *getent_func_name,
180                            const char *setent_func_name,
181                            db_lookup_function lookup_fct,
182                            service_user **nip, service_user **startp,
183                            service_user **last_nip, int *stayon_tmp,
184                            int res,
185                            void *resbuf, char *buffer, size_t buflen,
186                            void **result, int *h_errnop);
187 extern void *__nss_getent (getent_r_function func,
188                            void **resbuf, char **buffer, size_t buflen,
189                            size_t *buffer_size, int *h_errnop);
190 struct hostent;
191 extern int __nss_hostname_digits_dots (const char *name,
192                                        struct hostent *resbuf, char **buffer,
193                                        size_t *buffer_size, size_t buflen,
194                                        struct hostent **result,
195                                        enum nss_status *status, int af,
196                                        int *h_errnop);
197 libc_hidden_proto (__nss_hostname_digits_dots)
198
199 #endif  /* nsswitch.h */