(* Collection of code snippets by Arne VajhÃ¸j *)
(* (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) *)
(*
 *  Purpose       : tests all username for correct UAF quotas
 *  Author        : Arne Vajhøj
 *  Last modified : 13/06/94
 *  Context       : RUN UAFCHK
 *  Remarks       : needs SYSPRV priv
 *)

[inherit('sys$library:starlet','sys$library:pascal$lib_routines')]

program uafchk(input,output);

(* target quotas *)
const
   c_prclim=10;
   c_fillm=255;
   c_shrfillm=0;
   c_biolm=200;
   c_diolm=200;
   c_astlm=400;
   c_tqcnt=50;
   c_enqlm=300;
   c_bytlm=36000;
   c_jtquota=3072;
   c_wsdefault=512;
   c_wsquota=1024;
   c_wsextent=4096;
   c_pgflquota=25000;

type
   identifier = unsigned;
   username   = packed array [1..12] of char;
   item       = record
                   case boolean of
                      true  : (
                              buflen,itmcod : [word] 0..65535;
                              bufadr,retlenadr : unsigned;
                              );
                      false : (
                              zero : integer;
                              );
                end;
   itemlist   = array [1..15] of item;
   privmask   = record
                   l0,l1 : unsigned;
                end;

var
   id1,id2 : identifier;
   un      : username;
   ctx     : unsigned;
   quodata : itemlist;
   sysprv  : privmask;
   f1,f2   : text;
   prccnt,fillm,shrfillm,biolm,diolm,astlm,tqcnt,enqlm,bytlm,jtquota,dfwscnt,
   wsquota,wsextent,pgflquota : integer;

