1 /* Mapping NSS services to action lists.
2 Copyright (C) 2020-2022 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
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.
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.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
17 <https://www.gnu.org/licenses/>. */
19 #ifndef _NSS_DATABASE_H
20 #define _NSS_DATABASE_H
22 #include <file_change_detection.h>
24 /* Each "line" in nsswitch.conf maps a supported database (example:
25 passwd) to one or more name service providers (example: files dns).
26 Internally, each name service provider (example: dns) is a
27 dynamically loadable module (i.e. libnss_dns.so), managed by
28 nss_module.h. The sequence of providers and rules (example: files
29 [SUCCESS=RETURN] dns) is mapped by nss_action.h to a cached entry
30 which encodes the sequence of modules and rules. Keeping track of
31 all supported databases and their corresponding actions is done
34 The key entry is __nss_database_get, which provides a set of
35 actions which can be used with nss_lookup_function() and
36 nss_next(). Callers should assume that these functions are fast,
37 and should not cache the result longer than needed. */
39 #include "nss_action.h"
41 /* The enumeration literal in enum nss_database for the database NAME
42 (e.g., nss_database_hosts for hosts). */
43 #define NSS_DATABASE_LITERAL(name) nss_database_##name
47 #define DEFINE_DATABASE(name) NSS_DATABASE_LITERAL (name),
48 #include "databases.def"
49 #undef DEFINE_DATABASE
51 /* Total number of databases. */
55 /* Looks up the action list for DB and stores it in *ACTIONS. Returns
56 true on success or false on failure. Success can mean that
58 bool __nss_database_get (enum nss_database db
, nss_action_list
*actions
);
59 libc_hidden_proto (__nss_database_get
)
61 /* Like __nss_database_get, but does not reload /etc/nsswitch.conf
62 from disk. This assumes that there has been a previous successful
63 __nss_database_get call (which may not have returned any data). */
64 nss_action_list
__nss_database_get_noreload (enum nss_database db
)
67 /* Called from __libc_freeres. */
68 void __nss_database_freeres (void) attribute_hidden
;
70 /* Internal type. Exposed only for fork handling purposes. */
71 struct nss_database_data
73 struct file_change_detection nsswitch_conf
;
74 nss_action_list services
[NSS_DATABASE_COUNT
];
75 int reload_disabled
; /* Actually bool; int for atomic access. */
79 /* Called by fork in the parent process, before forking. */
80 void __nss_database_fork_prepare_parent (struct nss_database_data
*data
)
83 /* Called by fork in the new subprocess, after forking. */
84 void __nss_database_fork_subprocess (struct nss_database_data
*data
)
87 #endif /* _NSS_DATABASE_H */