nsswitch.h 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. /* Copyright (C) 1996-2026 Free Software Foundation, Inc.
  2. This file is part of the GNU C Library.
  3. The GNU C Library is free software; you can redistribute it and/or
  4. modify it under the terms of the GNU Lesser General Public
  5. License as published by the Free Software Foundation; either
  6. version 2.1 of the License, or (at your option) any later version.
  7. The GNU C Library is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  10. Lesser General Public License for more details.
  11. You should have received a copy of the GNU Lesser General Public
  12. License along with the GNU C Library; if not, see
  13. <https://www.gnu.org/licenses/>. */
  14. #ifndef _NSSWITCH_H
  15. #define _NSSWITCH_H 1
  16. /* This is an *internal* header. */
  17. #include <arpa/nameser.h>
  18. #include <netinet/in.h>
  19. #include <nss.h>
  20. #include <resolv.h>
  21. #include <search.h>
  22. #include <dlfcn.h>
  23. #include <stdbool.h>
  24. /* Actions performed after lookup finished. */
  25. typedef enum
  26. {
  27. NSS_ACTION_CONTINUE,
  28. NSS_ACTION_RETURN,
  29. NSS_ACTION_MERGE
  30. } lookup_actions;
  31. struct nss_action;
  32. typedef struct service_library
  33. {
  34. /* Name of service (`files', `dns', `nis', ...). */
  35. const char *name;
  36. /* Pointer to the loaded shared library. */
  37. void *lib_handle;
  38. /* And the link to the next entry. */
  39. struct service_library *next;
  40. } service_library;
  41. /* For mapping a function name to a function pointer. It is known in
  42. nsswitch.c:nss_lookup_function that a string pointer for the lookup key
  43. is the first member. */
  44. typedef struct
  45. {
  46. const char *fct_name;
  47. void *fct_ptr;
  48. } known_function;
  49. /* To access the action based on the status value use this macro. */
  50. #define nss_next_action(ni, status) nss_action_get (ni, status)
  51. #ifdef USE_NSCD
  52. /* Indices into DATABASES in nsswitch.c and __NSS_DATABASE_CUSTOM. */
  53. enum
  54. {
  55. # define DEFINE_DATABASE(arg) NSS_DBSIDX_##arg,
  56. # include "databases.def"
  57. # undef DEFINE_DATABASE
  58. NSS_DBSIDX_max
  59. };
  60. /* Flags whether custom rules for database is set. */
  61. extern bool __nss_database_custom[NSS_DBSIDX_max] attribute_hidden;
  62. #endif
  63. /* Warning for NSS functions, which don't require dlopen if glibc
  64. was built with --enable-static-nss. */
  65. #ifdef DO_STATIC_NSS
  66. # define nss_interface_function(name)
  67. #else
  68. # define nss_interface_function(name) static_link_warning (name)
  69. #endif
  70. /* Interface functions for NSS. */
  71. /* Put first function with name FCT_NAME for SERVICE in FCTP. The
  72. position is remembered in NI. The function returns a value < 0 if
  73. an error occurred or no such function exists. */
  74. extern int __nss_lookup (struct nss_action **ni, const char *fct_name,
  75. const char *fct2_name, void **fctp);
  76. libc_hidden_proto (__nss_lookup)
  77. /* Determine the next step in the lookup process according to the
  78. result STATUS of the call to the last function returned by
  79. `__nss_lookup' or `__nss_next'. NI specifies the last function
  80. examined. The function return a value > 0 if the process should
  81. stop with the last result of the last function call to be the
  82. result of the entire lookup. The returned value is 0 if there is
  83. another function to use and < 0 if an error occurred.
  84. If ALL_VALUES is nonzero, the return value will not be > 0 as long as
  85. there is a possibility the lookup process can ever use following
  86. services. In other words, only if all four lookup results have
  87. the action RETURN associated the lookup process stops before the
  88. natural end. */
  89. extern int __nss_next2 (struct nss_action **ni, const char *fct_name,
  90. const char *fct2_name, void **fctp, int status,
  91. int all_values) attribute_hidden;
  92. libc_hidden_proto (__nss_next2)
  93. extern int __nss_next (struct nss_action **ni, const char *fct_name, void **fctp,
  94. int status, int all_values);
  95. /* Search for the service described in NI for a function named FCT_NAME
  96. and return a pointer to this function if successful. */
  97. extern void *__nss_lookup_function (struct nss_action *ni, const char *fct_name);
  98. libc_hidden_proto (__nss_lookup_function)
  99. /* Called by NSCD to disable recursive calls and enable special handling
  100. when used in nscd. */
  101. struct traced_file;
  102. extern void __nss_disable_nscd (void (*) (size_t, struct traced_file *));
  103. typedef int (*db_lookup_function) (struct nss_action **, const char *, const char *,
  104. void **);
  105. typedef enum nss_status (*setent_function) (int);
  106. typedef enum nss_status (*endent_function) (void);
  107. typedef enum nss_status (*getent_function) (void *, char *, size_t,
  108. int *, int *);
  109. typedef int (*getent_r_function) (void *, char *, size_t,
  110. void **result, int *);
  111. extern void __nss_setent (const char *func_name,
  112. db_lookup_function lookup_fct,
  113. struct nss_action **nip, struct nss_action **startp,
  114. struct nss_action **last_nip, int stayon,
  115. int *stayon_tmp, int res)
  116. attribute_hidden;
  117. extern void __nss_endent (const char *func_name,
  118. db_lookup_function lookup_fct,
  119. struct nss_action **nip, struct nss_action **startp,
  120. struct nss_action **last_nip, int res)
  121. attribute_hidden;
  122. extern int __nss_getent_r (const char *getent_func_name,
  123. const char *setent_func_name,
  124. db_lookup_function lookup_fct,
  125. struct nss_action **nip, struct nss_action **startp,
  126. struct nss_action **last_nip, int *stayon_tmp,
  127. int res,
  128. void *resbuf, char *buffer, size_t buflen,
  129. void **result, int *h_errnop)
  130. attribute_hidden;
  131. extern void *__nss_getent (getent_r_function func,
  132. void **resbuf, char **buffer, size_t buflen,
  133. size_t *buffer_size, int *h_errnop)
  134. attribute_hidden;
  135. struct resolv_context;
  136. struct hostent;
  137. extern int __nss_hostname_digits_dots_context (struct resolv_context *,
  138. const char *name,
  139. struct hostent *resbuf,
  140. char **buffer,
  141. size_t *buffer_size,
  142. size_t buflen,
  143. struct hostent **result,
  144. enum nss_status *status, int af,
  145. int *h_errnop) attribute_hidden;
  146. extern int __nss_hostname_digits_dots (const char *name,
  147. struct hostent *resbuf, char **buffer,
  148. size_t *buffer_size, size_t buflen,
  149. struct hostent **result,
  150. enum nss_status *status, int af,
  151. int *h_errnop);
  152. libc_hidden_proto (__nss_hostname_digits_dots)
  153. /* Maximum number of aliases we allow. */
  154. #define MAX_NR_ALIASES 48
  155. #define MAX_NR_ADDRS 48
  156. /* Prototypes for __nss_*_lookup2 functions. */
  157. #define DEFINE_DATABASE(arg) \
  158. int __nss_##arg##_lookup2 (struct nss_action **, const char *, \
  159. const char *, void **); \
  160. libc_hidden_proto (__nss_##arg##_lookup2)
  161. #include "databases.def"
  162. #undef DEFINE_DATABASE
  163. #include <nss/nss_module.h>
  164. #include <nss/nss_action.h>
  165. #include <nss/nss_database.h>
  166. #endif /* nsswitch.h */