pwd.h 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. /* Copyright (C) 1991-2020 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. <https://www.gnu.org/licenses/>. */
  14. /*
  15. * POSIX Standard: 9.2.2 User Database Access <pwd.h>
  16. */
  17. #ifndef _PWD_H
  18. #define _PWD_H 1
  19. #include <features.h>
  20. __BEGIN_DECLS
  21. #include <bits/types.h>
  22. #define __need_size_t
  23. #include <stddef.h>
  24. #if defined __USE_XOPEN || defined __USE_XOPEN2K
  25. /* The Single Unix specification says that some more types are
  26. available here. */
  27. # ifndef __gid_t_defined
  28. typedef __gid_t gid_t;
  29. # define __gid_t_defined
  30. # endif
  31. # ifndef __uid_t_defined
  32. typedef __uid_t uid_t;
  33. # define __uid_t_defined
  34. # endif
  35. #endif
  36. /* A record in the user database. */
  37. struct passwd
  38. {
  39. char *pw_name; /* Username. */
  40. char *pw_passwd; /* Hashed passphrase, if shadow database
  41. not in use (see shadow.h). */
  42. __uid_t pw_uid; /* User ID. */
  43. __gid_t pw_gid; /* Group ID. */
  44. char *pw_gecos; /* Real name. */
  45. char *pw_dir; /* Home directory. */
  46. char *pw_shell; /* Shell program. */
  47. };
  48. #ifdef __USE_MISC
  49. # include <bits/types/FILE.h>
  50. #endif
  51. #if defined __USE_MISC || defined __USE_XOPEN_EXTENDED
  52. /* Rewind the user database stream.
  53. This function is a possible cancellation point and therefore not
  54. marked with __THROW. */
  55. extern void setpwent (void);
  56. /* Close the user database stream.
  57. This function is a possible cancellation point and therefore not
  58. marked with __THROW. */
  59. extern void endpwent (void);
  60. /* Read an entry from the user database stream, opening it if necessary.
  61. This function is a possible cancellation point and therefore not
  62. marked with __THROW. */
  63. extern struct passwd *getpwent (void);
  64. #endif
  65. #ifdef __USE_MISC
  66. /* Read a user database entry from STREAM.
  67. This function is not part of POSIX and therefore no official
  68. cancellation point. But due to similarity with an POSIX interface
  69. or due to the implementation it is a cancellation point and
  70. therefore not marked with __THROW. */
  71. extern struct passwd *fgetpwent (FILE *__stream) __nonnull ((1));
  72. /* Write a given user database entry onto the given stream.
  73. This function is not part of POSIX and therefore no official
  74. cancellation point. But due to similarity with an POSIX interface
  75. or due to the implementation it is a cancellation point and
  76. therefore not marked with __THROW. */
  77. extern int putpwent (const struct passwd *__restrict __p,
  78. FILE *__restrict __f);
  79. #endif
  80. /* Retrieve the user database entry for the given user ID.
  81. This function is a possible cancellation point and therefore not
  82. marked with __THROW. */
  83. extern struct passwd *getpwuid (__uid_t __uid);
  84. /* Retrieve the user database entry for the given username.
  85. This function is a possible cancellation point and therefore not
  86. marked with __THROW. */
  87. extern struct passwd *getpwnam (const char *__name) __nonnull ((1));
  88. #ifdef __USE_POSIX
  89. # ifdef __USE_MISC
  90. /* Reasonable value for the buffer sized used in the reentrant
  91. functions below. But better use `sysconf'. */
  92. # define NSS_BUFLEN_PASSWD 1024
  93. # endif
  94. /* Reentrant versions of some of the functions above.
  95. PLEASE NOTE: the `getpwent_r' function is not (yet) standardized.
  96. The interface may change in later versions of this library. But
  97. the interface is designed following the principals used for the
  98. other reentrant functions so the chances are good this is what the
  99. POSIX people would choose. */
  100. # ifdef __USE_MISC
  101. /* This function is not part of POSIX and therefore no official
  102. cancellation point. But due to similarity with an POSIX interface
  103. or due to the implementation it is a cancellation point and
  104. therefore not marked with __THROW. */
  105. extern int getpwent_r (struct passwd *__restrict __resultbuf,
  106. char *__restrict __buffer, size_t __buflen,
  107. struct passwd **__restrict __result)
  108. __nonnull ((1, 2, 4));
  109. # endif
  110. extern int getpwuid_r (__uid_t __uid,
  111. struct passwd *__restrict __resultbuf,
  112. char *__restrict __buffer, size_t __buflen,
  113. struct passwd **__restrict __result)
  114. __nonnull ((2, 3, 5));
  115. extern int getpwnam_r (const char *__restrict __name,
  116. struct passwd *__restrict __resultbuf,
  117. char *__restrict __buffer, size_t __buflen,
  118. struct passwd **__restrict __result)
  119. __nonnull ((1, 2, 3, 5));
  120. # ifdef __USE_MISC
  121. /* Read a user database entry from STREAM. This function is not
  122. standardized and probably never will.
  123. This function is not part of POSIX and therefore no official
  124. cancellation point. But due to similarity with an POSIX interface
  125. or due to the implementation it is a cancellation point and
  126. therefore not marked with __THROW. */
  127. extern int fgetpwent_r (FILE *__restrict __stream,
  128. struct passwd *__restrict __resultbuf,
  129. char *__restrict __buffer, size_t __buflen,
  130. struct passwd **__restrict __result)
  131. __nonnull ((1, 2, 3, 5));
  132. # endif
  133. #endif /* POSIX or reentrant */
  134. #ifdef __USE_GNU
  135. /* Write a traditional /etc/passwd line, based on the user database
  136. entry for the given UID, to BUFFER; space for BUFFER must be
  137. allocated by the caller.
  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 getpw (__uid_t __uid, char *__buffer);
  143. #endif
  144. __END_DECLS
  145. #endif /* pwd.h */