grp.h 6.5 KB

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