OSDN Git Service

LDP: Update original to LDP v3.79
[linuxjm/LDP_man-pages.git] / original / man3 / getpw.3
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 2015-01-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 .sp
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 .sp
50 .RS
51 .B name:passwd:uid:gid:gecos:dir:shell
52 .RE
53 .PP
54 The \fIpasswd\fP structure is defined in \fI<pwd.h>\fP as follows:
55 .sp
56 .in +4n
57 .nf
58 struct passwd {
59     char   *pw_name;       /* username */
60     char   *pw_passwd;     /* user password */
61     uid_t   pw_uid;        /* user ID */
62     gid_t   pw_gid;        /* group ID */
63     char   *pw_gecos;      /* user information */
64     char   *pw_dir;        /* home directory */
65     char   *pw_shell;      /* shell program */
66 };
67 .fi
68 .in
69 .PP
70 For more information about the fields of this structure, see
71 .BR passwd (5).
72 .SH RETURN VALUE
73 The
74 .BR getpw ()
75 function returns 0 on success; on error, it returns \-1, and
76 .I errno
77 is set to indicate the error.
78
79 If
80 .I uid
81 is not found in the password database,
82 .BR getpw ()
83 returns \-1, sets
84 .I errno
85 to 0, and leaves
86 .I buf
87 unchanged.
88 .SH ERRORS
89 .TP
90 .BR 0 " or " ENOENT
91 No user corresponding to
92 .IR uid .
93 .TP
94 .B EINVAL
95 .I buf
96 is NULL.
97 .TP
98 .B ENOMEM
99 Insufficient memory to allocate
100 .I passwd
101 structure.
102 .SH FILES
103 .TP
104 .I /etc/passwd
105 password database file
106 .SH CONFORMING TO
107 SVr2.
108 .SH BUGS
109 The
110 .BR getpw ()
111 function is dangerous as it may overflow the provided buffer
112 .IR buf .
113 It is obsoleted by
114 .BR getpwuid (3).
115 .SH SEE ALSO
116 .BR endpwent (3),
117 .BR fgetpwent (3),
118 .BR getpwent (3),
119 .BR getpwnam (3),
120 .BR getpwuid (3),
121 .BR putpwent (3),
122 .BR setpwent (3),
123 .BR passwd (5)
124 .SH COLOPHON
125 This page is part of release 3.79 of the Linux
126 .I man-pages
127 project.
128 A description of the project,
129 information about reporting bugs,
130 and the latest version of this page,
131 can be found at
132 \%http://www.kernel.org/doc/man\-pages/.