1 | /* Copyright (C) 1996-2018 Free Software Foundation, Inc. |
2 | This file is part of the GNU C Library. |
3 | |
4 | The GNU C Library is free software; you can redistribute it and/or |
5 | modify it under the terms of the GNU Lesser General Public |
6 | License as published by the Free Software Foundation; either |
7 | version 2.1 of the License, or (at your option) any later version. |
8 | |
9 | The GNU C Library is distributed in the hope that it will be useful, |
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
12 | Lesser General Public License for more details. |
13 | |
14 | You should have received a copy of the GNU Lesser General Public |
15 | License along with the GNU C Library; if not, see |
16 | <http://www.gnu.org/licenses/>. */ |
17 | |
18 | #ifndef _NSSWITCH_H |
19 | #define _NSSWITCH_H 1 |
20 | |
21 | /* This is an *internal* header. */ |
22 | |
23 | #include <arpa/nameser.h> |
24 | #include <netinet/in.h> |
25 | #include <nss.h> |
26 | #include <resolv.h> |
27 | #include <search.h> |
28 | #include <dlfcn.h> |
29 | #include <stdbool.h> |
30 | |
31 | /* Actions performed after lookup finished. */ |
32 | typedef enum |
33 | { |
34 | NSS_ACTION_CONTINUE, |
35 | NSS_ACTION_RETURN, |
36 | NSS_ACTION_MERGE |
37 | } lookup_actions; |
38 | |
39 | |
40 | typedef struct service_library |
41 | { |
42 | /* Name of service (`files', `dns', `nis', ...). */ |
43 | const char *name; |
44 | /* Pointer to the loaded shared library. */ |
45 | void *lib_handle; |
46 | /* And the link to the next entry. */ |
47 | struct service_library *next; |
48 | } service_library; |
49 | |
50 | |
51 | /* For mapping a function name to a function pointer. It is known in |
52 | nsswitch.c:nss_lookup_function that a string pointer for the lookup key |
53 | is the first member. */ |
54 | typedef struct |
55 | { |
56 | const char *fct_name; |
57 | void *fct_ptr; |
58 | } known_function; |
59 | |
60 | |
61 | typedef struct service_user |
62 | { |
63 | /* And the link to the next entry. */ |
64 | struct service_user *next; |
65 | /* Action according to result. */ |
66 | lookup_actions actions[5]; |
67 | /* Link to the underlying library object. */ |
68 | service_library *library; |
69 | /* Collection of known functions. */ |
70 | void *known; |
71 | /* Name of the service (`files', `dns', `nis', ...). */ |
72 | char name[0]; |
73 | } service_user; |
74 | |
75 | /* To access the action based on the status value use this macro. */ |
76 | #define nss_next_action(ni, status) ((ni)->actions[2 + status]) |
77 | |
78 | |
79 | typedef struct name_database_entry |
80 | { |
81 | /* And the link to the next entry. */ |
82 | struct name_database_entry *next; |
83 | /* List of service to be used. */ |
84 | service_user *service; |
85 | /* Name of the database. */ |
86 | char name[0]; |
87 | } name_database_entry; |
88 | |
89 | |
90 | typedef struct name_database |
91 | { |
92 | /* List of all known databases. */ |
93 | name_database_entry *entry; |
94 | /* List of libraries with service implementation. */ |
95 | service_library *library; |
96 | } name_database; |
97 | |
98 | |
99 | #ifdef USE_NSCD |
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] attribute_hidden; |
111 | #endif |
112 | |
113 | /* Warning for NSS functions, which don't require dlopen if glibc |
114 | was built with --enable-static-nss. */ |
115 | #ifdef DO_STATIC_NSS |
116 | # define nss_interface_function(name) |
117 | #else |
118 | # define nss_interface_function(name) static_link_warning (name) |
119 | #endif |
120 | |
121 | |
122 | /* Interface functions for NSS. */ |
123 | |
124 | /* Get the data structure representing the specified database. |
125 | If there is no configuration for this database in the file, |
126 | parse a service list from DEFCONFIG and use that. More |
127 | than one function can use the database. */ |
128 | extern int __nss_database_lookup (const char *database, |
129 | const char *alternative_name, |
130 | const char *defconfig, service_user **ni); |
131 | libc_hidden_proto (__nss_database_lookup) |
132 | |
133 | /* Put first function with name FCT_NAME for SERVICE in FCTP. The |
134 | position is remembered in NI. The function returns a value < 0 if |
135 | an error occurred or no such function exists. */ |
136 | extern int __nss_lookup (service_user **ni, const char *fct_name, |
137 | const char *fct2_name, void **fctp); |
138 | libc_hidden_proto (__nss_lookup) |
139 | |
140 | /* Determine the next step in the lookup process according to the |
141 | result STATUS of the call to the last function returned by |
142 | `__nss_lookup' or `__nss_next'. NI specifies the last function |
143 | examined. The function return a value > 0 if the process should |
144 | stop with the last result of the last function call to be the |
145 | result of the entire lookup. The returned value is 0 if there is |
146 | another function to use and < 0 if an error occurred. |
147 | |
148 | If ALL_VALUES is nonzero, the return value will not be > 0 as long as |
149 | there is a possibility the lookup process can ever use following |
150 | services. In other words, only if all four lookup results have |
151 | the action RETURN associated the lookup process stops before the |
152 | natural end. */ |
153 | extern int __nss_next2 (service_user **ni, const char *fct_name, |
154 | const char *fct2_name, void **fctp, int status, |
155 | int all_values) attribute_hidden; |
156 | libc_hidden_proto (__nss_next2) |
157 | extern int __nss_next (service_user **ni, const char *fct_name, void **fctp, |
158 | int status, int all_values); |
159 | |
160 | /* Search for the service described in NI for a function named FCT_NAME |
161 | and return a pointer to this function if successful. */ |
162 | extern void *__nss_lookup_function (service_user *ni, const char *fct_name); |
163 | libc_hidden_proto (__nss_lookup_function) |
164 | |
165 | |
166 | /* Called by NSCD to disable recursive calls and enable special handling |
167 | when used in nscd. */ |
168 | struct traced_file; |
169 | extern void __nss_disable_nscd (void (*) (size_t, struct traced_file *)); |
170 | |
171 | |
172 | typedef int (*db_lookup_function) (service_user **, const char *, const char *, |
173 | void **); |
174 | typedef enum nss_status (*setent_function) (int); |
175 | typedef enum nss_status (*endent_function) (void); |
176 | typedef enum nss_status (*getent_function) (void *, char *, size_t, |
177 | int *, int *); |
178 | typedef int (*getent_r_function) (void *, char *, size_t, |
179 | void **result, int *); |
180 | |
181 | extern void __nss_setent (const char *func_name, |
182 | db_lookup_function lookup_fct, |
183 | service_user **nip, service_user **startp, |
184 | service_user **last_nip, int stayon, |
185 | int *stayon_tmp, int res) |
186 | attribute_hidden; |
187 | extern void __nss_endent (const char *func_name, |
188 | db_lookup_function lookup_fct, |
189 | service_user **nip, service_user **startp, |
190 | service_user **last_nip, int res) |
191 | attribute_hidden; |
192 | extern int __nss_getent_r (const char *getent_func_name, |
193 | const char *setent_func_name, |
194 | db_lookup_function lookup_fct, |
195 | service_user **nip, service_user **startp, |
196 | service_user **last_nip, int *stayon_tmp, |
197 | int res, |
198 | void *resbuf, char *buffer, size_t buflen, |
199 | void **result, int *h_errnop) |
200 | attribute_hidden; |
201 | extern void *__nss_getent (getent_r_function func, |
202 | void **resbuf, char **buffer, size_t buflen, |
203 | size_t *buffer_size, int *h_errnop) |
204 | attribute_hidden; |
205 | struct resolv_context; |
206 | struct hostent; |
207 | extern int __nss_hostname_digits_dots_context (struct resolv_context *, |
208 | const char *name, |
209 | struct hostent *resbuf, |
210 | char **buffer, |
211 | size_t *buffer_size, |
212 | size_t buflen, |
213 | struct hostent **result, |
214 | enum nss_status *status, int af, |
215 | int *h_errnop) attribute_hidden; |
216 | extern int __nss_hostname_digits_dots (const char *name, |
217 | struct hostent *resbuf, char **buffer, |
218 | size_t *buffer_size, size_t buflen, |
219 | struct hostent **result, |
220 | enum nss_status *status, int af, |
221 | int *h_errnop); |
222 | libc_hidden_proto (__nss_hostname_digits_dots) |
223 | |
224 | /* Maximum number of aliases we allow. */ |
225 | #define MAX_NR_ALIASES 48 |
226 | #define MAX_NR_ADDRS 48 |
227 | |
228 | /* Prototypes for __nss_*_lookup2 functions. */ |
229 | #define DEFINE_DATABASE(arg) \ |
230 | service_user *__nss_##arg##_database attribute_hidden; \ |
231 | int __nss_##arg##_lookup2 (service_user **, const char *, \ |
232 | const char *, void **); \ |
233 | libc_hidden_proto (__nss_##arg##_lookup2) |
234 | #include "databases.def" |
235 | #undef DEFINE_DATABASE |
236 | |
237 | #endif /* nsswitch.h */ |
238 | |