| 1 |
'\" t |
| 2 |
.\" Copyright 1993, David Metcalfe <[email protected]> |
| 3 |
.\" Copyright, the authors of the Linux man-pages project |
| 4 |
.\" |
| 5 |
.\" SPDX-License-Identifier: Linux-man-pages-copyleft |
| 6 |
.\" |
| 7 |
.TH getpw 3 2026-02-08 "Linux man-pages 6.18" |
| 8 |
.SH NAME |
| 9 |
getpw \- reconstruct password line entry |
| 10 |
.SH LIBRARY |
| 11 |
Standard C library |
| 12 |
.RI ( libc ,\~ \-lc ) |
| 13 |
.SH SYNOPSIS |
| 14 |
.nf |
| 15 |
.BR "#define _GNU_SOURCE" " /* See feature_test_macros(7) */" |
| 16 |
.B #include <sys/types.h> |
| 17 |
.B #include <pwd.h> |
| 18 |
.P |
| 19 |
.BI "[[deprecated]] int getpw(uid_t " uid ", char *" buf ); |
| 20 |
.fi |
| 21 |
.SH DESCRIPTION |
| 22 |
The |
| 23 |
.BR getpw () |
| 24 |
function reconstructs the password line entry for |
| 25 |
the given user ID |
| 26 |
.I uid |
| 27 |
in the buffer |
| 28 |
.IR buf . |
| 29 |
The returned buffer contains a line of format |
| 30 |
.P |
| 31 |
.in +4n |
| 32 |
.EX |
| 33 |
.B name:passwd:uid:gid:gecos:dir:shell |
| 34 |
.EE |
| 35 |
.in |
| 36 |
.P |
| 37 |
The |
| 38 |
.I passwd |
| 39 |
structure is defined in |
| 40 |
.I <pwd.h> |
| 41 |
as follows: |
| 42 |
.P |
| 43 |
.in +4n |
| 44 |
.EX |
| 45 |
struct passwd { |
| 46 |
char *pw_name; /* username */ |
| 47 |
char *pw_passwd; /* user password */ |
| 48 |
uid_t pw_uid; /* user ID */ |
| 49 |
gid_t pw_gid; /* group ID */ |
| 50 |
char *pw_gecos; /* user information */ |
| 51 |
char *pw_dir; /* home directory */ |
| 52 |
char *pw_shell; /* shell program */ |
| 53 |
}; |
| 54 |
.EE |
| 55 |
.in |
| 56 |
.P |
| 57 |
For more information about the fields of this structure, see |
| 58 |
.BR passwd (5). |
| 59 |
.SH RETURN VALUE |
| 60 |
The |
| 61 |
.BR getpw () |
| 62 |
function returns 0 on success; |
| 63 |
on error, it returns \-1, and |
| 64 |
.I errno |
| 65 |
is set to indicate the error. |
| 66 |
.P |
| 67 |
If |
| 68 |
.I uid |
| 69 |
is not found in the password database, |
| 70 |
.BR getpw () |
| 71 |
returns \-1, sets |
| 72 |
.I errno |
| 73 |
to 0, and leaves |
| 74 |
.I buf |
| 75 |
unchanged. |
| 76 |
.SH ERRORS |
| 77 |
.TP |
| 78 |
.BR 0 " or " ENOENT |
| 79 |
No user corresponding to |
| 80 |
.IR uid . |
| 81 |
.TP |
| 82 |
.B EINVAL |
| 83 |
.I buf |
| 84 |
is NULL. |
| 85 |
.TP |
| 86 |
.B ENOMEM |
| 87 |
Insufficient memory to allocate |
| 88 |
.I passwd |
| 89 |
structure. |
| 90 |
.SH FILES |
| 91 |
.TP |
| 92 |
.I /etc/passwd |
| 93 |
password database file |
| 94 |
.SH ATTRIBUTES |
| 95 |
For an explanation of the terms used in this section, see |
| 96 |
.BR attributes (7). |
| 97 |
.TS |
| 98 |
allbox; |
| 99 |
lbx lb lb |
| 100 |
l l l. |
| 101 |
Interface Attribute Value |
| 102 |
T{ |
| 103 |
.na |
| 104 |
.nh |
| 105 |
.BR getpw () |
| 106 |
T} Thread safety MT-Safe locale |
| 107 |
.TE |
| 108 |
.SH STANDARDS |
| 109 |
None. |
| 110 |
.SH HISTORY |
| 111 |
SVr2. |
| 112 |
.SH BUGS |
| 113 |
The |
| 114 |
.BR getpw () |
| 115 |
function is dangerous as it may overflow the provided buffer |
| 116 |
.IR buf . |
| 117 |
It is obsoleted by |
| 118 |
.BR getpwuid (3). |
| 119 |
.SH SEE ALSO |
| 120 |
.BR endpwent (3), |
| 121 |
.BR fgetpwent (3), |
| 122 |
.BR getpwent (3), |
| 123 |
.BR getpwnam (3), |
| 124 |
.BR getpwuid (3), |
| 125 |
.BR putpwent (3), |
| 126 |
.BR setpwent (3), |
| 127 |
.BR passwd (5) |