| 1 | /* Global list of NSS service modules. |
| 2 | Copyright (c) 2020-2021 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_MODULE_H |
| 20 | #define _NSS_MODULE_H |
| 21 | |
| 22 | #include <nss.h> |
| 23 | #include <stdbool.h> |
| 24 | |
| 25 | /* See nss_database.h for a summary of how this relates. */ |
| 26 | |
| 27 | /* Typed function pointers for all functions that can be defined by a |
| 28 | service module. */ |
| 29 | struct nss_module_functions |
| 30 | { |
| 31 | #undef DEFINE_NSS_FUNCTION |
| 32 | #define DEFINE_NSS_FUNCTION(f) nss_##f *f; |
| 33 | #include "function.def" |
| 34 | }; |
| 35 | |
| 36 | /* Untyped version of struct nss_module_functions, for consistent |
| 37 | processing purposes. */ |
| 38 | typedef void *nss_module_functions_untyped[sizeof (struct nss_module_functions) |
| 39 | / sizeof (void *)]; |
| 40 | |
| 41 | /* Initialization state of a NSS module. */ |
| 42 | enum nss_module_state |
| 43 | { |
| 44 | nss_module_uninitialized, |
| 45 | nss_module_loaded, |
| 46 | nss_module_failed, |
| 47 | }; |
| 48 | |
| 49 | /* A NSS service module (potentially unloaded). Client code should |
| 50 | use the functions below. */ |
| 51 | struct nss_module |
| 52 | { |
| 53 | /* Actual type is enum nss_module_state. Use int due to atomic |
| 54 | access. Used in a double-checked locking idiom. */ |
| 55 | int state; |
| 56 | |
| 57 | /* The function pointers in the module. */ |
| 58 | union |
| 59 | { |
| 60 | struct nss_module_functions typed; |
| 61 | nss_module_functions_untyped untyped; |
| 62 | } functions; |
| 63 | |
| 64 | /* Only used for __libc_freeres unloading. */ |
| 65 | void *handle; |
| 66 | |
| 67 | /* The next module in the list. */ |
| 68 | struct nss_module *next; |
| 69 | |
| 70 | /* The name of the module (as it appears in /etc/nsswitch.conf). */ |
| 71 | char name[]; |
| 72 | }; |
| 73 | |
| 74 | /* Allocates the NSS module NAME (of NAME_LENGTH bytes) and places it |
| 75 | into the global list. If it already exists in the list, return the |
| 76 | pre-existing module. This does not actually load the module. |
| 77 | Returns NULL on memory allocation failure. */ |
| 78 | struct nss_module *__nss_module_allocate (const char *name, |
| 79 | size_t name_length) attribute_hidden; |
| 80 | |
| 81 | /* Ensures that MODULE is in a loaded or failed state. */ |
| 82 | bool __nss_module_load (struct nss_module *module) attribute_hidden; |
| 83 | |
| 84 | /* Ensures that MODULE is loaded and returns a pointer to the function |
| 85 | NAME defined in it. Returns NULL if MODULE could not be loaded, or |
| 86 | if the function NAME is not defined in the module. */ |
| 87 | void *__nss_module_get_function (struct nss_module *module, const char *name) |
| 88 | attribute_hidden; |
| 89 | |
| 90 | /* Block attempts to dlopen any module we haven't already opened. */ |
| 91 | void __nss_module_disable_loading (void); |
| 92 | |
| 93 | /* Called from __libc_freeres. */ |
| 94 | void __nss_module_freeres (void) attribute_hidden; |
| 95 | |
| 96 | #endif /* NSS_MODULE_H */ |
| 97 | |