Article 135050 of comp.os.vms:
Path: nntpd.lkg.dec.com!crl.dec.com!crl.dec.com!bloom-beacon.mit.edu!apollo.hp.com!lf.hp.com!news.dtc.hp.com!col.hp.com!usenet.eel.ufl.edu!gatech2!swrinde!newsfeed.internetmci.com!news.msfc.nasa.gov!elroy.jpl.nasa.gov!lll-winken.llnl.gov!fnnews.fnal.gov!nntp-server.caltech.edu!SOL1.GPS.CALTECH.EDU!CARL
From: carl@SOL1.GPS.CALTECH.EDU (Carl J Lydick)
Newsgroups: comp.os.vms
Subject: Re: Help with the SYS$GETUAI system service call with VAX C
Date: 29 Nov 1995 19:44:41 GMT
Organization: HST Wide Field/Planetary Camera
Lines: 144
Distribution: world
Message-ID: <49id79$54c@gap.cco.caltech.edu>
References: <951127162603.58a4@rmcs.cranfield.ac.uk>
Reply-To: carl@SOL1.GPS.CALTECH.EDU
NNTP-Posting-Host: sol1.gps.caltech.edu

In article <951127162603.58a4@rmcs.cranfield.ac.uk>, "Ja jestem piekny." <TIM@rmcs.cranfield.ac.uk> writes:
=Hello,
=
=I am having a little trouble in getting the SYS$GETUAI call to work properly
=I have included a sample program that will check for each user on the system
=whether or not the CLI, DCLTABLES and LGICMD are what they are supposed to be.
=The file that holds the usernames is all in upper case with one username per
=line and the username padded out to 12 characters with spaces.
=
=I get one sucessful call and then one failure, and also the items returned
=from sys$getuai seem to run into each other when output.
=
=Any pointers / advice on what I am doing wrong would be appreciated.

You're making a number of mistakes.  Among them are:
	fgets leaves in the newline character.  That's why you get the failure
		after the successful call:  The second time around, you're
		picking up the tail end of the record from the input file.
	the items returned by SYS$GETUAI are counted strings, not
		null-terminated strings; that's why things are running
		together.
Here's a modified version of your program that works properly:

#define MAXLEN 14
#include <stdio.h>
#include <lib$routines.h>
#include <starlet.h>
#include <descrip.h>
#include <uaidef.h>
#include "security.h"
#include <ssdef.h>
#include <rmsdef.h>
#include <string.h>

main(int argc, char *argv[])
{
        FILE *file_ptr;
        int finished = 0;
        int error_flag = 0;
        char line[14];
        $DESCRIPTOR(username,line);
        int status, i;

#define DEFCLI "DCL"
	char cli[34];
#define DEFTABLES "DCLTABLES"
	char tables[34];
#define DEFLGICMD "SYS$COM:NCHEK"
	char lgicmd[66];
	unsigned short cli_length;
	unsigned short tables_length;
	unsigned short lgicmd_length;
        ITEM_LIST uailist[4];

        if ( argc > 2 ) {
                printf("sec-f-parinvld, number of parameters invalid - check use.\n");
                error_flag = 1;
        }

        if (argc == 2) {
                file_ptr = fopen(argv[1],"r");
                if (file_ptr == NULL) {
                        printf("sec-f-nofile, %s file does not exist.\n",argv[1]);
                        error_flag = 1;
                }
        }

        if (argc == 1) {
                file_ptr = fopen("USERLIST.DAT","r");
                if (file_ptr == NULL) {
                        printf("sec-f-nofile, USERLIST.DAT file does not exist.\n");
                        error_flag = 1;
                }
        }

        uailist[0].buffer_length        = 32;
        uailist[0].item_code            = UAI$_CLITABLES;
        uailist[0].buffer_address       = tables;
        uailist[0].return_address       = &tables_length;
        uailist[1].buffer_length        = 32;
        uailist[1].item_code            = UAI$_DEFCLI;
        uailist[1].buffer_address       = cli;
        uailist[1].return_address       = &cli_length;
        uailist[2].buffer_length        = 64;
        uailist[2].item_code            = UAI$_LGICMD;
        uailist[2].buffer_address       = lgicmd;
        uailist[2].return_address       = &lgicmd_length;
        uailist[3].buffer_length        = 0;
        uailist[3].item_code            = 0;
        uailist[3].buffer_address       = 0;
        uailist[3].return_address       = 0;

        while ( error_flag == 0 && finished == 0 ) {
                fgets(line,MAXLEN,file_ptr);
                while (feof(file_ptr) == 0) {
			for( i = 0; i < MAXLEN; ++i)
				if (line[i] == '\n')
					line[i] = '\0';
		        username.dsc$w_length = strlen(line);
                        status = sys$getuai(NULL,NULL, &username, &uailist, NULL,NULL,NULL);

			if ( ( status == SS$_NOSYSPRV) || ( status == SS$_NOGRPPRV ) ) {
			        printf(" No privilege to perform operation. [%d]\n",status);}
			else if ( ( status == SS$_ACCVIO ) || ( status == SS$_BADPARAM ) ){
			        printf(" Error in system call. [%d]\n ",status);}
			else if ( ( status == RMS$_RSZ ) || ( status == RMS$_RNF ) ){
			        printf(" Error in access records in sysuaf. [%d]\n",status);}
			else if ( ( status & 7) != 1)
				printf(" Other error: %%%08X\n", status);
			if ( (cli[0] != strlen(DEFCLI)) ||
				(strncmp(DEFCLI,cli+1, cli[0]) != 0 )) {
				cli[cli[0]+1] = '\0';
        	        	printf("cli for user %s is different from the default, current value is %s\n",
					line,cli+1);
        		}

		        if ( (tables[0] != strlen(DEFTABLES)) ||
				(strncmp(DEFTABLES, tables+1, tables[0])) != 0) {
				tables[tables[0]+1] = '\0';
	        	        printf("tables for user %s is different from the default, current value is %s\n",
					line, tables+1);
		        }

        		if ( (lgicmd[0] != strlen(DEFLGICMD)) ||
				(strncmp(DEFLGICMD, lgicmd+1, lgicmd[0])) != 0 ) {
				lgicmd[lgicmd[0]+1] = '\0';
        	        	printf("lgicmd for user %s is different from the default, current value is %s\n",
					line, lgicmd+1);
		        }

                        fgets(line,MAXLEN,file_ptr);
                }
                fclose(file_ptr);
                finished = 1;
        }
}
--------------------------------------------------------------------------------
Carl J Lydick | INTERnet: CARL@SOL1.GPS.CALTECH.EDU | NSI/HEPnet: SOL1::CARL

Disclaimer:  Hey, I understand VAXen and VMS.  That's what I get paid for.  My
understanding of astronomy is purely at the amateur level (or below).  So
unless what I'm saying is directly related to VAX/VMS, don't hold me or my
organization responsible for it.  If it IS related to VAX/VMS, you can try to
hold me responsible for it, but my organization had nothing to do with it.


