Follow Techotopia on Twitter

On-line Guides
All Guides
eBook Store
iOS / Android
Linux for Beginners
Office Productivity
Linux Installation
Linux Security
Linux Utilities
Linux Virtualization
Linux Kernel
System/Network Admin
Programming
Scripting Languages
Development Tools
Web Development
GUI Toolkits/Desktop
Databases
Mail Systems
openSolaris
Eclipse Documentation
Techotopia.com
Virtuatopia.com
Answertopia.com

How To Guides
Virtualization
General System Admin
Linux Security
Linux Filesystems
Web Servers
Graphics & Desktop
PC Hardware
Windows
Problem Solutions
Privacy Policy

  




 

 

29.13.2 Looking Up One User

You can search the system user database for information about a specific user using getpwuid or getpwnam. These functions are declared in pwd.h.

— Function: struct passwd * getpwuid (uid_t uid)

This function returns a pointer to a statically-allocated structure containing information about the user whose user ID is uid. This structure may be overwritten on subsequent calls to getpwuid.

A null pointer value indicates there is no user in the data base with user ID uid.

— Function: int getpwuid_r (uid_t uid, struct passwd *result_buf, char *buffer, size_t buflen, struct passwd **result)

This function is similar to getpwuid in that it returns information about the user whose user ID is uid. However, it fills the user supplied structure pointed to by result_buf with the information instead of using a static buffer. The first buflen bytes of the additional buffer pointed to by buffer are used to contain additional information, normally strings which are pointed to by the elements of the result structure.

If a user with ID uid is found, the pointer returned in result points to the record which contains the wanted data (i.e., result contains the value result_buf). If no user is found or if an error occurred, the pointer returned in result is a null pointer. The function returns zero or an error code. If the buffer buffer is too small to contain all the needed information, the error code ERANGE is returned and errno is set to ERANGE.

— Function: struct passwd * getpwnam (const char *name)

This function returns a pointer to a statically-allocated structure containing information about the user whose user name is name. This structure may be overwritten on subsequent calls to getpwnam.

A null pointer return indicates there is no user named name.

— Function: int getpwnam_r (const char *name, struct passwd *result_buf, char *buffer, size_t buflen, struct passwd **result)

This function is similar to getpwnam in that is returns information about the user whose user name is name. However, like getpwuid_r, it fills the user supplied buffers in result_buf and buffer with the information instead of using a static buffer.

The return values are the same as for getpwuid_r.


 
 
  Published under the terms of the GNU General Public License Design by Interspire