diff options
Diffstat (limited to 'man-pages-posix-2003/man3p/getpwuid.3p')
-rw-r--r-- | man-pages-posix-2003/man3p/getpwuid.3p | 196 |
1 files changed, 196 insertions, 0 deletions
diff --git a/man-pages-posix-2003/man3p/getpwuid.3p b/man-pages-posix-2003/man3p/getpwuid.3p new file mode 100644 index 0000000..3298f6f --- /dev/null +++ b/man-pages-posix-2003/man3p/getpwuid.3p @@ -0,0 +1,196 @@ +.\" Copyright (c) 2001-2003 The Open Group, All Rights Reserved +.TH "GETPWUID" 3P 2003 "IEEE/The Open Group" "POSIX Programmer's Manual" +.\" getpwuid +.SH PROLOG +This manual page is part of the POSIX Programmer's Manual. +The Linux implementation of this interface may differ (consult +the corresponding Linux manual page for details of Linux behavior), +or the interface may not be implemented on Linux. +.SH NAME +getpwuid, getpwuid_r \- search user database for a user ID +.SH SYNOPSIS +.LP +\fB#include <pwd.h> +.br +.sp +struct passwd *getpwuid(uid_t\fP \fIuid\fP\fB); +.br +\fP +.LP +\fBint getpwuid_r(uid_t\fP \fIuid\fP\fB, struct passwd *\fP\fIpwd\fP\fB, +char +*\fP\fIbuffer\fP\fB, +.br +\ \ \ \ \ \ size_t\fP \fIbufsize\fP\fB, struct passwd **\fP\fIresult\fP\fB); +\fP +\fB +.br +\fP +.SH DESCRIPTION +.LP +The \fIgetpwuid\fP() function shall search the user database for an +entry with a matching \fIuid\fP. +.LP +The \fIgetpwuid\fP() function need not be reentrant. A function that +is not required to be reentrant is not required to be +thread-safe. +.LP +Applications wishing to check for error situations should set \fIerrno\fP +to 0 before calling \fIgetpwuid\fP(). If +\fIgetpwuid\fP() returns a null pointer and \fIerrno\fP is set to +non-zero, an error occurred. +.LP +The \fIgetpwuid_r\fP() function shall update the \fBpasswd\fP structure +pointed to by \fIpwd\fP and store a pointer to that +structure at the location pointed to by \fIresult\fP. The structure +shall contain an entry from the user database with a matching +\fIuid\fP. Storage referenced by the structure is allocated from the +memory provided with the \fIbuffer\fP parameter, which is +\fIbufsize\fP bytes in size. The maximum size needed for this buffer +can be determined with the {_SC_GETPW_R_SIZE_MAX} \fIsysconf\fP() +parameter. A NULL pointer shall be returned at the location pointed +to by +\fIresult\fP on error or if the requested entry is not found. +.SH RETURN VALUE +.LP +The \fIgetpwuid\fP() function shall return a pointer to a \fBstruct +passwd\fP with the structure as defined in \fI<pwd.h>\fP with a matching +entry if found. A null pointer shall be returned if the requested +entry is not found, or an error occurs. On error, \fIerrno\fP shall +be set to indicate the error. +.LP +The return value may point to a static area which is overwritten by +a subsequent call to \fIgetpwent\fP(), \fIgetpwnam\fP(), or +\fIgetpwuid\fP(). +.LP +If successful, the \fIgetpwuid_r\fP() function shall return zero; +otherwise, an error number shall be returned to indicate the +error. +.SH ERRORS +.LP +The \fIgetpwuid\fP() and \fIgetpwuid_r\fP() functions may fail if: +.TP 7 +.B EIO +An I/O error has occurred. +.TP 7 +.B EINTR +A signal was caught during \fIgetpwuid\fP(). +.TP 7 +.B EMFILE +{OPEN_MAX} file descriptors are currently open in the calling process. +.TP 7 +.B ENFILE +The maximum allowable number of files is currently open in the system. +.sp +.LP +The \fIgetpwuid_r\fP() function may fail if: +.TP 7 +.B ERANGE +Insufficient storage was supplied via \fIbuffer\fP and \fIbufsize\fP +to contain the data to be referenced by the resulting +\fBpasswd\fP structure. +.sp +.LP +\fIThe following sections are informative.\fP +.SH EXAMPLES +.SS Getting an Entry for the Root User +.LP +The following example gets the user database entry for the user with +user ID 0 (root). +.sp +.RS +.nf + +\fB#include <sys/types.h> +#include <pwd.h> +\&... +uid_t id = 0; +struct passwd *pwd; +.sp + +pwd = getpwuid(id); +\fP +.fi +.RE +.SS Finding the Name for the Effective User ID +.LP +The following example defines \fIpws\fP as a pointer to a structure +of type \fBpasswd\fP, which is used to store the structure +pointer returned by the call to the \fIgetpwuid\fP() function. The +\fIgeteuid\fP() +function shall return the effective user ID of the calling process; +this is used as the search criteria for the \fIgetpwuid\fP() +function. The call to \fIgetpwuid\fP() shall return a pointer to the +structure containing that user ID value. +.sp +.RS +.nf + +\fB#include <unistd.h> +#include <sys/types.h> +#include <pwd.h> +\&... +struct passwd *pws; +pws = getpwuid(geteuid()); +\fP +.fi +.RE +.SS Finding an Entry in the User Database +.LP +The following example uses \fIgetpwuid\fP() to search the user database +for a user ID that was previously stored in a +\fBstat\fP structure, then prints out the user name if it is found. +If the user is not found, the program prints the numeric value +of the user ID for the entry. +.sp +.RS +.nf + +\fB#include <sys/types.h> +#include <pwd.h> +#include <stdio.h> +\&... +struct stat statbuf; +struct passwd *pwd; +\&... +if ((pwd = getpwuid(statbuf.st_uid)) != NULL) + printf(" %-8.8s", pwd->pw_name); +else + printf(" %-8d", statbuf.st_uid); +\fP +.fi +.RE +.SH APPLICATION USAGE +.LP +Three names associated with the current process can be determined: +\fIgetpwuid\fP( \fIgeteuid\fP()) returns the name associated with +the effective user ID of the process; \fIgetlogin\fP() returns the +name associated with the current login activity; and +\fIgetpwuid\fP( \fIgetuid\fP()) returns the name associated with the +real user ID of the +process. +.LP +The \fIgetpwuid_r\fP() function is thread-safe and returns values +in a user-supplied buffer instead of possibly using a static +data area that may be overwritten by each call. +.SH RATIONALE +.LP +None. +.SH FUTURE DIRECTIONS +.LP +None. +.SH SEE ALSO +.LP +\fIgetpwnam\fP(), \fIgeteuid\fP(), \fIgetuid\fP(), \fIgetlogin\fP(), +the Base Definitions volume of +IEEE\ Std\ 1003.1-2001, \fI<limits.h>\fP, \fI<pwd.h>\fP, \fI<sys/types.h>\fP +.SH COPYRIGHT +Portions of this text are reprinted and reproduced in electronic form +from IEEE Std 1003.1, 2003 Edition, Standard for Information Technology +-- Portable Operating System Interface (POSIX), The Open Group Base +Specifications Issue 6, Copyright (C) 2001-2003 by the Institute of +Electrical and Electronics Engineers, Inc and The Open Group. In the +event of any discrepancy between this version and the original IEEE and +The Open Group Standard, the original IEEE and The Open Group Standard +is the referee document. The original Standard can be obtained online at +http://www.opengroup.org/unix/online.html . |