1GETPW(3)                   Linux Programmer's Manual                  GETPW(3)
2
3
4

NAME

6       getpw - reconstruct password line entry
7

SYNOPSIS

9       #define _GNU_SOURCE             /* See feature_test_macros(7) */
10       #include <sys/types.h>
11       #include <pwd.h>
12
13       int getpw(uid_t uid, char *buf);
14

DESCRIPTION

16       The getpw() function reconstructs the password line entry for the given
17       user ID uid in the buffer buf.  The returned buffer contains a line  of
18       format
19
20           name:passwd:uid:gid:gecos:dir:shell
21
22       The passwd structure is defined in <pwd.h> as follows:
23
24           struct passwd {
25               char   *pw_name;       /* username */
26               char   *pw_passwd;     /* user password */
27               uid_t   pw_uid;        /* user ID */
28               gid_t   pw_gid;        /* group ID */
29               char   *pw_gecos;      /* user information */
30               char   *pw_dir;        /* home directory */
31               char   *pw_shell;      /* shell program */
32           };
33
34       For more information about the fields of this structure, see passwd(5).
35

RETURN VALUE

37       The getpw() function returns 0 on success; on error, it returns -1, and
38       errno is set to indicate the error.
39
40       If uid is not found in the password database, getpw() returns -1,  sets
41       errno to 0, and leaves buf unchanged.
42

ERRORS

44       0 or ENOENT
45              No user corresponding to uid.
46
47       EINVAL buf is NULL.
48
49       ENOMEM Insufficient memory to allocate passwd structure.
50

FILES

52       /etc/passwd
53              password database file
54

ATTRIBUTES

56       For  an  explanation  of  the  terms  used  in  this  section,  see at‐
57       tributes(7).
58
59       ┌─────────────────────────────────────┬───────────────┬────────────────┐
60Interface                            Attribute     Value          
61       ├─────────────────────────────────────┼───────────────┼────────────────┤
62getpw()                              │ Thread safety │ MT-Safe locale │
63       └─────────────────────────────────────┴───────────────┴────────────────┘
64

CONFORMING TO

66       SVr2.
67

BUGS

69       The getpw() function is dangerous as it may overflow the provided  buf‐
70       fer buf.  It is obsoleted by getpwuid(3).
71

SEE ALSO

73       endpwent(3), fgetpwent(3), getpwent(3), getpwnam(3), getpwuid(3), putp‐
74       went(3), setpwent(3), passwd(5)
75

COLOPHON

77       This page is part of release 5.12 of the Linux  man-pages  project.   A
78       description  of  the project, information about reporting bugs, and the
79       latest    version    of    this    page,    can     be     found     at
80       https://www.kernel.org/doc/man-pages/.
81
82
83
84GNU                               2021-03-22                          GETPW(3)
Impressum