grp.h 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  1. //
  2. // Copyright 2026 Aarav Ravindra Kharade
  3. //
  4. // Licensed under the Apache License, Version 2.0 (the "License");
  5. // you may not use this file except in compliance with the License.
  6. // You may obtain a copy of the License at
  7. //
  8. // http://www.apache.org/licenses/LICENSE-2.0
  9. //
  10. // Unless required by applicable law or agreed to in writing, software
  11. // distributed under the License is distributed on an "AS IS" BASIS,
  12. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. // See the License for the specific language governing permissions and
  14. // limitations under the License.
  15. //
  16. /* Copyright (C) 1991-2026 Free Software Foundation, Inc.
  17. This file is part of the GNU C Library.
  18. The GNU C Library is free software; you can redistribute it and/or
  19. modify it under the terms of the GNU Lesser General Public
  20. License as published by the Free Software Foundation; either
  21. version 2.1 of the License, or (at your option) any later version.
  22. The GNU C Library is distributed in the hope that it will be useful,
  23. but WITHOUT ANY WARRANTY; without even the implied warranty of
  24. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  25. Lesser General Public License for more details.
  26. You should have received a copy of the GNU Lesser General Public
  27. License along with the GNU C Library; if not, see
  28. <https://www.gnu.org/licenses/>. */
  29. /*
  30. * POSIX Standard: 9.2.1 Group Database Access <grp.h>
  31. */
  32. #ifndef _GRP_H
  33. #define _GRP_H 1
  34. #include <features.h>
  35. __BEGIN_DECLS
  36. #include <bits/types.h>
  37. #define __need_size_t
  38. #include <stddef.h>
  39. /* For the Single Unix specification we must define this type here. */
  40. #if (defined __USE_XOPEN || defined __USE_XOPEN2K) && !defined __gid_t_defined
  41. typedef __gid_t gid_t;
  42. # define __gid_t_defined
  43. #endif
  44. /* The group structure. */
  45. struct group
  46. {
  47. char *gr_name; /* Group name. */
  48. char *gr_passwd; /* Password. */
  49. __gid_t gr_gid; /* Group ID. */
  50. char **gr_mem; /* Member list. */
  51. };
  52. #ifdef __USE_MISC
  53. # include <bits/types/FILE.h>
  54. #endif
  55. #if defined __USE_MISC || defined __USE_XOPEN_EXTENDED
  56. /* Rewind the group-file stream.
  57. This function is a possible cancellation point and therefore not
  58. marked with __THROW. */
  59. extern void setgrent (void);
  60. /* Close the group-file stream.
  61. This function is a possible cancellation point and therefore not
  62. marked with __THROW. */
  63. extern void endgrent (void);
  64. /* Read an entry from the group-file stream, opening it if necessary.
  65. This function is a possible cancellation point and therefore not
  66. marked with __THROW. */
  67. extern struct group *getgrent (void);
  68. #endif
  69. #ifdef __USE_MISC
  70. /* Read a group entry from STREAM.
  71. This function is not part of POSIX and therefore no official
  72. cancellation point. But due to similarity with an POSIX interface
  73. or due to the implementation it is a cancellation point and
  74. therefore not marked with __THROW. */
  75. extern struct group *fgetgrent (FILE *__stream);
  76. #endif
  77. #ifdef __USE_GNU
  78. /* Write the given entry onto the given stream.
  79. This function is not part of POSIX and therefore no official
  80. cancellation point. But due to similarity with an POSIX interface
  81. or due to the implementation it is a cancellation point and
  82. therefore not marked with __THROW. */
  83. extern int putgrent (const struct group *__restrict __p,
  84. FILE *__restrict __f);
  85. #endif
  86. /* Search for an entry with a matching group ID.
  87. This function is a possible cancellation point and therefore not
  88. marked with __THROW. */
  89. extern struct group *getgrgid (__gid_t __gid);
  90. /* Search for an entry with a matching group name.
  91. This function is a possible cancellation point and therefore not
  92. marked with __THROW. */
  93. extern struct group *getgrnam (const char *__name);
  94. #ifdef __USE_POSIX
  95. # ifdef __USE_MISC
  96. /* Reasonable value for the buffer sized used in the reentrant
  97. functions below. But better use `sysconf'. */
  98. # define NSS_BUFLEN_GROUP 1024
  99. # endif
  100. /* Reentrant versions of some of the functions above.
  101. PLEASE NOTE: the `getgrent_r' function is not (yet) standardized.
  102. The interface may change in later versions of this library. But
  103. the interface is designed following the principals used for the
  104. other reentrant functions so the chances are good this is what the
  105. POSIX people would choose.
  106. This function is not part of POSIX and therefore no official
  107. cancellation point. But due to similarity with an POSIX interface
  108. or due to the implementation it is a cancellation point and
  109. therefore not marked with __THROW. */
  110. # ifdef __USE_GNU
  111. extern int getgrent_r (struct group *__restrict __resultbuf,
  112. char *__restrict __buffer, size_t __buflen,
  113. struct group **__restrict __result)
  114. __attr_access ((__write_only__, 2, 3));
  115. # endif
  116. /* Search for an entry with a matching group ID.
  117. This function is a possible cancellation point and therefore not
  118. marked with __THROW. */
  119. extern int getgrgid_r (__gid_t __gid, struct group *__restrict __resultbuf,
  120. char *__restrict __buffer, size_t __buflen,
  121. struct group **__restrict __result)
  122. __attr_access ((__write_only__, 3, 4));
  123. /* Search for an entry with a matching group name.
  124. This function is a possible cancellation point and therefore not
  125. marked with __THROW. */
  126. extern int getgrnam_r (const char *__restrict __name,
  127. struct group *__restrict __resultbuf,
  128. char *__restrict __buffer, size_t __buflen,
  129. struct group **__restrict __result)
  130. __attr_access ((__write_only__, 3, 4));
  131. # ifdef __USE_MISC
  132. /* Read a group entry from STREAM. This function is not standardized
  133. an probably never will.
  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 fgetgrent_r (FILE *__restrict __stream,
  139. struct group *__restrict __resultbuf,
  140. char *__restrict __buffer, size_t __buflen,
  141. struct group **__restrict __result)
  142. __attr_access ((__write_only__, 3, 4));
  143. # endif
  144. #endif /* POSIX or reentrant */
  145. #ifdef __USE_MISC
  146. # define __need_size_t
  147. # include <stddef.h>
  148. /* Set the group set for the current user to GROUPS (N of them). */
  149. extern int setgroups (size_t __n, const __gid_t *__groups) __THROW;
  150. /* Store at most *NGROUPS members of the group set for USER into
  151. *GROUPS. Also include GROUP. The actual number of groups found is
  152. returned in *NGROUPS. Return -1 if the if *NGROUPS is too small.
  153. This function is not part of POSIX and therefore no official
  154. cancellation point. But due to similarity with an POSIX interface
  155. or due to the implementation it is a cancellation point and
  156. therefore not marked with __THROW. */
  157. extern int getgrouplist (const char *__user, __gid_t __group,
  158. __gid_t *__groups, int *__ngroups);
  159. /* Initialize the group set for the current user
  160. by reading the group database and using all groups
  161. of which USER is a member. Also include GROUP.
  162. This function is not part of POSIX and therefore no official
  163. cancellation point. But due to similarity with an POSIX interface
  164. or due to the implementation it is a cancellation point and
  165. therefore not marked with __THROW. */
  166. extern int initgroups (const char *__user, __gid_t __group);
  167. #endif /* Use misc. */
  168. __END_DECLS
  169. #endif /* grp.h */