grp.h 6.8 KB

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