Linux and UNIX Man Pages

Linux & Unix Commands - Search Man Pages

getpw(3) [redhat man page]

GETPW(3)						     Linux Programmer's Manual							  GETPW(3)

NAME
getpw - Re-construct password line entry SYNOPSIS
#include <pwd.h> #include <sys/types.h> int getpw(uid_t uid, char *buf); DESCRIPTION
The getpw() function re-constructs the password line entry for the given user uid 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; /* user name */ char *pw_passwd; /* user password */ uid_t pw_uid; /* user id */ gid_t pw_gid; /* group id */ char *pw_gecos; /* real name */ char *pw_dir; /* home directory */ char *pw_shell; /* shell program */ }; RETURN VALUE
The getpw() function returns 0 on success, or -1 if an error occurs. ERRORS
ENOMEM Insufficient memory to allocate passwd structure. FILES
/etc/passwd password database file CONFORMING TO
SYSVr2. BUGS
The getpw() function is dangerous as it may overflow the provided buffer buf. It is obsoleted by getpwuid(). SEE ALSO
fgetpwent(3), getpwent(3), setpwent(3), endpwent(3), getpwnam(3), getpwuid(3), putpwent(3), passwd(5) GNU
1996-05-27 GETPW(3)

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)
Man Page

15 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

ASCII character to accept logon password

Hey all, Just found your forum...Looks super rich with info! Can't wait to get through it all. I am currently writing a web app in .net that telnets into a unix server (require uid + passwd), runs a command, and returns that output to be displayed on the web page. I have gotten through the... (8 Replies)
Discussion started by: gord
8 Replies

2. Shell Programming and Scripting

sorting output

hi, I get an output like uid=user1 gecos=user uid=user2 gecos=admin gecos=sol admin uid=user3 uid=user4 gecos=sol, admin and need it modified to: uid=user1 gecos=user (3 Replies)
Discussion started by: funksen
3 Replies

3. Shell Programming and Scripting

checking uid

How do i go about getting the uid of the user and verify ? if then echo "You are not a superuser, please login as a superuser" exit1; fi the above code doesn't work. can some guru please help me. 1. how to get the uid of the user ? i know by typing id but how to... (7 Replies)
Discussion started by: filthymonk
7 Replies

4. Shell Programming and Scripting

extracting a line based on line number

i want to cut all the entries from the /etc/passwd file in which the uid is> 500 for this i was writing this ,m quiet new to all this.. scripting but on the 6th n 8th line ,, i hav to specify a line number .. to get the commnd working .. but i want to use variable i instead of that ,,... (2 Replies)
Discussion started by: narendra.pant
2 Replies

5. Shell Programming and Scripting

loop help

Hi there, I have 2 files: current.uid 5516 5517 5518 5519 5520 5521 5522 5523 5524 5525 user.uid 5506 (7 Replies)
Discussion started by: kkkk
7 Replies

6. Shell Programming and Scripting

Manipulating the etc/passwd file with sed

How can i use sed to extract the user name and home directory from the /etc/passwd/ file on my server. (11 Replies)
Discussion started by: Pauline mugisha
11 Replies

7. Shell Programming and Scripting

words extracting

Hi, Pls assist. dn: uid=test,ou=test,dc=com description: password sunIdentityServerDeviceStatus: Active uid: test objectClass: sunIdentityServerDevice objectClass: iplanet-am-user-service objectClass: top objectClass: iPlanetPreferences sunIdentityServerDeviceType: blabla cn: default... (3 Replies)
Discussion started by: hudson03051nh
3 Replies

8. Shell Programming and Scripting

Find Output Formatting

Greetings, I need to find few patterns related to password (pwsd, pwd, password etc) in a directory includig sub -directories. I need to redirect the output of find (in combination with grep) to a file which will be later used to verify the files. OS is Sun Solaris 5.10. The out put file format... (3 Replies)
Discussion started by: Rajpreet1985
3 Replies

9. Shell Programming and Scripting

uid script help

i need a script to process a password file and based on the UIDs in the password file, generate the new UID that is 1 greater than the highest uid. i have some script logic but i dont really understand it. any help? #!/usr/bin/perl ########################################## #... (3 Replies)
Discussion started by: livewire06
3 Replies

10. Shell Programming and Scripting

find a user on the system

i am prompting for a name to search. read user if then however, i get this error: please enter a username on the system: fool menu_script2.sh: line 123: (4 Replies)
Discussion started by: icelated
4 Replies

11. Solaris

can't open /etc/passwd file

Hi all, Yet another problem on one of my nodes. I am unable to open my password file .It shows some junk alphabets. root@ecosdp26a>cat /etc/passwd... (10 Replies)
Discussion started by: vivek.goel.piet
10 Replies

12. Shell Programming and Scripting

to hide uname and pwd

Hi all, In Unix shell script i am connecting to oracle database and it is executing fine, my problem is my user name and password is visible for all, how to hide. Note -- username and password is hard coded, it is my requirement example-- #!/bin/sh ------ ------ sqlplus uname/pwd... (4 Replies)
Discussion started by: krupasindhu18
4 Replies

13. Shell Programming and Scripting

Maintain health of passwd file

Hello guys I am about to write a script that is based on "The Linux Administration Handbook" The exercise is as follows: Write a shell script to help monitor the health of the /etc/passwd file. Find entries that have UID0 Find entries that have no password (needs /etc/shadow) Find any... (4 Replies)
Discussion started by: Learn4Life
4 Replies

14. UNIX for Advanced & Expert Users

Passing parameter inside the expression

Hello, i need to pass the variable in place of pwd. how to display variable in the bleow syntax. suppose, passwd="test", then 'id/$passwd..... FEDFlagResult=`sqlplus -S 'id/pwd@(DESCRIPTION= (ADDRESS=(PROTOCOL=TCP)(HOST=localhost)(PORT=1643))(CONNECT_DATA= (SID=peta1)))'<< EOF select... (4 Replies)
Discussion started by: balareddy
4 Replies

15. Shell Programming and Scripting

Copying characters on each line in a file

Hello, I would like to copy the first and third char on each line of a file and place them in the 14h and 17th char positions. The file name is listed first and is 6 char's and the dir name is second and also same char size on each line. The file has thousands of lines. Initial... (6 Replies)
Discussion started by: dmm
6 Replies