QlgGetpwnam_r()--Get User Information for User Name (using NLS-enabled path name)


  Syntax
 #include <sys/types.h>
 #include <pwd.h>

 int QlgGetpwnam_r(const char *name,
              struct qplg_passwd *pwd,
                           char *buffer,
                          size_t bufsize,
              struct qplg_passwd **result);  

  Service Program Name: QSYPAPI

  Default Public Authority: *USE

  Threadsafe: Yes

The QlgGetpwnam_r() function updates the qplg_passwd structure pointed to by pwd and stores a pointer to that structure in the location pointed to by result. The structure contains an entry from the user database with a matching name.


Parameters

name
(Input) A pointer to a user profile name.
pwd
(Input) A pointer to a qplg_passwd structure.
buffer
(Input) A pointer to a buffer from which memory is allocated to hold storage areas referenced by the structure pwd.
bufsize
(Input) The size of buffer in bytes.
result
(Input) A pointer to a location in which a pointer to the updated qplg_passwd structure is stored. If an error occurs or if the requested entry cannot be found, a NULL pointer is stored in this location.

The struct qplg_passwd, which is defined in the pwd.h header file, has the following elements:

See getpwnam_r()--Get User Information for User Name for more information about the pwd, result, and other parameters.


Authorities

*READ authority is required to the user profile associated with the name.


Return Value

0
QlgGetpwnam_r was successful.

Any other value
Failure: The return value contains an error number indicating the error.

Error Conditions

If QlgGetpwnam_r() is not successful, the return value usually indicates one of the following errors. Under some conditions, the value could indicate an error other than those listed here.


Usage Notes

The path name is returned in the default IFS UNICODE CCSID.


Related Information


Example

The following example gets the user database information for the user name of MYUSER. The uid is 22. The gid is 1012. The initial working directory is /home/MYUSER. The initial user program is *LIBL/QCMD.

Note: By using the code examples, you agree to the terms of the Code license and disclaimer information.

#include <sys/types.h>
#include <pwd.h>
#include <stdio.h>
#include <errno.h>

main()
{
  struct qplg_passwd pd;
  qplg_passwd ** tempPwdPtr;
  char pwdbuffer[200];
  int  pwdlinelen = sizeof(pwdbuffer);

  if ((QlgGetpwnam_r("MYUSER",&pd,pwdbuffer,pwdlinelen,tempPwdPtr))!=0   )
     perror("QlgGetpwnam_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 working directory length is: %d\n",
             pd->pw_dir->Path_Length);
     printf("The initial working directory CCSID is : %d\n",
             pd->pw_dir->CCSID);
     printf("The initial user program is: %s\n", pd->pw_shell);
  }

}

Output:

  The user name is: MYUSER
  The user id   is: 22
  The group id  is: 0
  The intial working directory length is: 24
  The intial working directory CCSID is : 13488
  The initial user program is: *LIBL/QCMD

API introduced: V5R1

[ Back to top | UNIX-Type APIs | APIs by category ]