nss_database.h 3.2 KB

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