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.
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, see
17 <https://www.gnu.org/licenses/>. */
18
19#ifndef _NSS_DATABASE_H
20#define _NSS_DATABASE_H
21
22#include <file_change_detection.h>
23
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
32 here.
33
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. */
38
39#include "nss_action.h"
40
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
44
45enum nss_database
46{
47#define DEFINE_DATABASE(name) NSS_DATABASE_LITERAL (name),
48#include "databases.def"
49#undef DEFINE_DATABASE
50
51 /* Total number of databases. */
52 NSS_DATABASE_COUNT
53};
54
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
57 *ACTIONS is NULL. */
58bool __nss_database_get (enum nss_database db, nss_action_list *actions);
59libc_hidden_proto (__nss_database_get)
60
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). */
64nss_action_list __nss_database_get_noreload (enum nss_database db)
65 attribute_hidden;
66
67/* Called from __libc_freeres. */
68void __nss_database_freeres (void) attribute_hidden;
69
70/* Internal type. Exposed only for fork handling purposes. */
71struct nss_database_data
72{
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. */
76 bool initialized;
77};
78
79/* Called by fork in the parent process, before forking. */
80void __nss_database_fork_prepare_parent (struct nss_database_data *data)
81 attribute_hidden;
82
83/* Called by fork in the new subprocess, after forking. */
84void __nss_database_fork_subprocess (struct nss_database_data *data)
85 attribute_hidden;
86
87#endif /* _NSS_DATABASE_H */
88

source code of glibc/nss/nss_database.h