begin
   (* open files *)
   open(f1,'up.com',new);
   rewrite(f1);
   open(f2,'down.com',new);
   rewrite(f2);
   writeln(f1,'$ set default sys$system');
   writeln(f1,'$ mcr authorize');
   (* write header *)
   writeln(f2,'$ set default sys$system');
   writeln(f2,'$ mcr authorize');
   (* initialize datastructures *)
   id1:=-1;
   ctx:=0;
   quodata[1].buflen:=4;
   quodata[2].buflen:=4;
   quodata[3].buflen:=4;
   quodata[4].buflen:=4;
   quodata[5].buflen:=4;
   quodata[6].buflen:=4;
   quodata[7].buflen:=4;
   quodata[8].buflen:=4;
   quodata[9].buflen:=4;
   quodata[10].buflen:=4;
   quodata[11].buflen:=4;
   quodata[12].buflen:=4;
   quodata[13].buflen:=4;
   quodata[14].buflen:=4;
   quodata[1].itmcod:=UAI$_prccnt;
   quodata[2].itmcod:=UAI$_fillm;
   quodata[3].itmcod:=UAI$_shrfillm;
   quodata[4].itmcod:=UAI$_biolm;
   quodata[5].itmcod:=UAI$_diolm;
   quodata[6].itmcod:=UAI$_astlm;
   quodata[7].itmcod:=UAI$_tqcnt;
   quodata[8].itmcod:=UAI$_enqlm;
   quodata[9].itmcod:=UAI$_bytlm;
   quodata[10].itmcod:=UAI$_jtquota;
   quodata[11].itmcod:=UAI$_dfwscnt;
   quodata[12].itmcod:=UAI$_wsquota;
   quodata[13].itmcod:=UAI$_wsextent;
   quodata[14].itmcod:=UAI$_pgflquota;
   quodata[1].bufadr:=iaddress(prccnt);
   quodata[2].bufadr:=iaddress(fillm);
   quodata[3].bufadr:=iaddress(shrfillm);
   quodata[4].bufadr:=iaddress(biolm);
   quodata[5].bufadr:=iaddress(diolm);
   quodata[6].bufadr:=iaddress(astlm);
   quodata[7].bufadr:=iaddress(tqcnt);
   quodata[8].bufadr:=iaddress(enqlm);
   quodata[9].bufadr:=iaddress(bytlm);
   quodata[10].bufadr:=iaddress(jtquota);
   quodata[11].bufadr:=iaddress(dfwscnt);
   quodata[12].bufadr:=iaddress(wsquota);
   quodata[13].bufadr:=iaddress(wsextent);
   quodata[14].bufadr:=iaddress(pgflquota);
   quodata[1].retlenadr:=0;
   quodata[2].retlenadr:=0;
   quodata[3].retlenadr:=0;
   quodata[4].retlenadr:=0;
   quodata[5].retlenadr:=0;
   quodata[6].retlenadr:=0;
   quodata[7].retlenadr:=0;
   quodata[8].retlenadr:=0;
   quodata[9].retlenadr:=0;
   quodata[10].retlenadr:=0;
   quodata[11].retlenadr:=0;
   quodata[12].retlenadr:=0;
   quodata[13].retlenadr:=0;
   quodata[14].retlenadr:=0;
   quodata[15].zero:=0;
   sysprv.l0:=PRV$M_SYSPRV;
   sysprv.l1:=0;
   (* turn on SYSPRV temporarily *)
   $setprv(enbflg:=1,prvadr:=sysprv,prmflg:=0);
   (* get all identifiers *)
   while odd($idtoasc(id:=id1,nambuf:=un,resid:=id2,contxt:=ctx)) do begin
      (* if it can not be ruled out that it is a username *)
      if id2<maxint then begin
         (* test if username and get UAF quotas *)
         if odd($getuai(usrnam:=un,itmlst:=quodata)) then begin
            if prccnt < c_prclim  then writeln(f1,'modi ',un,'/prclm=',c_prclim);
            if fillm < c_fillm  then writeln(f1,'modi ',un,'/fillm=',c_fillm);
            if shrfillm < c_shrfillm  then writeln(f1,'modi ',un,'/shrfillm=',c_shrfillm);
            if biolm < c_biolm  then writeln(f1,'modi ',un,'/biolm=',c_biolm);
            if diolm < c_diolm  then writeln(f1,'modi ',un,'/diolm=',c_diolm);
            if astlm < c_astlm  then writeln(f1,'modi ',un,'/astlm=',c_astlm);
            if tqcnt < c_tqcnt  then writeln(f1,'modi ',un,'/tqelm=',c_tqcnt);
            if enqlm < c_enqlm  then writeln(f1,'modi ',un,'/enqlm=',c_enqlm);
            if bytlm < c_bytlm  then writeln(f1,'modi ',un,'/bytlm=',c_bytlm);
            if jtquota < c_jtquota  then writeln(f1,'modi ',un,'/jtquota=',c_jtquota);
            if dfwscnt < c_wsdefault  then writeln(f1,'modi ',un,'/wsdefault=',c_wsdefault);
            if wsquota < c_wsquota  then writeln(f1,'modi ',un,'/wsquota=',c_wsquota);
            if wsextent < c_wsextent  then writeln(f1,'modi ',un,'/wsextent=',c_wsextent);
            if pgflquota < c_pgflquota  then writeln(f1,'modi ',un,'/pgflquota=',c_pgflquota);
            if prccnt > c_prclim  then writeln(f2,'modi ',un,'/prclm=',c_prclim);
            if fillm > c_fillm  then writeln(f2,'modi ',un,'/fillm=',c_fillm);
            if shrfillm > c_shrfillm  then writeln(f2,'modi ',un,'/shrfillm=',c_shrfillm);
            if biolm > c_biolm  then writeln(f2,'modi ',un,'/biolm=',c_biolm);
            if diolm > c_diolm  then writeln(f2,'modi ',un,'/diolm=',c_diolm);
            if astlm > c_astlm  then writeln(f2,'modi ',un,'/astlm=',c_astlm);
            if tqcnt > c_tqcnt  then writeln(f2,'modi ',un,'/tqelm=',c_tqcnt);
            if enqlm > c_enqlm  then writeln(f2,'modi ',un,'/enqlm=',c_enqlm);
            if bytlm > c_bytlm  then writeln(f2,'modi ',un,'/bytlm=',c_bytlm);
            if jtquota > c_jtquota  then writeln(f2,'modi ',un,'/jtquota=',c_jtquota);
            if dfwscnt > c_wsdefault  then writeln(f2,'modi ',un,'/wsdefault=',c_wsdefault);
            if wsquota > c_wsquota  then writeln(f2,'modi ',un,'/wsquota=',c_wsquota);
            if wsextent > c_wsextent  then writeln(f2,'modi ',un,'/wsextent=',c_wsextent);
            if pgflquota > c_pgflquota  then writeln(f2,'modi ',un,'/pgflquota=',c_pgflquota);
         end;
      end;
   end;
   (* write trailer *)
   writeln(f1,'EXIT');
   writeln(f1,'$ exit');
   writeln(f2,'EXIT');
   writeln(f2,'$ exit');
   (* close files *)
   close(f1);
   close(f2);
end.
