Article 764 of vmsnet.sources:
Xref: mv vmsnet.sources:764
Path: mv!news.sprintlink.net!rebecca!newserve!ub!csn!magnus.acs.ohio-state.edu!math.ohio-state.edu!uwm.edu!chi-news.cic.net!newsfeed.internetmci.com!news.mathworks.com!mvb.saic.com!mvb.saic.com!vmsnet-sources
From: morphis@fnalv1.fnal.gov
Newsgroups: vmsnet.sources
Subject: getuai com file, part 01/01
Date: Thu, 15 Feb 1996 05:35:21 GMT
Organization: Fermi National Accelerator Lab
Message-ID: <3240160@MVB.SAIC.COM>
Followup-To: vmsnet.sources.d
Approved: Mark.Berryman@Mvb.Saic.Com
Lines: 348

Submitted-by: morphis@fnalv1.fnal.gov
Posting-number: Volume 8, Issue 1
Archive-name: getuai_dcl/patch1_03

Hello,

Included in this post are three com files which I wrote partly as an exercize
in avoiding more productive work and partly to explore the mysteries of
symbols.  I fear I did not succeed very well in the second task.  I mostly
understand why the lexicals and symbols are behaving the way they are, 
but I suspect that the next time I write such a program I will have to
rehash all my experimenting to get it right. <sigh>

The first program is included for completeness and simply sets up necessary 
symbols.

$ getuai   :== $clu$common:[util.getuai]getuai.exe
$ f$getuai :== @clu$common:[util.getuai]getuai.com
$ exit

	[ The above 3 lines have been included in a file which I
	  have named DEFINE_SYMBOLS.COM.   The moderator. ]

GETUAI.EXE [NOT included as part of this posting] is a program written by
Frank Nagy that uses the system service $GETUAI to obtain  information from
the system authorization file.  It is available at various VMS software sites. 
Its usage takes the form

$ GETUAI username/qualifier=output_symbol

where "qualifier" is one of the fields in the UAF file.  One must then

$ SHO SYM output_symbol

to get your output.  This is very useful for use within com files but
somewhat short of ideal for interactive use.  So I decided to whip up
a com file to deal with the problem and along the way make it a bit 
closer to lexical usage.

$!GETUAI.COM first pass
$!usage:
$!f$getuai (username,qualifier,output_symbol)
$!parameters may be quoted strings or symbols
$!
$ params = p1 - "("-")"
$ param0 = 'f$element("0",",",params)
$ param1 = 'f$element("1",",",params)
$ pre2     ==  f$element("2",",",params)
$ if ( pre2 .eqs. "" ) .or. (pre2 .eqs. "," ) 
$ then
$   getuai 'param0'/'param1'=output
$   write sys$output output
$ else
$   param2 = 'pre2'
$   getuai 'param0'/'param1'='param2'
$   'param2'=='param2'
$ endif  
$ exit

	[ The above file has been extracted and included using
	  the name GETUAI_1.COM.   The moderator ]

This is fine except that if you want a list of the priviledges held by
someone you might need two output symbols because it is just possible 
to go over the 256 character limit for symbols.  In that case we get
the usage:

$ GETUAI username/PRIVILEGES=(output_symbol1,output_symbol2)

hmmm, extra parentheses, variable number of parameters, a symbol that
may hold one or two parameter, sounds messy but I think I did it.

I want to make a couple of observations before the final product.

The right way to do it would be to dig out my copy of VERB and look at how the
CLD of the lexicals are written, write a CLD and write the program in a high 
level language.

It would have been simpler to break with both lexical usage and GETUAI 
usage by making "output_symbol2" a fourth parameter.

Parentheses are interesting creatures
$ @file.com(parameter) is equivalent to
$ @file.com (parameter)
(Thus the change in usage notes)
After a bit of thought they behave as one might expect considering their
behaviour elsewhere, but none-the-less I hadn't given it that bit of thought.

A program that didn't have the option of storing the values in symbols
can be done in about 16 lines of code instead of the 70+ below.
After all getuai.exe can handle the need if you want symbols, but
this is more consistant usage.  There is another package available 
GETUAF which may well serve the same purposes.  It's only weakness
(that I am aware of) is that it reads the SYSUAF file so if for some 
unknown reason Digital changes the form of that file... I personally
think that is pretty unlikely.

I fear that the neatness (such as it is) in the program was more a result
of my trying to adequitely comment it for posting than a result of good
programming style.  But the final product seems to me to have some merit so...

Enjoy?

