CRAA055%UK.AC.KCL.CC.VAXB@AC.UK.UUCP (06/20/87)
Dear All, Several people have asked for examples of how to use the GETUAI service. What follows is a DCL archive containing a complete (and useful i hope) FORTRAN program that illustrates how to do it. It also contains a little routine which isolates the calls to the GETUAI service. This code was produced from a previous example code sent over the net and I hope the original sender does not mind this re-posting! Andy Harper Kings College Uk A.Harper @ VAXB.CC.KCL.AC.UK [ EARN/BITNET/NETNORTH ] A.Harper%KCL.CC.VAXB @ AC.UK A.Harper%KCL.CC.VAXB @ ucl-cs.arpa [ ARPA ] $! XXXXXXXXXXXXXXXXXXXXXX CUT HERE XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX $! ------------------------------------------------------------------------- $! This file is a DCL archive and contains one or more files to be unpacked. $! To unpack the files, copy this file into a scratch directory and then $! run it as a DCL command procedure. Each file will then be unpacked into $! a separate file with its original name. $! ------------------------------------------------------------------------- $ fail_list = "" ! Checksum failures $ say = "write sys$output" ! Shorten code below $ say "Extracting File WHO.DOC [ Checksum=1582070590]" $ create WHO.DOC $ deck/dollars=19:49:46.15 WHO: User information program Introduction WHO is a program that may be used by unprivileged users to display selected information about a given username, such as the owner and account fields. Usage WHO is designed to work as a foreign command and is used thus: WHO username Installation The program is written in FORTRAN and needs to be compiled and link thus: FORTRAN WHO LINK/NOTRACE WHO The program needs to be installed with SYSPRV in order to have access to the SYSUAF file: INSTALL = "$INSTALL/COMMAND_MODE" INSTALL CREAT dir:WHO /PRIV=SYSPRV A global symbol should be set up at LOGIN time which reflects the location of the program: WHO == "$dir:WHO" After this, WHO is ready to run. Andy Harper Kings College London 15-JUN-1987 19:49:46.15 $ checksum WHO.DOC $ ck=checksum$checksum $ if ck .nes. "1582070590" then $- fail_list=fail_list+" WHO.DOC" $ if ck .nes. "1582070590" then $- say "[CHECKSUM FAILED! Got ",ck," expected 1582070590]" $ say "Extracting File WHO.FOR [ Checksum=525737890]" $ create WHO.FOR $ deck/dollars=19:49:46.15 C ------------------------------------------------------------------ C WHO C Produce information about a given username C C C 2.0 Complete rewrite of original to use $GETUAI service C C Author: Andy Harper Site: Kings College London C System: VMS 4.4 and above C C ----------------------------------------------------------------------- implicit integer(a-z) character username*12, owner*32, account*12 include'($uaidef)' * * WHAT USERNAME DO WE WANT INFO ABOUT ?? istat = lib$get_foreign(username,'Username: ',l_u) if (.not. istat) call sys$exit(%val(istat)) * * GO GET THE INFORMATION istat = getuai(username(1:l_u),UAI$_OWNER, owner, 32) istat = getuai(username(1:l_u),UAI$_LGICMD, lgicmd, 64) istat = getuai(username(1:l_u),UAI$_ACCOUNT, account, 12) if (.not. istat) call lib$stop(%val(istat)) * * DEAL WITH POSSIBLY NULL FIELDS AND MAKE THEM SPACES len_own = ichar(owner(1:1)) if (len_own.lt.1) then owner = ' ' len_own = 1 else owner = owner(2:len_own+1) endif * * PRINT THE ANSWERS print *, username, ' ', Owner, ' ', account end C C GETUAI: Picks up a single item from the UAF and places it into the C user supplied buffer. C integer function getuai(username,item,buffer,length) implicit integer (a-z) character username*(*), buffer*(*) C --- Here is the SYS$GETUAI structure definition structure /itmlist_struct/ union map integer*2 buff_len ! length of equiv name integer*2 item_code ! code saying type of Eqiv name integer*4 buffaddr ! address of equiv name integer*4 ret_lenadr ! return addr for actual length end map map integer*4 end_list ! code to end list end map end union end structure C --- End of the SYS$GETUAI structure definition * record /itmlist_struct/ uaflist(2) integer dummy * * uaflist(1).buff_len = length uaflist(1).item_code = item uaflist(1).buffaddr = %loc(buffer) uaflist(1).ret_lenadr = %loc(dummy) * uaflist(2).end_list = 0 * getuai = sys$getuai(,,username,uaflist(1),,,) return end 19:49:46.15 $ checksum WHO.FOR $ ck=checksum$checksum $ if ck .nes. "525737890" then $- fail_list=fail_list+" WHO.FOR" $ if ck .nes. "525737890" then $- say "[CHECKSUM FAILED! Got ",ck," expected 525737890]" $ say "Extracting File WHO.HLP [ Checksum=1735875634]" $ create WHO.HLP $ deck/dollars=19:49:46.15 1 WHO Displays the owner and account of a registered username on SYS$OUTPUT. Format: $WHO username 2 Parameter Username is the username as it might be found in the $SHOW USERS command or in the From: field of a MAIL message header. Lists or wildcards are not allowed. 19:49:46.15 $ checksum WHO.HLP $ ck=checksum$checksum $ if ck .nes. "1735875634" then $- fail_list=fail_list+" WHO.HLP" $ if ck .nes. "1735875634" then $- say "[CHECKSUM FAILED! Got ",ck," expected 1735875634]" $ if fail_list .eqs. "" then $ goto unpack_complete $ say "--------------------------------------------------" $ say " The unpack failed with one or more checksum" $ say " errors in the following file(s):" $ say "" $ say " ",fail_list $ say "" $ say "--------------------------------------------------" $unpack_complete: $ say "Unpack is complete"