master
  1/* Copyright (C) 1991-2025 Free Software Foundation, Inc.
  2   This file is part of the GNU C Library.
  3
  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
  9   The GNU C Library is distributed in the hope that it will be useful,
 10   but WITHOUT ANY WARRANTY; without even the implied warranty of
 11   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 12   Lesser General Public License for more details.
 13
 14   You should have received a copy of the GNU Lesser General Public
 15   License along with the GNU C Library; if not, see
 16   <https://www.gnu.org/licenses/>.  */
 17
 18/*
 19 *	POSIX Standard: 9.2.2 User Database Access	<pwd.h>
 20 */
 21
 22#ifndef	_PWD_H
 23#define	_PWD_H	1
 24
 25#include <features.h>
 26
 27__BEGIN_DECLS
 28
 29#include <bits/types.h>
 30
 31#define __need_size_t
 32#include <stddef.h>
 33
 34#if defined __USE_XOPEN || defined __USE_XOPEN2K
 35/* The Single Unix specification says that some more types are
 36   available here.  */
 37# ifndef __gid_t_defined
 38typedef __gid_t gid_t;
 39#  define __gid_t_defined
 40# endif
 41
 42# ifndef __uid_t_defined
 43typedef __uid_t uid_t;
 44#  define __uid_t_defined
 45# endif
 46#endif
 47
 48/* A record in the user database.  */
 49struct passwd
 50{
 51  char *pw_name;		/* Username.  */
 52  char *pw_passwd;		/* Hashed passphrase, if shadow database
 53                                   not in use (see shadow.h).  */
 54  __uid_t pw_uid;		/* User ID.  */
 55  __gid_t pw_gid;		/* Group ID.  */
 56  char *pw_gecos;		/* Real name.  */
 57  char *pw_dir;			/* Home directory.  */
 58  char *pw_shell;		/* Shell program.  */
 59};
 60
 61
 62#ifdef __USE_MISC
 63# include <bits/types/FILE.h>
 64#endif
 65
 66
 67#if defined __USE_MISC || defined __USE_XOPEN_EXTENDED
 68/* Rewind the user database stream.
 69
 70   This function is a possible cancellation point and therefore not
 71   marked with __THROW.  */
 72extern void setpwent (void);
 73
 74/* Close the user database stream.
 75
 76   This function is a possible cancellation point and therefore not
 77   marked with __THROW.  */
 78extern void endpwent (void);
 79
 80/* Read an entry from the user database stream, opening it if necessary.
 81
 82   This function is a possible cancellation point and therefore not
 83   marked with __THROW.  */
 84extern struct passwd *getpwent (void);
 85#endif
 86
 87#ifdef	__USE_MISC
 88/* Read a user database entry from STREAM.
 89
 90   This function is not part of POSIX and therefore no official
 91   cancellation point.  But due to similarity with an POSIX interface
 92   or due to the implementation it is a cancellation point and
 93   therefore not marked with __THROW.  */
 94extern struct passwd *fgetpwent (FILE *__stream) __nonnull ((1));
 95
 96/* Write a given user database entry onto the given stream.
 97
 98   This function is not part of POSIX and therefore no official
 99   cancellation point.  But due to similarity with an POSIX interface
100   or due to the implementation it is a cancellation point and
101   therefore not marked with __THROW.  */
102extern int putpwent (const struct passwd *__restrict __p,
103		     FILE *__restrict __f);
104#endif
105
106/* Retrieve the user database entry for the given user ID.
107
108   This function is a possible cancellation point and therefore not
109   marked with __THROW.  */
110extern struct passwd *getpwuid (__uid_t __uid);
111
112/* Retrieve the user database entry for the given username.
113
114   This function is a possible cancellation point and therefore not
115   marked with __THROW.  */
116extern struct passwd *getpwnam (const char *__name) __nonnull ((1));
117
118#ifdef __USE_POSIX
119
120# ifdef __USE_MISC
121/* Reasonable value for the buffer sized used in the reentrant
122   functions below.  But better use `sysconf'.  */
123#  define NSS_BUFLEN_PASSWD	1024
124# endif
125
126/* Reentrant versions of some of the functions above.
127
128   PLEASE NOTE: the `getpwent_r' function is not (yet) standardized.
129   The interface may change in later versions of this library.  But
130   the interface is designed following the principals used for the
131   other reentrant functions so the chances are good this is what the
132   POSIX people would choose.  */
133
134# ifdef __USE_MISC
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.  */
139extern int getpwent_r (struct passwd *__restrict __resultbuf,
140		       char *__restrict __buffer, size_t __buflen,
141		       struct passwd **__restrict __result)
142    __nonnull ((1, 2, 4))
143    __attr_access ((__write_only__, 2, 3));
144# endif
145
146extern int getpwuid_r (__uid_t __uid,
147		       struct passwd *__restrict __resultbuf,
148		       char *__restrict __buffer, size_t __buflen,
149		       struct passwd **__restrict __result)
150    __nonnull ((2, 3, 5))
151    __attr_access ((__write_only__, 3, 4));
152
153extern int getpwnam_r (const char *__restrict __name,
154		       struct passwd *__restrict __resultbuf,
155		       char *__restrict __buffer, size_t __buflen,
156		       struct passwd **__restrict __result)
157    __nonnull ((1, 2, 3, 5))
158    __attr_access ((__write_only__, 3, 4));
159
160
161# ifdef	__USE_MISC
162/* Read a user database entry from STREAM.  This function is not
163   standardized and probably never will.
164
165   This function is not part of POSIX and therefore no official
166   cancellation point.  But due to similarity with an POSIX interface
167   or due to the implementation it is a cancellation point and
168   therefore not marked with __THROW.  */
169extern int fgetpwent_r (FILE *__restrict __stream,
170			struct passwd *__restrict __resultbuf,
171			char *__restrict __buffer, size_t __buflen,
172			struct passwd **__restrict __result)
173    __nonnull ((1, 2, 3, 5))
174    __attr_access ((__write_only__, 3, 4));
175# endif
176
177#endif	/* POSIX or reentrant */
178
179#ifdef __USE_GNU
180/* Write a traditional /etc/passwd line, based on the user database
181   entry for the given UID, to BUFFER; space for BUFFER must be
182   allocated by the caller.
183
184   This function is not part of POSIX and therefore no official
185   cancellation point.  But due to similarity with an POSIX interface
186   or due to the implementation it is a cancellation point and
187   therefore not marked with __THROW.  */
188extern int getpw (__uid_t __uid, char *__buffer);
189#endif
190
191__END_DECLS
192
193#endif /* pwd.h  */