1/* Copyright (C) 1996-2021 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 <https://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. */
32typedef enum
33{
34 NSS_ACTION_CONTINUE,
35 NSS_ACTION_RETURN,
36 NSS_ACTION_MERGE
37} lookup_actions;
38
39struct nss_action;
40
41typedef 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. */
55typedef struct
56{
57 const char *fct_name;
58 void *fct_ptr;
59} known_function;
60
61
62/* To access the action based on the status value use this macro. */
63#define nss_next_action(ni, status) nss_action_get (ni, status)
64
65
66#ifdef USE_NSCD
67/* Indices into DATABASES in nsswitch.c and __NSS_DATABASE_CUSTOM. */
68enum
69 {
70# define DEFINE_DATABASE(arg) NSS_DBSIDX_##arg,
71# include "databases.def"
72# undef DEFINE_DATABASE
73 NSS_DBSIDX_max
74 };
75
76/* Flags whether custom rules for database is set. */
77extern bool __nss_database_custom[NSS_DBSIDX_max] attribute_hidden;
78#endif
79
80/* Warning for NSS functions, which don't require dlopen if glibc
81 was built with --enable-static-nss. */
82#ifdef DO_STATIC_NSS
83# define nss_interface_function(name)
84#else
85# define nss_interface_function(name) static_link_warning (name)
86#endif
87
88
89/* Interface functions for NSS. */
90
91/* Get the data structure representing the specified database.
92 If there is no configuration for this database in the file,
93 parse a service list from DEFCONFIG and use that. More
94 than one function can use the database. */
95extern int __nss_database_lookup2 (const char *database,
96 const char *alternative_name,
97 const char *defconfig, struct nss_action **ni);
98libc_hidden_proto (__nss_database_lookup2)
99
100/* Put first function with name FCT_NAME for SERVICE in FCTP. The
101 position is remembered in NI. The function returns a value < 0 if
102 an error occurred or no such function exists. */
103extern int __nss_lookup (struct nss_action **ni, const char *fct_name,
104 const char *fct2_name, void **fctp);
105libc_hidden_proto (__nss_lookup)
106
107/* Determine the next step in the lookup process according to the
108 result STATUS of the call to the last function returned by
109 `__nss_lookup' or `__nss_next'. NI specifies the last function
110 examined. The function return a value > 0 if the process should
111 stop with the last result of the last function call to be the
112 result of the entire lookup. The returned value is 0 if there is
113 another function to use and < 0 if an error occurred.
114
115 If ALL_VALUES is nonzero, the return value will not be > 0 as long as
116 there is a possibility the lookup process can ever use following
117 services. In other words, only if all four lookup results have
118 the action RETURN associated the lookup process stops before the
119 natural end. */
120extern int __nss_next2 (struct nss_action **ni, const char *fct_name,
121 const char *fct2_name, void **fctp, int status,
122 int all_values) attribute_hidden;
123libc_hidden_proto (__nss_next2)
124extern int __nss_next (struct nss_action **ni, const char *fct_name, void **fctp,
125 int status, int all_values);
126
127/* Search for the service described in NI for a function named FCT_NAME
128 and return a pointer to this function if successful. */
129extern void *__nss_lookup_function (struct nss_action *ni, const char *fct_name);
130libc_hidden_proto (__nss_lookup_function)
131
132
133/* Called by NSCD to disable recursive calls and enable special handling
134 when used in nscd. */
135struct traced_file;
136extern void __nss_disable_nscd (void (*) (size_t, struct traced_file *));
137
138
139typedef int (*db_lookup_function) (struct nss_action **, const char *, const char *,
140 void **);
141typedef enum nss_status (*setent_function) (int);
142typedef enum nss_status (*endent_function) (void);
143typedef enum nss_status (*getent_function) (void *, char *, size_t,
144 int *, int *);
145typedef int (*getent_r_function) (void *, char *, size_t,
146 void **result, int *);
147
148extern void __nss_setent (const char *func_name,
149 db_lookup_function lookup_fct,
150 struct nss_action **nip, struct nss_action **startp,
151 struct nss_action **last_nip, int stayon,
152 int *stayon_tmp, int res)
153 attribute_hidden;
154extern void __nss_endent (const char *func_name,
155 db_lookup_function lookup_fct,
156 struct nss_action **nip, struct nss_action **startp,
157 struct nss_action **last_nip, int res)
158 attribute_hidden;
159extern int __nss_getent_r (const char *getent_func_name,
160 const char *setent_func_name,
161 db_lookup_function lookup_fct,
162 struct nss_action **nip, struct nss_action **startp,
163 struct nss_action **last_nip, int *stayon_tmp,
164 int res,
165 void *resbuf, char *buffer, size_t buflen,
166 void **result, int *h_errnop)
167 attribute_hidden;
168extern void *__nss_getent (getent_r_function func,
169 void **resbuf, char **buffer, size_t buflen,
170 size_t *buffer_size, int *h_errnop)
171 attribute_hidden;
172struct resolv_context;
173struct hostent;
174extern int __nss_hostname_digits_dots_context (struct resolv_context *,
175 const char *name,
176 struct hostent *resbuf,
177 char **buffer,
178 size_t *buffer_size,
179 size_t buflen,
180 struct hostent **result,
181 enum nss_status *status, int af,
182 int *h_errnop) attribute_hidden;
183extern int __nss_hostname_digits_dots (const char *name,
184 struct hostent *resbuf, char **buffer,
185 size_t *buffer_size, size_t buflen,
186 struct hostent **result,
187 enum nss_status *status, int af,
188 int *h_errnop);
189libc_hidden_proto (__nss_hostname_digits_dots)
190
191/* Maximum number of aliases we allow. */
192#define MAX_NR_ALIASES 48
193#define MAX_NR_ADDRS 48
194
195/* Prototypes for __nss_*_lookup2 functions. */
196#define DEFINE_DATABASE(arg) \
197 extern struct nss_action *__nss_##arg##_database attribute_hidden; \
198 int __nss_##arg##_lookup2 (struct nss_action **, const char *, \
199 const char *, void **); \
200 libc_hidden_proto (__nss_##arg##_lookup2)
201#include "databases.def"
202#undef DEFINE_DATABASE
203
204#include <nss/nss_module.h>
205#include <nss/nss_action.h>
206#include <nss/nss_database.h>
207
208#endif /* nsswitch.h */
209