grp.h 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. /* Copyright (C) 1991-2020 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. /*
  15. * POSIX Standard: 9.2.1 Group Database Access <grp.h>
  16. */
  17. #ifndef _GRP_H
  18. #define _GRP_H 1
  19. #include <features.h>
  20. __BEGIN_DECLS
  21. #include <bits/types.h>
  22. #define __need_size_t
  23. #include <stddef.h>
  24. /* For the Single Unix specification we must define this type here. */
  25. #if (defined __USE_XOPEN || defined __USE_XOPEN2K) && !defined __gid_t_defined
  26. typedef __gid_t gid_t;
  27. # define __gid_t_defined
  28. #endif
  29. /* The group structure. */
  30. struct group
  31. {
  32. char *gr_name; /* Group name. */
  33. char *gr_passwd; /* Password. */
  34. __gid_t gr_gid; /* Group ID. */
  35. char **gr_mem; /* Member list. */
  36. };
  37. #ifdef __USE_MISC
  38. # include <bits/types/FILE.h>
  39. #endif
  40. #if defined __USE_MISC || defined __USE_XOPEN_EXTENDED
  41. /* Rewind the group-file stream.
  42. This function is a possible cancellation point and therefore not
  43. marked with __THROW. */
  44. extern void setgrent (void);
  45. /* Close the group-file stream.
  46. This function is a possible cancellation point and therefore not
  47. marked with __THROW. */
  48. extern void endgrent (void);
  49. /* Read an entry from the group-file stream, opening it if necessary.
  50. This function is a possible cancellation point and therefore not
  51. marked with __THROW. */
  52. extern struct group *getgrent (void);
  53. #endif
  54. #ifdef __USE_MISC
  55. /* Read a group entry from STREAM.
  56. This function is not part of POSIX and therefore no official
  57. cancellation point. But due to similarity with an POSIX interface
  58. or due to the implementation it is a cancellation point and
  59. therefore not marked with __THROW. */
  60. extern struct group *fgetgrent (FILE *__stream);
  61. #endif
  62. #ifdef __USE_GNU
  63. /* Write the given entry onto the given stream.
  64. This function is not part of POSIX and therefore no official
  65. cancellation point. But due to similarity with an POSIX interface
  66. or due to the implementation it is a cancellation point and
  67. therefore not marked with __THROW. */
  68. extern int putgrent (const struct group *__restrict __p,
  69. FILE *__restrict __f);
  70. #endif
  71. /* Search for an entry with a matching group ID.
  72. This function is a possible cancellation point and therefore not
  73. marked with __THROW. */
  74. extern struct group *getgrgid (__gid_t __gid);
  75. /* Search for an entry with a matching group name.
  76. This function is a possible cancellation point and therefore not
  77. marked with __THROW. */
  78. extern struct group *getgrnam (const char *__name);
  79. #ifdef __USE_POSIX
  80. # ifdef __USE_MISC
  81. /* Reasonable value for the buffer sized used in the reentrant
  82. functions below. But better use `sysconf'. */
  83. # define NSS_BUFLEN_GROUP 1024
  84. # endif
  85. /* Reentrant versions of some of the functions above.
  86. PLEASE NOTE: the `getgrent_r' function is not (yet) standardized.
  87. The interface may change in later versions of this library. But
  88. the interface is designed following the principals used for the
  89. other reentrant functions so the chances are good this is what the
  90. POSIX people would choose.
  91. This function is not part of POSIX and therefore no official
  92. cancellation point. But due to similarity with an POSIX interface
  93. or due to the implementation it is a cancellation point and
  94. therefore not marked with __THROW. */
  95. # ifdef __USE_GNU
  96. extern int getgrent_r (struct group *__restrict __resultbuf,
  97. char *__restrict __buffer, size_t __buflen,
  98. struct group **__restrict __result);
  99. # endif
  100. /* Search for an entry with a matching group ID.
  101. This function is a possible cancellation point and therefore not
  102. marked with __THROW. */
  103. extern int getgrgid_r (__gid_t __gid, struct group *__restrict __resultbuf,
  104. char *__restrict __buffer, size_t __buflen,
  105. struct group **__restrict __result);
  106. /* Search for an entry with a matching group name.
  107. This function is a possible cancellation point and therefore not
  108. marked with __THROW. */
  109. extern int getgrnam_r (const char *__restrict __name,
  110. struct group *__restrict __resultbuf,
  111. char *__restrict __buffer, size_t __buflen,
  112. struct group **__restrict __result);
  113. # ifdef __USE_MISC
  114. /* Read a group entry from STREAM. This function is not standardized
  115. an probably never will.
  116. This function is not part of POSIX and therefore no official
  117. cancellation point. But due to similarity with an POSIX interface
  118. or due to the implementation it is a cancellation point and
  119. therefore not marked with __THROW. */
  120. extern int fgetgrent_r (FILE *__restrict __stream,
  121. struct group *__restrict __resultbuf,
  122. char *__restrict __buffer, size_t __buflen,
  123. struct group **__restrict __result);
  124. # endif
  125. #endif /* POSIX or reentrant */
  126. #ifdef __USE_MISC
  127. # define __need_size_t
  128. # include <stddef.h>
  129. /* Set the group set for the current user to GROUPS (N of them). */
  130. extern int setgroups (size_t __n, const __gid_t *__groups) __THROW;
  131. /* Store at most *NGROUPS members of the group set for USER into
  132. *GROUPS. Also include GROUP. The actual number of groups found is
  133. returned in *NGROUPS. Return -1 if the if *NGROUPS is too small.
  134. This function is not part of POSIX and therefore no official
  135. cancellation point. But due to similarity with an POSIX interface
  136. or due to the implementation it is a cancellation point and
  137. therefore not marked with __THROW. */
  138. extern int getgrouplist (const char *__user, __gid_t __group,
  139. __gid_t *__groups, int *__ngroups);
  140. /* Initialize the group set for the current user
  141. by reading the group database and using all groups
  142. of which USER is a member. Also include GROUP.
  143. This function is not part of POSIX and therefore no official
  144. cancellation point. But due to similarity with an POSIX interface
  145. or due to the implementation it is a cancellation point and
  146. therefore not marked with __THROW. */
  147. extern int initgroups (const char *__user, __gid_t __group);
  148. #endif /* Use misc. */
  149. __END_DECLS
  150. #endif /* grp.h */