1 | /* Copyright (C) 1996-2017 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 | /* Indices into DATABASES in nsswitch.c and __NSS_DATABASE_CUSTOM. */ |
100 | enum |
101 | { |
102 | #define DEFINE_DATABASE(arg) NSS_DBSIDX_##arg, |
103 | #include "databases.def" |
104 | #undef DEFINE_DATABASE |
105 | NSS_DBSIDX_max |
106 | }; |
107 | |
108 | /* Flags whether custom rules for database is set. */ |
109 | extern bool __nss_database_custom[NSS_DBSIDX_max]; |
110 | |
111 | /* Warning for NSS functions, which don't require dlopen if glibc |
112 | was built with --enable-static-nss. */ |
113 | #ifdef DO_STATIC_NSS |
114 | # define nss_interface_function(name) |
115 | #else |
116 | # define nss_interface_function(name) static_link_warning (name) |
117 | #endif |
118 | |
119 | |
120 | /* Interface functions for NSS. */ |
121 | |
122 | /* Get the data structure representing the specified database. |
123 | If there is no configuration for this database in the file, |
124 | parse a service list from DEFCONFIG and use that. More |
125 | than one function can use the database. */ |
126 | extern int __nss_database_lookup (const char *database, |
127 | const char *alternative_name, |
128 | const char *defconfig, service_user **ni); |
129 | libc_hidden_proto (__nss_database_lookup) |
130 | |
131 | /* Put first function with name FCT_NAME for SERVICE in FCTP. The |
132 | position is remembered in NI. The function returns a value < 0 if |
133 | an error occurred or no such function exists. */ |
134 | extern int __nss_lookup (service_user **ni, const char *fct_name, |
135 | const char *fct2_name, void **fctp); |
136 | libc_hidden_proto (__nss_lookup) |
137 | |
138 | /* Determine the next step in the lookup process according to the |
139 | result STATUS of the call to the last function returned by |
140 | `__nss_lookup' or `__nss_next'. NI specifies the last function |
141 | examined. The function return a value > 0 if the process should |
142 | stop with the last result of the last function call to be the |
143 | result of the entire lookup. The returned value is 0 if there is |
144 | another function to use and < 0 if an error occurred. |
145 | |
146 | If ALL_VALUES is nonzero, the return value will not be > 0 as long as |
147 | there is a possibility the lookup process can ever use following |
148 | services. In other words, only if all four lookup results have |
149 | the action RETURN associated the lookup process stops before the |
150 | natural end. */ |
151 | extern int __nss_next2 (service_user **ni, const char *fct_name, |
152 | const char *fct2_name, void **fctp, int status, |
153 | int all_values) attribute_hidden; |
154 | libc_hidden_proto (__nss_next2) |
155 | extern int __nss_next (service_user **ni, const char *fct_name, void **fctp, |
156 | int status, int all_values); |
157 | |
158 | /* Search for the service described in NI for a function named FCT_NAME |
159 | and return a pointer to this function if successful. */ |
160 | extern void *__nss_lookup_function (service_user *ni, const char *fct_name); |
161 | libc_hidden_proto (__nss_lookup_function) |
162 | |
163 | |
164 | /* Called by NSCD to disable recursive calls and enable special handling |
165 | when used in nscd. */ |
166 | struct traced_file; |
167 | extern void __nss_disable_nscd (void (*) (size_t, struct traced_file *)); |
168 | |
169 | |
170 | typedef int (*db_lookup_function) (service_user **, const char *, const char *, |
171 | void **) |
172 | internal_function; |
173 | typedef enum nss_status (*setent_function) (int); |
174 | typedef enum nss_status (*endent_function) (void); |
175 | typedef enum nss_status (*getent_function) (void *, char *, size_t, |
176 | int *, int *); |
177 | typedef int (*getent_r_function) (void *, char *, size_t, |
178 | void **result, int *); |
179 | |
180 | extern void __nss_setent (const char *func_name, |
181 | db_lookup_function lookup_fct, |
182 | service_user **nip, service_user **startp, |
183 | service_user **last_nip, int stayon, |
184 | int *stayon_tmp, int res); |
185 | extern void __nss_endent (const char *func_name, |
186 | db_lookup_function lookup_fct, |
187 | service_user **nip, service_user **startp, |
188 | service_user **last_nip, int res); |
189 | extern int __nss_getent_r (const char *getent_func_name, |
190 | const char *setent_func_name, |
191 | db_lookup_function lookup_fct, |
192 | service_user **nip, service_user **startp, |
193 | service_user **last_nip, int *stayon_tmp, |
194 | int res, |
195 | void *resbuf, char *buffer, size_t buflen, |
196 | void **result, int *h_errnop); |
197 | extern void *__nss_getent (getent_r_function func, |
198 | void **resbuf, char **buffer, size_t buflen, |
199 | size_t *buffer_size, int *h_errnop); |
200 | struct resolv_context; |
201 | struct hostent; |
202 | extern int __nss_hostname_digits_dots_context (struct resolv_context *, |
203 | const char *name, |
204 | struct hostent *resbuf, |
205 | char **buffer, |
206 | size_t *buffer_size, |
207 | size_t buflen, |
208 | struct hostent **result, |
209 | enum nss_status *status, int af, |
210 | int *h_errnop) attribute_hidden; |
211 | extern int __nss_hostname_digits_dots (const char *name, |
212 | struct hostent *resbuf, char **buffer, |
213 | size_t *buffer_size, size_t buflen, |
214 | struct hostent **result, |
215 | enum nss_status *status, int af, |
216 | int *h_errnop); |
217 | libc_hidden_proto (__nss_hostname_digits_dots) |
218 | |
219 | /* Maximum number of aliases we allow. */ |
220 | #define MAX_NR_ALIASES 48 |
221 | #define MAX_NR_ADDRS 48 |
222 | |
223 | #endif /* nsswitch.h */ |
224 | |