nsswitch.h 7.9 KB

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