grp.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. /* Copyright (C) 1991,92,95,96,97,98,99,2000,01 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 __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. extern void setgrent (void) __THROW;
  45. /* Close the group-file stream. */
  46. extern void endgrent (void) __THROW;
  47. /* Read an entry from the group-file stream, opening it if necessary. */
  48. extern struct group *getgrent (void) __THROW;
  49. #endif
  50. #ifdef __USE_SVID
  51. /* Read a group entry from STREAM. */
  52. extern struct group *fgetgrent (FILE *__stream) __THROW;
  53. #endif
  54. #ifdef __USE_GNU
  55. /* Write the given entry onto the given stream. */
  56. extern int putgrent (__const struct group *__restrict __p,
  57. FILE *__restrict __f) __THROW;
  58. #endif
  59. /* Search for an entry with a matching group ID. */
  60. extern struct group *getgrgid (__gid_t __gid) __THROW;
  61. /* Search for an entry with a matching group name. */
  62. extern struct group *getgrnam (__const char *__name) __THROW;
  63. #if defined __USE_POSIX || defined __USE_MISC
  64. # ifdef __USE_MISC
  65. /* Reasonable value for the buffer sized used in the reentrant
  66. functions below. But better use `sysconf'. */
  67. # define NSS_BUFLEN_GROUP 1024
  68. # endif
  69. /* Reentrant versions of some of the functions above.
  70. PLEASE NOTE: the `getgrent_r' function is not (yet) standardized.
  71. The interface may change in later versions of this library. But
  72. the interface is designed following the principals used for the
  73. other reentrant functions so the chances are good this is what the
  74. POSIX people would choose. */
  75. # ifdef __USE_GNU
  76. extern int getgrent_r (struct group *__restrict __resultbuf,
  77. char *__restrict __buffer, size_t __buflen,
  78. struct group **__restrict __result) __THROW;
  79. # endif
  80. /* Search for an entry with a matching group ID. */
  81. extern int getgrgid_r (__gid_t __gid, struct group *__restrict __resultbuf,
  82. char *__restrict __buffer, size_t __buflen,
  83. struct group **__restrict __result) __THROW;
  84. /* Search for an entry with a matching group name. */
  85. extern int getgrnam_r (__const char *__restrict __name,
  86. struct group *__restrict __resultbuf,
  87. char *__restrict __buffer, size_t __buflen,
  88. struct group **__restrict __result) __THROW;
  89. # ifdef __USE_SVID
  90. /* Read a group entry from STREAM. This function is not standardized
  91. an probably never will. */
  92. extern int fgetgrent_r (FILE *__restrict __stream,
  93. struct group *__restrict __resultbuf,
  94. char *__restrict __buffer, size_t __buflen,
  95. struct group **__restrict __result) __THROW;
  96. # endif
  97. #endif /* POSIX or reentrant */
  98. #ifdef __USE_BSD
  99. # define __need_size_t
  100. # include <stddef.h>
  101. /* Set the group set for the current user to GROUPS (N of them). */
  102. extern int setgroups (size_t __n, __const __gid_t *__groups) __THROW;
  103. /* Store at most *NGROUPS members of the group set for USER into
  104. *GROUPS. Also include GROUP. The actual number of groups found is
  105. returned in *NGROUPS. Return -1 if the if *NGROUPS is too small. */
  106. extern int getgrouplist (__const char *__user, __gid_t __group,
  107. __gid_t *__groups, int *__ngroups) __THROW;
  108. /* Initialize the group set for the current user
  109. by reading the group database and using all groups
  110. of which USER is a member. Also include GROUP. */
  111. extern int initgroups (__const char *__user, __gid_t __group) __THROW;
  112. #endif /* Use BSD. */
  113. __END_DECLS
  114. #endif /* grp.h */