grp.h 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  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. # 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. /* Search for an entry with a matching group name.
  109. This function is a possible cancellation point and therefore not
  110. marked with __THROW. */
  111. extern int getgrnam_r (__const char *__restrict __name,
  112. struct group *__restrict __resultbuf,
  113. char *__restrict __buffer, size_t __buflen,
  114. struct group **__restrict __result);
  115. # ifdef __USE_SVID
  116. /* Read a group entry from STREAM. This function is not standardized
  117. an probably never will.
  118. This function is not part of POSIX and therefore no official
  119. cancellation point. But due to similarity with an POSIX interface
  120. or due to the implementation it is a cancellation point and
  121. therefore not marked with __THROW. */
  122. extern int fgetgrent_r (FILE *__restrict __stream,
  123. struct group *__restrict __resultbuf,
  124. char *__restrict __buffer, size_t __buflen,
  125. struct group **__restrict __result);
  126. # endif
  127. #endif /* POSIX or reentrant */
  128. #if defined __USE_BSD || defined __USE_GNU
  129. # define __need_size_t
  130. # include <stddef.h>
  131. /* Store at most *NGROUPS members of the group set for USER into
  132. *GROUPS. Also include GROUP. The actual number of groups found is
  133. returned in *NGROUPS. Return -1 if the if *NGROUPS is too small.
  134. In all cases the actual number of groups is stored in *NGROUPS.
  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. #endif
  142. #if defined __USE_BSD
  143. /* Set the group set for the current user to GROUPS (N of them). */
  144. extern int setgroups (size_t __n, __const __gid_t *__groups) __THROW;
  145. /* Initialize the group set for the current user
  146. by reading the group database and using all groups
  147. of which USER is a member. Also include GROUP.
  148. This function is not part of POSIX and therefore no official
  149. cancellation point. But due to similarity with an POSIX interface
  150. or due to the implementation it is a cancellation point and
  151. therefore not marked with __THROW. */
  152. extern int initgroups (__const char *__user, __gid_t __group);
  153. #endif /* Use BSD. */
  154. __END_DECLS
  155. #endif /* grp.h */