Robert Morphis
$! ------------------ CUT HERE -----------------------
$ v='f$verify(f$trnlnm("SHARE_UNPACK_VERIFY"))'
$!
$! This archive created:
$!  Name : GETUAI_DCL
$!  By   : mark.berryman@MVB.SAIC.COM
$!  Date : 14-FEB-1996 21:17:03.15
$!  Using: VMS_SHARE 8.5-1, (C) 1993 Andy Harper, Kings College London UK
$!
$! Credit is due to these people for their original ideas:
$!    James Gray, Michael Bednarek 
$!
$! To unpack this archive:
$!    Minimum of VMS 4.4 (VAX) / OpenVMS 1.0 (Alpha) is required.
$!    Remove the headers of the first part, up to `cut here' line.
$!    Execute file as a command procedure.
$!
$! The following file(s) will be created after unpacking:
$!       1. DEFINE_SYMBOLS.COM;1
$!       2. GETUAI.COM;1
$!       3. GETUAI_1.COM;1
$!
$ set="set"
$ set symbol/scope=(nolocal,noglobal)
$ f="SYS$SCRATCH:."+f$getjpi("","PID")+";"
$ if f$trnlnm("SHARE_UNPACK") .nes. "" then $ -
 f=f$parse("SHARE_UNPACK_TEMP",f)
$ e="write sys$error  ""%UNPACK"", "
$ w="write sys$output ""%UNPACK"", "
$ if .not. f$trnlnm("SHARE_UNPACK_LOG") then $ w = "!"
$ if f$getsyi("CPU") .gt. 127 then $ goto start
$ ve=f$getsyi("version")
$ if ve-f$extract(0,1,ve) .ges. "4.4" then $ goto start
$ e "-E-OLDVER, Must run at least VMS 4.4"
$ v=f$verify(v)
$ exit 44
$unpack:subroutine!P1=file,P2=chksum,P3=attrib,P4=size,P5=fileno,P6=filetotal
$ if f$parse(P1) .nes. "" then $ goto dirok
$ dn=f$parse(P1,,,"DIRECTORY")
$ w "-I-CREDIR, Creating directory ''dn'"
$ create/dir 'dn'
$ if $status then $ goto dirok
$ e "-E-CREDIRFAIL, Unable to create ''dn' File skipped"
$ delete 'f'*
$ exit
$dirok:
$ x=f$search(P1)
$ if x .eqs. "" then $ goto file_absent
$ e "-W-EXISTS, File ''P1' exists. Skipped"
$ delete 'f'*
$ exit
$file_absent:
$ w "-I-UNPACK, Unpacking ", P5, " of ", P6, " - ", P1, " - ", P4, " Blocks"
$ n=P1
$ if P3 .nes. "" then $ n=f
$ if .not. f$verify() then $ define/user sys$output nl:
$ EDIT/TPU/NOSEC/NODIS/COM=SYS$INPUT/NOJOURNAL 'f'/OUT='n'
PROCEDURE GetHex(s,p)LOCAL x1,x2;x1:=INDEX(t,SUBSTR(s,p,1))-1;x2:=INDEX(t,
SUBSTR(s,p+1,1))-1;RETURN 16*x1+x2;ENDPROCEDURE;PROCEDURE SkipPartsep LOCAL m;
LOOP m:=MARK(NONE);EXITIF m=END_OF(CURRENT_BUFFER);DELETE(m);EXITIF INDEX(
ERASE_LINE,"-+-+-+-+-+-+-+-+")=1;ENDLOOP;ENDPROCEDURE;
PROCEDURE ProcessLine LOCAL c,s,l,b,n,p;s := ERASE_LINE;c := SUBSTR(s,1,1);s :=
 s-c;IF c = "X" THEN SPLIT_LINE; ENDIF;MOVE_HORIZONTAL(-1);l := LENGTH(s);p :=
 1;LOOP EXITIF p > l;c := SUBSTR(s,p,1);p := p+1;CASE c FROM ' ' TO '`' ['`']
: COPY_TEXT(ASCII(GetHex(s,p))); p:=p+2;[' ']: p:=p+1;[INRANGE,OUTRANGE]
: COPY_TEXT(c);ENDCASE;ENDLOOP;ENDPROCEDURE;PROCEDURE Decode(b)LOCAL m;
POSITION(BEGINNING_OF(b));LOOP m:=MARK(NONE);EXITIF m=END_OF(b);DELETE(m);
IF INDEX(CURRENT_LINE,"+-+-+-+-+-+-+-+-")=1 THEN SkipPartSep;ELSE ProcessLine;
MOVE_HORIZONTAL(1);ENDIF;ENDLOOP;ENDPROCEDURE;SET(FACILITY_NAME,"UNPACK");SET(
SUCCESS,OFF);SET(INFORMATIONAL,OFF);t:="0123456789ABCDEF";f:=GET_INFO(
COMMAND_LINE,"file_name");o:=CREATE_BUFFER(f,f);Decode(o);WRITE_FILE(o,
GET_INFO(COMMAND_LINE,"output_file"));QUIT;
$ if p3 .eqs. "" then $ goto dl
$ open/write fdl &f
$ write fdl "RECORD"
$ write fdl P3
$ close fdl
$ w "-I-CONVRFM, Converting record format to ", P3
$ convert/fdl='f' 'f'-1 'f'
$ fa=f$getdvi(f$parse(f),"ALLDEVNAM")
$ Pa=f$getdvi(f$parse(P1),"ALLDEVNAM")
$ if fa .eqs. Pa then $ rename &f 'f$parse(P1)'
$ if fa .nes. Pa then $ copy &f 'f$parse(P1)'
$dl: delete 'f'*
$ checksum 'P1'
$ if checksum$checksum .nes. P2 then $ -
  e "-E-CHKSMFAIL, Checksum of ''P1' failed."
$ exit
$ endsubroutine
$start:
$!
$ create 'f'
X$`20getuai`20`20`20:==`20$clu$common:`5Butil.getuai`5Dgetuai.exe
X$`20f$getuai`20:==`20@clu$common:`5Butil.getuai`5Dgetuai.com
X$`20exit
$ call unpack DEFINE_SYMBOLS.COM;1 1198619548 "" 1 1 3
$!
$ create 'f'
X$!GETUAI.COM`20?final?`20product
X$`20if`20p1`20.eqs.`20"?"
X$`20then
X$`20`20`20say`20:=`20write`20sys$output
X$`20`20`20say`20"usage:`20F$GETUAI(username,uaf_field,output_symbol)"
X$`20`20`20say`20"`09username`20`20`20`20`20`20:`20account`20for`20which`20you
V`20want`20information"
X$`20`20`20say`20"`09uaf_field`20`20`20`20`20:`20uaf`20field`20you`20want`20inf
Vormation`20from"
X$`20`20`20say`20"`09output_symbol`20:`20symbol`20to`20dump`20the`20output`20in
Vto"
X$`20`20`20say`20"The`20parameters`20should`20either`20be`20quoted`20strings`20
Vor`20symbols."
X$`20`20`20say`20"$`20MOST`20CLU$COMMON:`5BUTIL.GETUAI`5DGETUAI.HLP"
X$`20`20`20say`20"will`20provide`20a`20list`20of`20uaf`20fields`20available."
X$`20`20`20say`20"If`20output_symbol`20is`20left`20blank`20then`20it`20will`20w
Vrite`20the`20value`20to"`20+`20-`20
X`09"`20SYS$OUTPUT."
X$`20`20`20goto`20exit
X$`20endif
X$!
X$`20no_output_symbol`20=`200
X$`20priv`20`09`09`20`20`20=`200
X$`20two_priv_sym`09`20`20`20=`200
X$!
X$`20p1len`20`20=`20f$length(p1)
X$`20params`20=`20f$extract("1",p1len-2,p1)`20`20!get`20rid`20of`20the`20parent
Vheses`20surrounding
X$`09`09`09`09`20`20`20`20`20`20!the`20parameters
X$`20param0`20=`20'f$element("0",",",params)
X$`20param1`20=`20'f$element("1",",",params)
X$`20pre2`20`20`20=`20`20f$element("2",",",params)
X$!
X$`20if`20f$extract(0,4,f$edit(param1,"trim,upcase"))`20.eqs.`20"PRIV"
X$`20then
X$!`20`20priv`20may`20require`20two`20symbols`20to`20handle`20output
X$`20`20`20priv`20=`201
X$`20endif
X$!
X$`20if`20(pre2`20.eqs.`20","`20)`20.or.`20(pre2`20.eqs.`20""`20)`20then`20no_o
Vutput_symbol`20=`201
X$!
X$!`20`20`09It`20should`20be`20noted`20that`20f$element`20returns`20the`20delim
Viter`20
X$!`09(","`20in`20this`20case)`20if`20there`20are`20no`20more`20elements`20left
V.
X$!`09If`20there`20is`20a`20dangling`20delimiter`20it`20will`20return`20"".
X$!
X$!`09These`20two`20symbols`20("priv"`20and`20"no_output_symbol")`20currently
X$!`09exist`20more`20for`20understandability`20than`20any`20other`20reason.
X$!
X$`20if`20no_output_symbol`20
X$!
X$!then`20"life`20is`20much`20easier"`20==`20"True"
X$!
X$`20then
X$`20`20`20if`20priv`20
X$`20`20`20then
X$`20`20`20`20`20getuai`20'param0'/'param1'=(out0,out1)
X$`20`20`20`20`20write`20sys$output`20out0,out1
X$`20`20`20else
X$`20`20`20`20`20getuai`20'param0'/'param1'=out0
X$`20`20`20`20`20write`20sys$output`20out0
X$`20`20`20endif
X$`20else
X$!
X$!actually`20this`20could`20be`20much`20simpler`20if`20we`20didn't`20have`20to
V`20worry`20about
X$!needing`202`20symbols`20for`20all`20the`20possible`20priviledges.
X$!
X$!First`20I`20parse`20the`20possible`20output`20symbols.
X$!
X$`20`20`20openparen`20`20=`20f$locate("(",params)
X$`20`20`20closeparen`20=`20f$locate(")",params)
X$`20`20`20if`20openparen`20.ne.`20closeparen`20
X$`20`20`20then`20
X$`20`20`20`20`20difpar`20=`20closeparen`20-`20openparen
X$`20`20`20`20`20end`20`20`20`20=`20'f$extract(openparen-1,difpar+3,params)'`20
V-`20"("`20-`20")"
X$`20`20`20`20`20pre20`20`20=`20f$element("0",",",end)
X$`20`20`20`20`20pre21`20`20=`20f$element("1",",",end)
X$`20`20`20else
X$`20`20`20`20`20pre20`20`20=`20`20f$element("0",",",'pre2')`20-`20"("`20-`20")
V"
X$`20`20`20`20`20pre21`20`20=`20`20f$element("1",",",'pre2')`20-`20")"
X$`20`20`20endif
X$!
X$!Now`20I`20decide`20whether`20there`20are`20one`20or`20two`20output`20symbols
V`20
X$!being`20requested`20and`20assign`20symbols`20accordingly.
X$!
X$`20`20`20if`20(pre21`20.nes.`20"")`20.and.`20(`20pre21`20.nes.`20",")`20
X$`20`20`20then`20
X$`20`20`20`20`20two_priv_sym`20=`201
X$`20`20`20`20`20out0`20`20`20=`20pre20
X$`20`20`20`20`20out1`20`20`20=`20pre21
X$`20`20`20`20`20param2`20=`20"("`20+`20pre20`20+`20","`20+`20pre21`20+`20")"
X$`20`20`20else
X$`20`20`20`20`20out0`20`20`20=`20pre20
X$`20`20`20`20`20param2`20=`20pre20
X$`20`20`20endif
X$!
X$!Now`20that`20we`20are`20done`20parsing`20the`20bloody`20thing`20we`20can`20a
Vctually`20
X$!get`20the`20information.`20`20Only`20the`20symbols`20that`20"out0"`20and`20"
Vout1"`20
X$!represent`20are`20of`20interest`20outside`20of`20this`20proceedure`20so`20th
Vey`20
X$!get`20defined`20as`20global`20symbols.
X$!
X$`20`20`20getuai`20'param0'/'param1'='param2'
X$`20`20`20if`20two_priv_sym
X$`20`20`20then
X$`20`20`20`20`20'out0'=='out0'
X$`20`20`20`20`20'out1'=='out1'
X$`20`20`20else
X$`20`20`20`20`20'out0'=='out0'
X$`20`20`20endif
X$`20endif`20`20
X$EXIT:
X$`20exit
$ call unpack GETUAI.COM;1 1259492304 "" 7 2 3
$!
$ create 'f'
X$!GETUAI.COM`20first`20pass
X$!usage:
X$!f$getuai`20(username,qualifier,output_symbol)
X$!parameters`20may`20be`20quoted`20strings`20or`20symbols
X$!
X$`20params`20=`20p1`20-`20"("-")"
X$`20param0`20=`20'f$element("0",",",params)
X$`20param1`20=`20'f$element("1",",",params)
X$`20pre2`20`20`20`20`20==`20`20f$element("2",",",params)
X$`20if`20(`20pre2`20.eqs.`20""`20)`20.or.`20(pre2`20.eqs.`20","`20)
X$`20then
X$`20`20`20getuai`20'param0'/'param1'=output
X$`20`20`20write`20sys$output`20output
X$`20else
X$`20`20`20param2`20=`20'pre2'
X$`20`20`20getuai`20'param0'/'param1'='param2'
X$`20`20`20'param2'=='param2'
X$`20endif
X$`20exit
$ call unpack GETUAI_1.COM;1 269044264 "" 2 3 3
$ v=f$verify(v)
$ exit


