349 lines
8.7 KiB
HTML
349 lines
8.7 KiB
HTML
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
|
|
<html>
|
|
<head>
|
|
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
|
|
<meta name="Copyright" content="Copyright (c) 2006 by IBM Corporation">
|
|
<title>getpwuid_r()--Get User Information for User ID</title>
|
|
<!-- Begin Header Records -->
|
|
<!-- All rights reserved. Licensed Materials Property of IBM -->
|
|
<!-- US Government Users Restricted Rights -->
|
|
<!-- Use, duplication or disclosure restricted by -->
|
|
<!-- GSA ADP Schedule Contract with IBM Corp. -->
|
|
<!-- Change History: -->
|
|
<!-- Unix2 SCRIPT J converted by B2H R4.1 (346) (CMS) by V2KEA304 -->
|
|
<!-- at RCHVMW2 on 17 Feb 1999 at 11:05:09 -->
|
|
<!-- This file has undergone html cleanup May 2002 by JET -->
|
|
<link rel="stylesheet" type="text/css" href="../rzahg/ic.css">
|
|
</head>
|
|
<body>
|
|
<!--End Header Records --><!-- Java sync-link -->
|
|
<script type="text/javascript" language="Javascript" src="../rzahg/synch.js">
|
|
</script>
|
|
|
|
<a name="Top_Of_Page"></a>
|
|
|
|
<h2>getpwuid_r()--Get User Information for User ID</h2>
|
|
|
|
<div class="box" style="width: 80%;">
|
|
<br>
|
|
|
|
Syntax<br>
|
|
|
|
<pre>
|
|
#include <sys/types.h>
|
|
#include <pwd.h>
|
|
|
|
int getpwuid_r(uid_t <em>uid</em>, struct passwd <em>*pwd</em>,
|
|
char <em>*buffer</em>, size_t <em>bufsize</em>, struct passwd
|
|
<em>**result</em>);
|
|
</pre>
|
|
|
|
<br>
|
|
Service Program Name: QSYPAPI<br>
|
|
<!-- iddvc RMBR -->
|
|
<br>
|
|
Default Public Authority: *USE<br>
|
|
<!-- iddvc RMBR -->
|
|
<br>
|
|
Threadsafe: Yes<br>
|
|
<!-- iddvc RMBR -->
|
|
<br>
|
|
</div>
|
|
|
|
<p>The <strong>getpwuid_r()</strong> function updates the <em>passwd</em>
|
|
structure pointed to by <em>pwd</em> and stores a pointer to that structure in
|
|
the location pointed to by <em>result</em>. The structure contains an entry
|
|
from the user database with a matching <em>uid</em>.</p>
|
|
|
|
<br>
|
|
<h3>Parameters</h3>
|
|
|
|
<dl>
|
|
<dt><strong><em>uid</em></strong></dt>
|
|
|
|
<dd>(Input) User ID.<br>
|
|
<br>
|
|
</dd>
|
|
|
|
<dt><strong><em>pwd</em></strong></dt>
|
|
|
|
<dd>(Input) A pointer to a struct passwd.<br>
|
|
<br>
|
|
</dd>
|
|
|
|
<dt><strong><em>buffer</em></strong></dt>
|
|
|
|
<dd>(Input) A pointer to a buffer from which memory is allocated to hold
|
|
storage areas referenced by the structure passwd.<br>
|
|
<br>
|
|
</dd>
|
|
|
|
<dt><strong><em>bufsize</em></strong></dt>
|
|
|
|
<dd>(Input) The size of <em>buffer</em> in bytes.<br>
|
|
<br>
|
|
</dd>
|
|
|
|
<dt><strong><em>result</em></strong></dt>
|
|
|
|
<dd>(Input) A pointer to a location in which a pointer to the updated passwd
|
|
structure is stored. If an error occurs or if the requested entry cannot be
|
|
found, a NULL pointer is stored in this location.</dd>
|
|
</dl>
|
|
|
|
<p>The <samp>struct passwd</samp>, which is defined in the <strong>
|
|
pwd.h</strong> header file, has the following elements:</p>
|
|
|
|
<table border>
|
|
<tr>
|
|
<td align="left" valign="top" width="10%">char *</td>
|
|
<td align="left" valign="top" width="15%">pw_name</td>
|
|
<td align="left" valign="top" width="75%">User name</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td align="left" valign="top">uid_t</td>
|
|
<td align="left" valign="top">pw_uid</td>
|
|
<td align="left" valign="top">User ID</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td align="left" valign="top">uid_t</td>
|
|
<td align="left" valign="top">pw_gid</td>
|
|
<td align="left" valign="top">Group ID of the user's first group. If the user
|
|
does not have a first group, the GID value will be set to 0.</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td align="left" valign="top">char *</td>
|
|
<td align="left" valign="top">pw_dir</td>
|
|
<td align="left" valign="top">Initial working directory. If the user does not
|
|
have *READ authority to the user profile, the pw_dir pointer will be set to
|
|
NULL.</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td align="left" valign="top">char *</td>
|
|
<td align="left" valign="top">pw_shell</td>
|
|
<td align="left" valign="top">Initial user program. If the user does not have
|
|
*READ authority to the user profile, the pw_shell pointer will be set to
|
|
NULL.</td>
|
|
</tr>
|
|
</table>
|
|
|
|
<p>See <a href="gtpwuidru.htm">QlgGetpwuid_r()--Get User Information for User
|
|
ID (using NLS-enabled path name)</a> for a description and an example where the
|
|
path name is returned in any CCSID.<br>
|
|
</p>
|
|
|
|
<h3>Authorities</h3>
|
|
|
|
<p>*READ authority is required to the user profile associated with the <em>
|
|
UID</em>. If the user does not have *READ authority, only the user name, user
|
|
ID, and group ID values are returned.</p>
|
|
|
|
<p><strong>Note:</strong> Adopted authority is not used.<br>
|
|
</p>
|
|
|
|
<h3>Return Value</h3>
|
|
|
|
<dl>
|
|
<dt><em>0</em></dt>
|
|
|
|
<dd><strong>getpwuid_r()</strong> was successful.<br>
|
|
<br>
|
|
</dd>
|
|
|
|
<dt><em>Any other value</em></dt>
|
|
|
|
<dd>Failure: The return value contains an error number indicating the
|
|
error.</dd>
|
|
</dl>
|
|
|
|
<br>
|
|
|
|
|
|
<h3>Error Conditions</h3>
|
|
|
|
<p>If <strong>getpwuid_r()</strong> is not successful, the error value usually
|
|
indicates one of the following errors. Under some conditions, the value could
|
|
indicate an error other than those listed here.</p>
|
|
|
|
<table cellpadding="5">
|
|
<!-- cols="25 75" -->
|
|
|
|
<tr>
|
|
<th align="left" valign="bottom">Error condition</th>
|
|
<th align="left" valign="bottom">Additional information</th>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td align="left" valign="top">
|
|
<em>[<a href="unix14.htm#EAGAIN">EAGAIN</a>]</em></td>
|
|
|
|
<td align="left" valign="top">
|
|
<p>The user profile associated with the <em>UID</em> is currently locked by
|
|
another process.</p>
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td align="left" valign="top">
|
|
<em>[<a href="unix14.htm#EC2">EC2</a>]</em></td>
|
|
|
|
<td align="left" valign="top">
|
|
<p>Detected pointer that is not valid.</p>
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td align="left" valign="top">
|
|
<em>[<a href="unix14.htm#EINVAL">EINVAL</a>]</em></td>
|
|
|
|
<td align="left" valign="top">
|
|
<p>Value is not valid. Check the job log for messages.</p>
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td align="left" valign="top">
|
|
<em>[<a href="unix14.htm#ENOENT">ENOENT</a>]</em></td>
|
|
|
|
<td align="left" valign="top">
|
|
<p>The user profile associated with the <em>UID</em> was not found.</p>
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td align="left" valign="top">
|
|
<em>[<a href="unix14.htm#ENOMEM">ENOMEM</a>]</em></td>
|
|
|
|
<td align="left" valign="top">
|
|
<p>The user profile associated with the <em>UID</em> has exceeded its storage
|
|
limit or is unable to allocate memory.</p>
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td align="left" valign="top">
|
|
<em>[<a href="unix14.htm#ENOSPC">ENOSPC</a>]</em></td>
|
|
|
|
<td align="left" valign="top">
|
|
<p>Machine storage limit exceeded.</p>
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td align="left" valign="top">
|
|
<em>[<a href="unix14.htm#ERANGE">ERANGE</a>]</em></td>
|
|
|
|
<td align="left" valign="top">
|
|
<p>Insufficient storage was supplied through <em>buffer</em> and <em>
|
|
bufsize</em> to contain the data to be referenced by the resulting group
|
|
structure.</p>
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td align="left" valign="top">
|
|
<em>[<a href="unix14.htm#EUNKNOWN">EUNKNOWN</a>]</em></td>
|
|
|
|
<td align="left" valign="top">
|
|
<p>Unknown system state. Check the job log for a CPF9872 message. If there is
|
|
no message, verify that the home directory field in the user profile can be
|
|
displayed.</p>
|
|
</td>
|
|
</tr>
|
|
</table>
|
|
|
|
<br>
|
|
|
|
|
|
<h3>Usage Notes</h3>
|
|
|
|
<p>The initial working directory is returned in the CCSID value of the job.</p>
|
|
|
|
<br>
|
|
|
|
|
|
<h3>Related Information</h3>
|
|
|
|
<ul>
|
|
<li>The <<strong>pwd.h</strong>> file (see <a href="unix13.htm">Header
|
|
Files for UNIX-Type Functions</a>)<br>
|
|
<br>
|
|
</li>
|
|
|
|
<li><a href="getpwuid.htm">getpwuid()</a>--Get User Information for User
|
|
ID</li>
|
|
</ul>
|
|
|
|
<br>
|
|
|
|
|
|
<h3>Example</h3>
|
|
|
|
<p>See <a href="../apiref/aboutapis.htm#codedisclaimer">Code disclaimer information</a>
|
|
for information pertaining to code examples.</p>
|
|
|
|
<p>The following example gets the user database information for the UID of 22.
|
|
The user name is MYUSER. The GID of MYUSER's first group is 1012. The initial
|
|
directory is /home/MYUSER. The initial user program is *LIBL/QCMD.</p>
|
|
|
|
<pre>
|
|
#include <sys/types.h>
|
|
#include <pwd.h>
|
|
#include <stdio.h>
|
|
#include <errno.h>
|
|
|
|
main()
|
|
{
|
|
struct passwd pd;
|
|
struct passwd* pwdptr=&pd;
|
|
struct passwd* tempPwdPtr;
|
|
char pwdbuffer[200];
|
|
int pwdlinelen = sizeof(pwdbuffer);
|
|
|
|
if ((getpwuid_r(22,pwdptr,pwdbuffer,pwdlinelen,&tempPwdPtr))!=0)
|
|
perror("getpwuid_r() error.");
|
|
else
|
|
{
|
|
printf("\nThe user name is: %s\n", pd.pw_name);
|
|
printf("The user id is: %u\n", pd.pw_uid);
|
|
printf("The group id is: %u\n", pd.pw_gid);
|
|
printf("The initial directory is: %s\n", pd.pw_dir);
|
|
printf("The initial user program is: %s\n", pd.pw_shell);
|
|
}
|
|
|
|
}
|
|
</pre>
|
|
|
|
<strong>Output:</strong>
|
|
|
|
<pre>
|
|
The user name is: MYUSER
|
|
The user ID is: 22
|
|
The group ID is: 1012
|
|
The initial directory is: /home/MYUSER
|
|
The initial user program is: *LIBL/QCMD
|
|
</pre>
|
|
|
|
<br>
|
|
|
|
|
|
<hr>
|
|
API introduced: V4R4
|
|
|
|
<hr>
|
|
<center>
|
|
<table cellpadding="2" cellspacing="2">
|
|
<tr align="center">
|
|
<td valign="middle" align="center"><a href="#top_Of_Page">Top</a> | <a href=
|
|
"unix.htm">UNIX-Type APIs</a> | <a href="aplist.htm">APIs by category</a></td>
|
|
</tr>
|
|
</table>
|
|
</center>
|
|
</body>
|
|
</html>
|
|
|