getpw(3C) Standard C Library Functions getpw(3C)NAME
getpw - get passwd entry from UID
SYNOPSIS
#include <stdlib.h>
int getpw(uid_t uid, char *buf);
DESCRIPTION
The getpw() function searches the user data base for a user id number that equals uid, copies the line of the password file in which uid
was found into the array pointed to by buf, and returns 0. getpw() returns non-zero if uid cannot be found.
USAGE
This function is included only for compatibility with prior systems and should not be used; the functions described on the getpwnam(3C)
manual page should be used instead.
If the /etc/passwd and the /etc/group files have a plus sign (+) for the NIS entry, then getpwent() and getgrent() will not return NULL
when the end of file is reached. See getpwnam(3C).
RETURN VALUES
The getpw() function returns non-zero on error.
ATTRIBUTES
See attributes(5) for descriptions of the following attributes:
+-----------------------------+-----------------------------+
| ATTRIBUTE TYPE | ATTRIBUTE VALUE |
+-----------------------------+-----------------------------+
|MT-Level |Safe |
+-----------------------------+-----------------------------+
SEE ALSO getpwnam(3C), passwd(4), attributes(5)SunOS 5.11 29 Dec 1996 getpw(3C)
Check Out this Related Man Page
GETPW(3) Linux Programmer's Manual GETPW(3)NAME
getpw - reconstruct password line entry
SYNOPSIS
#define _GNU_SOURCE /* See feature_test_macros(7) */
#include <sys/types.h>
#include <pwd.h>
int getpw(uid_t uid, char *buf);
DESCRIPTION
The getpw() function reconstructs the password line entry for the given user ID uid in the buffer buf. The returned buffer contains a line
of format
name:passwd:uid:gid:gecos:dir:shell
The passwd structure is defined in <pwd.h> as follows:
struct passwd {
char *pw_name; /* username */
char *pw_passwd; /* user password */
uid_t pw_uid; /* user ID */
gid_t pw_gid; /* group ID */
char *pw_gecos; /* user information */
char *pw_dir; /* home directory */
char *pw_shell; /* shell program */
};
For more information about the fields of this structure, see passwd(5).
RETURN VALUE
The getpw() function returns 0 on success; on error, it returns -1, and errno is set to indicate the error.
If uid is not found in the password database, getpw() returns -1, sets errno to 0, and leaves buf unchanged.
ERRORS
0 or ENOENT
No user corresponding to uid.
EINVAL buf is NULL.
ENOMEM Insufficient memory to allocate passwd structure.
FILES
/etc/passwd
password database file
ATTRIBUTES
For an explanation of the terms used in this section, see attributes(7).
+----------+---------------+----------------+
|Interface | Attribute | Value |
+----------+---------------+----------------+
|getpw() | Thread safety | MT-Safe locale |
+----------+---------------+----------------+
CONFORMING TO
SVr2.
BUGS
The getpw() function is dangerous as it may overflow the provided buffer buf. It is obsoleted by getpwuid(3).
SEE ALSO endpwent(3), fgetpwent(3), getpwent(3), getpwnam(3), getpwuid(3), putpwent(3), setpwent(3), passwd(5)COLOPHON
This page is part of release 4.15 of the Linux man-pages project. A description of the project, information about reporting bugs, and the
latest version of this page, can be found at https://www.kernel.org/doc/man-pages/.
GNU 2017-09-15 GETPW(3)
Is it possible given a uid to determine information about the person with the uid? An example would be simple information regarding what group and the name of the person associated with that uid. It seems there is probably an easy staring me in the face but i cant seem to find it... (3 Replies)
Hi,
I know the uid and I wan to know the user name the uid belongs to. How can I get it.
Suppose My user name is ssnayak and coresponding uid is 1110
Similarly I know one uid 1212 and how can I come to know the user name for this uid.
Thanks & Regards,
Siba (3 Replies)
Hi,
I need to find a string, if it finds then I need to print it , otherwise it has to goto next line....
input is====>
uid = shashi, india uid ,uid= asia
uid= none, uid=india. none
==========
output shold be
uid = shashi, india
uid ,
uid= asia
uid= none,
uid=india. none
... (1 Reply)
Hi,
I need to get the value of 'uid' from a line in file f1. For example, in the line below, I need to get the value '150', from the 'anonuid=150' key, and I need to verify that this is a valid uid by checking it against /etc/passwd (i.e) I want to compare this uid, 150 (or more if there are any... (2 Replies)
Hi all
I have a strange problem on one my my AIX machines. We have created a user called testroot with the same UID as root (uid=0) by changing the uid of that user in the /etc/passwd file. I know that this is a security breach but this is a test system.
Now the strange thing that happens is that... (3 Replies)