futex.2: Rework the description of FUTEX_LOCK_PI2
[man-pages.git] / man3 / getpw.3
blob8a64e1897eaa1cf7a5c15038126779b5a871ce11
1 .\" Copyright 1993 David Metcalfe (david@prism.demon.co.uk)
2 .\"
3 .\" %%%LICENSE_START(VERBATIM)
4 .\" Permission is granted to make and distribute verbatim copies of this
5 .\" manual provided the copyright notice and this permission notice are
6 .\" preserved on all copies.
7 .\"
8 .\" Permission is granted to copy and distribute modified versions of this
9 .\" manual under the conditions for verbatim copying, provided that the
10 .\" entire resulting derived work is distributed under the terms of a
11 .\" permission notice identical to this one.
12 .\"
13 .\" Since the Linux kernel and libraries are constantly changing, this
14 .\" manual page may be incorrect or out-of-date.  The author(s) assume no
15 .\" responsibility for errors or omissions, or for damages resulting from
16 .\" the use of the information contained herein.  The author(s) may not
17 .\" have taken the same level of care in the production of this manual,
18 .\" which is licensed free of charge, as they might when working
19 .\" professionally.
20 .\"
21 .\" Formatted or processed versions of this manual, if unaccompanied by
22 .\" the source, must acknowledge the copyright and authors of this work.
23 .\" %%%LICENSE_END
24 .\"
25 .\" References consulted:
26 .\"     Linux libc source code
27 .\"     Lewine's _POSIX Programmer's Guide_ (O'Reilly & Associates, 1991)
28 .\"     386BSD man pages
29 .\" Modified Sat Jul 24 19:23:25 1993 by Rik Faith (faith@cs.unc.edu)
30 .\" Modified Mon May 27 21:37:47 1996 by Martin Schulze (joey@linux.de)
31 .\"
32 .TH GETPW 3 2021-03-22 "GNU" "Linux Programmer's Manual"
33 .SH NAME
34 getpw \- reconstruct password line entry
35 .SH SYNOPSIS
36 .nf
37 .BR "#define _GNU_SOURCE" "             /* See feature_test_macros(7) */"
38 .B #include <sys/types.h>
39 .B #include <pwd.h>
40 .PP
41 .BI "int getpw(uid_t " uid ", char *" buf );
42 .fi
43 .SH DESCRIPTION
44 The
45 .BR getpw ()
46 function reconstructs the password line entry for
47 the given user ID \fIuid\fP in the buffer \fIbuf\fP.
48 The returned buffer contains a line of format
49 .PP
50 .in +4n
51 .EX
52 .B name:passwd:uid:gid:gecos:dir:shell
53 .EE
54 .in
55 .PP
56 The \fIpasswd\fP structure is defined in \fI<pwd.h>\fP as follows:
57 .PP
58 .in +4n
59 .EX
60 struct passwd {
61     char   *pw_name;       /* username */
62     char   *pw_passwd;     /* user password */
63     uid_t   pw_uid;        /* user ID */
64     gid_t   pw_gid;        /* group ID */
65     char   *pw_gecos;      /* user information */
66     char   *pw_dir;        /* home directory */
67     char   *pw_shell;      /* shell program */
69 .EE
70 .in
71 .PP
72 For more information about the fields of this structure, see
73 .BR passwd (5).
74 .SH RETURN VALUE
75 The
76 .BR getpw ()
77 function returns 0 on success; on error, it returns \-1, and
78 .I errno
79 is set to indicate the error.
80 .PP
82 .I uid
83 is not found in the password database,
84 .BR getpw ()
85 returns \-1, sets
86 .I errno
87 to 0, and leaves
88 .I buf
89 unchanged.
90 .SH ERRORS
91 .TP
92 .BR 0 " or " ENOENT
93 No user corresponding to
94 .IR uid .
95 .TP
96 .B EINVAL
97 .I buf
98 is NULL.
99 .TP
100 .B ENOMEM
101 Insufficient memory to allocate
102 .I passwd
103 structure.
104 .SH FILES
106 .I /etc/passwd
107 password database file
108 .SH ATTRIBUTES
109 For an explanation of the terms used in this section, see
110 .BR attributes (7).
111 .ad l
114 allbox;
115 lbx lb lb
116 l l l.
117 Interface       Attribute       Value
119 .BR getpw ()
120 T}      Thread safety   MT-Safe locale
124 .sp 1
125 .SH CONFORMING TO
126 SVr2.
127 .SH BUGS
129 .BR getpw ()
130 function is dangerous as it may overflow the provided buffer
131 .IR buf .
132 It is obsoleted by
133 .BR getpwuid (3).
134 .SH SEE ALSO
135 .BR endpwent (3),
136 .BR fgetpwent (3),
137 .BR getpwent (3),
138 .BR getpwnam (3),
139 .BR getpwuid (3),
140 .BR putpwent (3),
141 .BR setpwent (3),
142 .BR passwd (5)