ibm-information-center/dist/eclipse/plugins/i5OS.ic.apis_5.4.0.1/getpwnam.htm

286 lines
7.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>getpwnam()--Get User Information for User Name</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: -->
<!-- file cleaned -->
<!-- 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 on 05/14/02 by JET -->
<link rel="stylesheet" type="text/css" href="../rzahg/ic.css">
</head>
<body>
<!--End Header Records --><!-- Java sync-link -->
<script language="Javascript" src="../rzahg/synch.js" type="text/javascript">
</script>
<a name="Top_Of_Page"></a>
<h2>getpwnam()--Get User Information for User Name</h2>
<div class="box" style="width: 70%;">
<br>
&nbsp;&nbsp;Syntax<br>
<pre>
#include &lt;pwd.h&gt;
struct passwd *getpwnam(const char <em>*name</em>);
</pre>
&nbsp;&nbsp;Service Program Name: QSYPAPI<br>
<!-- iddvc RMBR -->
<br>
&nbsp;&nbsp;Default Public Authority: *USE<br>
<!-- iddvc RMBR -->
<br>
&nbsp;&nbsp;Threadsafe: No<br>
<!-- iddvc RMBR -->
<br>
</div>
<p>The <strong>getpwnam()</strong> function returns a pointer to an object of
type <samp>struct passwd</samp> containing an entry from the user database with
a matching <em>name</em>.</p>
<br>
<h3>Parameters</h3>
<dl>
<dt><strong><em>name</em></strong></dt>
<dd>(Input) A pointer to a user profile name.</dd>
</dl>
<br>
<h3>Authorities</h3>
<p>*READ authority is required to the user profile associated with the <em>
name</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.</p>
<br>
<h3>Return Value</h3>
<dl compact>
<dt><em>struct passwd *</em></dt>
<dd><strong>getpwnam()</strong> was successful. The return value points to
static data of the format <samp>struct passwd</samp>, which is defined in the
<strong>pwd.h</strong> header file. This storage is overwritten on each call to
this function. This static storage area is also used by the <strong>
getpwuid()</strong> function. The <samp>struct passwd</samp> has the following
elements:<br>
<br>
<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>
<br>
</dd>
<dt><em>NULL pointer</em></dt>
<dd><strong>getpwnam()</strong> was not successful. The <em>errno</em> global
variable is set to indicate the error.</dd>
</dl>
<p>See <a href="getpwnamu.htm">QlgGetpwnam()--Get User Information for User
Name (using NLS-enabled path name)</a> for a description and an example where
the path name is returned in any CCSID.</p>
<br>
<h3>Error Conditions</h3>
<p>If <strong>getpwnam()</strong> is not successful, <em>errno</em> usually
indicates one of the following errors. Under some conditions, <em>errno</em>
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>name</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>name</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#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 &lt;<strong>pwd.h</strong>&gt; file (see <a href="unix13.htm">Header
Files for UNIX-Type APIs</a>)<br>
</li>
<li><a href="gtpwnamr.htm">getpwnam_r()</a>--Get User Information for User
Name<br>
</li>
<li><a href="getpwnamu.htm">QlgGetpwnam()</a>--Get User Information for User
Name (using NLS-enabled path name)</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 user name
of MYUSER. The UID is 22. 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 &lt;pwd.h&gt;
main()
{
struct passwd *pd;
if (NULL == (pd = getpwnam("MYUSER")))
perror("getpwnam() error.");
else
{
printf("The user name is: %s\n", pd-&gt;pw_name);
printf("The user id is: %u\n", pd-&gt;pw_uid);
printf("The group id is: %u\n", pd-&gt;pw_gid);
printf("The initial directory is: %s\n", pd-&gt;pw_dir);
printf("The initial user program is: %s\n", pd-&gt;pw_shell);
}
}
</pre>
<p><strong>Output:</strong></p>
<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>
<hr>
API introduced: V3R1
<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>