sgetsgent_r.c 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. /* Copyright (C) 2009-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. #include <ctype.h>
  15. #include <errno.h>
  16. #include <gshadow.h>
  17. #include <stdio.h>
  18. #include <string.h>
  19. /* Define a line parsing function using the common code
  20. used in the nss_files module. */
  21. #define STRUCTURE sgrp
  22. #define ENTNAME sgent
  23. struct sgent_data {};
  24. #define TRAILING_LIST_MEMBER sg_mem
  25. #define TRAILING_LIST_SEPARATOR_P(c) ((c) == ',')
  26. #include <nss/nss_files/files-parse.c>
  27. LINE_PARSER
  28. (,
  29. STRING_FIELD (result->sg_namp, ISCOLON, 0);
  30. if (line[0] == '\0'
  31. && (result->sg_namp[0] == '+' || result->sg_namp[0] == '-'))
  32. {
  33. result->sg_passwd = NULL;
  34. result->sg_adm = NULL;
  35. result->sg_mem = NULL;
  36. }
  37. else
  38. {
  39. STRING_FIELD (result->sg_passwd, ISCOLON, 0);
  40. STRING_LIST (result->sg_adm, ':');
  41. }
  42. )
  43. /* Read one shadow entry from the given stream. */
  44. int
  45. __sgetsgent_r (const char *string, struct sgrp *resbuf, char *buffer,
  46. size_t buflen, struct sgrp **result)
  47. {
  48. char *sp;
  49. if (string < buffer || string >= buffer + buflen)
  50. {
  51. buffer[buflen - 1] = '\0';
  52. sp = strncpy (buffer, string, buflen);
  53. if (buffer[buflen - 1] != '\0')
  54. {
  55. __set_errno (ERANGE);
  56. return ERANGE;
  57. }
  58. }
  59. else
  60. sp = (char *) string;
  61. int parse_result = parse_line (sp, resbuf, (void *) buffer, buflen, &errno);
  62. *result = parse_result > 0 ? resbuf : NULL;
  63. return *result == NULL ? errno : 0;
  64. }
  65. weak_alias (__sgetsgent_r, sgetsgent_r)