nss_test_errno.c 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. /* NSS service provider with errno clobber.
  2. Copyright (C) 2022-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. #include <errno.h>
  16. #include <nss.h>
  17. #include <stdlib.h>
  18. /* Catch misnamed and functions. */
  19. #pragma GCC diagnostic error "-Wmissing-prototypes"
  20. NSS_DECLARE_MODULE_FUNCTIONS (test_errno)
  21. static void __attribute__ ((constructor))
  22. init (void)
  23. {
  24. /* An arbitrary error code which is otherwise not used. */
  25. errno = -1009;
  26. }
  27. /* Lookup functions for pwd follow that do not return any data. */
  28. /* Catch misnamed function definitions. */
  29. enum nss_status
  30. _nss_test_errno_setpwent (int stayopen)
  31. {
  32. setenv ("_nss_test_errno_setpwent", "yes", 1);
  33. return NSS_STATUS_SUCCESS;
  34. }
  35. enum nss_status
  36. _nss_test_errno_getpwent_r (struct passwd *result,
  37. char *buffer, size_t size, int *errnop)
  38. {
  39. setenv ("_nss_test_errno_getpwent_r", "yes", 1);
  40. return NSS_STATUS_NOTFOUND;
  41. }
  42. enum nss_status
  43. _nss_test_errno_endpwent (void)
  44. {
  45. setenv ("_nss_test_errno_endpwent", "yes", 1);
  46. return NSS_STATUS_SUCCESS;
  47. }