OpenVMS Source Code Demos

GETUAI.C

//===========================================================================
// Title  : GetUai_demo.c
// Author : Neil S. Rieck (Waterloo, Ontario, Canada)
// email  : [email protected]
// web    : https://neilrieck.net/
// Purpose: demos $getuai (a VMS system call) for my internet friends
// History:
// 100 1999.10.14 original quick hack
// 101 1999.10.15 refinements
// 102 1999.10.15 add more UAI items
// 103 2011.10.18 updated for "HP C V7.3-009 on OpenVMS Alpha V8.4"
//===========================================================================
#include <string.h>
#include <stdio.h>
#include <starlet.h>		// vms specific library
#include <lib$routines.h>	// vms specific library
#include <uaidef.h>		// vms specific library
#include <descrip.h>		// vms specific library for vms-style strings

    long rc;			// return code
    char username[12];
    char my_account[9];
    char my_owner[32];
    long my_uic;		// uic (grp + member)
    long my_grp;		// group
    long my_mem;		// member
    long uaicnt;

struct {			// uai list entry
	short len, code;
	void *bufadr;
	int retadr;
	} uailst[8];

main() {
//
// Macro for inserting items into item lists
//
#define set_uailst(size,itemcode,buffadr, retlenadr)	\
    uaicnt++;						\
    uailst[uaicnt].len     =  size;			\
    uailst[uaicnt].code    =  itemcode;			\
    uailst[uaicnt].bufadr  =  buffadr;			\
    uailst[uaicnt].retadr  =  retlenadr;

    struct dsc$descriptor_s username_dx = { 0, DSC$K_DTYPE_T, DSC$K_CLASS_S, 0};

    printf ("enter a Username to lookup (12 chars max): ");
    gets (username);

    //
    // set up a VMS-style string descriptor
    //
    username_dx.dsc$w_length = strlen(username);
    username_dx.dsc$a_pointer = username;

    uaicnt = -1;
    set_uailst(  4, UAI$_UIC, &my_uic, 0);
    set_uailst(  4, UAI$_GRP, &my_grp, 0);
    set_uailst(  4, UAI$_MEM, &my_mem, 0);
    set_uailst( 32, UAI$_OWNER, my_owner, 0);
    set_uailst(  9, UAI$_ACCOUNT, my_account, 0);
    //
    // put more 'set uai lst' lines here
    //
    set_uailst( 0, 0, 0, 0);	// terminate list

    rc = sys$getuai (0, 0, &username_dx, uailst, 0, 0, 0);

    // legend for lowest 3 bits of VMS return codes
    // ...000 -w- (warning)
    // ...001 -s- (success)
    // ...010 -e- (error)
    // ...011 -i- (informational)
    // ...100 -f- (fatal)
    // ...101 -?- (undefined)
    // ...110 -?- (undefined)
    // ...111 -?- (undefined)
    //
    if (!(rc & 1)) {
	printf ("Error: %x for username: %s\n", rc, username);
    }
    else {
	printf ("UAI info for username: %s\n", username);
        printf ("UIC     : %o (octal) %x (hex)\n"  ,my_uic, my_uic);
        printf ("UIC grp : %o (octal)\n", my_grp);
        printf ("UIC mem : %o (octal)\n", my_mem);
	printf ("OWNER   : %s\n"        ,my_owner);
	printf ("ACCOUNT : %s\n"        ,my_account);
    }
}