HP OpenVMS Systems

ask the wizard
Content starts here

UIC associated with Username?

» close window

The Question is:

 
 
   I need a system call that will return the UIC group if I pass it the
 username.    I know how to use GETJPI to get the UIC for the current process,
 but I don't know how to get this from the username.
 


The Answer is :

 
  The OpenVMS system service SYS$GETUAI permits you to translate an
  arbitrary username to its associated UIC value.  This system service
  can (and very often does) require SYSPRV, GRPPRV, or another powerful
  privilege.
 
  For details on UIC and username specifications, please see the
  System Security Manual.  For details on programming with SYS$GETUAI
  and other system services, please see the System Service Reference
  Manual and the Programming Concepts Manual.
 
  The following is an example of working with the SYS$GETUAI service:
 
#include <descrip.h>
#include <ssdef.h>
#include <starlet.h>
#include <stdio.h>
#include <stsdef.h>
#include <uaidef.h>
#include <unixlib.h>
 
#define MAXACCLEN 16
 
struct ItemList3
    {
    short int ItemLength;
    short int ItemCode;
    void *ItemBuffer;
    void *ItemRetLen;
    };
 
main()
    {
    int RetStat;
#define MAXIL 5
    struct ItemList3 ItmLst[MAXIL];
    $DESCRIPTOR( UsernameDsc, "SYSTEM" );
    char Account[MAXACCLEN];
    int i;
 
    i = 0;
    ItmLst[i].ItemLength    = MAXACCLEN;
    ItmLst[i].ItemCode	    = UAI$_ACCOUNT;
    ItmLst[i].ItemBuffer    = (void *) Account;
    ItmLst[i++].ItemRetLen  = NULL;
    ItmLst[i].ItemLength    = 0;
    ItmLst[i].ItemCode	    = 0;
    ItmLst[i].ItemBuffer    = NULL;
    ItmLst[i++].ItemRetLen  = NULL;
 
    RetStat = sys$getuai( 0, 0, &UsernameDsc, ItmLst, 0, 0, 0);
    if (!$VMS_STATUS_SUCCESS( RetStat ))
	return RetStat;
 
    return SS$_NORMAL;
    }
 
 
  There also exists a Compaq C run-time library (RTL) function called
  getpwnam(), and this call provides C programmers with a standard
  interface into the SYS$GETUAI interface.  For example:
 
 
#include <pwd.h>
#include <stdio.h>
#include <stdlib.h>
 
main()
  {
  struct passwd *p;
 
  if ( !(p = getpwnam(getenv("USER"))) )
    {
    perror("getpwnam");
    }
  else
    {
    printf("uid = %o\n", p->pw_uid);
    printf("gid = %o\n", p->pw_gid);
    printf("home directory = %s\n", p->pw_dir);
    printf("initial shell = %s\n", p->pw_shell);
    }
 
  return EXIT_SUCCESS;
  }
 
 

answer written or last revised on ( 30-OCT-2001 )

» close window