grp.h 7.0 KB

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