grp.h 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. /* Copyright (C) 1991,1992,1995-2001,2003,2004 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. #if defined __USE_SVID || defined __USE_GNU
  38. # define __need_FILE
  39. # include <stdio.h>
  40. #endif
  41. #if defined __USE_SVID || defined __USE_BSD || 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_SVID
  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. #if defined __USE_POSIX || defined __USE_MISC
  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. libc_hidden_proto(getgrent_r)
  101. # endif
  102. /* Search for an entry with a matching group ID.
  103. This function is a possible cancellation point and therefore not
  104. marked with __THROW. */
  105. extern int getgrgid_r (__gid_t __gid, struct group *__restrict __resultbuf,
  106. char *__restrict __buffer, size_t __buflen,
  107. struct group **__restrict __result);
  108. libc_hidden_proto(getgrgid_r)
  109. /* Search for an entry with a matching group name.
  110. This function is a possible cancellation point and therefore not
  111. marked with __THROW. */
  112. extern int getgrnam_r (const char *__restrict __name,
  113. struct group *__restrict __resultbuf,
  114. char *__restrict __buffer, size_t __buflen,
  115. struct group **__restrict __result);
  116. libc_hidden_proto(getgrnam_r)
  117. # ifdef __USE_SVID
  118. /* Read a group entry from STREAM. This function is not standardized
  119. an probably never will.
  120. This function is not part of POSIX and therefore no official
  121. cancellation point. But due to similarity with an POSIX interface
  122. or due to the implementation it is a cancellation point and
  123. therefore not marked with __THROW. */
  124. extern int fgetgrent_r (FILE *__restrict __stream,
  125. struct group *__restrict __resultbuf,
  126. char *__restrict __buffer, size_t __buflen,
  127. struct group **__restrict __result);
  128. libc_hidden_proto(fgetgrent_r)
  129. # endif
  130. #endif /* POSIX or reentrant */
  131. #if defined __USE_BSD || defined __USE_GNU
  132. # define __need_size_t
  133. # include <stddef.h>
  134. /* Store at most *NGROUPS members of the group set for USER into
  135. *GROUPS. Also include GROUP. The actual number of groups found is
  136. returned in *NGROUPS. Return -1 if the if *NGROUPS is too small.
  137. In all cases the actual number of groups is stored in *NGROUPS.
  138. This function is not part of POSIX and therefore no official
  139. cancellation point. But due to similarity with an POSIX interface
  140. or due to the implementation it is a cancellation point and
  141. therefore not marked with __THROW. */
  142. extern int getgrouplist (const char *__user, __gid_t __group,
  143. __gid_t *__groups, int *__ngroups);
  144. #endif
  145. #if defined __USE_BSD
  146. /* Set the group set for the current user to GROUPS (N of them). */
  147. extern int setgroups (size_t __n, const __gid_t *__groups) __THROW;
  148. libc_hidden_proto(setgroups)
  149. /* Initialize the group set for the current user
  150. by reading the group database and using all groups
  151. of which USER is a member. Also include GROUP.
  152. This function is not part of POSIX and therefore no official
  153. cancellation point. But due to similarity with an POSIX interface
  154. or due to the implementation it is a cancellation point and
  155. therefore not marked with __THROW. */
  156. extern int initgroups (const char *__user, __gid_t __group);
  157. #endif /* Use BSD. */
  158. __END_DECLS
  159. #endif /* grp.h */