home *** CD-ROM | disk | FTP | other *** search
/ Super Net 1 / SUPERNET_1.iso / PC / OTROS / UNIX / ARCHIE / CLIENTS / C_ARCHI1.COM < prev    next >
Encoding:
Text File  |  1992-01-12  |  247.5 KB  |  9,169 lines

  1. $ write sys$output "Unpacking..."
  2. $ if f$search("archie.dir") .eqs. "" then create/dir [.ARCHIE]
  3. $ if f$search("[.ARCHIE]vms.dir") .eqs. "" then create/dir [.ARCHIE.VMS]
  4. $ if f$search("[.ARCHIE]msdos.dir") .eqs. "" then create/dir [.ARCHIE.MSDOS]
  5. $ set noverify
  6. $! This is a DCL shar-type archive created by Unix dclshar.
  7. $!
  8. $CREATE [.archie]INSTALL
  9. $DECK
  10. [Last changed: 01/09/92 v1.3]
  11.  
  12.  This is the minimal set of things you need to build an Archie client
  13. that takes advantage of the Prospero system.  It is derived from the
  14. 4.2beta version of Prospero, currently available as the file prospero.tar.Z
  15. on the host cs.washington.edu.
  16.  
  17.  * To make the client under Unix:
  18.    * edit the Makefile, changing CC, OPTIONS, LDFLAGS, and RM if
  19.      necessary (odds are you won't have to do this..see below)
  20.    * edit the DEFINEs as necessary
  21.    * if archie.ans.net isn't "close" to you netwise, please edit
  22.      ARCHIE in the Makefile appropriately.  This is particularly important
  23.      if you're not in the US.  You don't need to touch archie.h anymore.
  24.    * type `make'
  25.  
  26.  I've tried to make this as portable as possible.  I'd encourage you
  27. to try doing a "make" without any changes to the Makefile, and see how
  28. it goes.  If it pukes, and you have to define something, please drop
  29. me a line---my goal is for anybody to just type "make" and not have to
  30. worry about things like what functions their system supports.
  31.  
  32.  * To make the client under VMS, you should edit MAKE.COM and select
  33. the appropriate define for your version of TCP/IP (currently Multinet,
  34. UCX, or Wollongong).  It will sense if you're using Gnu C or not.
  35. It's currently only been ported to VMS 5.4-2 -- I can't guarantee
  36. it'll work with older versions.  As with Unix, if you're in a country
  37. other than the United States (or archie.ans.net isn't close), please edit
  38. the default archie server; it's in archie.h for VMS, though, not MAKE.COM.
  39. (If anyone knows how to make MAKE.COM pass the value of ARCHIE, namely
  40. "foo.bar" *with* quotes, into the compiler, please let me know!)
  41.  
  42.  * To make the client under MSDOS or OS/2:
  43.    * with FTP Software's PC/TCP for MSDOS (version 2.1 or higher) and
  44.      OS/2 (version 1.1 and higher), use makefile.os2 or makefile.dos
  45.    * with CUTCP (NCSA telnet), use makefile.cut
  46.  
  47.  
  48.  It's been successfully built on:
  49.  
  50.   Machine            OS
  51.  
  52. * Apollo            Domain/OS 10.3
  53. * Apple Mac IIsomething        A/UX v2.01
  54. * CDC Mips systems, all sorts    EP/IX 1.2.3 and 1.3.1
  55. * Convex c210 & others        ConvexOS 9.0 & 9.1
  56. * DecStations -- all sorts    Ultrix 4.1 and 4.2
  57. * Encore Multimax 520 (XPC)    Encore UMAX 4.3
  58. * Encore Multimax 520        Encore Mach 1.1alpha
  59. * Harris HCX-9 (tahoe)        CX/UX 5.1
  60. * HP systems            MORE/bsd-4.3, HP/UX 7.0, and HP/UX 8.0
  61. * IBM PC            MSDOS and OS/2 w/ PC/TCP
  62. * IBM RS/6000            AIX
  63. * IBM RT            4.3BSD, and AIX
  64. * ISI 68020            4.3BSD
  65. * NeXT                NeXT OS 2.1
  66. * Pyramid 9815            OSx 5.0
  67. * Sequent Symmetry        Dynix 3.1.1
  68. * SGI 4D/220GTX            SGI Irix 3.3.2
  69. * Solbourne Series 5/600    OS/MP 4.0Da
  70. * Stardent 3030            SysV Rel 3.0.1
  71. * Suns -- all sorts        SunOS 4.0.3, 4.1, and 4.1.1
  72. * Vax 8600            MORE/bsd-4.3
  73. * Vax 6000/310            VMS 5.4/Wollongong 5.1
  74. * MicroVax 3400            VMS 5.4-2/Multinet 2.2 and Multinet 3.0
  75.  
  76. -- Brendan Kehoe (brendan@cs.widener.edu)
  77. $EOD
  78. $!
  79. $CREATE [.archie]Makefile
  80. $DECK
  81. #
  82. # Last changed: 1/9/92, v1.3
  83. #
  84. # Makefile for the minimal build for an archie Prospero client.
  85.  
  86. # Your C compiler:
  87. CC=cc
  88.  
  89. # For most systems, these OPTIONS will suffice.  Exceptions:
  90. #
  91. #    * If you're on a Stardent, add  -43
  92. #    * If you're running EP/IX, you may need to add  -systype bsd43
  93. #      but try it without it first.
  94. OPTIONS= -O -I. -I/usr/netinclude
  95.  
  96. # For this, DEFINES is usually ok as-is.  Try it without any of these
  97. # first; if some stuff fails or shows up undefined, then come back and
  98. # add 'em.
  99. #
  100. #     * if you're on an Apple running A/UX, add              -DAUX
  101. #     * if you want to include the debugging code (so you
  102. #       can help with problem-solving if any crop up), add    -DDEBUG
  103. #     * if you're running Interactive Unix, add              -DISC
  104. #     * if you're running System V, add                  -DSYSV
  105. #     * if you're running a USG (System V.2) system, add      -DUSG
  106. #     * if you're running UTS, add                  -DUTS
  107. #     * if your system doesn't have the functions index(),
  108. #       rindex(), bcopy(), or bzero(), add                    -DFUNCS
  109. #     * if your system is missing the getenv(3) routine, add  -DGETENV
  110. #     * if your system doesn't have the re_comp/regcmp or re_exec/regex
  111. #       routines (no regex(3)/regcmp(3X) library), then add   -DNOREGEX
  112. #     * if your system is lacking strspn(), add               -DSTRSPN
  113. DEFINES= -DDEBUG
  114.  
  115. # The default Archie server; choose one of:
  116. #    archie.ans.net        (USA [NY])
  117. #    archie.rutgers.edu        (USA [NJ])
  118. #    archie.sura.net        (USA [MD])
  119. #    archie.mcgill.ca        (Canada)
  120. #    archie.funet.fi        (Finland/Mainland Europe)
  121. #    archie.au            (Australia)
  122. #    archie.doc.ic.ac.uk    (Great Britain/Ireland)
  123. #
  124. ARCHIE= archie.ans.net
  125.  
  126. #    Usually LDFLAGS is empty; if, after you build this, archie
  127. #     complains that it can't resolve ARCHIE.ANS.NET (or whatever
  128. #     you defined ARCHIE_HOST as), you need to add `-lresolv'.
  129. #    * If you need the PW library (e.g. A/UX), add -lPW
  130. #    * If you're using ISC, add -linet
  131. #    * If you're using Wollongong TCP/IP on an AT&T box, use the
  132. #      arguments -lnet -lnsl_s .
  133. LDFLAGS= # -lresolv
  134. #LDFLAGS= # -lnet -lnsl_s
  135.  
  136. # Change this if necessary.
  137. RM=/bin/rm
  138.  
  139. # =========================
  140. # Yer' done....make archie.
  141. # =========================
  142. #
  143. CFLAGS=$(OPTIONS) $(DEFINES) -DARCHIE_HOST=\"$(ARCHIE)\"
  144. #
  145. OBJS=    aquery.o archie.o atalloc.o dirsend.o get_pauth.o get_vdir.o \
  146.     perrmesg.o procquery.o ptalloc.o regex.o stcopy.o support.o \
  147.     vlalloc.o vl_comp.o
  148. #
  149. all: archie
  150.  
  151. archie: $(OBJS)
  152.     $(CC) $(CFLAGS) -o $@ $(OBJS) $(LDFLAGS)
  153.  
  154. $(OBJS): archie.h pmachine.h pcompat.h Makefile
  155.  
  156. procquery.o: copyright.h
  157.  
  158. clean:
  159.     $(RM) -f *.o archie archie.doc
  160.  
  161. gclean: clean
  162.     $(RM) -f *~ archie.0* archie.com archie.tar* gmon.out archie.doc
  163.  
  164. unx-deadly:
  165.     unifdef -UXARCHIE xprocquery.c > procquery.c
  166.  
  167. udp: udp.o
  168.     $(CC) -o $@ udp.o
  169.  
  170. udptest: udp
  171.     @echo "This should print the date, if UDP's enabled, or hang if not:"
  172.     @./udp
  173.  
  174. FILES=    INSTALL Makefile Prospero README README.dos archie.c archie.h \
  175.     archie.lnk archie.doc archie.man aquery.c atalloc.c dirsend.c \
  176.     get_pauth.c get_vdir.c make.com makefile.cut makefile.dos makefile.os2 \
  177.     msdos/cutcp.h msdos/hostform.h msdos/netevent.h \
  178.     perrmesg.c patchlevel.h pauthent.h pcompat.h perrno.h pfs.h pmachine.h \
  179.     pprot.h procquery.c ptalloc.c rdgram.h regex.c regex.h stcopy.c \
  180.     support.c copyright.h udp.c vl_comp.c vlalloc.c vms.h vms_support.c \
  181.     vms/fd.h vms/in.h vms/pseudos.h vms/signal.h vms/socket.h vms/time.h \
  182.     vms/types.h vms/network.h vms/multi.opt vms/ucx.opt vms/woll.opt
  183.  
  184. BFILES= $(FILES) xprocquery.c
  185.  
  186. dist: tar shar dcl
  187.  
  188. shar: archie.doc
  189.     makekit -narchie. $(FILES) vms msdos > Manifest
  190.  
  191. archie.doc: archie.man
  192.     nroff -man archie.man | tr '\010' _ | sed -e s/__//g > archie.doc
  193.  
  194. dcl: archie.doc
  195.     echo '$$ write sys$$output "Unpacking..."' > archie.com
  196.     echo '$$ if f$$search("archie.dir") .eqs. "" then create/dir [.ARCHIE]' >> archie.com
  197.     echo '$$ if f$$search("[.ARCHIE]vms.dir") .eqs. "" then create/dir [.ARCHIE.VMS]' >> archie.com
  198.     echo '$$ if f$$search("[.ARCHIE]msdos.dir") .eqs. "" then create/dir [.ARCHIE.MSDOS]' >> archie.com
  199.     echo '$$ set noverify' >> archie.com
  200.     (cd .. ; dclshar `echo $(FILES) | tr ' ' '\012' |\
  201.      sed -e "s/^/archie\//g"` >> archie/archie.com )
  202.     echo '$$ write sys$$output "Ok, now enter the ARCHIE directory, look at MAKE.COM, then type @MAKE ."' >> archie.com
  203.  
  204. tar: archie.doc
  205.     ( cd .. ; tar cvf archie/archie.tar `echo $(FILES) |\
  206.      tr ' ' '\012' | sed -e "s/^/archie\//g"` )
  207.     compress -f archie.tar
  208.  
  209. atest: archie.doc
  210.     ( cd .. ; tar cvf archie/atest.tar `echo $(BFILES) |\
  211.      tr ' ' '\012' | sed -e "s/^/archie\//g"` )
  212.     compress -f atest.tar
  213. $EOD
  214. $!
  215. $CREATE [.archie]Prospero
  216. $DECK
  217. Prospero also allows users to access Archie as if it were part of a
  218. file system.  Here is an example of how Prospero can be used to access
  219. Archie in this manner.
  220.  
  221.   Script started on Mon Jul  1 22:36:42 1991
  222.   % source /home/ftp/archie/pfs/bin/vfsetup.source
  223.   % vfsetup guest
  224.   % venable
  225.   % cd /archive-sites/archie/regex
  226.   % cd prospero (This command specifies the query)
  227.   % ls -l
  228.   total 0
  229.   -r--r--r--   0 -               0 -            info-prospero.arc
  230.   dr-xr-xr-x   0 -               0 -            prospero
  231.   dr-xr-xr-x   0 -               0 -            prospero-papers
  232.   -r--r--r--   0 -               0 -            prospero.arc
  233.   -r--r--r--   0 -               0 -            prospero.tar.Z
  234.   (Note that the "vls" command could have been used)
  235.   (to show where the files were actually stored    )
  236.   % ls prospero (list a result if it is a directory)
  237.   prog.tar.Z      prospero.tar.Z
  238.   % cat info-prospero.arc  (The file is automatically retrieved and displayed)
  239.   >From bcn@n1dmm  Tue Dec  4 02:33:36 1990
  240.   Received: from n1dmm.cs.washington.edu by june.cs.washington.edu (5.64/7.0jh)
  241.           id AA24763; Tue, 4 Dec 90 02:33:36 -0800
  242.   Received: by n1dmm.cs.washington.edu (5.64/7.0h)
  243.           id AA08497; Tue, 4 Dec 90 02:33:31 -0800
  244.   Date: Tue, 4 Dec 90 02:33:31 -0800
  245.   From: bcn@cs.washington.edu (Clifford Neuman)
  246.   ...
  247.   % vdisable
  248.   % exit
  249.   script done on Mon Jul  1 22:39:33 1991
  250. $EOD
  251. $!
  252. $CREATE [.archie]README
  253. $DECK
  254. [Last changed 01/09/92 v1.3]
  255.  
  256.  Enclosed you'll find a Prospero client for the archie service.  It'll
  257. let you query the archie databases without actually using an
  258. interactive process on the remote server's machine (e.g. archie.ans.net),
  259. resulting in a MUCH better response time.  It also helps lessen the
  260. load on the archie server itself.
  261.  
  262.  What's Archie?  It's a system that will let you check a database containing
  263. thousands of entries for the files that're available at FTP sites around
  264. the world.
  265.  
  266.  This is a third child of Clifford Neuman's Prospero project.  It's really
  267. the Archie client that's included in the prospero stuff, but I've taken out
  268. everything that's unnecessary for this client to work.  (Aka, you don't
  269. have to build all of Prospero to get the Archie client.)  Khun Yee Fung
  270. wrote an archie client in Perl, and George Ferguson has written a client
  271. for use with XWindows, based in part upon this code.
  272.  
  273.  Using the Archie Prospero interface in its true form will probably be of
  274. interest---check out the file `Prospero' for an example of its interface.
  275. If you find it intriguing, you should probably get the full prospero kit
  276. from the University of Washington on cs.washington.edu in pub/prospero.tar.Z.
  277.  
  278.  Suffice to say, there are now a number of ways to query Archie without
  279. bogging a server down with your logins.
  280.  
  281.  Check out the man page (or archie.doc, if you're using VMS or DOS)
  282. for instructions on how to use this archie client.
  283.  
  284.  Please check to make sure you don't have "archie" aliased or modified
  285. in some way to do a telnet or rlogin (which you may've done before
  286. this command-line ability came into being).
  287.  
  288.  If Archie consistently hangs (at different times of day with
  289. different queries), it's possible that your site has UDP traffic on
  290. ports > 1000 blocked, for security reasons.  Type `make udptest' to
  291. check---if it prints out the date, the Archie server is probably down;
  292. if it doesn't print out the date, either Widener's computer is down
  293. (God forbid ;-) ) or you do indeed have UDP blocked.  See your system
  294. administrator in this case.  If the problem persists and haven't the
  295. vaguest, then write me describing the situation and what machine/OS
  296. you're using.
  297.  
  298.  Write to archie-l@cs.mcgill.ca with questions about Archie itself.
  299.  Write to info-prospero@isi.edu about the Prospero protocol.
  300.  Write to brendan@cs.widener.edu with questions about this specific package.
  301. $EOD
  302. $!
  303. $CREATE [.archie]README.dos
  304. $DECK
  305. 11/22/91  Readme.dos -- Readme file for CUTCP DOS version of Archie.
  306.  
  307. --
  308. This version requires the use of a `standard' NCSA or CUTCP compatible
  309. CONFIG.TEL file.  If you are running NCSA telnet or CUTCP/CUTE telnet,
  310. you should be able to run this program without modification.
  311.  
  312. As with all CUTCP programs, you may set a DOS environment variable to
  313. point to the location of your config.tel file.
  314.  
  315.     set CONFIGTEL=C:\net\config.tel
  316.  
  317. You may also set the $CUTCPnn dos environment variables to include other
  318. 'local' information (such as client IP address on a Novell lan).
  319.  
  320. This version has been compiled with the US (archie.sura.net) Prospero/Archie
  321. server as the default. This may not be appropriate for your location. Here's
  322. how to change it.
  323.  
  324.  
  325.     1. Run the archie program with the -L argument to list known
  326.        archie/prospero servers.
  327.  
  328.     2. Select the server name that is closest to your site. For this example
  329.        we'll pick archie.funet.fi
  330.  
  331.     3. Edit your config.tel file and add the following lines at the end
  332.        of the file.
  333.  
  334.             name=archie
  335.             host=archie.funet.fi    # actually substitute your select
  336.                         # server name here
  337.  
  338.     4. If you happen to know the IP address of the server, you may also
  339.        add the appropriate
  340.  
  341.             hostip=<insert IP address here>
  342.  
  343.     5. If you don't enter an IP address, archie will perform a DNS lookup
  344.        use the domain nameserver information that is in your config.tel 
  345.        file.
  346.  
  347.  
  348. An additional command line option (-H) has been added (vs -h) to allow the
  349. user to specify the config.tel file location on the command line. 
  350.  
  351.     archie -H c:\net\config.tel emacs
  352.  
  353. During a search, you may press the <ESCAPE> key to abort the query.
  354.  
  355.  
  356.  
  357. If you have problems, try running archie with the -D9 option (debug).
  358.  
  359. As usual, bugs/comments to:
  360.  
  361.         cutcp-bugs@omnigate.clarkson.edu
  362.  
  363. Brad Clements, Sr. Network Engineer
  364. Educational Resources Center
  365. Clarkson University 
  366. Potsdam, NY 13699
  367.  
  368. bkc@draco.erc.clarkson.edu
  369.  
  370. -----------
  371. Sample Config.tel file 
  372. ------------------------------
  373. #  Example host file for ARCHIE/ CUTCP version
  374. #  11/21/91
  375. #
  376. #      Bugs to  cutcp-bugs@omnigate.clarkson.edu
  377.  
  378. #---------------------------------------------------------------------------#
  379. #                                        #
  380. #** ATTENTION ATTENTION ATTENTION ATTENTION ATTENTION ATTENTION ATTENTION **#
  381. #                                        #
  382. #   This sample config.tel file contains every single option that you could #
  383. #   possibly use. Its meant as an example only. Please Please PLEASE don't  #
  384. #   use all these options in your working config.tel file, just the ones    #
  385. #   that you actually need. Many options can be left out, the default action#
  386. #   (if defined) is shown in parens () next to the option.             #
  387. #                                        #
  388. #                         Thank you for your support                #
  389. #---------------------------------------------------------------------------#
  390.  
  391. #
  392. #  This example file is for my=bootp, in which case the following items are
  393. #  determined from the bootp server: (and are thus commented out in this file)
  394. #       1. This machine's IP Address
  395. #       2. The network NETMASK
  396. #       3. The default gateway (one or more)
  397. #       4. Nameservers (one or more)
  398. #       5. The domain search list (if this clients hostname is in the bootp packet)
  399. #
  400. #  Your BOOTP server needs to be RFC 1048 compliant for this to work
  401. #  
  402. #  If you have nameservers, gateways or a domainslist already specified
  403. #  in this file, then the file's entry takes precedence.
  404. #  Extra gateways and nameservers will be added by BOOTP if found, however.
  405. #----------------------------------------------------------------------------
  406. #  You can set a DOS environment variable  CONFIGTEL to point to this file
  407. #  then you don't need batch files or the -h option.
  408. #
  409. #       C> set CONFIGTEL=C:\net\myconfig.tel
  410. #
  411. #  You may also use environment variables to include config.tel options,
  412. #  such as:
  413. #    C> set $CUTCP1=myip~197.001.42.98;netmask~255.255.252.0
  414. #    C> set $CUTCP2=name~x;hostip~128.163.298.2
  415. #
  416. #  and so on up to $CUTCP99. Note that you use a tilde (~) instead of (=)
  417. #  in the dos set command because two ='s are not allowed by Dos.
  418. #
  419. #  Additionally, there is a new config.tel option called include= which
  420. #  allows the nesting (up to 3) configuration files deep.
  421. #
  422. #
  423. #  You can use these new options on networks to make your configuration job
  424. #  easier. CUTCP always opens config.tel files as read-only, so you can mark
  425. #  your files as sharable, read only. Also, you can use the include= command
  426. #  in a $CUTCP environment variable, and on the command line.
  427.  
  428. #  *Note* that you can not include a machine specific parameter before
  429. #  name=default... This used to work in old versions, but is strictly
  430. #  enforced in this version.
  431. # --------------------------------------------------------------------------  
  432. #  This file is free form
  433. #  Separators are any char <33 and :;=
  434. #
  435. #  The form is keyword=value for each parameter.
  436. #  The first set of parameters refer to the whole program's defaults.
  437. #  These parameter values can be in any order.
  438. #  Following this are the individual machine specs.
  439. #
  440.  
  441. myip=128.153.28.65                      #  (bootp)
  442.                 #  myip types are:
  443.                                 #  bootp        - sends out a BOOTP request for your IP
  444.                                 #  rarp         - Uses reverse ARp to get your IP
  445.                                 #  xx.yy.zz.qq  - your IP address
  446.  
  447. vjc=no                # (no)
  448.                 # set  vjc=yes if you're running slip and
  449.                 # you want to use Van Jacobson TCP header
  450.                 # compression
  451.  
  452. splayc=no            # (no) ack. splay compression w/ vjc.. don't
  453.                 # use it, not standard, development option only
  454.  
  455. myname=userid            # put your userid here, used for Rlogin
  456.                 # PC-NFS version ignores this value and uses the name
  457.                 # that you specified to your pcnfsd.
  458.  
  459. netmask=255.255.252.0           #  needed if not using BOOTP. 
  460.                                 #  otherwise not needed because Bootp gets your netmask
  461.                 #  for you
  462.  
  463. hardware=packet            # (packet)
  464.                                 # harware choices
  465.                                 #  3com         - 3com 3c501
  466.                                 #  3c523        - 3com 3c523
  467.                                 #  wd800        - Western Digitial 800E
  468.                                 #  nicpc        - 
  469.                                 #  nicps        -
  470.                                 #  ni5210       - Micom Interlan NI5210 card
  471.                                 #  packet       - FTP packet Driver spec 
  472.                                 # (currently only Ethernet and Slip class devices are supported)
  473.  
  474. interrupt=2                     # hardware IRQ interrupt
  475. address=0                       # (0)
  476.                 # base memory address or packet driver class
  477.                                 # if using packet driver (0 == default == ethernet)
  478.                                 # or class=6 for slip
  479.  
  480. ioaddr=0                        # (0)
  481.                 # I/O address  or packet int vector if using packet driver
  482.                                 # If = 0 and packet driver, telbin looks for first
  483.                                 # packet driver found between 60H and 7FH
  484.  
  485. noarpme=yes            # Don't arp for myself before running? (no)
  486.                 # if yes, inhibits the initial arp request
  487.                 # for this IP address. However, if yes, won't
  488.                 # warn you if another user is using this IP
  489.                 # address. For some token ring systems, you'll
  490.                 # need noarpme=yes.
  491.  
  492. include="nul"            # if you want to include another file as part
  493.                 # of this one (you can nest up to three includes)
  494.                 # otherwise, don't use this option
  495.  
  496. domaintime=4            # domain name lookup timeout (first retry)
  497. domainretry=4            # domain name max number of retries 
  498. domainslist="clarkson.edu,aux.clarkson.edu" # domain name search path
  499.                                 # domain name lookup will attach each of these
  500.                                 # comma seperated suffixes to
  501.                                 # the end of the name you are looking for to
  502.                                 # discover the full name and IP address.
  503.                                 # so, looking for x tries x.clarkson.edu and x.aux.clarkson.edu then just x
  504.                                 # unless you use  x.  which ONLY looks for x
  505.  
  506.     ## Also, the fewer suffixes in the domainslist
  507.     ## the less time you will have to wait if you mis-type an entry.
  508.     ## Finally, try not to use a suffix like   .  or .edu or .com this will
  509.     ## waste a lot of time looking for a bogus host name if you mis-type an entry.
  510.  
  511. ## ----------------------------------------------------------------- ##
  512. ##   BEGIN MACHINE SPECIFIC PARAMETERS...                 ##
  513. ## ----------------------------------------------------------------- ##
  514.  
  515. name=default            # default entry sets defaults for all following
  516.                 # machines.
  517.  
  518. arptime=10            # arp timeout in seconds
  519.                 #
  520.  
  521. retrans=1                       # starting retransmit time out in ticks
  522.                 #   1/18ths of sec MAX 100, min 1
  523.  
  524. mtu=1024                        # maximum transmit unit in bytes
  525.                 #   outgoing packet size, MAX=1500
  526.  
  527. maxseg=1024            # largest segment we can receive
  528.                 #   whatever the hardware can take, MAX=4096
  529. rwin=2048                       # most bytes we can receive without ACK
  530.                 #   =TCP window size, MAX=4096
  531.  
  532. contime=20                      # timeout in seconds to try connection
  533.                 #   before returning error to user
  534.  
  535. #  Following are individual machine specifications
  536. #  Gateways are used in order that they appear in the file
  537. #  Nameservers rotate, #1, #2, #3, #1, #2 when a request fails
  538. #
  539.  
  540. # ********************************************************************* ###
  541. # Note: If you are using BOOTP above for myip=, then you do not need
  542. #       to enter a default gateway, nameserver, netmask etc (unless you want to)
  543. #       only IF your BOOTP server is rfc_1048 compliant. (Ask your Net Manager)
  544. #       You can use both bootp and entries here, in which case the entries in
  545. #       this file over-ride what BOOTP discovers. (however, bootp nameservers
  546. #       and gateways are ADDED to this file's list of entries
  547. # ********************************************************************* ####
  548.  
  549. #  Below this line, most of the communication parameters are obtained
  550. #  from the "default" host entry.  Those parameters listed for a host 
  551. #  override the default host values.
  552. #
  553. #  These are examples, replace them with the correct values for your site.
  554. #name=mynameserver
  555. #host=omnigate.clarkson.edu
  556. #hostip=197.001.4.2
  557. #nameserver=1
  558.  
  559. #name=backupserver
  560. #host=clutx.clarkson.edu
  561. #hostip=197.001.4.3
  562. #nameserver=2
  563.  
  564. #name=lastserver
  565. #host=n2ngw.nyser.net
  566. #hostip=128.145.198.2
  567. #nameserver=3
  568.  
  569. #name=mygateway
  570. #host=nysernet.clarkson.edu
  571. #hostip=197.001.4.1
  572. #gateway=1
  573.  
  574.  
  575. name=archie
  576. host=archie.funet.fi
  577. $EOD
  578. $!
  579. $CREATE [.archie]archie.c
  580. $DECK
  581. /*
  582.  * Copyright (c) 1991 by the University of Washington
  583.  *
  584.  * For copying and distribution information, please see the file
  585.  * <copyright.h>.
  586.  *
  587.  * v1.2.1 - 11/21/91 (bkc) - added CUTCP library support for MSDOS
  588.  * v1.2.0 - 11/19/91 (mmt) - added MSDOS & OS2 stuff
  589.  * v1.1.2 - 08/27/91 (bpk) - added <pmachine.h> for index()
  590.  * v1.1.1 - 08/22/91 (bpk) - added 0-9 as arguments
  591.  */
  592.  
  593. #include <copyright.h>
  594.  
  595. /*
  596.  * Archie client using the Prospero protocol.
  597.  *
  598.  * Suggestions and improvements to Brendan Kehoe (brendan@cs.widener.edu).
  599.  */
  600.  
  601. #include <stdio.h>
  602. #if defined(OS2)
  603. # include <pctcp.h>
  604. #endif
  605. #ifdef MSDOS
  606. # include <string.h>
  607. # include <stdlib.h>
  608. # ifdef CUTCP
  609. #  include <msdos/cutcp.h>
  610. #  include <msdos/hostform.h>
  611. # endif
  612. #endif
  613.  
  614. #include <pfs.h>
  615. #include <rdgram.h>
  616. #include <archie.h>
  617. #include <pmachine.h>
  618.  
  619. int        listflag = 0;
  620. int        sortflag = 0;   /* 1 = by date                    */
  621. char        *progname;
  622. #ifdef DEBUG
  623. extern int    pfs_debug;
  624. #endif
  625. extern int    rdgram_priority;
  626.  
  627. /* To keep the code clean.. */
  628. #ifdef VMS
  629. # define NFLAG    "\"N\""
  630. # define LFLAG    "\"L\""
  631. # define A_EXIT    SS$_NORMAL
  632. #else
  633. # define NFLAG    "N"
  634. # define LFLAG    "L"
  635. # define A_EXIT    1
  636. #endif
  637. #ifdef CUTCP
  638. # define HFLAG    "[H config.tel]]"
  639. #else
  640. # define HFLAG    "]"
  641. #endif
  642.  
  643. main(argc,argv)
  644.     int        argc;
  645.     char    *argv[];
  646.     {
  647.     char        *cur_arg;
  648.     char        qtype = '=';    /* Default to exact string match  */
  649.     char        etype = '=';    /* Type if only -e is specified   */
  650.     int        eflag = 0;    /* Exact flag specified          */
  651.     int        max_hits = MAX_HITS;
  652.     int        offset = 0;
  653.     int        exitflag = 0;    /* Display release identifier     */
  654.     int        tmp;
  655.     char        *host = ARCHIE_HOST;
  656.     char        *p;
  657.     static char *archies[] = { ARCHIES };
  658. #ifdef CUTCP
  659.     int        hostset = 0;
  660. #endif
  661.     char        *getenv();
  662.  
  663.     progname = *argv;
  664.     argc--; argv++;
  665.  
  666. #ifdef    CUTCP
  667.     if(getenv("CONFIGTEL"))
  668.         if(Shostfile(getenv("CONFIGTEL")) < 0) {
  669.             fprintf(stderr,"Error, couldn't open configtel file %s\n",
  670.                 getenv("CONFIGTEL"));
  671.             exit(1);
  672.         }
  673. #endif
  674.  
  675.     if ((p = getenv("ARCHIE_HOST")) != (char *)NULL)
  676.       host = p;
  677.         
  678.     while (argc > 0 && **argv == '-') {
  679.         cur_arg = argv[0]+1;
  680.  
  681.         /* If a - by itself, or --, then no more arguments */
  682.         if(!*cur_arg || ((*cur_arg == '-') && (!*(cur_arg+1)))) {
  683.             argc--, argv++;
  684.         goto scandone;
  685.         }
  686.  
  687.         while (*cur_arg) {
  688.         switch (*cur_arg++) {
  689. #ifdef DEBUG        
  690.         case 'D':  /* Debug level */
  691.             pfs_debug = 1; /* Default debug level */
  692.             if(*cur_arg && index("0123456789",*cur_arg)) {
  693.             sscanf(cur_arg,"%d",&pfs_debug);
  694.             cur_arg += strspn(cur_arg,"0123456789");
  695.             }
  696.             else if(argc > 2) {
  697.                 tmp = sscanf(argv[1],"%d",&pfs_debug);
  698.             if (tmp == 1) {argc--;argv++;}
  699.             }
  700.             break;
  701. #endif
  702. #ifdef    CUTCP
  703.         case 'H' :
  704.             if(Shostfile(argv[1]) < 0) {
  705.                 fprintf(stderr,"Error, couldn't open configtel file %s\n",argv[1]);
  706.                 exit(1);
  707.             }
  708.              argc--;argv++;
  709.             break;
  710. #endif
  711. #ifndef XARCHIE
  712.         case 'L':
  713.             printf("Known archie servers:\n");
  714.             for (tmp = 0; tmp < NARCHIES; tmp++)
  715.             printf("\t%s\n", archies[tmp]);
  716.             printf(" * %s is the default Archie server.\n", ARCHIE_HOST);
  717.             printf(" * For the most up-to-date list, write to an Archie server and give it\n   the command `servers'.\n");
  718.             exitflag = 1;
  719.             break;
  720. #endif
  721.  
  722.         case 'N':  /* Priority (nice) */
  723.             rdgram_priority = RDGRAM_MAX_PRI; /* Use this if no # */
  724.             if(*cur_arg && index("-0123456789",*cur_arg)) {
  725.             sscanf(cur_arg,"%d",&rdgram_priority);
  726.             cur_arg += strspn(cur_arg,"-0123456789");
  727.             }
  728.             else if(argc > 2) {
  729.                 tmp = sscanf(argv[1],"%d",&rdgram_priority);
  730.             if (tmp == 1) {argc--;argv++;}
  731.             }
  732.             if(rdgram_priority > RDGRAM_MAX_SPRI) 
  733.             rdgram_priority = RDGRAM_MAX_PRI;
  734.             if(rdgram_priority < RDGRAM_MIN_PRI) 
  735.             rdgram_priority = RDGRAM_MIN_PRI;
  736.               break;
  737.  
  738.         case 'c':  /* substring (case sensitive) */
  739.             qtype = 'C';
  740.             etype = 'c';
  741.             break;
  742.  
  743.         case 'e':  /* Exact match */
  744.             /* If -e specified by itself, then we use the  */
  745.             /* default value of etype which must be '='    */
  746.             eflag++;
  747.             break;
  748.  
  749.         case 'h':  /* Host */
  750.             host = argv[1];
  751. #ifdef CUTCP
  752.             hostset++;
  753. #endif
  754.             argc--; argv++;
  755.             break;
  756.  
  757.         case 'l':  /* List one match per line */
  758.             listflag++;
  759.             break;
  760.  
  761.         case '0': case '1': case '2': case '3': case '4':
  762.         case '5': case '6': case '7': case '8': case '9':
  763.             cur_arg--;
  764.         case 'm':  /* Max hits */
  765.             max_hits = -1;  
  766.             if(*cur_arg && index("0123456789",*cur_arg)) {
  767.             sscanf(cur_arg,"%d",&max_hits);
  768.             cur_arg += strspn(cur_arg,"0123456789");
  769.             }
  770.             else if(argc > 1) {
  771.                 tmp = sscanf(argv[1],"%d",&max_hits);
  772.             if (tmp == 1) {argc--;argv++;}
  773.             }
  774.             if (max_hits < 1) {
  775.             fprintf(stderr, "%s: -m option requires a value for max hits (>= 1)\n",
  776.                 progname);
  777.             exit(A_EXIT);
  778.             }
  779.             break;
  780.  
  781.         case 'o':  /* Offset */
  782.             if(argc > 1) {
  783.               tmp = sscanf(argv[1],"%d",&offset);
  784.               if (tmp != 1)
  785.             argc = -1;
  786.               else {
  787.             argc--; argv++;
  788.               }
  789.             }
  790.             break;
  791.  
  792.         case 'r':  /* Regular expression search */
  793.             qtype = 'R';
  794.             etype = 'r';
  795.             break;
  796.  
  797.         case 's':  /* substring (case insensitive) */
  798.             qtype = 'S';
  799.             etype = 's';
  800.             break;
  801.  
  802.         case 't':  /* Sort inverted by date */
  803.             sortflag = 1;
  804.             break;
  805.  
  806.         case 'v':  /* Display version */
  807.             fprintf(stderr,
  808.             "Client version %s based upon Prospero version %s\n",
  809.                 CLIENT_VERSION, PFS_RELEASE);
  810.             exitflag++;
  811.             break;
  812.  
  813.         default:
  814.             fprintf(stderr,"Usage: %s [-[cers][l][t][m#][h host][%s][%s#]%s string\n", progname, LFLAG, NFLAG, HFLAG);
  815.             exit(A_EXIT);
  816.         }
  817.         }
  818.         argc--; argv++;
  819.     }
  820.  
  821.       scandone:
  822.  
  823.     if (eflag) qtype = etype;
  824.  
  825.     if ((argc != 1) && exitflag) exit(0);
  826.  
  827.     if (argc != 1) {
  828.         fprintf(stderr, "Usage: %s [-[cers][l][t][m#][h host][%s][%s#]%s string\n", progname, LFLAG, NFLAG, HFLAG);
  829.         fprintf(stderr,"       -c : case sensitive substring search\n");
  830.         fprintf(stderr,"       -e : exact string match (default)\n");
  831.         fprintf(stderr,"       -r : regular expression search\n");
  832.         fprintf(stderr,"       -s : case insensitive substring search\n");
  833.         fprintf(stderr,"       -l : list one match per line\n");
  834.         fprintf(stderr,"       -t : sort inverted by date\n");
  835.         fprintf(stderr,"      -m# : specifies maximum number of hits to return (default %d)\n", max_hits);
  836.         fprintf(stderr,"  -h host : specifies server host\n");
  837.         fprintf(stderr,"       -%s : list known servers and current default\n", LFLAG);
  838.         fprintf(stderr,"      -%s# : specifies query niceness level (0-35765)\n", NFLAG);
  839. #ifdef CUTCP
  840.         fprintf(stderr,"-H config.tel: specify location of config.tel file\n");
  841. #endif
  842.         exit(A_EXIT);
  843.     }
  844.  
  845. #ifdef    CUTCP
  846.     if(argc = Snetinit()) {
  847.                fprintf(stderr,"Error %d from SNetinit (bad or missing config.tel ?)\n",argc);
  848.         if(argc == -2)
  849.                    netshut();    /* rarp lookup failure */
  850.         exit(1);
  851.     }
  852.     if(!hostset) {        /* if no host on command line, look in config.tel file
  853.                           for name=archie */
  854.         struct machinfo *mp;
  855.  
  856.          mp = Shostlook("archie");
  857.         if(mp) {
  858.                    host = mp->hname ? mp->hname : mp->sname;
  859.         }
  860.        }
  861. #endif
  862.  
  863.     procquery(host, argv[0], max_hits, offset, qtype, sortflag, listflag);
  864.  
  865. #ifdef CUTCP
  866.     netshut();
  867. #endif
  868.     exit(0);
  869.     }
  870. $EOD
  871. $!
  872. $CREATE [.archie]archie.h
  873. $DECK
  874. /*
  875.  * archie.h : Definitions for the programmatic Prospero interface to Archie
  876.  *
  877.  *     Written by Brendan Kehoe (brendan@cs.widener.edu), 
  878.  *                George Ferguson (ferguson@cs.rochester.edu), and
  879.  *                Clifford Neuman (bcn@isi.edu).
  880.  */
  881.  
  882. #ifdef VMS
  883. /*
  884.  * This has to be edited if you're running VMS, cuz I gave up after about
  885.  * an hour trying to make DCL do       /define(archie_host="\"FOO\"")
  886.  *
  887.  * Edit ARCHIE_HOST to be one of :
  888.  *    archie.ans.net        (USA [NY])
  889.  *    archie.rutgers.edu        (USA [NJ])
  890.  *    archie.sura.net        (USA [MD])
  891.  *    archie.mcgill.ca        (Canada)
  892.  *    archie.funet.fi        (Finland/Mainland Europe)
  893.  *    archie.au            (Australia)
  894.  *    archie.doc.ic.ac.uk    (Great Britain/Ireland)
  895.  */
  896. #define ARCHIE_HOST    "archie.ans.net"
  897. #endif /* VMS */
  898.  
  899. /* You can't touch this.  */
  900. #ifndef XARCHIE
  901. # define ARCHIES    "archie.ans.net (USA [NY])","archie.rutgers.edu (USA [NJ])","archie.sura.net (USA [MD])","archie.mcgill.ca (Canada)","archie.funet.fi (Finland/Mainland Europe)","archie.au (Australia)","archie.doc.ic.ac.uk (Great Britain/Ireland)"
  902. # define NARCHIES    7
  903. #endif
  904.  
  905. /*
  906.  * Default value for max hits.  Note that this is normally different
  907.  * for different client implementations.  Doing so makes it easier to
  908.  * collect statistics on the use of the various clients.
  909.  */
  910. #ifdef VMS
  911. # define    MAX_HITS    98    /* VMS Client */
  912. #else
  913. # ifdef XARCHIE
  914. #  define    MAX_HITS    99    /* X Client */
  915. # else
  916. #  define    MAX_HITS    95    /* Normal client */
  917. # endif
  918. #endif
  919.  
  920. /*
  921.  * CLIENT_VERSION may be used to identify the version of the client if 
  922.  * distributed separately from the Prospero distribution.  The version
  923.  * command should then identify both the client version and the Prospero
  924.  * version identifiers.   
  925.  */
  926. #ifdef XARCHIE
  927. # define CLIENT_VERSION    "1.3-X"
  928. #else
  929. # define CLIENT_VERSION "1.3"
  930. #endif
  931.  
  932. /* Procedures from user/aquery.c */
  933.  
  934. /* archie_query(host,string,max_hits,offset,query_type,cmp_proc,flags) */
  935. extern VLINK archie_query(); 
  936.  
  937. /* defcmplink(p,q) and invdatecmplink(p,q)                             */
  938. extern int defcmplink();    /* Compare by host then by filename    */
  939. extern int invdatecmplink();    /* Compare links inverted by date      */
  940.  
  941. /* Definitions for the comparison procedures                           */
  942. #define AQ_DEFCMP    defcmplink
  943. #define AQ_INVDATECMP    invdatecmplink
  944.  
  945. /* Flags                                                               */
  946. #define AQ_NOSORT    0x01    /* Don't sort                          */
  947. #define AQ_NOTRANS    0x02    /* Don't translate Archie responses    */
  948. $EOD
  949. $!
  950. $CREATE [.archie]archie.lnk
  951. $DECK
  952. aquery.lo archie.lo atalloc.lo dirsend.lo+
  953. Get_pauth.lo get_vdir.lo perrmesg.lo procquery.lo+
  954. ptalloc.lo regex.lo stcopy.lo support.lo+
  955. vlalloc.lo vl_comp.lo
  956. archie.unp
  957. archie/map/noi/co/li/stack:45000
  958. lsocket lnetlib lconfig lpc llibce
  959. $EOD
  960. $!
  961. $CREATE [.archie]archie.doc
  962. $DECK
  963.  
  964.  
  965.  
  966. ARCHIE(1)                USER COMMANDS                  ARCHIE(1)
  967.  
  968.  
  969.  
  970. NAME
  971.      archie - query the  Archie  anonymous  FTP  databases  using
  972.      Prospero
  973.  
  974. SYNOPSIS
  975.      archie [ -cers ] [ -l ] [ -t ] [ -m# ] [ -N# ] [ -h hostname ]
  976.             [ -L ] string
  977.  
  978. DESCRIPTION
  979.      archie queries an archie anonymous FTP database looking  for
  980.      the  specified  string  using  the  Prospero protocol.  This
  981.      client is based on Prospero version Beta.4.2 and is provided
  982.      to  encourage non-interactive use of the Archie servers (and
  983.      subsequently better performance on both  sides).   This  man
  984.      page describes version 1.3 of the client.
  985.  
  986.      The general method of use is of the form
  987.  
  988.           % archie string
  989.  
  990.      This will go to the archie server and ask it to look for all
  991.      known  systems  that have a file named `string' in their FTP
  992.      area.  archie will wait, and print out any matches.
  993.  
  994.      For example,
  995.  
  996.           % archie emacs
  997.  
  998.      will find all anonymous FTP sites  in  the  archie  database
  999.      that  have  files  named  emacs somewhere in their FTP area.
  1000.      (This particular query would probably return a lot of direc-
  1001.      tories.)  If you want a list of every filename that contains
  1002.      emacs anywhere in it, you'd use
  1003.  
  1004.           % archie -c emacs
  1005.  
  1006.      Regular expressions, such as
  1007.  
  1008.           % archie -r '[xX][lL]isp'
  1009.  
  1010.      may also be used for searches.  (See the manual of a reason-
  1011.      ably good editor, like GNU Emacs or vi, for more information
  1012.      on using regular expressions.)
  1013.  
  1014.  
  1015. OPTIONS
  1016.      The options currently available to this archie client are:
  1017.  
  1018.      -c          Search substrings paying attention  to  upper  &
  1019.                  lower case.
  1020.      -e          Exact string match.  (This is the default.)
  1021.      -r          Search using a regular expression.
  1022.  
  1023.  
  1024.  
  1025. Archie (Prospero)  Last change: 9 January 1992                  1
  1026.  
  1027.  
  1028.  
  1029.  
  1030.  
  1031.  
  1032. ARCHIE(1)                USER COMMANDS                  ARCHIE(1)
  1033.  
  1034.  
  1035.  
  1036.      -s          Search  substrings  ignoring  the  case  of  the
  1037.                  letters.
  1038.      -l          Output results in a form suitable for parsing by
  1039.                  programs.
  1040.      -t          Sort the results inverted by date.
  1041.      -m#         Specifies the maximum number of  hits  (matches)
  1042.                  to return (default of 95).
  1043.      -N#         Sets the niceness of a query; by  default,  it's
  1044.                  set  to 0.  Without an argument, ``-N'' defaults
  1045.                  to 35765.   If  you  use  -N  with  an  argument
  1046.                  between 0 and 35765, it'll adjust itself accord-
  1047.                  ingly.  (Note: VMS users will have to put quotes
  1048.                  around  this  argument, and -L, like "-N45"; VMS
  1049.                  will otherwise convert it to lowercase.)
  1050.      -h hostname Tells the client  to  query  the  Archie  server
  1051.                  hostname.
  1052.      -L          Lists the Archie servers known  to  the  program
  1053.                  when it was compiled, as well as the name of the
  1054.                  default Archie server.  For an up-to-date  list,
  1055.                  write  to  ``archie@archie.mcgill.ca''  (or  any
  1056.                  Archie  server)  with  the  single  command   of
  1057.                  servers.
  1058.  
  1059.      The three search-modifying arguments  (``-c'',  ``-r'',  and
  1060.      ``-s'')  are  all  mutually  exclusive;  only  the  last one
  1061.      counts.  If you specify -e with any of  ``-c'',  ``-r'',  or
  1062.      ``-s'', the server will first check for an exact match, then
  1063.      fall back to the case-sensitive, case-insensitive, or  regu-
  1064.      lar expression search.  This is so if there are matches that
  1065.      are particularly obvious, it will take a minimal  amount  of
  1066.      time to satisfy your request.
  1067.  
  1068.      If you list a single `-' by itself,  any  further  arguments
  1069.      will  be  taken  as  part  of  the  search  string.  This is
  1070.      intended to enable searching for strings that begin  with  a
  1071.      `-'; for example:
  1072.  
  1073.           % archie -s - -old
  1074.  
  1075.      will search for all filenames that contain the string `-old'
  1076.      in them.
  1077.  
  1078. RESPONSE
  1079.      Archie servers are set up to respond to a number of requests
  1080.      in  a  queued fashion.  That is, smaller requests get served
  1081.      much more quickly than do large requests.  As a result,  the
  1082.      more  often  you query the Archie server, or the larger your
  1083.      requests, the longer the queue will become, resulting  in  a
  1084.      longer  waiting  period  for everyone's requests.  Please be
  1085.      frugal when possible, for your benefit as well  as  for  the
  1086.      other users.
  1087.  
  1088.  
  1089.  
  1090.  
  1091. Archie (Prospero)  Last change: 9 January 1992                  2
  1092.  
  1093.  
  1094.  
  1095.  
  1096.  
  1097.  
  1098. ARCHIE(1)                USER COMMANDS                  ARCHIE(1)
  1099.  
  1100.  
  1101.  
  1102. QUERY PRIORITY
  1103.      Please use the  ``-N''  option  whenever  you  don't  demand
  1104.      immediacy,  or when you're requesting things that could gen-
  1105.      erate large responses.  Even when using the nice option, you
  1106.      should  still  try  to  avoid  big jobs during busy periods.
  1107.      Here is a list of what we consider to be  nice  values  that
  1108.      accurately reflect the priority of a job to the server.
  1109.  
  1110.           Normal              0
  1111.           Nice                500
  1112.           Nicer               1000
  1113.           Very Nice           5000
  1114.           Extremely Nice      10000
  1115.           Nicest              32765
  1116.  
  1117.      The last priority, Nicest, would be used when a  job  should
  1118.      wait  until  the  queue is essentially empty before running.
  1119.      You should pick one of these values to use, possibly modify-
  1120.      ing  it  slightly depending on where you think your priority
  1121.      should land.  For example, 32760 would mean wait  until  the
  1122.      queue  is  empty,  but  jump  ahead  of other jobs that have
  1123.      selected Nicest.
  1124.  
  1125.      There are certain types of  things  that  we  suggest  using
  1126.      Nicest  for,  irregardless.  In particular, any searches for
  1127.      which you would have a hard time justifying the use of  any-
  1128.      thing but extra resources.  (We all know what those searches
  1129.      would be for.)
  1130.  
  1131. ENVIRONMENT
  1132.      ARCHIE_HOST
  1133.              This will change the host archie will  consult  when
  1134.              making  queries.   (The default value is what's been
  1135.              compiled in.)  The ``-h'' option will override this.
  1136.              If  you're  running  VMS,  create  a  symbol  called
  1137.              ARCHIE_HOST.
  1138.  
  1139. SEE ALSO
  1140.      For more information on regular expressions, see the  manual
  1141.      pages on:
  1142.  
  1143.      regex(3), ed(1)
  1144.  
  1145.      Also   read    the    file    archie/doc/whatis.archie    on
  1146.      archie.mcgill.ca for a detailed paper on Archie as a whole.
  1147.  
  1148. AUTHORS
  1149.      The archie service was conceived  and  implemented  by  Alan
  1150.      Emtage       (bajan@cs.mcgill.ca),       Peter       Deutsch
  1151.      (peterd@cs.mcgill.ca),        and        Bill         Heelan
  1152.      (wheelan@cs.mcgill.ca).   The  entire  Internet  is in their
  1153.      debt.
  1154.  
  1155.  
  1156.  
  1157. Archie (Prospero)  Last change: 9 January 1992                  3
  1158.  
  1159.  
  1160.  
  1161.  
  1162.  
  1163.  
  1164. ARCHIE(1)                USER COMMANDS                  ARCHIE(1)
  1165.  
  1166.  
  1167.  
  1168.      The  Prospero  system  was  created   by   Clifford   Neuman
  1169.      (bcn@isi.edu);   write  to  info-prospero@isi.edu  for  more
  1170.      information on the protocol and its use.
  1171.  
  1172.      This stripped client  was  put  together  by  Brendan  Kehoe
  1173.      (brendan@cs.widener.edu),  with  modifications  by  Clifford
  1174.      Neuman and George Ferguson (ferguson@cs.rochester.edu).
  1175.  
  1176. BUGS
  1177.      There are none; only a few unexpected features.
  1178.  
  1179.  
  1180.  
  1181.  
  1182.  
  1183.  
  1184.  
  1185.  
  1186.  
  1187.  
  1188.  
  1189.  
  1190.  
  1191.  
  1192.  
  1193.  
  1194.  
  1195.  
  1196.  
  1197.  
  1198.  
  1199.  
  1200.  
  1201.  
  1202.  
  1203.  
  1204.  
  1205.  
  1206.  
  1207.  
  1208.  
  1209.  
  1210.  
  1211.  
  1212.  
  1213.  
  1214.  
  1215.  
  1216.  
  1217.  
  1218.  
  1219.  
  1220.  
  1221.  
  1222.  
  1223. Archie (Prospero)  Last change: 9 January 1992                  4
  1224.  
  1225.  
  1226.  
  1227. $EOD
  1228. $!
  1229. $CREATE [.archie]archie.man
  1230. $DECK
  1231. .\" Originally by Jeff Kellem (composer@chem.bu.edu).
  1232. .\"
  1233. .\" This is from rn (1):
  1234. .de Ip
  1235. .br
  1236. .ie \\n.$>=3 .ne \\$3
  1237. .el .ne 3
  1238. .IP "\\$1" \\$2
  1239. ..
  1240. .\"
  1241. .TH ARCHIE 1 "9 January 1992" "Archie (Prospero)"
  1242. .SH NAME
  1243. archie \- query the Archie anonymous FTP databases using Prospero
  1244. .SH SYNOPSIS
  1245. .in +\w'\fBarchie \fR'u
  1246. .ti -\w'\fBarchie \fR'u
  1247. .B archie\
  1248. \ [\ \fB\-cers\fR\ ]\
  1249. \ [\ \fB\-l\fR\ ]\ [\ \fB\-t\fR\ ]\
  1250. \ [\ \fB\-m#\fR\ ]\ [\ \fB\-N#\fR\ ]\
  1251. \ [\ \fB\-h\fR\ \fIhostname\fR\ ]
  1252. [\ \fB\-L\fR\ ]\ \fIstring\fR
  1253. .SH DESCRIPTION
  1254. .B archie
  1255. queries an archie anonymous FTP database looking for the specified
  1256. .I string
  1257. using the
  1258. .B Prospero
  1259. protocol.  This client is based on
  1260. .B Prospero
  1261. version Beta.4.2 and is provided to encourage non-interactive use of
  1262. the Archie servers (and subsequently better performance on both
  1263. sides).  This man page describes version 1.3 of the client.
  1264.  
  1265. The general method of use is of the form
  1266.  
  1267. .RS
  1268. %
  1269. .B archie string
  1270. .RE
  1271. .PP
  1272.  
  1273. This will go to the archie server and ask it to look for all known
  1274. systems that have a file named `string' in their FTP area.  \fBarchie\fP
  1275. will wait, and print out any matches.
  1276.  
  1277. For example,
  1278.  
  1279. .RS
  1280. %
  1281. .B archie emacs
  1282. .RE
  1283. .PP
  1284.  
  1285. will find all anonymous FTP sites in the archie database that have files
  1286. named
  1287. .B emacs
  1288. somewhere in their FTP area.  (This particular query would probably
  1289. return a lot of directories.)  If you want a list of every filename
  1290. that contains \fBemacs\fR \fIanywhere\fR in it, you'd use
  1291.  
  1292. .RS
  1293. %
  1294. .B archie -c emacs
  1295. .RE
  1296. .PP
  1297.  
  1298. Regular expressions, such as
  1299.  
  1300. .RS
  1301. %
  1302. .B archie -r '[xX][lL]isp'
  1303. .RE
  1304. .PP
  1305.  
  1306. may also be used for searches.  (See the manual of a reasonably good
  1307. editor, like GNU Emacs or vi, for more information on using regular
  1308. expressions.)
  1309.  
  1310. .SH OPTIONS
  1311. The options currently available to this
  1312. .B archie
  1313. client are:
  1314.  
  1315. .PD 0
  1316. .TP 12
  1317. .BR \-c
  1318. Search substrings paying attention to upper & lower case.
  1319. .TP
  1320. .BR \-e
  1321. Exact string match.  (This is the default.)
  1322. .TP
  1323. .BR \-r
  1324. Search using a regular expression.
  1325. .TP
  1326. .BR \-s
  1327. Search substrings ignoring the case of the letters.
  1328. .TP
  1329. .BR \-l
  1330. Output results in a form suitable for parsing by programs.
  1331. .TP
  1332. .BR \-t
  1333. Sort the results inverted by date.
  1334. .TP
  1335. .BI \-m#
  1336. Specifies the maximum number of hits (matches) to return (default of 
  1337. \fB95\fR).
  1338. .TP
  1339. .BI \-N#
  1340. Sets the \fIniceness\fR of a query; by default, it's set to 0.
  1341. Without an argument, ``\-N'' defaults to \fB35765\fR.  If you use
  1342. \fB\-N\fR with an argument between 0 and 35765, it'll adjust itself
  1343. accordingly.  (\fBNote\fR: VMS users will have to put quotes around
  1344. this argument, and \fB\-L\fR, like "\fB\-N45\fR"; VMS will otherwise convert
  1345. it to lowercase.)
  1346. .TP
  1347. .BI \-h\ \fIhostname\fR
  1348. Tells the client to query the Archie server \fIhostname\fR.
  1349. .TP
  1350. .BI \-L
  1351. Lists the Archie servers known to the program when it was compiled, as
  1352. well as the name of the default Archie server.  For an up-to-date
  1353. list, write to ``archie@archie.mcgill.ca'' (or any Archie server) with
  1354. the single command of \fIservers\fR.
  1355.  
  1356. .PP
  1357. The three search-modifying arguments (``\-c'', ``\-r'', and ``\-s'')
  1358. are all mutually exclusive; only the last one counts.  If you specify
  1359. \fB\-e\fR with any of ``\-c'', ``\-r'', or ``\-s'',
  1360. the server will first check for an exact match, then fall back to the
  1361. case-sensitive, case-insensitive, or regular expression search.  This is
  1362. so if there are matches that are particularly obvious, it will take a
  1363. minimal amount of time to satisfy your request.
  1364.  
  1365. If you list a single `\-' by itself, any further arguments will be
  1366. taken as part of the search string.  This is intended to enable
  1367. searching for strings that begin with a `\-'; for example:
  1368.  
  1369. .RS
  1370. %
  1371. .B archie \-s \- \-old
  1372. .RE
  1373.  
  1374. will search for all filenames that contain the string `\-old' in them.
  1375.  
  1376. .SH RESPONSE
  1377. Archie servers are set up to respond to a number of requests in a
  1378. queued fashion.  That is, smaller requests get served much more
  1379. quickly than do large requests.  As a result, the more often you query
  1380. the Archie server, or the larger your requests, the longer the queue
  1381. will become, resulting in a longer waiting period for everyone's
  1382. requests.  Please be frugal when possible, for your benefit as well as
  1383. for the other users.
  1384.  
  1385. .SH QUERY PRIORITY
  1386. Please use the ``-N'' option whenever you don't demand immediacy, or
  1387. when you're requesting things that could generate large responses.
  1388. Even when using the nice option, you should still try to avoid big
  1389. jobs during busy periods.  Here is a list of what we consider to be
  1390. nice values that accurately reflect the priority of a job to the server.
  1391.  
  1392. .RS
  1393. .TP 20
  1394. .B Normal
  1395. 0
  1396. .TP
  1397. .B Nice
  1398. 500
  1399. .TP
  1400. .B Nicer
  1401. 1000
  1402. .TP
  1403. .B Very Nice
  1404. 5000
  1405. .TP
  1406. .B Extremely Nice
  1407. 10000
  1408. .TP
  1409. .B Nicest
  1410. 32765
  1411. .RE
  1412.  
  1413. The last priority, \fBNicest\fR, would be used when a job should wait until
  1414. the queue is essentially empty before running.  You should pick one of
  1415. these values to use, possibly modifying it slightly depending on where
  1416. you think your priority should land.  For example, 32760 would mean
  1417. wait until the queue is empty, but jump ahead of other jobs that have
  1418. selected \fBNicest\fR.
  1419.  
  1420. There are certain types of things that we suggest using \fBNicest\fR
  1421. for, irregardless.  In particular, any searches for which you would
  1422. have a hard time justifying the use of anything but extra resources.
  1423. (We all know what those searches would be for.)
  1424.  
  1425. .SH ENVIRONMENT
  1426. .Ip "ARCHIE_HOST" 8
  1427. This will change the host
  1428. .IR archie
  1429. will consult when making queries.  (The default value is what's been
  1430. compiled in.)  The ``\-h'' option will override this.  If you're
  1431. running VMS, create a symbol called ARCHIE_HOST.
  1432.  
  1433. .SH SEE ALSO
  1434. For more information on regular expressions, see the manual pages on:
  1435.  
  1436. .BR regex (3) ,
  1437. .BR ed (1)
  1438.  
  1439. Also read the file \fBarchie/doc/whatis.archie\fR on
  1440. \fBarchie.mcgill.ca\fR for a detailed paper on Archie as a whole.
  1441.  
  1442. .SH AUTHORS
  1443. The 
  1444. .B archie
  1445. service was conceived and implemented by Alan Emtage (\fBbajan@cs.mcgill.ca\fR),
  1446. Peter Deutsch (\fBpeterd@cs.mcgill.ca\fR), and Bill Heelan
  1447. (\fBwheelan@cs.mcgill.ca\fR).  The entire Internet is in their debt.
  1448.  
  1449. The \fBProspero\fR system was created by Clifford Neuman
  1450. (\fBbcn@isi.edu\fR); write to \fBinfo\-prospero@isi.edu\fR for more
  1451. information on the protocol and its use.
  1452.  
  1453. This stripped client was put together by Brendan Kehoe
  1454. (\fBbrendan@cs.widener.edu\fR), with modifications by
  1455. Clifford Neuman and George Ferguson (\fBferguson@cs.rochester.edu\fR).
  1456.  
  1457. .SH BUGS
  1458. There are none; only a few unexpected features.
  1459.  
  1460. $EOD
  1461. $!
  1462. $CREATE [.archie]aquery.c
  1463. $DECK
  1464. /*
  1465.  * aquery.c : Programmatic Prospero interface to Archie
  1466.  *
  1467.  * Copyright (c) 1991 by the University of Washington
  1468.  *
  1469.  * For copying and distribution information, please see the file
  1470.  * <copyright.h>.
  1471.  *
  1472.  * Originally part of the Prospero Archie client by Clifford 
  1473.  * Neuman (bcn@isi.edu).  Modifications, addition of programmatic interface,
  1474.  * and new sorting code by George Ferguson (ferguson@cs.rochester.edu) 
  1475.  * and Brendan Kehoe (brendan@cs.widener.edu).  MSDOS and OS2 modifications
  1476.  * to use with PC/TCP by Mark Towfiq (towfiq@FTP.COM).
  1477.  *
  1478.  * v1.2.1 - 11/19/91 (mmt) - added MSDOS & OS2 stuff
  1479.  * v1.2.0 - 09/17/91 (bpk) - added BULL & USG stuff, thanks to Jim Sillas
  1480.  * v1.1.3 - 08/30/91 (bpk) - cast index()
  1481.  * v1.1.2 - 08/20/91 (bcn) - make it do it properly (new invdatecmplink)
  1482.  * v1.1.1 - 08/20/91 (bpk) - made sorting go inverted as we purport it does
  1483.  */
  1484. #include <copyright.h>
  1485.  
  1486. #include <stdio.h>
  1487.  
  1488. #include <pfs.h>
  1489. #include <perrno.h>
  1490. #include <archie.h>
  1491.  
  1492. #include <pmachine.h>
  1493. #ifdef NEED_STRING_H
  1494. # include <string.h>            /* for char *index() */
  1495. #else
  1496. # include <strings.h>            /* for char *index() */
  1497. #endif
  1498.  
  1499. static void translateArchieResponse();
  1500.  
  1501. extern int pwarn;
  1502. extern char p_warn_string[];
  1503.  
  1504. /*
  1505.  * archie_query : Sends a request to _host_, telling it to search for
  1506.  *                _string_ using _query_type_ as the search method.
  1507.  *                No more than _max_hits_ matches are to be returned
  1508.  *                skipping over _offset_ matches.
  1509.  *
  1510.  *          archie_query returns a linked list of virtual links. 
  1511.  *                If _flags_ does not include AQ_NOTRANS, then the Archie
  1512.  *                responses will be translated. If _flags_ does not include 
  1513.  *                AQ_NOSORT, then the list will be sorted using _cmp_proc_ to
  1514.  *                compare pairs of links.  If _cmp_proc_ is NULL or AQ_DEFCMP,
  1515.  *                then the default comparison procedure, defcmplink(), is used
  1516.  *                sorting by host, then filename. If cmp_proc is AQ_INVDATECMP
  1517.  *                then invdatecmplink() is used, sorting inverted by date.
  1518.  *                otherwise a user-defined comparison procedure is called.
  1519.  *
  1520.  *                archie_query returns NULL and sets perrno if the query
  1521.  *                failed. Note that it can return NULL with perrno == PSUCCESS
  1522.  *                if the query didn't fail but there were simply no matches.
  1523.  *
  1524.  *   query_type:  S  Substring search ignoring case   
  1525.  *                C  Substring search with case significant
  1526.  *                R  Regular expression search
  1527.  *                =  Exact String Match
  1528.  *            s,c,e  Tries exact match first and falls back to S, C, or R 
  1529.  *                   if not found.
  1530.  *
  1531.  *     cmp_proc:  AQ_DEFCMP      Sort by host, then filename
  1532.  *                AQ_INVDATECMP  Sort inverted by date
  1533.  *
  1534.  *        flags:  AQ_NOSORT      Don't sort results
  1535.  *                AQ_NOTRANS     Don't translate results
  1536.  */
  1537. VLINK 
  1538. archie_query(host,string,max_hits,offset,query_type,cmp_proc,flags)
  1539.     char    *host,*string;
  1540.     int        max_hits,offset;
  1541.     char    query_type;
  1542.     int        (*cmp_proc)();
  1543.     int        flags;
  1544.     {
  1545.     char qstring[MAX_VPATH];    /* For construting the query  */
  1546.     VLINK    links;        /* Matches returned by server */
  1547.     VDIR_ST    dir_st;         /* Filled in by get_vdir      */
  1548.     VDIR    dir= &dir_st;
  1549.     
  1550.     VLINK    p,q,r,lowest,nextp,pnext,pprev;
  1551.     int    tmp;
  1552.  
  1553.     /* Set the cmp_proc if not given */
  1554.     if (cmp_proc == NULL) cmp_proc = defcmplink;
  1555.  
  1556.     /* Make the query string */
  1557.     sprintf(qstring,"ARCHIE/MATCH(%d,%d,%c)/%s",
  1558.         max_hits,offset,query_type,string);
  1559.  
  1560.     /* Initialize Prospero structures */
  1561.     perrno = PSUCCESS; *p_err_string = '\0';
  1562.     pwarn = PNOWARN; *p_warn_string = '\0';
  1563.     vdir_init(dir);
  1564.     
  1565.     /* Retrieve the list of matches, return error if there was one */
  1566. #if defined(MSDOS)
  1567.     if(tmp = get_vdir(host, qstring, "", dir, (long)GVD_ATTRIB|GVD_NOSORT,
  1568.         NULL, NULL)) {
  1569. #else
  1570.     if(tmp = get_vdir(host,qstring,"",dir,GVD_ATTRIB|GVD_NOSORT,NULL,NULL)) {
  1571. # endif
  1572.         perrno = tmp;
  1573.         return(NULL);
  1574.     }
  1575.  
  1576.     /* Save the links, and clear in dir in case it's used again   */
  1577.     links = dir->links; dir->links = NULL;
  1578.  
  1579.     /* As returned, list is sorted by suffix, and conflicting     */
  1580.     /* suffixes appear on a list of "replicas".  We want to       */
  1581.     /* create a one-dimensional list sorted by host then filename */
  1582.     /* and maybe by some other parameter                          */
  1583.  
  1584.     /* First flatten the doubly-linked list */
  1585.     for (p = links; p != NULL; p = nextp) {
  1586.         nextp = p->next;
  1587.         if (p->replicas != NULL) {
  1588.         p->next = p->replicas;
  1589.         p->next->previous = p;
  1590.         for (r = p->replicas; r->next != NULL; r = r->next)
  1591.             /*EMPTY*/ ;
  1592.         r->next = nextp;
  1593.         nextp->previous = r;
  1594.         p->replicas = NULL;
  1595.         }
  1596.     }
  1597.  
  1598.     /* Translate the filenames unless NOTRANS was given */
  1599.     if (!(flags & AQ_NOTRANS))
  1600.         for (p = links; p != NULL; p = p->next)
  1601.         translateArchieResponse(p);
  1602.  
  1603.     /* If NOSORT given, then just hand it back */
  1604.     if (flags & AQ_NOSORT) {
  1605.         perrno = PSUCCESS;
  1606.         return(links);
  1607.     }
  1608.  
  1609.     /* Otherwise sort it using a selection sort and the given cmp_proc */
  1610.     for (p = links; p != NULL; p = nextp) {
  1611.         nextp = p->next;
  1612.         lowest = p;
  1613.         for (q = p->next; q != NULL; q = q->next)
  1614.         if ((*cmp_proc)(q,lowest) < 0)
  1615.             lowest = q;
  1616.         if (p != lowest) {
  1617.         /* swap the two links */
  1618.         pnext = p->next;
  1619.         pprev = p->previous;
  1620.         if (lowest->next != NULL)
  1621.             lowest->next->previous = p;
  1622.         p->next = lowest->next;
  1623.         if (nextp == lowest) {
  1624.             p->previous = lowest;
  1625.         } else {
  1626.             lowest->previous->next = p;
  1627.             p->previous = lowest->previous;
  1628.         }
  1629.         if (nextp == lowest) {
  1630.             lowest->next = p;
  1631.         } else {
  1632.             pnext->previous = lowest;
  1633.             lowest->next = pnext;
  1634.         }
  1635.         if (pprev != NULL)
  1636.             pprev->next = lowest;
  1637.         lowest->previous = pprev;
  1638.         /* keep the head of the list in the right place */
  1639.         if (links == p)
  1640.             links = lowest;
  1641.         }
  1642.     }
  1643.  
  1644.     /* Return the links */
  1645.     perrno = PSUCCESS;
  1646.     return(links);
  1647.     }
  1648.  
  1649. /*
  1650.  * translateArchieResponse: 
  1651.  *
  1652.  *   If the given link is for an archie-pseudo directory, fix it. 
  1653.  *   This is called unless AQ_NOTRANS was given to archie_query().
  1654.  */
  1655. static void
  1656. translateArchieResponse(l)
  1657.     VLINK l;
  1658.     {
  1659.     char *slash;
  1660.  
  1661.     if (strcmp(l->type,"DIRECTORY") == 0) {
  1662.         if (strncmp(l->filename,"ARCHIE/HOST",11) == 0) {
  1663.         l->type = stcopyr("EXTERNAL(AFTP,DIRECTORY)",l->type);
  1664.         l->host = stcopyr(l->filename+12,l->host);
  1665.         slash = (char *)index(l->host,'/');
  1666.         if (slash) {
  1667.             l->filename = stcopyr(slash,l->filename);
  1668.             *slash++ = '\0';
  1669.         } else
  1670.             l->filename = stcopyr("",l->filename);
  1671.         }
  1672.     }
  1673.     }
  1674.  
  1675. /*
  1676.  * defcmplink: The default link comparison function for sorting. Compares
  1677.  *           links p and q first by host then by filename. Returns < 0 if p
  1678.  *             belongs before q, > 0 if p belongs after q, and == 0 if their
  1679.  *             host and filename fields are identical.
  1680.  */
  1681. int
  1682. defcmplink(p,q)
  1683.     VLINK p,q;
  1684.     {
  1685.     int result;
  1686.  
  1687.     if ((result=strcmp(p->host,q->host)) != 0)
  1688.         return(result);
  1689.     else
  1690.         return(strcmp(p->filename,q->filename));
  1691.     }
  1692.  
  1693. /*
  1694.  * invdatecmplink: An alternative comparison function for sorting that
  1695.  *               compares links p and q first by LAST-MODIFIED date,
  1696.  *                 if they both have that attribute. If both links
  1697.  *                 don't have that attribute or the dates are the
  1698.  *                 same, it then calls defcmplink() and returns its 
  1699.  *           value.
  1700.  */
  1701. int
  1702. invdatecmplink(p,q)
  1703.     VLINK p,q;
  1704.     {
  1705.     PATTRIB pat,qat;
  1706.     char *pdate,*qdate;
  1707.     int result;
  1708.     
  1709.     pdate = qdate = NULL;
  1710.     for (pat = p->lattrib; pat; pat = pat->next)
  1711.         if(strcmp(pat->aname,"LAST-MODIFIED") == 0)
  1712.         pdate = pat->value.ascii;
  1713.     for (qat = q->lattrib; qat; qat = qat->next)
  1714.         if(strcmp(qat->aname,"LAST-MODIFIED") == 0)
  1715.         qdate = qat->value.ascii;
  1716.     if(!pdate && !qdate) return(defcmplink(p,q));
  1717.     if(!pdate) return(1); 
  1718.     if(!qdate) return(-1);
  1719.     if((result=strcmp(qdate,pdate)) == 0) return(defcmplink(p,q));
  1720.     else return(result);
  1721.     }
  1722. $EOD
  1723. $!
  1724. $CREATE [.archie]atalloc.c
  1725. $DECK
  1726. /*
  1727.  * Copyright (c) 1989, 1990 by the University of Washington
  1728.  *
  1729.  * For copying and distribution information, please see the file
  1730.  * <copyright.h>.
  1731.  */
  1732.  
  1733. #include <copyright.h>
  1734. #include <stdio.h>
  1735.  
  1736. #include <pfs.h>
  1737. #include <pmachine.h> /* for correct definition of ZERO */
  1738.  
  1739. static PATTRIB    lfree = NULL;
  1740. int        pattrib_count = 0;
  1741. int        pattrib_max = 0;
  1742.  
  1743. /*
  1744.  * atalloc - allocate and initialize vlink structure
  1745.  *
  1746.  *    ATALLOC returns a pointer to an initialized structure of type
  1747.  *    PATTRIB.  If it is unable to allocate such a structure, it
  1748.  *    returns NULL.
  1749.  */
  1750. PATTRIB
  1751. atalloc()
  1752.     {
  1753.     PATTRIB    at;
  1754.     if(lfree) {
  1755.         at = lfree;
  1756.         lfree = lfree->next;
  1757.     }
  1758.     else {
  1759.         at = (PATTRIB) malloc(sizeof(PATTRIB_ST));
  1760.         if (!at) return(NULL);
  1761.         pattrib_max++;
  1762.     }
  1763.  
  1764.     pattrib_count++;
  1765.  
  1766.     ZERO(at);
  1767.     /* Initialize and fill in default values; all items are
  1768.        0 [or NULL] save precedence */
  1769.     at->precedence = ATR_PREC_OBJECT;
  1770.  
  1771.     return(at);
  1772.     }
  1773.  
  1774. /*
  1775.  * atfree - free a PATTRIB structure
  1776.  *
  1777.  *    ATFREE takes a pointer to a PATTRRIB structure and adds it to
  1778.  *    the free list for later reuse.
  1779.  */
  1780. void
  1781. atfree(at)
  1782.     PATTRIB    at;
  1783.     {
  1784.     if(at->aname) stfree(at->aname);
  1785.  
  1786.     if((strcmp(at->avtype,"ASCII") == 0) && at->value.ascii) 
  1787.         stfree(at->value.ascii);
  1788.     if((strcmp(at->avtype,"LINK") == 0) && at->value.link) 
  1789.         vlfree(at->value.link);
  1790.     
  1791.     if(at->avtype) stfree(at->avtype);
  1792.  
  1793.     at->next = lfree;
  1794.     at->previous = NULL;
  1795.     lfree = at;
  1796.     pattrib_count--;
  1797.     }
  1798.  
  1799. /*
  1800.  * atlfree - free a PATTRIB structure
  1801.  *
  1802.  *    ATLFREE takes a pointer to a PATTRIB structure frees it and any linked
  1803.  *    PATTRIB structures.  It is used to free an entrie list of PATTRIB
  1804.  *    structures.
  1805.  */
  1806. void
  1807. atlfree(at)
  1808.     PATTRIB    at;
  1809.     {
  1810.     PATTRIB    nxt;
  1811.  
  1812.     while(at != NULL) {
  1813.         nxt = at->next;
  1814.         atfree(at);
  1815.         at = nxt;
  1816.     }
  1817.     }
  1818.  
  1819. $EOD
  1820. $!
  1821. $CREATE [.archie]dirsend.c
  1822. $DECK
  1823. /*
  1824.  * Copyright (c) 1989, 1990, 1991 by the University of Washington
  1825.  *
  1826.  * For copying and distribution information, please see the file
  1827.  * <copyright.h>.
  1828.  *
  1829.  * v1.2.8 - 12/17/91 (jwb) - fixed warning message
  1830.  * v1.2.7 - 12/13/91 (bpk) - took out XARCHIE code since we've diverged
  1831.  * v1.2.6 - 12/13/91 (jwb) - UCX stuff
  1832.  * v1.2.5 - 11/21/91 (bkc) - new version for CUTCP, ugly as it is.
  1833.  * v1.2.4 - 11/19/91 (mmt) - added MSDOS & OS2 stuff
  1834.  * v1.2.3 - 11/04/91 (bcn) - removed host comparison and replaced with check
  1835.  *                 for connection id (undoes effect of v1.2.2.).
  1836.  * v1.2.2 - 11/02/91 (gf)  - removed extra inet_ntoa() calls and stuff for
  1837.  *                 multi-interface nets (lmjm@doc.imperial.ac.uk)
  1838.  * v1.2.1 - 10/20/91 (gf)  - asynch implementation
  1839.  * v1.2.0 - 09/17/91 (bpk) - added BULL & USG stuff, thanks to Jim Sillas
  1840.  * v1.1.2 - 08/30/91 (bpk) - added VMS support
  1841.  * v1.1.1 - 08/29/91 (bcn) - changed backoff handling
  1842.  * v1.1.0 - 08/13/91 (gf)  - added XArchie status calls
  1843.  *
  1844.  * gf: 20 Oct 1991:
  1845.  *  Broken into pieces so that under X dirsend() doesn't block in select()
  1846.  *  but rather uses Xt calls to allow continued event processing. If
  1847.  *  XARCHIE is not defined, can still be used since processEvent() will
  1848.  *  use select() in this case.
  1849.  */
  1850.  
  1851. /* If you're going to hack on this, I'd suggest using unifdef with -UCUTCP
  1852.    and possibly -UVMS, for your working copy.  When you've got your changes
  1853.    done, come back and add them into this main file.  It's getting pretty
  1854.    nasty down there.  */
  1855.  
  1856. #include <copyright.h>
  1857. #include <stdio.h>
  1858. #include <errno.h>
  1859.  
  1860. #ifdef VMS
  1861. # ifdef WOLLONGONG
  1862. #  include "twg$tcp:[netdist.include]netdb.h"
  1863. # else /* not Wollongong */
  1864. #  ifdef UCX
  1865. #   include netdb
  1866. #  else /* Multinet */
  1867. #   include "multinet_root:[multinet.include]netdb.h"
  1868. #  endif
  1869. # endif
  1870. # include <vms.h>
  1871. #else /* not VMS */
  1872. # include <sys/types.h> /* this may/will define FD_SET etc */
  1873. # ifdef u3b2
  1874. #  include <sys/inet.h> /* THIS does FD_SET etc on AT&T 3b2s.  */
  1875. # endif /* u3b2 */
  1876. # include <pmachine.h>
  1877. # if defined(NEED_TIME_H) && !defined(AUX)
  1878. #  include <time.h>
  1879. # else
  1880. #  include <sys/time.h>
  1881. # endif
  1882. # ifdef NEED_STRING_H
  1883. #  include <string.h>
  1884. # else
  1885. #  include <strings.h>
  1886. # endif
  1887. # ifdef CUTCP
  1888. #  include <msdos/cutcp.h>
  1889. #  include <msdos/netevent.h>
  1890. #  include <msdos/hostform.h>
  1891. # else /* not CUTCP */
  1892. #  include <netdb.h>
  1893. #  include <sys/socket.h>
  1894. # endif
  1895. # ifdef NEED_SELECT_H
  1896. #  include <sys/select.h>
  1897. # endif /* NEED_SELECT_H */
  1898. # ifndef IN_H
  1899. #  include <netinet/in.h>
  1900. #  define IN_H
  1901. # endif
  1902. # ifndef hpux
  1903. #  include <arpa/inet.h>
  1904. # endif
  1905. #endif /* !VMS */
  1906.  
  1907. /* Interactive UNIX keeps some of the socket definitions in funny places.  */
  1908. #ifdef ISC
  1909. # include <net/errno.h>
  1910. #endif /* ISC */
  1911.  
  1912. #include <pfs.h>
  1913. #include <pprot.h>
  1914. #include <pcompat.h>
  1915. #include <perrno.h>
  1916.  
  1917. /* Gnu C currently fails to pass structures on Sparcs properly.  This directly
  1918.    effects the calling of inet_ntoa().  To get around it, we use this hack;
  1919.    take the address of what's being called to inet_ntoa, so it gets it
  1920.    properly.  This won't be necessary with gcc 2.0.  */
  1921. #if defined(sun) && defined(__GNUC__) && !defined(__GNU_LIBRARY__)
  1922. # define SUN_GNU_FIX &
  1923. #else
  1924. # define SUN_GNU_FIX
  1925. #endif
  1926.  
  1927. static int notprived = 0;
  1928. #ifndef MSDOS
  1929. extern int errno;
  1930. #endif
  1931. extern int perrno;
  1932. extern int rdgram_priority;
  1933. #ifdef DEBUG
  1934. extern int pfs_debug;
  1935. #endif
  1936. extern int pfs_disable_flag;
  1937.  
  1938. char    *nlsindex();
  1939.  
  1940. #define max(X, Y)  ((X) > (Y) ? (X) : (Y))
  1941.  
  1942. static int        dir_udp_port = 0;    /* Remote UDP port number */
  1943.  
  1944. #ifdef CUTCP
  1945. # define    NS_TIMEOUT    15
  1946. #endif
  1947.  
  1948. static unsigned short    next_conn_id = 0;
  1949.  
  1950. static int client_dirsrv_timeout = CLIENT_DIRSRV_TIMEOUT;
  1951. static int client_dirsrv_retry = CLIENT_DIRSRV_RETRY; 
  1952.  
  1953. /* These were parameters to dirsend() */
  1954. static PTEXT pkt;
  1955. static char *hostname;
  1956. static struct sockaddr_in *hostaddr;
  1957.  
  1958. /* These were locals in dirsend(). Note that the initializations here
  1959.  * are really meaningless since we have to redo them for each call to
  1960.  * dirsend() since they were formerly automatically initialized.
  1961.  */
  1962. static PTEXT        first = NULL;    /* First returned packet     */
  1963. static PTEXT        next;        /* The one we are waiting for      */
  1964. static PTEXT        vtmp;           /* For reorganizing linked list  */
  1965. static PTEXT        comp_thru;    /* We have all packets though    */
  1966. static int        lp = -1;    /* Opened UDP port             */
  1967. static int        hdr_len;    /* Header Length                 */
  1968. static int        nd_pkts;    /* Number of packets we want     */
  1969. static int        no_pkts;    /* Number of packets we have     */
  1970. static int        pkt_cid;        /* Packet connection identifier  */
  1971. static unsigned short    this_conn_id;    /* Connection ID we are using    */
  1972. static unsigned short    recvd_thru;    /* Received through              */
  1973. static short        priority;    /* Priority for request          */
  1974. static short        one = 0;    /* Pointer to value 1            */
  1975. static short        zero = 0;    /* Pointer to value 0         */
  1976. static char        *seqtxt;    /* Pointer to text w/ sequence # */
  1977. static struct sockaddr_in  us;        /* Our address                   */
  1978. static struct sockaddr_in  to;        /* Address to send query     */
  1979. static struct sockaddr_in  from;    /* Reply received from         */
  1980. static int        from_sz;    /* Size of from structure     */
  1981. static struct hostent    *host;        /* Host info from gethostbyname  */
  1982. static long        newhostaddr;    /* New host address from *host   */
  1983. static int        req_udp_port=0; /* Requested port (optional)     */
  1984. static char        *openparen;    /* Delimits port in name         */
  1985. static char        hostnoport[500];/* Host name without port        */
  1986. static int        ns;        /* Number of bytes actually sent */
  1987. static int        nr;        /* Number of bytes received      */
  1988. static SELECTARG    readfds;    /* Used for select         */
  1989. static int        tmp;
  1990. static char        *ctlptr;    /* Pointer to control field      */
  1991. static short        stmp;        /* Temp short for conversions    */
  1992. static int        backoff;    /* Server requested backoff      */
  1993. static unsigned char    rdflag11;    /* First byte of flags (bit vect)*/
  1994. static unsigned char    rdflag12;    /* Second byte of flags (int)    */
  1995. static int        scpflag = 0;    /* Set if any sequencd cont pkts */
  1996. static int        ackpend = 0;    /* Acknowledgement pending      */
  1997. static int        gaps = 0;    /* Gaps present in recvd pkts   */
  1998. static struct timeval    timeout;    /* Time to wait for response    */
  1999. static struct timeval    ackwait;    /* Time to wait before acking   */
  2000. static struct timeval    gapwait;    /* Time to wait b4 filling gaps */
  2001. static struct timeval    *selwait;    /* Time to wait for select      */
  2002. static int        retries;    /* was = client_dirsrv_retry    */
  2003. char   to_hostname[512];        /* lmjm: saves inet_ntoa() str  */
  2004.  
  2005. /* These are added so dirsend() "blocks" properly */
  2006. static PTEXT dirsendReturn;
  2007. static int dirsendDone;
  2008.  
  2009. /* And here are the values for dirsendDone */
  2010. #define DSRET_DONE        1
  2011. #define DSRET_SEND_ERROR    -1
  2012. #define DSRET_RECV_ERROR    -2
  2013. #define DSRET_SELECT_ERROR    -3
  2014. #define DSRET_TIMEOUT        -4
  2015. #define DSRET_ABORTED        -5
  2016.  
  2017. /* New procedures to break up dirsend() */
  2018. static int initDirsend();
  2019. static void retryDirsend(), keepWaitingDirsend();
  2020. static void timeoutProc();
  2021. static void readProc();
  2022.  
  2023. /* Wrappers around X calls to allow non-X usage */
  2024. static void processEvent();
  2025.  
  2026. /* Extra stuff for the asynchronous X version of dirsend() */
  2027. typedef char *XtPointer;
  2028. typedef char *XtInputId;
  2029. typedef char *XtIntervalId;
  2030.  
  2031. static XtInputId inputId;
  2032. static XtIntervalId timerId = (XtIntervalId)0;
  2033.  
  2034. /*
  2035.  * dirsend - send packet and receive response
  2036.  *
  2037.  *   DIRSEND takes a pointer to a structure of type PTEXT, a hostname,
  2038.  *   and a pointer to a host address.  It then sends the supplied
  2039.  *   packet off to the directory server on the specified host.  If
  2040.  *   hostaddr points to a valid address, that address is used.  Otherwise,
  2041.  *   the hostname is looked up to obtain the address.  If hostaddr is a
  2042.  *   non-null pointer to a 0 address, then the address will be replaced
  2043.  *   with that found in the hostname lookup.
  2044.  *
  2045.  *   DIRSEND will wait for a response and retry an appropriate
  2046.  *   number of times as defined by timeout and retries (both static
  2047.  *   variables).  It will collect however many packets form the reply, and
  2048.  *   return them in a structure (or structures) of type PTEXT.
  2049.  *
  2050.  *   DIRSEND will free the packet that it is presented as an argument.
  2051.  *   The packet is freed even if dirsend fails.
  2052.  */
  2053. PTEXT
  2054. dirsend(pkt_p,hostname_p,hostaddr_p)
  2055.     PTEXT pkt_p;
  2056.     char *hostname_p;
  2057.     struct sockaddr_in    *hostaddr_p;
  2058. {
  2059.     /* copy parameters to globals since other routines use them */
  2060.     pkt = pkt_p;
  2061.     hostname = hostname_p;
  2062.     hostaddr = hostaddr_p;
  2063.     /* Do the initializations of formerly auto variables */
  2064.     first = NULL;
  2065.     lp = -1;
  2066.     one = 0;
  2067.     zero = 0;
  2068.     req_udp_port=0;
  2069.     scpflag = 0;
  2070.     ackpend = 0;
  2071.     gaps = 0;
  2072.     retries = client_dirsrv_retry;
  2073.  
  2074.     if (initDirsend() < 0)
  2075.     return(NULL);
  2076.  
  2077.     /* set the first timeout */
  2078.     retryDirsend();
  2079.  
  2080.     dirsendReturn = NULL;
  2081.     dirsendDone = 0;
  2082.     /* Until one of the callbacks says to return, keep processing events */
  2083.     while (!dirsendDone)
  2084.     processEvent();
  2085.  
  2086.     /* Return whatever we're supposed to */
  2087.     return(dirsendReturn);
  2088. }
  2089.  
  2090.  
  2091. /*    -    -    -    -    -    -    -    -    */
  2092. /* This function does all the initialization that used to be done at the
  2093.  * start of dirsend(), including opening the socket descriptor "lp". It
  2094.  * returns the descriptor if successful, otherwise -1 to indicate that
  2095.  * dirsend() should return NULL immediately.
  2096.  */
  2097. static int
  2098. initDirsend()
  2099. {
  2100.     if(one == 0) one = htons((short) 1);
  2101.  
  2102.     priority = htons(rdgram_priority);
  2103.  
  2104.     timeout.tv_sec = client_dirsrv_timeout;
  2105.     timeout.tv_usec = 0;
  2106.  
  2107.     ackwait.tv_sec = 0;
  2108.     ackwait.tv_usec = 500000;
  2109.  
  2110.     gapwait.tv_sec = (client_dirsrv_timeout < 5 ? client_dirsrv_timeout : 5);
  2111.     gapwait.tv_usec = 0;
  2112.  
  2113.     comp_thru = NULL;
  2114.     perrno = 0;
  2115.     nd_pkts = 0;
  2116.     no_pkts = 0;
  2117.     pkt_cid = 0;
  2118.  
  2119.     /* Find first connection ID */
  2120.     if(next_conn_id == 0) {
  2121.     srand(getpid()+time(0)); /* XXX: arg ok, but not right type. */
  2122.     next_conn_id = rand();
  2123.     }
  2124.  
  2125.  
  2126.     /* If necessary, find out what udp port to send to */
  2127.     if (dir_udp_port == 0) {
  2128.         register struct servent *sp;
  2129.     tmp = pfs_enable; pfs_enable = PMAP_DISABLE;
  2130. #ifdef USE_ASSIGNED_PORT
  2131.     /* UCX needs 0 & -1 */
  2132.         if ((sp = getservbyname("prospero","udp")) <= 0) {
  2133. #ifdef DEBUG
  2134.         if (pfs_debug)
  2135.         fprintf(stderr, "dirsrv: udp/prospero unknown service - using %d\n", 
  2136.             PROSPERO_PORT);
  2137. #endif
  2138.         dir_udp_port = htons((u_short) PROSPERO_PORT);
  2139.         }
  2140. #else
  2141.     /* UCX needs 0 & -1 */
  2142.         sp = getservbyname("dirsrv","udp");
  2143.     if (sp == (struct servent *)0 || sp == (struct servent *)-1) {
  2144. #ifdef DEBUG
  2145.         if (pfs_debug)
  2146.         fprintf(stderr, "dirsrv: udp/dirsrv unknown service - using %d\n", 
  2147.             DIRSRV_PORT);
  2148. #endif
  2149.         dir_udp_port = htons((u_short) DIRSRV_PORT);
  2150.         }
  2151. #endif
  2152.     else dir_udp_port = sp->s_port;
  2153.     pfs_enable = tmp;
  2154. #ifdef DEBUG
  2155.         if (pfs_debug > 3)
  2156.             fprintf(stderr,"dir_udp_port is %d\n", ntohs(dir_udp_port));
  2157. #endif
  2158.     }
  2159.  
  2160.     /* If we were given the host address, then use it.  Otherwise  */
  2161.     /* lookup the hostname.  If we were passed a host address of   */
  2162.     /* 0, we must lookup the host name, then replace the old value */
  2163.     if(!hostaddr || (hostaddr->sin_addr.s_addr == 0)) {
  2164.     /* I we have a null host name, return an error */
  2165.     if((hostname == NULL) || (*hostname == '\0')) {
  2166. #ifdef DEBUG
  2167.             if (pfs_debug)
  2168.                 fprintf(stderr, "dirsrv: Null hostname specified\n");
  2169. #endif
  2170.         perrno = DIRSEND_BAD_HOSTNAME;
  2171.         ptlfree(pkt);
  2172.             /* return(NULL); */
  2173.         return(-1);
  2174.     }
  2175.     /* If a port is included, save it away */
  2176.     if(openparen = index(hostname,'(')) {
  2177.         sscanf(openparen+1,"%d",&req_udp_port);
  2178.         strncpy(hostnoport,hostname,400);
  2179.         if((openparen - hostname) < 400) {
  2180.         *(hostnoport + (openparen - hostname)) = '\0';
  2181.         hostname = hostnoport;
  2182.         }
  2183.     }
  2184.     tmp = pfs_enable; pfs_enable = PMAP_DISABLE;
  2185.     if((host = gethostbyname(hostname)) == NULL) {
  2186.         pfs_enable = tmp;
  2187.         /* Check if a numeric address */
  2188.         newhostaddr = inet_addr(hostname);
  2189.         if(newhostaddr == -1) {
  2190. #ifdef DEBUG
  2191.         if (pfs_debug)
  2192.           fprintf(stderr, "dirsrv: Can't resolve host %s\n",hostname);
  2193. #endif
  2194.         perrno = DIRSEND_BAD_HOSTNAME;
  2195.         ptlfree(pkt);
  2196.         /* return(NULL); */
  2197.         return(-1);
  2198.         }
  2199.         bzero((char *)&to, S_AD_SZ);
  2200.         to.sin_family = AF_INET;
  2201.         bcopy((char *) &newhostaddr, (char *)&to.sin_addr, 4);
  2202.         if(hostaddr) bcopy(&to,hostaddr, S_AD_SZ);
  2203.     }
  2204.     else {
  2205.         pfs_enable = tmp;
  2206.         bzero((char *)&to, S_AD_SZ);
  2207.         to.sin_family = host->h_addrtype;
  2208. #ifdef CUTCP
  2209.         bcopy((char *) &host->h_addr, (char *)&to.sin_addr, host->h_length);
  2210. #else
  2211.         bcopy(host->h_addr, (char *)&to.sin_addr, host->h_length);
  2212. #endif
  2213.         if(hostaddr) bcopy(&to,hostaddr, S_AD_SZ);
  2214.     }
  2215.     }
  2216.     else bcopy(hostaddr,&to, S_AD_SZ);
  2217.     /* lmjm: Save away the hostname */
  2218.     strncpy(to_hostname,
  2219.         inet_ntoa(SUN_GNU_FIX *(struct in_addr *)&to.sin_addr),
  2220.         sizeof(to_hostname)-1);
  2221.  
  2222.     if(req_udp_port) to.sin_port = htons(req_udp_port);
  2223.     else to.sin_port = dir_udp_port;
  2224.  
  2225.     /* If a port was specified in hostaddr, use it, otherwise fill it in */
  2226.     if(hostaddr) {
  2227.     if(hostaddr->sin_port) to.sin_port = hostaddr->sin_port;
  2228.     else hostaddr->sin_port = to.sin_port;
  2229.     }
  2230.  
  2231. #ifndef CUTCP
  2232.     /* Must open a new port each time. we do not want to see old */
  2233.     /* responses to messages we are done with                    */
  2234.     if ((lp = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
  2235. #ifdef DEBUG
  2236.         if (pfs_debug)
  2237.             fprintf(stderr,"dirsrv: Can't open socket\n");
  2238. #endif
  2239.     perrno = DIRSEND_UDP_CANT;
  2240.     ptlfree(pkt);
  2241.         /* return(NULL); */
  2242.     return(-1);
  2243.     }
  2244. #endif /* not CUTCP */
  2245.  
  2246.     /* Try to bind it to a privileged port - loop through candidate */
  2247.     /* ports trying to bind.  If failed, that's OK, we will let the */
  2248.     /* system assign a non-privileged port later                    */
  2249. #ifndef CUTCP
  2250.     if(!notprived) {
  2251.     for(tmp = PROS_FIRST_PRIVP; tmp < PROS_FIRST_PRIVP+PROS_NUM_PRIVP; 
  2252.         tmp++) {
  2253. #endif
  2254.         bzero((char *)&us, sizeof(us));
  2255.         us.sin_family = AF_INET;
  2256. #ifndef CUTCP
  2257.         us.sin_port = htons((u_short) tmp);
  2258.         if (bind(lp, (struct sockaddr *)&us, sizeof(us))) {
  2259.         if(errno != EADDRINUSE) {
  2260.             notprived++;
  2261.             break;
  2262.         }
  2263.         }
  2264.         else break;
  2265.     }
  2266.     }
  2267. #else
  2268.     us.sin_port = htons(PROS_FIRST_PRIVP);
  2269.     netulisten(PROS_FIRST_PRIVP);
  2270. #endif
  2271.  
  2272. #ifndef USE_V3_PROT
  2273.     /* Add header */
  2274.     if(rdgram_priority) {
  2275.     pkt->start -= 15;
  2276.     pkt->length += 15;
  2277.     *(pkt->start) = (char) 15;
  2278.     bzero(pkt->start+9,4);
  2279.     *(pkt->start+11) = 0x02;
  2280.     bcopy(&priority,pkt->start+13,2);
  2281.     }
  2282.     else {
  2283.     pkt->start -= 9;
  2284.     pkt->length += 9;
  2285.     *(pkt->start) = (char) 9;
  2286.     }
  2287.     this_conn_id = htons(next_conn_id++);
  2288.     if(next_conn_id == 0) next_conn_id++;
  2289.     bcopy(&this_conn_id,pkt->start+1,2);
  2290.     bcopy(&one,pkt->start+3,2);
  2291.     bcopy(&one,pkt->start+5,2);
  2292.     bzero(pkt->start+7,2);
  2293. #endif
  2294.  
  2295. #ifdef DEBUG
  2296.     if (pfs_debug > 2) {
  2297. #ifndef USE_V3_PROT
  2298.         if (to.sin_family == AF_INET) {
  2299.         if(req_udp_port) 
  2300.         fprintf(stderr,"Sending message to %s+%d(%d)...",
  2301.             to_hostname, req_udp_port, ntohs(this_conn_id));
  2302.         else fprintf(stderr,"Sending message to %s(%d)...",
  2303.              to_hostname, ntohs(this_conn_id));
  2304.     }
  2305. #else
  2306.         if (to.sin_family == AF_INET) 
  2307.         fprintf(stderr,"Sending message to %s...", to_hostname);
  2308. #endif /* USE_V3_PROT */
  2309.         else
  2310.             fprintf(stderr,"Sending message...");
  2311.         (void) fflush(stderr);
  2312.     }
  2313. #endif /* DEBUG */
  2314.  
  2315.     first = ptalloc();
  2316.     next = first;
  2317.  
  2318. #ifndef CUTCP
  2319.     return(lp);
  2320. #else
  2321.     return(1);
  2322. #endif /* CUTCP */
  2323. }
  2324.  
  2325. /*    -    -    -    -    -    -    -    -    */
  2326. /*
  2327.  * This used to be a label to goto to retry the last packet. Now we resend
  2328.  * the packet and call keepWaitingDirsend() to wait for a reply. (We
  2329.  * call keepWaitingDirsend() because formerly the code dropped through
  2330.  * the keep_waiting label.)
  2331.  */
  2332. static void
  2333. retryDirsend()
  2334. {
  2335. #ifdef CUTCP
  2336.     int lretry = 3;
  2337. #endif
  2338.     gaps = ackpend = 0;
  2339.  
  2340. #ifndef CUTCP
  2341.     ns = sendto(lp,(char *)(pkt->start), pkt->length, 0, (struct sockaddr *)&to, S_AD_SZ);
  2342. #else
  2343.     while(--lretry) {
  2344.         ns = netusend(&to.sin_addr,ntohs(to.sin_port),ntohs(us.sin_port),
  2345.               (char *) pkt->start, pkt->length);
  2346.         if(!ns)
  2347.         break;
  2348.         Stask();
  2349.         Stask();
  2350.         Stask();
  2351.     }
  2352. #endif /* CUTCP */
  2353.  
  2354. #ifndef CUTCP
  2355.     if(ns != pkt->length) {
  2356. #else
  2357.     if(ns != 0) {
  2358. #endif
  2359. #ifdef DEBUG
  2360.     if (pfs_debug) {
  2361.     fprintf(stderr,"\nsent only %d/%d: ",ns, pkt->length);
  2362.         perror("");
  2363.     }
  2364. #endif
  2365.     close(lp);
  2366.     perrno = DIRSEND_NOT_ALL_SENT;
  2367.     ptlfree(first);
  2368.     ptlfree(pkt);
  2369.     /* return(NULL); */
  2370.     dirsendReturn = NULL;
  2371.     dirsendDone = DSRET_SEND_ERROR;
  2372.     }
  2373. #ifdef DEBUG
  2374.     if (pfs_debug > 2) fprintf(stderr,"Sent.\n");
  2375. #endif
  2376.     keepWaitingDirsend();
  2377. }
  2378.  
  2379. /*    -    -    -    -    -    -    -    -    */
  2380. /*
  2381.  * This used to be a label to goto to set the appropriate timeout value
  2382.  * and blocked in select(). Now we set selwait and the SELECTARGs to the
  2383.  * appropriate values, and in X register a new timeout, then return to
  2384.  * allow event processing.
  2385.  */
  2386. static void
  2387. keepWaitingDirsend()
  2388. {
  2389.     /* We come back to this point (by a goto) if the packet */
  2390.     /* received is only part of the response, or if the     */
  2391.     /* response came from the wrong host            */
  2392.  
  2393. #ifdef DEBUG
  2394.     if (pfs_debug > 2) fprintf(stderr,"Waiting for reply...");
  2395. #endif
  2396.  
  2397. #ifndef CUTCP
  2398.     FD_ZERO(&readfds);
  2399.     FD_SET(lp, &readfds);
  2400. #endif
  2401.  
  2402.     if(ackpend) selwait = &ackwait;
  2403.     else if(gaps) selwait = &gapwait;
  2404.     else selwait = &timeout;
  2405. }
  2406.  
  2407. /*    -    -    -    -    -    -    -    -    */
  2408. /*
  2409.  * This routine is called when a timeout occurs. It includes the code that
  2410.  * was formerly used when select() returned 0 (indicating a timeout).
  2411.  */
  2412. /*ARGSUSED*/
  2413. static void
  2414. timeoutProc(client_data,id)
  2415. XtPointer client_data;
  2416. XtIntervalId *id;
  2417. {
  2418.     if (gaps || ackpend) { /* Send acknowledgment */
  2419.     /* Acks are piggybacked on retries - If we have received */
  2420.     /* an ack from the server, then the packet sent is only  */
  2421.     /* an ack and the rest of the message will be empty      */
  2422. #ifdef DEBUG
  2423.     if (pfs_debug > 2) {
  2424.             fprintf(stderr,"Acknowledging (%s).\n",
  2425.             (ackpend ? "requested" : "gaps"));
  2426.     }    
  2427. #endif
  2428.     retryDirsend();
  2429.     return;
  2430.     }
  2431.  
  2432.     if (retries-- > 0) {
  2433.     timeout.tv_sec = CLIENT_DIRSRV_BACKOFF(timeout.tv_sec);
  2434. #ifdef DEBUG
  2435.     if (pfs_debug > 2) {
  2436.             fprintf(stderr,"Timed out.  Setting timeout to %d seconds.\n",
  2437.             timeout.tv_sec);
  2438.     }
  2439. #endif
  2440.     retryDirsend();
  2441.     return;
  2442.     }
  2443.  
  2444. #ifdef DEBUG
  2445.     if (pfs_debug) {
  2446.     fprintf(stderr, "select failed(timeoutProc): readfds=%x ",
  2447.         readfds);
  2448.     perror("");
  2449.     }
  2450. #endif
  2451. #ifndef CUTCP
  2452.     close(lp);
  2453. #endif
  2454.     perrno = DIRSEND_SELECT_FAILED;
  2455.     ptlfree(first);
  2456.     ptlfree(pkt);
  2457.     /* return(NULL); */
  2458.     dirsendReturn = NULL;
  2459.     dirsendDone = DSRET_TIMEOUT;
  2460. }
  2461.  
  2462. /*    -    -    -    -    -    -    -    -    */
  2463. /*
  2464.  * This function is called whenever there's something to read on the
  2465.  * connection. It includes the code that was run when select() returned
  2466.  * greater than 0 (indicating read ready).
  2467.  */
  2468. /*ARGSUSED*/
  2469. static void
  2470. readProc(client_data,source,id)
  2471. XtPointer client_data;
  2472. int *source;
  2473. XtInputId *id;
  2474. {
  2475. #ifdef CUTCP
  2476.     int lretry = 3;
  2477. #endif
  2478.  
  2479.     from_sz = sizeof(from);
  2480.     next->start = next->dat;
  2481.  
  2482. #ifndef CUTCP
  2483.     if ((nr = recvfrom(lp, next->start, sizeof(next->dat), 0, (struct sockaddr *)&from, &from_sz)) < 0) {
  2484. #else
  2485.     nr = neturead(next->start);
  2486.     if (nr < 1) {
  2487. #endif
  2488. #ifdef DEBUG
  2489.         if (pfs_debug) perror("recvfrom");
  2490. #endif
  2491. #ifndef CUTCP
  2492.     close(lp);
  2493. #endif
  2494.     perrno = DIRSEND_BAD_RECV;
  2495.     ptlfree(first);
  2496.     ptlfree(pkt);
  2497.     /* return(NULL) */
  2498.     dirsendReturn = NULL;
  2499.     dirsendDone = DSRET_RECV_ERROR;
  2500.         return;
  2501.     }
  2502.  
  2503.     next->length = nr;
  2504.     next->start[next->length] = 0;
  2505.  
  2506. #ifdef DEBUG
  2507.     if (pfs_debug > 2)
  2508.         fprintf(stderr,"Received packet from %s\n",
  2509.         inet_ntoa(SUN_GNU_FIX *(struct in_addr *)&from.sin_addr));
  2510. #endif
  2511.  
  2512.  
  2513.     /* For the current format, if the first byte is less than             */
  2514.     /* 20, then the first two bits are a version number and the next six  */
  2515.     /* are the header length (including the first byte).                  */
  2516.     if((hdr_len = (unsigned char) *(next->start)) < 20) {
  2517.     ctlptr = next->start + 1;
  2518.     next->seq = 0;
  2519.     if(hdr_len >= 3) {     /* Connection ID */
  2520.         bcopy(ctlptr,&stmp,2);
  2521.         if(stmp) pkt_cid = ntohs(stmp);
  2522.         ctlptr += 2;
  2523.     }
  2524.     if(pkt_cid && this_conn_id && (pkt_cid != this_conn_id)) {
  2525.         /* The packet is not for us */
  2526.         /* goto keep_waiting; */
  2527.         keepWaitingDirsend();
  2528.         return;
  2529.     }
  2530.     if(hdr_len >= 5) {    /* Packet number */
  2531.         bcopy(ctlptr,&stmp,2);
  2532.         next->seq = ntohs(stmp);
  2533.         ctlptr += 2;
  2534.     }
  2535.     else { /* No packet number specified, so this is the only one */
  2536.         next->seq = 1;
  2537.         nd_pkts = 1;
  2538.     }
  2539.     if(hdr_len >= 7) {        /* Total number of packets */
  2540.         bcopy(ctlptr,&stmp,2);  /* 0 means don't know      */
  2541.         if(stmp) nd_pkts = ntohs(stmp);
  2542.         ctlptr += 2;
  2543.     }
  2544.     if(hdr_len >= 9) {    /* Receievd through */
  2545.         bcopy(ctlptr,&stmp,2);  /* 1 means received request */
  2546. #ifndef USE_V3_PROT
  2547.         if((stmp) && (ntohs(stmp) == 1)) {
  2548.         /* Future retries will be acks only */
  2549.         pkt->length = 9;
  2550.         bcopy(&zero,pkt->start+3,2);
  2551. #ifdef DEBUG
  2552.         if(pfs_debug > 2) 
  2553.             fprintf(stderr,"Server acked request - retries will be acks only\n");
  2554. #endif
  2555.         }
  2556. #endif
  2557.         ctlptr += 2;
  2558.     }
  2559.     if(hdr_len >= 11) {    /* Backoff */
  2560.         bcopy(ctlptr,&stmp,2);
  2561.         if(stmp) {
  2562.         backoff = ntohs(stmp);
  2563. #ifdef DEBUG
  2564.         if(pfs_debug > 2) 
  2565.             fprintf(stderr,"Backing off to %d seconds\n", backoff);
  2566. #endif
  2567.         timeout.tv_sec = backoff;
  2568.         if ((backoff > 60) && (first == next) && (no_pkts == 0)) {
  2569.             /* Probably a long queue on the server - don't give up */
  2570.             retries = client_dirsrv_retry;
  2571.         }
  2572.         }
  2573.         ctlptr += 2;
  2574.     }
  2575.     if(hdr_len >= 12) {    /* Flags (1st byte) */
  2576.         bcopy(ctlptr,&rdflag11,1);
  2577.         if(rdflag11 & 0x80) {
  2578. #ifdef DEBUG
  2579.         if(pfs_debug > 2) 
  2580.             fprintf(stderr,"Ack requested\n");
  2581. #endif
  2582.         ackpend++;
  2583.         }
  2584.         if(rdflag11 & 0x40) {
  2585. #ifdef DEBUG
  2586.         if(pfs_debug > 2) 
  2587.             fprintf(stderr,"Sequenced control packet\n");
  2588. #endif
  2589.         next->length = -1;
  2590.         scpflag++;
  2591.         }
  2592.         ctlptr += 1;
  2593.     }
  2594.     if(hdr_len >= 13) {    /* Flags (2nd byte) */
  2595.         /* Reserved for future use */
  2596.         bcopy(ctlptr,&rdflag12,1);
  2597.         ctlptr += 1;
  2598.     }
  2599.     if(next->seq == 0) {
  2600.         /* goto keep_waiting; */
  2601.         keepWaitingDirsend();
  2602.         return;
  2603.     }
  2604.     if(next->length >= 0) next->length -= hdr_len;
  2605.     next->start += hdr_len;
  2606.     goto done_old;
  2607.     }
  2608.  
  2609.     pkt_cid = 0;
  2610.  
  2611.     /* if intermediate format (between old and new), then process */
  2612.     /* and go to done_old                                         */
  2613.     ctlptr = next->start + max(0,next->length-20);
  2614.     while(*ctlptr) ctlptr++;
  2615.     /* Control fields start after the terminating null */
  2616.     ctlptr++;
  2617.     /* Until old version are gone, must be 4 extra bytes minimum */
  2618.     /* When no version 3 servers, can remove the -4              */
  2619.     if(ctlptr < (next->start + next->length - 4)) {
  2620.     /* Connection ID */
  2621.     bcopy(ctlptr,&stmp,2);
  2622.     if(stmp) pkt_cid = ntohs(stmp);
  2623.     ctlptr += 2;
  2624.     if(pkt_cid && this_conn_id && (pkt_cid != this_conn_id)) {
  2625.         /* The packet is not for us */
  2626.         /* goto keep_waiting; */
  2627.         keepWaitingDirsend();
  2628.         return;
  2629.     }
  2630.     /* Packet number */
  2631.     if(ctlptr < (next->start + next->length)) {
  2632.         bcopy(ctlptr,&stmp,2);
  2633.         next->seq = ntohs(stmp);
  2634.         ctlptr += 2;
  2635.     }
  2636.     /* Total number of packets */
  2637.     if(ctlptr < (next->start + next->length)) {
  2638.         bcopy(ctlptr,&stmp,2);
  2639.         if(stmp) nd_pkts = ntohs(stmp);
  2640.         ctlptr += 2;
  2641.     }
  2642.     /* Receievd through */
  2643.     if(ctlptr < (next->start + next->length)) {
  2644.         /* Not supported by clients */
  2645.         ctlptr += 2;
  2646.     }
  2647.     /* Backoff */
  2648.     if(ctlptr < (next->start + next->length)) {
  2649.         bcopy(ctlptr,&stmp,2);
  2650.         backoff = ntohs(stmp);
  2651. #ifdef DEBUG
  2652.         if(pfs_debug > 2) 
  2653.         fprintf(stderr,"Backing off to %d seconds\n", backoff);
  2654. #endif
  2655.         if(backoff) timeout.tv_sec = backoff;
  2656.         ctlptr += 2;
  2657.     }
  2658.     if(next->seq == 0) {
  2659.         /* goto keep_waiting; */
  2660.         keepWaitingDirsend();
  2661.         return;
  2662.     }
  2663.     goto done_old;
  2664.  
  2665.     }
  2666.  
  2667.     /* Notes that we have to start searching 11 bytes before the    */
  2668.     /* expected start of the MULTI-PACKET line because the message  */
  2669.     /* might include up to 10 bytes of data after the trailing null */
  2670.     /* The order of those bytes is two bytes each for Connection ID */
  2671.     /* Packet-no, of, Received-through, Backoff                     */
  2672.     seqtxt = nlsindex(next->start + max(0,next->length - 40),"MULTI-PACKET"); 
  2673.     if(seqtxt) seqtxt+= 13;
  2674.  
  2675.     if((nd_pkts == 0) && (no_pkts == 0) && (seqtxt == NULL)) goto all_done;
  2676.  
  2677.     tmp = sscanf(seqtxt,"%d OF %d", &(next->seq), &nd_pkts);
  2678. #ifdef DEBUG    
  2679.     if (pfs_debug && (tmp == 0)) 
  2680.     fprintf(stderr,"Cant read packet sequence number: %s", seqtxt);    
  2681. #endif
  2682.  done_old:
  2683. #ifdef DEBUG
  2684.     if(pfs_debug > 2) fprintf(stderr,"Packet %d of %d\n",next->seq,nd_pkts);
  2685. #endif
  2686.     if ((first == next) && (no_pkts == 0)) {
  2687.     if(first->seq == 1) {
  2688.         comp_thru = first;
  2689.         /* If only one packet, then return it */
  2690.         if(nd_pkts == 1) goto all_done;
  2691.     }
  2692.     else gaps++;
  2693.     no_pkts = 1;
  2694.     next = ptalloc();
  2695.     /* goto keep_waiting; */
  2696.     keepWaitingDirsend();
  2697.     return;
  2698.     }
  2699.     
  2700.     if(comp_thru && (next->seq <= comp_thru->seq))
  2701.     ptfree(next);
  2702.     else if (next->seq < first->seq) {
  2703.     vtmp = first;
  2704.     first = next;
  2705.     first->next = vtmp;
  2706.     first->previous = NULL;
  2707.     vtmp->previous = first;
  2708.     if(first->seq == 1) comp_thru = first;
  2709.     no_pkts++;
  2710.     }
  2711.     else {
  2712.     vtmp = (comp_thru ? comp_thru : first);
  2713.     while (vtmp->seq < next->seq) {
  2714.         if(vtmp->next == NULL) {
  2715.         vtmp->next = next;
  2716.         next->previous = vtmp;
  2717.         next->next = NULL;
  2718.         no_pkts++;
  2719.         goto ins_done;
  2720.         }
  2721.         vtmp = vtmp->next;
  2722.     }
  2723.     if(vtmp->seq == next->seq)
  2724.         ptfree(next);
  2725.     else {
  2726.         vtmp->previous->next = next;
  2727.         next->previous = vtmp->previous;
  2728.         next->next = vtmp;
  2729.         vtmp->previous = next;
  2730.         no_pkts++;
  2731.     }
  2732.     }   
  2733.  
  2734. ins_done:
  2735.     
  2736.     while(comp_thru && comp_thru->next && 
  2737.       (comp_thru->next->seq == (comp_thru->seq + 1))) {
  2738.     comp_thru = comp_thru->next;
  2739. #ifndef USE_V3_PROT
  2740.     recvd_thru = htons(comp_thru->seq);
  2741.     bcopy(&recvd_thru,pkt->start+7,2); /* Let server know we got it */
  2742. #endif
  2743.     /* We've made progress, so reset retry count */
  2744.     retries = client_dirsrv_retry;
  2745.     /* Also, next retry will be only an acknowledgement */
  2746.     /* but for now, we can't fill in the ack field      */
  2747. #ifdef DEBUG
  2748.     if(pfs_debug > 2) 
  2749.         fprintf(stderr,"Packets now received through %d\n",comp_thru->seq);
  2750. #endif
  2751.     }
  2752.  
  2753.     /* See if there are any gaps */
  2754.     if(!comp_thru || comp_thru->next) gaps++;
  2755.     else gaps = 0;
  2756.  
  2757.     if ((nd_pkts == 0) || (no_pkts < nd_pkts)) {
  2758.     next = ptalloc();
  2759.     /* goto keep_waiting; */
  2760.     keepWaitingDirsend();
  2761.     return;
  2762.     }
  2763.  
  2764.  all_done:
  2765.     if(ackpend) { /* Send acknowledgement if requested */
  2766. #ifdef DEBUG
  2767.     if (pfs_debug > 2) {
  2768.         if (to.sin_family == AF_INET)
  2769.         fprintf(stderr,"Acknowledging final packet to %s(%d)\n",
  2770.             to_hostname, ntohs(this_conn_id));
  2771.             else
  2772.                 fprintf(stderr,"Acknowledging final packet\n");
  2773.         (void) fflush(stderr);
  2774.     }
  2775. #endif
  2776. #ifndef CUTCP
  2777.     ns = sendto(lp,(char *)(pkt->start), pkt->length, 0, (struct sockaddr *)&to, S_AD_SZ);
  2778. #else
  2779.     while(--lretry) {
  2780.         ns = netusend(&to.sin_addr, ntohs(to.sin_port), ntohs(us.sin_port),(char *) pkt->start, pkt->length);
  2781.         if(!ns)
  2782.             break;
  2783.         Stask();
  2784.         Stask();
  2785.     }
  2786. #endif
  2787.  
  2788. #ifndef CUTCP
  2789.     if(ns != pkt->length) {
  2790. #else
  2791.     if(ns != 0) {
  2792. #endif
  2793.  
  2794. #ifdef DEBUG
  2795.         if (pfs_debug) {
  2796.         fprintf(stderr,"\nsent only %d/%d: ",ns, pkt->length);
  2797.         perror("");
  2798.         }
  2799. #endif
  2800.     }
  2801.  
  2802.     }
  2803. #ifndef CUTCP
  2804.     close(lp);
  2805. #endif
  2806.     ptlfree(pkt);
  2807.  
  2808.     /* Get rid of any sequenced control packets */
  2809.     if(scpflag) {
  2810.     while(first && (first->length < 0)) {
  2811.         vtmp = first;
  2812.         first = first->next;
  2813.         if(first) first->previous = NULL;
  2814.         ptfree(vtmp);
  2815.     }
  2816.     vtmp = first;
  2817.     while(vtmp && vtmp->next) {
  2818.         if(vtmp->next->length < 0) {
  2819.         if(vtmp->next->next) {
  2820.             vtmp->next = vtmp->next->next;
  2821.             ptfree(vtmp->next->previous);
  2822.             vtmp->next->previous = vtmp;
  2823.         }
  2824.         else {
  2825.             ptfree(vtmp->next);
  2826.             vtmp->next = NULL;
  2827.         }
  2828.         }
  2829.         vtmp = vtmp->next;
  2830.     }
  2831.     }
  2832.  
  2833.     /* return(first); */
  2834.     dirsendReturn = first;
  2835.     dirsendDone = DSRET_DONE;
  2836.  
  2837. }
  2838.  
  2839. static void
  2840. processEvent()
  2841. {
  2842. #ifdef CUTCP
  2843.     unsigned long now;
  2844. #endif
  2845.     /* select - either recv is ready, or timeout */
  2846.     /* see if timeout or error or wrong descriptor */
  2847. #ifndef CUTCP
  2848.     tmp = select(lp + 1, &readfds, (SELECTARG *)0, (SELECTARG *)0, selwait);
  2849.     if (tmp == 0) {
  2850.     timeoutProc(NULL,&timerId);
  2851.     } else if ((tmp < 0) || !FD_ISSET(lp,&readfds)) {
  2852. #ifdef DEBUG
  2853.     if (pfs_debug) {
  2854.         fprintf(stderr, "select failed(processEvent): readfds=%x ",
  2855.             readfds);
  2856.         perror("");
  2857.     }
  2858. #endif
  2859.     close(lp);
  2860. #else /* CUTCP's flood. */
  2861.     /* while not timeout in selwait loop, stask looking for uevents */
  2862.     now = time(NULL) + selwait->tv_sec;
  2863. #ifdef    DEBUG
  2864.      if(pfs_debug) {
  2865.         fprintf(stderr,"Waiting %d seconds\n",selwait->tv_sec);
  2866.     }
  2867.  
  2868. #endif
  2869.     while(now > time(NULL)) {
  2870.         int    i, cl, dat;
  2871.  
  2872.         Stask();
  2873.         if (0 < (i = Sgetevent(USERCLASS, &cl, &dat))) {
  2874.             /* got a user class event */
  2875.             if(cl == USERCLASS &&
  2876.                 i == UDPDATA) {
  2877.                     readProc(NULL,&lp,&inputId);
  2878.                     return;
  2879.             }
  2880.         }
  2881.         if(kbhit()) {
  2882.             int c = getch();
  2883.             if(c == 27 || c == 3)
  2884.                 break;
  2885.             fprintf(stderr,"Press <ESCAPE> to abort\n");
  2886.         }
  2887.     }
  2888.     if(now <= time(NULL)) {    /* timeout */
  2889.         timeoutProc(NULL,&timerId);
  2890.          return;
  2891.     }
  2892.  
  2893. #endif /* CUTCP */
  2894.     perrno = DIRSEND_SELECT_FAILED;
  2895.     ptlfree(first);
  2896.     ptlfree(pkt);
  2897.     /* return(NULL); */
  2898.     dirsendReturn = NULL;
  2899.     dirsendDone = DSRET_SELECT_ERROR;
  2900. #ifndef CUTCP
  2901.     } else {
  2902.     readProc(NULL,&lp,&inputId);
  2903.     }
  2904. #endif /* CUTCP */
  2905. }
  2906.  
  2907. void
  2908. abortDirsend()
  2909. {
  2910.     if (!dirsendDone) {
  2911. #ifndef CUTCP
  2912.     close(lp);
  2913. #endif
  2914.     ptlfree(first);
  2915.     ptlfree(pkt);
  2916.     dirsendReturn = NULL;
  2917.     dirsendDone = DSRET_ABORTED;
  2918.     }
  2919.     return;
  2920. }
  2921. $EOD
  2922. $!
  2923. $CREATE [.archie]get_pauth.c
  2924. $DECK
  2925. /*
  2926.  * Copyright (c) 1989, 1990 by the University of Washington
  2927.  *
  2928.  * For copying and distribution information, please see the file
  2929.  * <copyright.h>.
  2930.  *
  2931.  * v1.2.2 - 11/19/91 (mmt) - added MSDOS & OS2 stuff
  2932.  * v1.2.1 - 09/17/91 (bpk) - added BULL & USG stuff, thanks to Jim Sillas
  2933.  * v1.2.0 - 09/17/91 (bpk) - fixed it up (thanks to synful)
  2934.  * v1.1.1 - 08/30/91 (bpk) - added VMS support
  2935.  */
  2936.  
  2937. #include <copyright.h>
  2938. #include <stdio.h>
  2939. #ifndef VMS
  2940. # include <sys/types.h> /* this may/will define FD_SET etc */
  2941. # include <pmachine.h>
  2942. #endif
  2943.  
  2944. #ifdef NEED_STRING_H
  2945. # include <string.h>
  2946. #else
  2947. # include <strings.h>
  2948. #endif
  2949.  
  2950. #ifndef VMS
  2951. # if defined(MSDOS) && !defined(OS2)
  2952. #  ifndef CUTCP
  2953. #   include <rwconf.h>
  2954. #  endif
  2955. # else
  2956. #  include <pwd.h>
  2957. # endif
  2958. #else
  2959. # include <jpidef.h>
  2960. # include <vms.h>
  2961. #endif
  2962.  
  2963. #include <pcompat.h>
  2964. #include <pauthent.h>
  2965.  
  2966. PAUTH
  2967. get_pauth(type)
  2968.     int        type;
  2969.     {
  2970.     static PAUTH_ST   no_auth_st;
  2971.     static PAUTH          no_auth = NULL;
  2972. #if !defined(VMS) && !defined(MSDOS) || defined(OS2)
  2973.     struct passwd *whoiampw;
  2974. #else
  2975.     char username[13];
  2976.     unsigned short usernamelen;
  2977.     struct {
  2978.         unsigned short buflen;
  2979.         unsigned short itmcod;
  2980.         char *bufadr;
  2981.         unsigned short *retlenadr;
  2982.         unsigned long null;
  2983.     } jpi_itemlist;
  2984. #endif
  2985.  
  2986.     if(no_auth == NULL) {
  2987.         no_auth = &no_auth_st;
  2988.         strcpy(no_auth->auth_type,"UNAUTHENTICATED");
  2989.  
  2990.         /* find out who we are */
  2991. #ifndef VMS
  2992. #if defined(MSDOS) && !defined(OS2)
  2993. #ifndef CUTCP
  2994.         if (!getconf("general", "user", no_auth->authenticator, 250)
  2995.         || (strlen (no_auth->authenticator) == 0))
  2996. #endif
  2997.           strcpy(no_auth->authenticator,"nobody");
  2998. #else /* not MSDOS */
  2999.         DISABLE_PFS(whoiampw = getpwuid(getuid()));
  3000.         if (whoiampw == 0) strcpy(no_auth->authenticator,"nobody");
  3001.         else strcpy(no_auth->authenticator, whoiampw->pw_name);
  3002. #endif /* not MSDOS */
  3003. #else
  3004.         jpi_itemlist.buflen = sizeof(username);
  3005.         jpi_itemlist.itmcod = JPI$_USERNAME;
  3006.         jpi_itemlist.bufadr = &username;
  3007.         jpi_itemlist.retlenadr = &usernamelen;
  3008.         jpi_itemlist.null = 0;
  3009.         if (SYS$GETJPI(0, 0, 0, &jpi_itemlist, 0, 0, 0) & 0x1)
  3010.         {
  3011.         username[usernamelen] = 0;
  3012.         strcpy(no_auth->authenticator, username);
  3013.         } else
  3014.         strcpy(no_auth->authenticator, "nobody");
  3015. #endif
  3016.     }
  3017.     return(no_auth);
  3018.     }
  3019. $EOD
  3020. $!
  3021. $CREATE [.archie]get_vdir.c
  3022. $DECK
  3023. /*
  3024.  * Copyright (c) 1989, 1990, 1991 by the University of Washington
  3025.  *
  3026.  * For copying and distribution information, please see the file
  3027.  * <copyright.h>.
  3028.  *
  3029.  * v1.2.2 - 11/19/91 (mmt) - added MSDOS & OS2 stuff
  3030.  * v1.2.1 - 10/23/91 (bpk) - added missing code
  3031.  * v1.2.0 - 09/17/91 (bpk) - added new get_vdir code
  3032.  * v1.1.1 - 08/30/91 (bpk) - cast rindex()
  3033.  */
  3034.  
  3035. #include <copyright.h>
  3036. #include <stdio.h>
  3037.  
  3038. #include <pfs.h>
  3039. #include <pprot.h>
  3040. #include <perrno.h>
  3041. #include <pcompat.h>
  3042. #include <pauthent.h>
  3043. #include <pmachine.h>
  3044.  
  3045. #ifdef NEED_STRING_H
  3046. # include <string.h>
  3047. #else
  3048. # include <strings.h>
  3049. #endif
  3050.  
  3051. #ifdef DEBUG
  3052. extern int    pfs_debug;
  3053. #endif
  3054.  
  3055. extern int    pwarn;
  3056. extern char    p_warn_string[];
  3057. extern int    perrno;
  3058. extern char    p_err_string[];
  3059.  
  3060. /*
  3061.  * get_vdir - Get contents of a directory given its location
  3062.  *
  3063.  *          GET_VDIR takes a directory location, a list of desired
  3064.  *          components, a pointer to a directory structure to be 
  3065.  *          filled in, and flags.  It then queries the appropriate 
  3066.  *          directory server and retrieves the desired information.
  3067.  *
  3068.  *      ARGS:   dhost       - Host on which directory resides
  3069.  *              dfile       - Directory on that host
  3070.  *              components  - The names from the directory we want
  3071.  *        dir        - Structure to be filled in
  3072.  *            flags       - Options.  See FLAGS
  3073.  *        filters     - filters to be applied to result 
  3074.  *              acomp       - Pointer to remaining components
  3075.  *
  3076.  *     FLAGS:    GVD_UNION   - Do not expand union links
  3077.  *        GVD_EXPAND  - Expand union links locally
  3078.  *        GVD_REMEXP  - Request remote expansion (& local if refused)
  3079.  *        GVD_LREMEXP - Request remote expansion of local union links
  3080.  *        GVD_VERIFY  - Only verify that args are for a directory
  3081.  *              GVD_ATTRIB  - Request attributes from directory server
  3082.  *              GVD_NOSORT  - Do not sort links when adding to directory
  3083.  *
  3084.  *   RETURNS:   PSUCCESS (0) or error code
  3085.  *        On some codes addition information in p_err_string
  3086.  *
  3087.  *     NOTES:   If acomp is non-null the string it points to might be modified
  3088.  *
  3089.  *              If the directory passed as an argument already has
  3090.  *        links or union links, then those lists will be freed
  3091.  *              before the new contents are filled in.
  3092.  *
  3093.  *              If a filter is passed to the procedure, and application of
  3094.  *              the filter results in additional union link, then those links
  3095.  *              will (or will not) be expanded as specified in the FLAGS field.
  3096.  *
  3097.  *              If the list of components in NULL, or the null string, then
  3098.  *              get_vdir will return all links in the requested directory.
  3099.  *
  3100.  *      BUGS:   Doesn't process union links yet
  3101.  *              Doesn't process errors returned from server
  3102.  *        Doesn't expand union links if requested to
  3103.  */
  3104. int
  3105. get_vdir(dhost,dfile,components,dir,flags,filters,acomp)
  3106.     char    *dhost;        /* Host on which directory resides           */
  3107.     char    *dfile;        /* Name of file on that host                 */
  3108.     char    *components;    /* Component name (wildcards allowed)        */
  3109.     VDIR    dir;        /* Structure to be filled in             */
  3110.     long    flags;        /* Flags                         */
  3111.     VLINK    filters;    /* Filters to be applied to result           */
  3112.     char    *acomp;        /* Components left to be resolved            */
  3113.     {
  3114.         PTEXT    request;    /* Text of request to dir server             */
  3115.     PTEXT    resp;            /* Response from dir server                 */
  3116.  
  3117.     char    ulcomp[MAX_VPATH];/* Work space for new current component    */
  3118.     char    *comp = components;
  3119.  
  3120.     VLINK    cur_link = NULL;/* Current link being filled in              */
  3121.     VLINK     exp = NULL;     /* The current ulink being expanded         */
  3122.     VLINK    pul = NULL;     /* Prev union link (insert new one after it) */
  3123.     VLINK    l;        /* Temp link pointer                  */
  3124.     int    mcomp;        /* Flag - check multiple components          */
  3125.     int    unresp;        /* Flag - received unresolved response       */
  3126.     int    getattrib = 0;  /* Get attributes from server                */
  3127.     int    vl_insert_flag; /* Flags to vl_insert                        */
  3128.  
  3129.     int    fwdcnt = MAX_FWD_DEPTH;
  3130.  
  3131.     int    no_links = 0;   /* Count of number of links found         */
  3132.  
  3133.     char    options[40];    /* LIST option                               */
  3134.     char    *opt;           /* After leading +                           */
  3135.  
  3136.     PAUTH    authinfo;
  3137.  
  3138.     /* Treat null string like NULL (return entire directory) */
  3139.     if(!components || !*components) comp = NULL;
  3140.  
  3141.     if(acomp && !filters) mcomp = 1;
  3142.     else mcomp = 0;
  3143.  
  3144.     if(flags&GVD_ATTRIB) {
  3145.         getattrib++;
  3146.         flags &= (~GVD_ATTRIB);
  3147.     }
  3148.  
  3149.     if(flags&GVD_NOSORT) vl_insert_flag = VLI_NOSORT;
  3150.     else vl_insert_flag = VLI_ALLOW_CONF;
  3151.     flags &= (~GVD_NOSORT);
  3152.  
  3153.     if(filters) comp = NULL;
  3154.  
  3155.     perrno = 0;
  3156.  
  3157.     authinfo = get_pauth(PFSA_UNAUTHENTICATED);
  3158.  
  3159.     *options = '\0';
  3160.  
  3161.     if(getattrib) {
  3162.         strcat(options,"+ATTRIBUTES");
  3163.         flags &= (~GVD_ATTRIB);
  3164.     }
  3165.  
  3166.     if(!filters) { /* Can't do remote expansion if filters to be applied */
  3167.         if(flags == GVD_REMEXP) strcat(options,"+EXPAND");
  3168.         if(flags == GVD_LREMEXP) strcat(options,"+LEXPAND");
  3169.     }
  3170.  
  3171.     /* If all we are doing is verifying that dfile is a directory */
  3172.     /* then we do not want a big response from the directory      */
  3173.     /* server.  A NOT-FOUND is sufficient.                  */
  3174.     if(flags == GVD_VERIFY)
  3175. #ifdef NEWVERIFYOPT
  3176.         strcat(options,"+VERIFY");
  3177. #else
  3178.     comp = "%#$PRobably_nOn_existaNT$#%";
  3179. #endif
  3180.  
  3181.     if(*options) opt = options+1;
  3182.     else opt = "''";
  3183.  
  3184.     startover:
  3185.     request = ptalloc();
  3186.  
  3187.     sprintf(request->start,
  3188.         "VERSION %d\nAUTHENTICATOR %s %s\nDIRECTORY ASCII %s\nLIST %s COMPONENTS %s%s%s\n",
  3189.         VFPROT_VNO, authinfo->auth_type, authinfo->authenticator,
  3190.         dfile,opt, (comp ? comp : ""), (mcomp ? "/" : ""),
  3191.         (mcomp ? acomp : ""));
  3192.  
  3193.     request->length = strlen(request->start);
  3194.  
  3195. #ifdef DEBUG
  3196.     if(pfs_debug > 2)
  3197.         fprintf(stderr,"Sending message to dirsrv:\n%s",request->start);
  3198. #endif
  3199.  
  3200. #if defined(MSDOS)
  3201.     resp = dirsend(request,dhost,0L);
  3202. #else
  3203.     resp = dirsend(request,dhost,0);
  3204. #endif
  3205.  
  3206. #ifdef DEBUG
  3207.     if(pfs_debug && (resp == NULL)) {
  3208.         fprintf(stderr,"Dirsend failed: %d\n",perrno);
  3209.     }
  3210. #endif
  3211.  
  3212.     /* If we don't get a response, then if the requested       */
  3213.     /* directory, return error, if a ulink, mark it unexpanded */
  3214.     if(resp == NULL) {
  3215.         if(exp) exp->expanded = FAILED;
  3216.         else return(perrno);
  3217.     }
  3218.  
  3219.     unresp = 0;
  3220.  
  3221.     /* Here we must parse reponse and put in directory */
  3222.     /* While looking at each packet            */
  3223.     while(resp) {
  3224.         PTEXT        vtmp;
  3225.         char        *line;
  3226.  
  3227.         vtmp = resp;
  3228. #ifdef DEBUG
  3229.         if(pfs_debug > 3) fprintf(stderr,"%s\n",resp->start);
  3230. #endif
  3231.         /* Look at each line in packet */
  3232.         for(line = resp->start;line != NULL;line = nxtline(line)) {
  3233.         switch (*line) {
  3234.             
  3235.             /* Temporary variables to hold link info */
  3236.             char    l_linktype;
  3237.             char     l_name[MAX_DIR_LINESIZE];
  3238.             char    l_type[MAX_DIR_LINESIZE];
  3239.             char     l_htype[MAX_DIR_LINESIZE];
  3240.             char     l_host[MAX_DIR_LINESIZE];
  3241.             char     l_ntype[MAX_DIR_LINESIZE];
  3242.             char     l_fname[MAX_DIR_LINESIZE];
  3243.             int        l_version;
  3244.             char     t_unresolved[MAX_DIR_LINESIZE];
  3245.             int        l_magic;
  3246.             int        tmp;
  3247.  
  3248.         case 'L': /* LINK or LINK-INFO */
  3249.             if(strncmp(line,"LINK-INFO",9) == 0) {
  3250.             PATTRIB        at;
  3251.             PATTRIB        last_at;
  3252.             at = parse_attribute(line);
  3253.             if(!at) break;
  3254.  
  3255.             /* Cant have link info without a link */
  3256.             if(!cur_link) {
  3257.                 perrno = DIRSRV_BAD_FORMAT;
  3258.                 atfree(at);
  3259.                 break;
  3260.             }
  3261.             
  3262.             if(cur_link->lattrib) {
  3263.                 last_at = cur_link->lattrib;
  3264.                 while(last_at->next) last_at = last_at->next;
  3265.                 at->previous = last_at;
  3266.                 last_at->next = at;
  3267.             }
  3268.             else {
  3269.                 cur_link->lattrib = at;
  3270.                 at->previous = NULL;
  3271.             }
  3272.             break;
  3273.             }
  3274.  
  3275.             /* Not LINK-INFO, must be LINK - if not check for error */
  3276.             if(strncmp(line,"LINK",4) != 0) goto scanerr;
  3277.  
  3278.             /* If only verifying, don't want to change dir */
  3279.             if(flags == GVD_VERIFY) {
  3280.             break;
  3281.             }
  3282.             /* If first link and some links in dir, free them */
  3283.             if(!no_links++) {
  3284.             if(dir->links) vllfree(dir->links); dir->links=NULL;
  3285.             if(dir->ulinks) vllfree(dir->ulinks); dir->ulinks=NULL;
  3286.             }
  3287.             
  3288.             cur_link = vlalloc();
  3289.  
  3290.             /* parse and insert file info */
  3291.             tmp = sscanf(line,"LINK %c %s %s %s %s %s %s %d %d", &l_linktype,
  3292.                  l_type, l_name, l_htype, l_host, 
  3293.                  l_ntype, l_fname, &(cur_link->version),
  3294.                  &(cur_link->f_magic_no));
  3295.  
  3296.             if(tmp != 9) {
  3297.             perrno = DIRSRV_BAD_FORMAT;
  3298.             vlfree(cur_link);
  3299.             break;
  3300.             }
  3301.  
  3302.             cur_link->linktype = l_linktype;
  3303.             cur_link->type = stcopyr(l_type,cur_link->type);
  3304.             cur_link->name = stcopyr(unquote(l_name),cur_link->name);
  3305.             cur_link->hosttype = stcopyr(l_htype,cur_link->hosttype);
  3306.             cur_link->host = stcopyr(l_host,cur_link->host);
  3307.             cur_link->nametype = stcopyr(l_ntype,cur_link->nametype);
  3308.             cur_link->filename = stcopyr(l_fname,cur_link->filename);
  3309.  
  3310.             /* Double check to make sure we don't get */
  3311.             /* back unwanted components              */
  3312.             /* OK to keep if special (URP) links      */
  3313.             /* or if mcomp specified                  */
  3314.             if(!mcomp && (cur_link->linktype == 'L') && 
  3315.                (!wcmatch(cur_link->name,comp))) {
  3316.             vlfree(cur_link);
  3317.             break;
  3318.             }
  3319.  
  3320.             /* If other optional info was sent back, it must */
  3321.             /* also be parsed before inserting link     ***  */
  3322.             
  3323.             
  3324.             if(cur_link->linktype == 'L') 
  3325.             vl_insert(cur_link,dir,vl_insert_flag);
  3326.             else {
  3327.             tmp = ul_insert(cur_link,dir,pul);
  3328.  
  3329.             /* If inserted after pul, next one after cur_link */
  3330.             if(pul && (!tmp || (tmp == UL_INSERT_SUPERSEDING)))
  3331.                 pul = cur_link;
  3332.             }
  3333.             
  3334.             break;
  3335.  
  3336.         case 'F': /* FILTER, FAILURE or FORWARDED*/
  3337.             /* FORWARDED */
  3338.             if(strncmp(line,"FORWARDED",9) == 0) {
  3339.             if(fwdcnt-- <= 0) {
  3340.                 ptlfree(resp);
  3341.                 perrno = PFS_MAX_FWD_DEPTH;
  3342.                 return(perrno);
  3343.             }
  3344.             /* parse and start over */
  3345.  
  3346.             tmp = sscanf(line,"FORWARDED %s %s %s %s %d %d", 
  3347.                      l_htype,l_host,l_ntype,l_fname,
  3348.                      &l_version, &l_magic);
  3349.  
  3350.             dhost = stcopy(l_host);
  3351.             dfile = stcopy(l_fname);
  3352.  
  3353.             if(tmp < 4) {
  3354.                 perrno = DIRSRV_BAD_FORMAT;
  3355.                 break;
  3356.             }
  3357.  
  3358.             ptlfree(resp);
  3359.             goto startover;
  3360.             }
  3361.             if(strncmp(line,"FILTER",6) != 0) goto scanerr;
  3362.             break;
  3363.  
  3364.  
  3365.         case 'M': /* MULTI-PACKET (processed by dirsend) */
  3366.         case 'P': /* PACKET (processed by dirsend) */
  3367.             break;
  3368.  
  3369.         case 'N': /* NOT-A-DIRECTORY or NONE-FOUND */
  3370.             /* NONE-FOUND, we just have no links to insert */
  3371.             /* It is not an error, but we must clear any   */
  3372.             /* old links in the directory arg              */
  3373.             if(strncmp(line,"NONE-FOUND",10) == 0) {
  3374.             /* If only verifying, don't want to change dir */
  3375.             if(flags == GVD_VERIFY) {
  3376.                 break;
  3377.             }
  3378.  
  3379.             /* If first link and some links in dir, free them */
  3380.             if(!no_links++) {
  3381.                 if(dir->links) vllfree(dir->links);
  3382.                 if(dir->ulinks) vllfree(dir->ulinks);
  3383.                 dir->links = NULL;
  3384.                 dir->ulinks = NULL;
  3385.             }
  3386.             break;
  3387.             }
  3388.             /* If NOT-A-DIRECTORY or anything else, scan error */
  3389.             goto scanerr;
  3390.  
  3391.         case 'U': /* UNRESOLVED */
  3392.             if(strncmp(line,"UNRESOLVED",10) != 0) {
  3393.             goto scanerr;
  3394.             }
  3395.             tmp = sscanf(line,"UNRESOLVED %s", t_unresolved);
  3396.             if(tmp < 1) {
  3397.             perrno = DIRSRV_BAD_FORMAT;
  3398.             break;
  3399.             }
  3400.             /* If multiple components were resolved */
  3401.             if(strlen(t_unresolved) < strlen(acomp)) {
  3402.             strcpy(ulcomp,acomp);
  3403.             /* ulcomp is the components that were resolved */
  3404.             *(ulcomp+strlen(acomp)-strlen(t_unresolved)-1) = '\0';
  3405.             /* Comp gets the last component resolved */
  3406.             comp = (char *) rindex(ulcomp,'/');
  3407.             if(comp) comp++;
  3408.             else comp = ulcomp;
  3409.             /* Let rd_vdir know what remains */
  3410.             strcpy(acomp,t_unresolved);
  3411.             }
  3412.             unresp = 1;
  3413.             break;
  3414.  
  3415.         case 'V': /* VERSION-NOT-SUPPORTED */
  3416.             if(strncmp(line,"VERSION-NOT-SUPPORTED",21) == 0) {
  3417.             perrno = DIRSRV_BAD_VERS;
  3418.             return(perrno);
  3419.             }
  3420.             goto scanerr;
  3421.  
  3422.         scanerr:
  3423.         default:
  3424.             if(*line && (tmp = scan_error(line))) {
  3425.             ptlfree(resp);
  3426.             return(tmp);
  3427.             }
  3428.             break;
  3429.         }
  3430.         }
  3431.  
  3432.         resp = resp->next;
  3433.  
  3434.         ptfree(vtmp);
  3435.     }
  3436.  
  3437.     /* We sent multiple components and weren't told any */
  3438.     /* were unresolved                                  */
  3439.     if(mcomp && !unresp) {
  3440.         /* ulcomp is the components that were resolved */
  3441.         strcpy(ulcomp,acomp);
  3442.         /* Comp gets the last component resolved */
  3443.         comp = (char *) rindex(ulcomp,'/');
  3444.         if(comp) comp++;
  3445.         else comp = ulcomp;
  3446.         /* If we have union links to resolve, only one component remains */
  3447.         mcomp = 0;
  3448.         /* Let rd_vdir know what remains */
  3449.         *acomp = '\0';
  3450.     }
  3451.  
  3452.     /* If only verifying, we already know it is a directory */
  3453.     if(flags == GVD_VERIFY) return(PSUCCESS);
  3454.  
  3455.     /* Don't return if matching was delayed by the need to filter    */
  3456.     /* if FIND specified, and dir->links is non null, then we have   */
  3457.     /* found a match, and should return.                             */
  3458.     if((flags & GVD_FIND) && dir->links && (!filters))
  3459.         return(PSUCCESS);
  3460.  
  3461.     /* If expand specified, and ulinks must be expanded, making sure */
  3462.         /* that the order of the links is maintained properly            */
  3463.  
  3464. expand_ulinks:
  3465.  
  3466.     if((flags != GVD_UNION) && (flags != GVD_VERIFY)) {
  3467.  
  3468.         l = dir->ulinks;
  3469.  
  3470.         /* Find first unexpanded ulink */
  3471.         while(l && l->expanded && (l->linktype == 'U')) l = l->next;
  3472.         
  3473.         /* Only expand if a FILE or DIRECTORY -  Mark as  */
  3474.             /* failed otherwise                               */
  3475.         /* We must still add support for symbolic ulinks */
  3476.         if(l) {
  3477.         if ((strcmp(l->type,"DIRECTORY") == 0) || 
  3478.             (strcmp(l->type,"FILE") == 0)) {
  3479.             l->expanded = TRUE;
  3480.             exp = l;
  3481.             pul = l;
  3482.             dhost = l->host;
  3483.             dfile = l->filename;
  3484.             goto startover; /* was get_contents; */
  3485.         }
  3486.         else l->expanded = FAILED;
  3487.         }
  3488.     }
  3489.  
  3490.     /* Double check to make sure we don't get */
  3491.     /* back unwanted components          */
  3492.     /* OK to keep if special (URP) links      */
  3493.     if(components && *components) {
  3494.         l = dir->links;
  3495.         while(l) {
  3496.         VLINK    ol;
  3497.         if((l->linktype == 'L') && (!wcmatch(l->name,components))) {
  3498.             if(l == dir->links)
  3499.             dir->links = l->next;
  3500.             else l->previous->next = l->next;
  3501.             if(l->next) l->next->previous = l->previous;
  3502.             ol = l;
  3503.             l = l->next;
  3504.             vlfree(ol);
  3505.         }
  3506.         else l = l->next;
  3507.         }
  3508.     }
  3509.  
  3510.     return(PSUCCESS);
  3511.     }
  3512. $EOD
  3513. $!
  3514. $CREATE [.archie]make.com
  3515. $DECK
  3516. $!
  3517. $! MAKE.COM - build the Archie client for VMS (5.4-2, others?)
  3518. $!            for MultiNet TCP/IP, v2.2 & 3.0, and Wollongong 5.xx+
  3519. $!          and UCX
  3520. $!
  3521. $! Many thanks to Jim Barbour (jwbarbour@clipr.colorado.edu) for all
  3522. $! of his help getting this up to par.
  3523. $!
  3524. $! v1.2.2 - 12/13/91 (jwb) - ported to UCX & added dependencies
  3525. $! v1.2.1 - 11/12/91 (bpk) - use option files
  3526. $! v1.2   - 09/25/91 (bpk) - ported to Wollongong
  3527. $!        - 09/20/91 (bpk) - fixed up strings.h stuff, etc
  3528. $! v1.1   - 09/17/91 (bpk) - works with 3.0 now
  3529. $! v1.0   - 08/30/91 (bpk) - Original
  3530. $!
  3531. $! If you want to force a compile (i.e. after modifying a .H file) then
  3532. $! give @make the argument force.  i.e. $ make force
  3533. $ force_compile = 0
  3534. $ if p1 .eqs. "FORCE" then force_compile = 1
  3535. $!
  3536. $! * If you're running Multinet 3.0, leave this alone.  If you're
  3537. $! running any version of Multinet less than 3.0 (e.g. 2.2), comment
  3538. $! it out.
  3539. $ mdef := ,multinet_30=1
  3540. $! * If you're running Wollongong TCP, uncomment this.
  3541. $!woll := ,wollongong=1
  3542. $! * If you're running UCX, uncomment this.
  3543. $!ucx := ,ucx=1
  3544. $!
  3545. $! * If you aren't in the US, or archie.ans.net doesn't ping "close" to
  3546. $!   your site, edit the file ARCHIE.H and change ARCHIE_HOST appropriately.
  3547. $! * Type @MAKE now.
  3548. $!
  3549. $!-----
  3550. $ ve := f$verify(0)
  3551. $!set noverify
  3552. $ on control_y then goto hell
  3553. $ on error then goto hell
  3554. $ echo := write sys$output
  3555. $!
  3556. $ cc := cc/opt=noinline
  3557. $ cflags := /define=(debug=1,funcs=1,noregex=1'mdef 'woll 'ucx)
  3558. $!g := /debug
  3559. $ if f$trnlnm("GNU_CC") .nes. "" then cc := gcc/optimize
  3560. $!
  3561. $ if f$search("strings.h") .nes. "" then delete/nolog/noconfirm []strings.h;*
  3562. $ if "''cc'" .nes. "GCC" then copy/noconfirm sys$library:string.h []strings.h
  3563. $ needs_linking = 0
  3564. $!
  3565. $ file := aquery
  3566. $ gosub possibly_compile
  3567. $ file := archie
  3568. $ gosub possibly_compile
  3569. $ file := atalloc
  3570. $ gosub possibly_compile
  3571. $ file := dirsend
  3572. $ gosub possibly_compile
  3573. $ file := get_pauth
  3574. $ gosub possibly_compile
  3575. $ file := get_vdir
  3576. $ gosub possibly_compile
  3577. $ file := perrmesg
  3578. $ gosub possibly_compile
  3579. $ file := procquery
  3580. $ gosub possibly_compile
  3581. $ file := ptalloc
  3582. $ gosub possibly_compile
  3583. $ file := regex
  3584. $ gosub possibly_compile
  3585. $ file := stcopy
  3586. $ gosub possibly_compile
  3587. $ file := support
  3588. $ gosub possibly_compile
  3589. $ file := vlalloc
  3590. $ gosub possibly_compile
  3591. $ file := vl_comp
  3592. $ gosub possibly_compile
  3593. $!
  3594. $ do_vs := ,
  3595. $ if "''ucx'" .nes. "" then libs :=  [.vms]ucx
  3596. $ if "''mdef'" .nes. "" then libs := [.vms]multi
  3597. $ if "''woll'" .nes. "" then libs := [.vms]woll
  3598. $ if "''mdef'" .eqs. "" .and. "''woll'" .eqs. "" .and "''ucx'" .eqs. "" then-
  3599.                                 gosub dosup
  3600. $!
  3601. $ file :=
  3602. $ if f$search("ARCHIE.EXE") .eqs. "" then needs_linking = 1
  3603. $ if needs_linking
  3604. $ then
  3605. $ echo "Linking..."
  3606. $ link'g/exe=archie aquery+archie+atalloc+-
  3607. dirsend+get_pauth+get_vdir+-
  3608. perrmesg+procquery+ptalloc+regex+stcopy+support+vlalloc+vl_comp'do_vs-
  3609. 'libs/option
  3610. $ else
  3611. $ echo "ARCHIE is up to date."
  3612. $ endif
  3613. $ out:
  3614. $ echo "Done! Define the symbol ARCHIE & fire away."
  3615. $!
  3616. $ hell:
  3617. $ if "''file'" .nes. "" then delete/noconfirm/nolog 'file.obj;
  3618. $ if 've .eq. 1 then set verify
  3619. $ exit
  3620. $!
  3621. $ dosup:
  3622. $ file := vms_support
  3623. $ gosub possibly_compile
  3624. $ do_vs := +vms_support,
  3625. $ return
  3626. $ possibly_compile:
  3627. $ if force_compile then goto build
  3628. $ if f$search("''file'.obj") .eqs. "" then goto build
  3629. $ if f$cvtime(f$file("''file'.c","cdt")) .gts. -
  3630.      f$cvtime(f$file("''file'.obj","cdt")) then goto build
  3631. $ return
  3632. $ build:
  3633. $ echo "Compiling ''file'.C..."
  3634. $ 'cc/include=([])'cflags 'g 'file.c
  3635. $ needs_linking = 1
  3636. $ return
  3637. $EOD
  3638. $!
  3639. $CREATE [.archie]makefile.cut
  3640. $DECK
  3641. #
  3642. # CUTCP/CUTE BC++ version 11/22/91 bkc@omnigate.clarkson.edu
  3643. # Last changed: 12/03/91 1.2.1
  3644. #
  3645. # Makefile for the minimal build for an archie Prospero client.
  3646. #.INCLUDE ../../../builtins
  3647.  
  3648. OBJS    = aquery.obj    archie.obj    atalloc.obj \ 
  3649.       get_pauth.obj    get_vdir.obj    perrmesg.obj    procquery.obj    \
  3650.       ptalloc.obj    regex.obj    stcopy.obj    support.obj\
  3651.       vlalloc.obj    vl_comp.obj     dirsend.obj    misc.obj
  3652.  
  3653. # dirsend.obj
  3654.  
  3655. HDRS    = archie.h    pmachine.h    pcompat.h
  3656.  
  3657. DEFINES    = -DDEBUG -DCUTCP
  3658.  
  3659. CFLAGS= -ml -r -v $(DEFINES) -I.
  3660. LFLAGS= /P/m/s
  3661. CC = bccx
  3662.  
  3663. EXE    = archie.exe
  3664.  
  3665. all: $(EXE)
  3666.  
  3667. $(OBJS): $(HDRS)
  3668.  
  3669. .c.obj:
  3670.     $(CC)  $(CFLAGS) -c $<
  3671.  
  3672. $(EXE): $(OBJS) Makefile 
  3673.     tlink $(LFLAGS) @&&!
  3674. c0l $(OBJS)
  3675. !,archie,archie,@&&!
  3676. lib\tcp lib\sess lib\enet lib\vjc lib\over cl
  3677. !
  3678.  
  3679. clean:
  3680.     +-del *.obj
  3681. $EOD
  3682. $!
  3683. $CREATE [.archie]makefile.dos
  3684. $DECK
  3685. #
  3686. # Last changed: 11/20/91, v1.2
  3687. #
  3688. # Makefile for the minimal build for an archie Prospero client.
  3689. #.INCLUDE ../../../builtins
  3690.  
  3691. OBJS    = aquery.lo    archie.lo    atalloc.lo    dirsend.lo    \
  3692.       get_pauth.lo    get_vdir.lo    perrmesg.lo    procquery.lo    \
  3693.       ptalloc.lo    regex.lo    stcopy.lo    support.lo    \
  3694.       vlalloc.lo    vl_comp.lo
  3695. HDRS    = archie.h    pmachine.h    pcompat.h
  3696.  
  3697. DEFINES    = -DDEBUG -DNOREGEX -DUSG
  3698.  
  3699. CFLAGS    = -Oeclgsz -Gs -Zi -W4 -I. $(DEFINES)
  3700.  
  3701. EXE    = archie.exe
  3702.  
  3703. all: $(EXE)
  3704.  
  3705. $(OBJS): $(HDRS)
  3706.  
  3707. $(EXE): $(OBJS) Makefile archie.lnk
  3708.     link @archie.lnk
  3709.     exepack archie.unp archie.exe
  3710.  
  3711. clean:
  3712.     +-del *.lo
  3713.     +-del *.exe
  3714.  
  3715. $EOD
  3716. $!
  3717. $CREATE [.archie]makefile.os2
  3718. $DECK
  3719. #
  3720. # Last changed: 11/20/91, v1.2
  3721. #
  3722. # Makefile for the minimal build for an archie Prospero client.
  3723. .INCLUDE ../../../builtins
  3724.  
  3725. OBJS    = aquery.obj    archie.obj    atalloc.obj    dirsend.obj    \
  3726.       get_pauth.obj    get_vdir.obj    perrmesg.obj    procquery.obj    \
  3727.       ptalloc.obj    regex.obj    stcopy.obj    support.obj    \
  3728.       vlalloc.obj    vl_comp.obj
  3729. HDRS    = archie.h    pmachine.h    pcompat.h
  3730.  
  3731. DEFINES    = -DDEBUG -DNOREGEX
  3732.  
  3733. IFLAGS    = -I. -I../../../include $(DEFINES)
  3734.  
  3735. LFLAGS     = /stack:30000/nod/noe/noi/map/CO
  3736. LIBS    = pctcp bsd ftpcrt socket os2
  3737. EXE    = archie.exe
  3738.  
  3739. all: $(EXE)
  3740.  
  3741. install: $(EXE)
  3742.     cp $[m,*.exe,$**] ..\..\..\bin
  3743.     @touch install
  3744.  
  3745. $(OBJS): $(HDRS)
  3746.  
  3747. $(EXE): $(OBJS) Makefile
  3748.     $(LD) $(LFLAGS) $(L_DEBUG) <@<
  3749. $[s,"+ \n",$[m,*.obj,$**]]
  3750. $*
  3751. $*
  3752. $(LIBS)
  3753.  
  3754. <
  3755.     +markexe lfns $@
  3756.     +markexe windowcompat $@
  3757.  
  3758. clean:
  3759.     +-del *.obj
  3760.     +-del *.exe
  3761.  
  3762. $EOD
  3763. $!
  3764. $CREATE [.archie.msdos]cutcp.h
  3765. $DECK
  3766. /* cutcp.h -- defs for cutcp code */
  3767.  
  3768.  
  3769. int         netlisten(unsigned int port);
  3770. struct machinfo *Shostlook(char *name);
  3771. int         Sdomain(char *name);
  3772. struct machinfo *Sgethost(char *name);
  3773. struct machinfo *Slookip(unsigned long *address);
  3774. void        netgetftp(unsigned int array[], unsigned int port);
  3775. int         netopen(unsigned long *address, unsigned int port);
  3776. int         Snetopen(struct machinfo *m, unsigned int port);
  3777. int        netqlen(int handle);
  3778. int        netroom(int handle);
  3779. int        netread(int pnum, unsigned char *buffer, unsigned int n);
  3780. int        netwrite(int pnum, unsigned char *buffer, unsigned int n);
  3781. int        netest(int pnum);
  3782. int        netpush(int pnum);
  3783. void        netulisten(unsigned int portnum);
  3784. int        netusend(unsigned long *address, unsigned destport, 
  3785.             unsigned sourceport, unsigned char *buffer, int count);
  3786. int        neturead(unsigned char    *buffer);
  3787. struct machinfo *Slooknum(int pnum);
  3788. int        Snetinit();
  3789. int        Shostfile(char *name);
  3790. int        netshut();
  3791. int        Sgetevent(int classes, int *clss, int *data);
  3792. int        netclose(int pnum);
  3793. unsigned int    intswap(unsigned int val);
  3794. unsigned long    n_clicks(void *p);
  3795. void        Stask();
  3796.  
  3797. #define    ntohs(a)    (intswap(a))
  3798. #define    htons(a)    (intswap(a))
  3799. $EOD
  3800. $!
  3801. $CREATE [.archie.msdos]hostform.h
  3802. $DECK
  3803. /* hfile.inc - placed into all .h files to set up for PVCS 
  3804.    $Header:   E:/pcdirs/vcs/hostform.h_v   1.0   15 Jan 1990 19:30:22   bkc  $
  3805.    Revision History ----------------------------------------------------
  3806.    $Log:   E:/pcdirs/vcs/hostform.h_v  $
  3807.  * 
  3808.  *    Rev 1.0   15 Jan 1990 19:30:22   bkc
  3809. */
  3810.  
  3811.  
  3812. /*
  3813. *  Host and local machine configuration information.
  3814. *
  3815. ****************************************************************************
  3816. *                                                                          *
  3817. *      NCSA Telnet for the PC                                              *
  3818. *      by Tim Krauskopf, VT100 by Gaige Paulsen, Tek by Aaron Contorer     *
  3819. *                                                                          *
  3820. *      National Center for Supercomputing Applications                     *
  3821. *      152 Computing Applications Building                                 *
  3822. *      605 E. Springfield Ave.                                             *
  3823. *      Champaign, IL  61820                                                *
  3824. *                                                                          *
  3825. *      This program is in the public domain.                               *
  3826. *                                                                          *
  3827. ****************************************************************************
  3828. */
  3829.  
  3830. /*
  3831. *  Linked list of structures which describe other machines.
  3832. *  Arranged one per session with unique session names.
  3833. */
  3834.  
  3835. struct machinfo {
  3836.     unsigned char 
  3837.         *sname,                    /* pointer to name of session */
  3838.         *hname,                 /* pointer to name of that machine */
  3839.         *font,                    /* font name, if we can do it */
  3840.         *keymap,                /* pointer to keymap file name */
  3841.         hostip[4],                /* IP number of this machine */
  3842.         gateway,                /* gateway preference, start with 1 */
  3843.         nameserv,                /* nameserver preference, start with 1 */
  3844.         bksp,                    /* backspace value */
  3845.         halfdup,                /* half duplex required */
  3846.         crmap,                    /* Strange Berkeley 4.3 CR mode needed */
  3847.         vtwrap,                    /* flag on when need wrap mode */
  3848.         vtmargin;                /* col to ring bell at */
  3849.     int
  3850.         clearsave,                /* whether to save cleared lines */
  3851.         fsize,                    /* font size in points */
  3852.         nfcolor[3],                /* normal foreground */
  3853.         nbcolor[3],                /* normal background */
  3854.         bfcolor[3],                /* blink             */
  3855.         bbcolor[3],
  3856.         ufcolor[3],             /* underline */
  3857.         ubcolor[3],
  3858.         mno,                    /* machine number for reference */
  3859.         mstat,                    /* status of this machine entry */
  3860.         bkscroll,                /* how many lines to save */
  3861.         retrans,                /* initial retrans timeout */
  3862.         conto,                    /* time out in seconds to wait for connect */
  3863.         window,                    /* window, will be checked against buffers */
  3864.         maxseg,                    /* maximum receivable segment size */
  3865.         mtu,                    /* maximum transfer unit MTU (out) */
  3866.                 domainsremaining,                       /* how many domain search list entries remain */
  3867.                 destport,                               /* yepper, you can telnet to a different port than 23 */
  3868.         flags;                    /* general flags holder */        
  3869. #define    MFLAGS_SCRIPT    0x80
  3870.     struct machinfo *next;        /* surprise, its a linked list! */
  3871. };
  3872.  
  3873. struct machinfo *Sgethost(),*Shostlook(),*Slooknum(),*Slookip(),*Smadd();
  3874.  
  3875. /*
  3876. *  status fields for mstat, what do we know about that machine?
  3877. */
  3878. #define NOIP 1                    /* we don't have IP number */
  3879. #define UDPDOM 3                /* there is a UDP request pending on it */
  3880. /*  The next 20 numbers are reserved for UDPDOM */
  3881. #define HAVEIP 50                /* at least we have the # */
  3882. #define HFILE 70                /* we have IP number from host file */
  3883. #define DOM 71                    /* we have an IP number from DOMAIN */
  3884. #define FROMKIP 72                /* have IP# from KIP server */
  3885.  
  3886.  
  3887.  
  3888. /*
  3889. *   Configuration information which 
  3890. *   the calling program may want to obtain from the hosts file.
  3891. *   The calling program should include hostform.h and call
  3892. *   Sgetconfig(cp)
  3893. *     struct config *cp;
  3894. *   which will copy the information to the user's data structure.
  3895. */
  3896. struct config {
  3897.     unsigned char
  3898.         netmask[4],                /* subnetting mask being used */
  3899.         havemask,                /* do we have a netmask? */
  3900.         irqnum,                    /* which hardware interrupt */
  3901.         myipnum[4],                /* what is my IP #? */
  3902.         me[32],                    /* my name description (first 30 chars) */
  3903.         color[3],                /* default colors to use */
  3904.         hw[10],                    /* hardware type for network */
  3905.         video[10],                /* video graphics hardware available */
  3906.         bios,                    /* flag, do we want to use BIOS for screen access */
  3907.         tek,                    /* flag, enable tektronix graphics */
  3908.         ftp,                    /* flag, enable ftp server */
  3909.         rcp,                    /* flag, enable rcp server */
  3910.         comkeys,                /* flag, commandkeys=yes */
  3911.         *termtype,                /* terminal type specification */
  3912.         *zone,                    /* AppleTalk zone for KIP NBP */
  3913.         *defdom,                /* default domain */
  3914.         *capture,                /* pointer to where the capture file name is */
  3915.         *pass,                    /* pointer to where the password file name is */
  3916.         *hpfile,                /* HP file name */
  3917.         *psfile,                /* PS file name */
  3918.         *tekfile;                /* tek file name */
  3919. int
  3920.         nstype,                    /* nameserver = 1-domain 2-IEN116  */
  3921.         domto,                    /* time out for UDP domain request */
  3922.         ndom,                    /* number of retries for domain requests */
  3923.         timesl,                    /* time slice */
  3924.         address,                /* segment address */
  3925.         ioaddr;                    /* I/O address */
  3926. char            *domainpath;                               /* domain name search path */
  3927. char            *map3270;                               /* path to 3270 map */
  3928. char            tnmode;                                 /* how we decide to connect to 3270 streams */
  3929. long        sys_flags;
  3930. #define    SYS_FLAGS_VISUAL_BELL    0x1        /* use visual bell */
  3931.  
  3932. };
  3933.  
  3934.  
  3935. #define TNMODE_FLAGGED  0
  3936. #define TNMODE_AUTO     1
  3937. #define TNMODE_NOTFLAGGED 2
  3938. #define TNMODE_OFF      3
  3939. $EOD
  3940. $!
  3941. $CREATE [.archie.msdos]netevent.h
  3942. $DECK
  3943. /* hfile.inc - placed into all .h files to set up for PVCS 
  3944.    $Header:   E:/pcdirs/vcs/netevent.h_v   1.0   15 Jan 1990 19:29:26   bkc  $
  3945.    Revision History ----------------------------------------------------
  3946.    $Log:   E:/pcdirs/vcs/netevent.h_v  $
  3947.  * 
  3948.  *    Rev 1.0   15 Jan 1990 19:29:26   bkc
  3949. */
  3950.  
  3951.  
  3952. /*
  3953. *  Events for event processing in NCSA Telnet.
  3954. *  Used for netgetevent().
  3955. */
  3956.  
  3957.  
  3958. #define USERCLASS    1    /* the user program will accept these events */
  3959. #define ICMPCLASS    2    /* ICMP in netsleep will look for these */
  3960. #define ERRCLASS    4    /* the user may or may not read these error messages */
  3961. #define SCLASS        8    /* the background server will take these */
  3962. #define CONCLASS    0x10    /* the application manages connections with these */
  3963.  
  3964. #define ERR1    1        /* an error message is waiting, ERRCLASS */
  3965.  
  3966. #define IREDIR    1        /* ICMP redirect, ICMPCLASS */
  3967.  
  3968. #define CONOPEN 1        /* connection has opened, CONCLASS */
  3969. #define CONDATA 2       /* there is data available on this connection */
  3970. #define CONCLOSE 3        /* the other side has closed its side of the connection */
  3971. #define CONFAIL 4        /* connection open attempt has failed */
  3972.  
  3973. #define UDPDATA 1        /* UDP data has arrived on listening port, USERCLASS */
  3974. #define DOMOK    2        /* domain name ready */
  3975. #define DOMFAIL 3        /* domain name lookup failed */
  3976. #define FTPCOPEN 20     /* FTP command connection has opened */
  3977. #define FTPCLOSE 21     /* FTP command connection has closed */
  3978. #define FTPBEGIN 22     /* FTP transfer beginning, dat =1 for get, 0 for put */
  3979. #define FTPEND   23     /* FTP transfer ending */
  3980. #define FTPLIST  24     /* FTP file listing taking place */
  3981. #define FTPUSER  25     /* FTP user name has been entered */
  3982. #define FTPPWOK    26        /* FTP password verified */
  3983. #define FTPPWNO 27        /* FTP password failed */
  3984. #define RCPBEGIN 30        /* RCP beginning */
  3985. #define RCPEND 31        /* RCP ending */
  3986.  
  3987. #define UDPTO 1            /* UDP request from DOMAIN timed out, SCLASS */
  3988. #define FTPACT 2        /* FTP transfer is active, keep sending */
  3989. #define TCPTO  3        /* TCP for DOMAIN timed out */
  3990. #define RCPACT 4        /* rcp is active, needs CPU time */
  3991. #define RETRYCON 5        /* retry connection packet, might be lost */
  3992. #define DOMNEXT 6               /* search next domain list entry */
  3993. #define E_CLOCK 7
  3994. #ifdef    SCRIPT
  3995. #define    SCRIPT_EVENT    1    /* script next step */
  3996. #define    SCRIPT_DATA    2    /* received some data */
  3997. #define    SCRIPT_PROC    3    /* just process stuff */
  3998. #define    SCRIPT_CLOSE    4    /* connection was closed */
  3999. #define    SCRIPT_FORCE    5    /* user forced connection closed */
  4000. #define    SCRIPT_DOMAIN    6    /* domain name lookup ok */
  4001. #define    SCRIPT_FUNC    8
  4002. /* int Script_Event(int type, void *twin, unsigned int data); */
  4003. #endif
  4004. $EOD
  4005. $!
  4006. $CREATE [.archie]perrmesg.c
  4007. $DECK
  4008. /*
  4009.  * Copyright (c) 1989, 1990, 1991 by the University of Washington
  4010.  *
  4011.  * For copying and distribution information, please see the file
  4012.  * <copyright.h>.
  4013.  */
  4014.  
  4015. #include <copyright.h>
  4016. #include <perrno.h>
  4017. #include <stdio.h>
  4018.  
  4019. /* This file and perrno.h should always be updated simultaneously */
  4020.  
  4021. int    perrno = 0;
  4022. int    pwarn = 0;
  4023. char    p_err_string[P_ERR_STRING_SZ];
  4024. char    p_warn_string[P_ERR_STRING_SZ];
  4025.  
  4026. char    *p_err_text[256] = {
  4027.     /*   0 */ "Success (prospero)",
  4028.     /*   1 */ "Port unknown (dirsend)",
  4029.     /*   2 */ "Can't open local UDP port (dirsend)",
  4030.     /*   3 */ "Can't resolve hostname (dirsend)",
  4031.     /*   4 */ "Unable to send entire message (dirsend)",
  4032.     /*   5 */ "Timed out (dirsend)",
  4033.     /*   6 */ "Recvfrom failed (dirsend)",
  4034.     /*   7 */ "",    /*   8 */ "",    /*   9 */ "",    /*  10 */ "",
  4035.     /*  11 */ "Sendto failed (reply)",
  4036.     /*  12 */ "",    /*  13 */ "",    /*  14 */ "",    /*  15 */ "",
  4037.     /*  16 */ "",    /*  17 */ "",    /*  18 */ "",    /*  19 */ "",
  4038.     /*  20 */ "",
  4039.     /*  21 */ "Link already exists (vl_insert)",
  4040.     /*  22 */ "Link with same name already exists (vl_insert)",
  4041.     /*  23 */ "",    /*  24 */ "",
  4042.     /*  25 */ "Link already exists (ul_insert)",
  4043.     /*  26 */ "Replacing existing link (ul_insert)",
  4044.     /*  27 */ "Previous entry not found in dir->ulinks (ul_insert)",
  4045.     /*  28 */ "",    /*  29 */ "",    /*  30 */ "",    /*  31 */ "",
  4046.     /*  32 */ "",    /*  33 */ "",    /*  34 */ "",    /*  35 */ "",
  4047.     /*  36 */ "",    /*  37 */ "",    /*  38 */ "",    /*  39 */ "",
  4048.     /*  40 */ "",
  4049.     /*  41 */ "Temporary not found (rd_vdir)",
  4050.     /*  42 */ "Namespace not closed with object (rd_vdir)",
  4051.     /*  43 */ "Alias for namespace not defined (rd_vdir)",
  4052.     /*  44 */ "Specified namespace not found (rd_vdir)",
  4053.     /*  45 */ "",    /*  46 */ "",    /*  47 */ "",    /*  48 */ "",
  4054.     /*  49 */ "",    /*  50 */ "",
  4055.     /*  51 */ "File access method not supported (pfs_access)",
  4056.     /*  52 */ "",    /*  53 */ "",    /*  54 */ "",
  4057.     /*  55 */ "Pointer to cached copy - delete on close (pmap_cache)",
  4058.     /*  56 */ "Unable to retrieve file (pmap_cache)",
  4059.     /*  57 */ "",    /*  58 */ "",    /*  59 */ "",    /*  60 */ "",
  4060.     /*  61 */ "Directory already exists (mk_vdir)",
  4061.     /*  62 */ "Link with same name already exists (mk_vdir)",
  4062.     /*  63 */ "",    /*  64 */ "",
  4063.     /*  65 */ "Not a virtual system (vfsetenv)",
  4064.     /*  66 */ "Can't find directory (vfsetenv)",
  4065.     /*  67 */ "",    /*  68 */ "",    /*  69 */ "",    /*  70 */ "",
  4066.     /*  71 */ "Link already exists (add_vlink)",
  4067.     /*  72 */ "Link with same name already exists (add_vlink)",
  4068.     /*  73 */ "",    /*  74 */ "",    /*  75 */ "",    /*  76 */ "",
  4069.     /*  77 */ "",    /*  78 */ "",    /*  79 */ "",    /*  80 */ "",
  4070.     /*  81 */ "",    /*  82 */ "",    /*  83 */ "",    /*  84 */ "",
  4071.     /*  85 */ "",    /*  86 */ "",    /*  87 */ "",    /*  88 */ "",
  4072.     /*  89 */ "",    /*  90 */ "",    /*  91 */ "",    /*  92 */ "",
  4073.     /*  93 */ "",    /*  94 */ "",    /*  95 */ "",    /*  96 */ "",
  4074.     /*  97 */ "",    /*  98 */ "",    /*  99 */ "",    /* 100 */ "",
  4075.     /* 101 */ "",    /* 102 */ "",    /* 103 */ "",    /* 104 */ "",
  4076.     /* 105 */ "",    /* 106 */ "",    /* 107 */ "",    /* 108 */ "",
  4077.     /* 109 */ "",    /* 110 */ "",    /* 111 */ "",    /* 112 */ "",
  4078.     /* 113 */ "",    /* 114 */ "",    /* 115 */ "",    /* 116 */ "",
  4079.     /* 117 */ "",    /* 118 */ "",    /* 119 */ "",    /* 120 */ "",
  4080.     /* 121 */ "",    /* 122 */ "",    /* 123 */ "",    /* 124 */ "",
  4081.     /* 125 */ "",    /* 126 */ "",    /* 127 */ "",    /* 128 */ "",
  4082.     /* 129 */ "",    /* 130 */ "",    /* 131 */ "",    /* 132 */ "",
  4083.     /* 133 */ "",    /* 134 */ "",    /* 135 */ "",    /* 136 */ "",
  4084.     /* 137 */ "",    /* 138 */ "",    /* 139 */ "",    /* 140 */ "",
  4085.     /* 141 */ "",    /* 142 */ "",    /* 143 */ "",    /* 144 */ "",
  4086.     /* 145 */ "",    /* 146 */ "",    /* 147 */ "",    /* 148 */ "",
  4087.     /* 149 */ "",    /* 150 */ "",    /* 151 */ "",    /* 152 */ "",
  4088.     /* 153 */ "",    /* 154 */ "",    /* 155 */ "",    /* 156 */ "",
  4089.     /* 157 */ "",    /* 158 */ "",    /* 159 */ "",    /* 160 */ "",
  4090.     /* 161 */ "",    /* 162 */ "",    /* 163 */ "",    /* 164 */ "",
  4091.     /* 165 */ "",    /* 166 */ "",    /* 167 */ "",    /* 168 */ "",
  4092.     /* 169 */ "",    /* 170 */ "",    /* 171 */ "",    /* 172 */ "",
  4093.     /* 173 */ "",    /* 174 */ "",    /* 175 */ "",    /* 176 */ "",
  4094.     /* 177 */ "",    /* 178 */ "",    /* 179 */ "",    /* 180 */ "",
  4095.     /* 181 */ "",    /* 182 */ "",    /* 183 */ "",    /* 184 */ "",
  4096.     /* 185 */ "",    /* 186 */ "",    /* 187 */ "",    /* 188 */ "",
  4097.     /* 189 */ "",    /* 190 */ "",    /* 191 */ "",    /* 192 */ "",
  4098.     /* 193 */ "",    /* 194 */ "",    /* 195 */ "",    /* 196 */ "",
  4099.     /* 197 */ "",    /* 198 */ "",    /* 199 */ "",    /* 200 */ "",
  4100.     /* 201 */ "",    /* 202 */ "",    /* 203 */ "",    /* 204 */ "",
  4101.     /* 205 */ "",    /* 206 */ "",    /* 207 */ "",    /* 208 */ "",
  4102.     /* 209 */ "",    /* 210 */ "",    /* 211 */ "",    /* 212 */ "",
  4103.     /* 213 */ "",    /* 214 */ "",    /* 215 */ "",    /* 216 */ "",
  4104.     /* 217 */ "",    /* 218 */ "",    /* 219 */ "",    /* 220 */ "",
  4105.     /* 221 */ "",    /* 222 */ "",    /* 223 */ "",    /* 224 */ "",
  4106.     /* 225 */ "",    /* 226 */ "",    /* 227 */ "",    /* 228 */ "",
  4107.     /* 229 */ "",
  4108.     /* 230 */ "File not found (prospero)",
  4109.     /* 231 */ "Directory not found (prospero)",
  4110.     /* 232 */ "Symbolic links nested too deep (prospero)",
  4111.     /* 233 */ "Environment not initialized - source vfsetup.source then run vfsetup",
  4112.     /* 234 */ "Can't traverse an external file (prospero)",
  4113.     /* 235 */ "Forwarding chain is too long (prospero)",
  4114.     /* 236 */ "",    /* 237 */ "",    /* 238 */ "",    /* 239 */ "",
  4115.     /* 240 */ "",    /* 241 */ "",
  4116.     /* 242 */ "Authentication required (prospero server)",
  4117.     /* 243 */ "Not authorized (prospero server)",
  4118.     /* 244 */ "Not found (prospero server)",
  4119.     /* 245 */ "Bad version number (prospero server)",
  4120.     /* 246 */ "Not a directory (prospero server)",
  4121.     /* 247 */ "Already exists (prospero server)",
  4122.     /* 248 */ "Link with same name already exists (prospero server)",
  4123.     /* 249 */ "",    /* 250 */ "",
  4124.     /* 251 */ "Command not implemented on server (dirsrv)",
  4125.     /* 252 */ "Bad format for response (dirsrv)",
  4126.     /* 253 */ "Protocol error (prospero server)",
  4127.     /* 254 */ "Unspecified server failure (prospero server)",
  4128.     /* 255 */ "Generic Failure (prospero)"};
  4129.  
  4130. char    *p_warn_text[256] = {
  4131.     /*   0 */ "No warning",
  4132.     /*   1 */ "You are using an old version of this program",
  4133.     /*   2 */ "From server",
  4134.     /*   3 */ "Unrecognized line in response from server",
  4135.   /* 4-254 */ "", "", "", "", "", "", "", "", "", "", "", "", "",
  4136.   "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "",
  4137.   "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "",
  4138.   "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "",
  4139.   "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "",
  4140.   "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "",
  4141.   "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "",
  4142.   "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "",
  4143.   "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "",
  4144.   "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "",
  4145.   "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "",
  4146.   "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "",
  4147.   "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "",
  4148.   "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "",
  4149.   "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "",
  4150.     /* 255 */ ""};
  4151.  
  4152. #ifndef ARCHIE
  4153. perrmesg(prefix,no,text)
  4154.     char    *prefix;
  4155.     int        no;
  4156.     char    *text;
  4157.     {
  4158.     fprintf(stderr,"%s%s%s%s\n", (prefix ? prefix : ""),
  4159.         (no ? p_err_text[no] : p_err_text[perrno]),
  4160.         ((text ? (*text ? " - " : "") : 
  4161.           (!no && *p_err_string ? " - " : ""))),
  4162.         (text ? text : (no ? "" : p_err_string)));
  4163.     }
  4164.  
  4165. sperrmesg(buf,prefix,no,text)
  4166.     char    *buf;
  4167.     char    *prefix;
  4168.     int        no;
  4169.     char    *text;
  4170.     {
  4171.     sprintf(buf,"%s%s%s%s\n", (prefix ? prefix : ""),
  4172.         (no ? p_err_text[no] : p_err_text[perrno]),
  4173.         ((text ? (*text ? " - " : "") : 
  4174.           (!no && *p_err_string ? " - " : ""))),
  4175.         (text ? text : (no ? "" : p_err_string)));
  4176.     }
  4177.  
  4178. pwarnmesg(prefix,no,text)
  4179.     char    *prefix;
  4180.     int        no;
  4181.     char    *text;
  4182.     {
  4183.     fprintf(stderr,"%s%s%s%s\n", (prefix ? prefix : ""),
  4184.         (no ? p_warn_text[no] : p_warn_text[pwarn]),
  4185.         ((text ? (*text ? " - " : "") : 
  4186.           (!no && *p_warn_string ? " - " : ""))),
  4187.         (text ? text : (no ? "" : p_warn_string)));
  4188.     }
  4189.  
  4190. spwarnmesg(buf,prefix,no,text)
  4191.     char    *buf;
  4192.     char    *prefix;
  4193.     int        no;
  4194.     char    *text;
  4195.     {
  4196.     sprintf(buf,"%s%s%s%s\n", (prefix ? prefix : ""),
  4197.         (no ? p_warn_text[no] : p_warn_text[pwarn]),
  4198.         ((text ? (*text ? " - " : "") : 
  4199.           (!no && *p_warn_string ? " - " : ""))),
  4200.         (text ? text : (no ? "" : p_warn_string)));
  4201.     }
  4202. #endif
  4203. $EOD
  4204. $!
  4205. $CREATE [.archie]patchlevel.h
  4206. $DECK
  4207. /*
  4208.  * Archie v1.3
  4209.  *
  4210.  * History:
  4211.  *
  4212.  * 01/10/92 v1.3.1 - Release.
  4213.  * 01/09/92 v1.3 - Release.
  4214.  * 12/13/91      - added UCX support
  4215.  * 12/03/91      - added CUTCP support
  4216.  * 11/20/91 v1.2 - Release.
  4217.  * 11/18/91      - ported to DOS & OS/2
  4218.  * 11/12/91      - finally got to test under Multinet 3.0
  4219.  * 10/03/91      - replaced regex.c for oz
  4220.  * 09/25/91     - added Wollongong support
  4221.  * 08/30/91      - ported to VMS
  4222.  * 08/20/91 v1.1 - Major revisions
  4223.  * 07/31/91 v1.0 - Original
  4224.  */
  4225. $EOD
  4226. $!
  4227. $CREATE [.archie]pauthent.h
  4228. $DECK
  4229. /*
  4230.  * Copyright (c) 1989, 1990, 1991 by the University of Washington
  4231.  *
  4232.  * For copying and distribution information, please see the file
  4233.  * <copyright.h>.
  4234.  */
  4235.  
  4236. #include <copyright.h>
  4237.  
  4238. #define PFSA_UNAUTHENTICATED        1
  4239.  
  4240. struct pfs_auth_info {
  4241.     char            auth_type[100];
  4242.     char            authenticator[250];
  4243. };
  4244.  
  4245. typedef struct pfs_auth_info *PAUTH;
  4246. typedef struct pfs_auth_info PAUTH_ST;
  4247.  
  4248. PAUTH get_pauth();
  4249.  
  4250. #ifndef VMS
  4251. # ifndef IN_H
  4252. #  include <netinet/in.h>
  4253. #  define IN_H
  4254. # endif
  4255. #else
  4256. # ifndef _ARCHIE_VMS
  4257. #  include <vms.h>
  4258. # endif
  4259. #endif
  4260.  
  4261. struct client_info {
  4262.     int                ainfo_type;
  4263.     char            *auth_type;
  4264.     char            *authenticator;
  4265.     char            *userid;
  4266.     short            port;
  4267.     struct in_addr        haddr;
  4268.     struct pfs_auth_info    *previous;
  4269.     struct pfs_auth_info    *next;
  4270. };
  4271.  
  4272. typedef struct client_info *CINFO;
  4273. typedef struct client_info CINFO_ST;
  4274. $EOD
  4275. $!
  4276. $CREATE [.archie]pcompat.h
  4277. $DECK
  4278. /*
  4279.  * Copyright (c) 1989, 1990 by the University of Washington
  4280.  *
  4281.  * For copying and distribution information, please see the file
  4282.  * <copyright.h>.
  4283.  */
  4284.  
  4285. #include <copyright.h>
  4286.  
  4287. /* 
  4288.  * pcompat.h - Definitions for compatability library
  4289.  *
  4290.  * This file contains the defintions used by the compatability
  4291.  * library.  Among the definitions are the possible values for
  4292.  * pfs_disable_flag.  This file also contains the external 
  4293.  * declaration of that variable.  Note, however that the 
  4294.  * the module pfs_disable_flag.o is included in libpfs.a
  4295.  * because some of the routines in that library set it.
  4296.  * The only place it is checked, however, is in pfs_access, 
  4297.  * found in libpcompat.a
  4298.  *
  4299.  */
  4300.  
  4301. extern    int        pfs_default;
  4302. extern    int        pfs_enable;
  4303.  
  4304. /* Definitions for values of pfs_enable */
  4305. #define PMAP_DISABLE      0
  4306. #define PMAP_ENABLE       1
  4307. #define PMAP_COLON      2
  4308. #define PMAP_ATSIGN_NF      3
  4309. #define PMAP_ATSIGN      4
  4310.  
  4311. #define DISABLE_PFS(stmt) {int DpfStmp; DpfStmp = pfs_enable;\
  4312.                pfs_enable = PMAP_DISABLE; \
  4313.                stmt; \
  4314.                pfs_enable = DpfStmp;}
  4315.  
  4316. /* Definitions for PFS_ACCESS */
  4317. #define PFA_MAP           0  /* Map the file name only                       */
  4318. #define PFA_CREATE        1  /* Create file if not found                     */
  4319. #define PFA_CRMAP         2  /* Map file name.  Map to new name if not found */
  4320. #define PFA_RO            4  /* Access to file is read only                  */
  4321.  
  4322. #define check_pfs_default() if(pfs_default == -1) get_pfs_default()
  4323. $EOD
  4324. $!
  4325. $CREATE [.archie]perrno.h
  4326. $DECK
  4327. /*
  4328.  * Copyright (c) 1989, 1990 by the University of Washington
  4329.  *
  4330.  * For copying and distribution information, please see the file
  4331.  * <copyright.h>.
  4332.  */
  4333.  
  4334. #include <copyright.h>
  4335.  
  4336. /* this file and p_err_text.c should be updated simultaneously */
  4337.  
  4338. /*
  4339.  * perrno.h - definitions for perrno
  4340.  *
  4341.  * This file contains the declarations and defintions of of the external
  4342.  * error values in which errors are returned by the pfs and psrv
  4343.  * libraries.
  4344.  */
  4345.  
  4346. #define        P_ERR_STRING_SZ 100     /* Size of error string        */
  4347.  
  4348. extern int    perrno;
  4349. extern char    p_err_string[];
  4350. extern char    *p_err_text[];
  4351.  
  4352. extern int    pwarn;
  4353. extern char    p_warn_string[];
  4354. extern char    *p_warn_text[];
  4355.  
  4356. /* Error codes returned or found in verrno */
  4357.  
  4358. #ifndef PSUCCESS
  4359. #define    PSUCCESS        0
  4360. #endif
  4361.  
  4362. /* dirsend (perrno) */
  4363. #define DIRSEND_PORT_UNKN    1    /* DIRSRV UDP port unknown      */
  4364. #define DIRSEND_UDP_CANT    2    /* Can't open local UDP port    */
  4365. #define DIRSEND_BAD_HOSTNAME    3    /* Can't resolve hostname       */
  4366. #define DIRSEND_NOT_ALL_SENT    4    /* Didn't send entire message   */
  4367. #define DIRSEND_SELECT_FAILED    5    /* Select failed            */
  4368. #define DIRSEND_BAD_RECV    6    /* Recvfrom failed             */
  4369.  
  4370. /* reply */
  4371. #define REPLY_NOTSENT        11    /* Reply: sendto failed            */
  4372.  
  4373. /* vl_insert */
  4374. #define VL_INSERT_ALREADY_THERE    21    /* Link already exists            */
  4375. #define VL_INSERT_CONFLICT    22    /* Link exists with same name   */
  4376.  
  4377. /* ul_insert */
  4378. #define UL_INSERT_ALREADY_THERE 25    /* Link already exists        */
  4379. #define UL_INSERT_SUPERSEDING   26    /* Replacing existing link    */
  4380. #define UL_INSERT_POS_NOTFOUND  27    /* Prv entry not in dir->ulinks */
  4381.  
  4382. /* rd_vdir */
  4383. #define RVD_DIR_NOT_THERE    41    /* Temporary NOT_FOUND            */
  4384. #define RVD_NO_CLOSED_NS    42    /* Namespace not closed w/ object:: */
  4385. #define RVD_NO_NS_ALIAS        43    /* No alias for namespace NS#:      */
  4386. #define RVD_NS_NOT_FOUND    44    /* Specified namespace not found    */
  4387.  
  4388. /* pfs_access */
  4389. #define PFSA_AM_NOT_SUPPORTED   51      /* Access method not supported  */
  4390.  
  4391. /* pmap_cache */
  4392. #define PMC_DELETE_ON_CLOSE     55    /* Delete cached copy on close   */
  4393. #define PMC_RETRIEVE_FAILED     56      /* Unable to retrieve file       */
  4394.  
  4395. /* mk_vdir */
  4396. /* #define MKVD_ALREADY_EXISTS     61    /* Directory already exists      */
  4397. /* #define MKVD_NAME_CONFLICT    62    /* Link with name already exists */
  4398.  
  4399. /* vfsetenv */
  4400. #define VFSN_NOT_A_VS        65    /* Not a virtual system          */
  4401. #define VFSN_CANT_FIND_DIR    66    /* Not a virtual system          */
  4402.  
  4403. /* add_vlink */
  4404. /* #define ADDVL_ALREADY_EXISTS    71    /* Directory already exists      */
  4405. /* #define ADDVL_NAME_CONFLICT    72    /* Link with name already exists */
  4406.  
  4407. /* Local error codes on server */
  4408.  
  4409. /* dsrdir */
  4410. #define DSRDIR_NOT_A_DIRECTORY 111    /* Not a directory name        */
  4411. /* dsrfinfo */
  4412. #define DSRFINFO_NOT_A_FILE    121      /* Object not found             */
  4413. #define DSRFINFO_FORWARDED     122      /* Object has moved             */
  4414.  
  4415. /* Error codes that may be returned by various procedures               */
  4416. #define PFS_FILE_NOT_FOUND     230      /* File not found               */
  4417. #define PFS_DIR_NOT_FOUND      231      /* Directory in path not found  */
  4418. #define PFS_SYMLINK_DEPTH      232    /* Max sym-link depth exceeded  */
  4419. #define PFS_ENV_NOT_INITIALIZED    233    /* Can't read environment    */
  4420. #define PFS_EXT_USED_AS_DIR    234    /* Can't use externals as dirs  */
  4421. #define PFS_MAX_FWD_DEPTH      235    /* Exceeded max forward depth   */
  4422.  
  4423. /* Error codes returned by directory server                    */
  4424. /* some of these duplicate errors from individual routines     */
  4425. /* some of those error codes should be eliminated              */
  4426. #define DIRSRV_AUTHENT_REQ     242      /* Authentication required       */
  4427. #define DIRSRV_NOT_AUTHORIZED  243      /* Not authorized                */
  4428. #define DIRSRV_NOT_FOUND       244      /* Not found                     */
  4429. #define DIRSRV_BAD_VERS        245
  4430. #define DIRSRV_NOT_DIRECTORY   246
  4431. #define DIRSRV_ALREADY_EXISTS  247    /* Identical link already exists */
  4432. #define DIRSRV_NAME_CONFLICT   248    /* Link with name already exists */
  4433.  
  4434. #define DIRSRV_UNIMPLEMENTED   251      /* Unimplemented command         */
  4435. #define DIRSRV_BAD_FORMAT      252
  4436. #define DIRSRV_ERROR           253
  4437. #define DIRSRV_SERVER_FAILED   254      /* Unspecified server failure    */
  4438.  
  4439. #ifndef PFAILURE
  4440. #define    PFAILURE            255
  4441. #endif
  4442.  
  4443. /* Warning codes */
  4444.  
  4445. #define PNOWARN             0    /* No warning indicated         */
  4446. #define PWARN_OUT_OF_DATE     1    /* Software is out of date       */
  4447. #define PWARN_MSG_FROM_SERVER     2      /* Warning in p_warn_string      */
  4448. #define PWARN_UNRECOGNIZED_RESP  3    /* Unrecognized line in response */
  4449. #define PWARNING           255    /* Warning in p_warn_string      */
  4450. $EOD
  4451. $!
  4452. $CREATE [.archie]pfs.h
  4453. $DECK
  4454. /*
  4455.  * Copyright (c) 1989, 1990, 1991 by the University of Washington
  4456.  *
  4457.  * For copying and distribution information, please see the file
  4458.  * <copyright.h>.
  4459.  *
  4460.  * v1.2.0 - 11/19/91 (mmt) - added MSDOS & OS2 stuff
  4461.  * v1.1.2 - 08/30/91 (bpk) - added VMS support
  4462.  * v1.1.1 - 08/20/91 (bpk) - 4.2 -> 4.2B
  4463.  */
  4464.  
  4465. #include <copyright.h>
  4466.  
  4467. #ifdef VMS
  4468. # include <vms.h>
  4469. #else /* not VMS */
  4470. # ifndef _TYPES_
  4471. #  include <sys/types.h>
  4472. # endif /* _TYPES_ */
  4473. # ifndef IN_H
  4474. #  include <netinet/in.h> 
  4475. #  define IN_H
  4476. # endif
  4477. #endif /* VMS */
  4478.  
  4479. #ifndef NULL
  4480. # ifdef MSDOS
  4481. #  include <stdio.h>
  4482. # else
  4483. #  define NULL 0
  4484. # endif /* MSDOS */
  4485. #endif /* NULL */
  4486.  
  4487. #define        PFS_RELEASE    "Beta.4.2D"
  4488. /* moved up for vdir_init */
  4489. #define ZERO(p)        bzero((char *)(p), sizeof(*(p)))
  4490.  
  4491. /* General Definitions */
  4492.  
  4493. #define        MAX_PTXT_LEN    1250     /* Max length of PTEXT structure   */
  4494. #define        MAX_PTXT_HDR    32       /* Max offset for start            */
  4495. #define        P_ERR_STRING_SZ 100     /* Size of error string        */
  4496. #define        MAX_VPATH    1024     /* Max length of virtual pathname  */
  4497.  
  4498. /* Definition of text structure used to pass text around */
  4499.  
  4500. struct ptext {
  4501.     int            length;          /* Length of text (from start)    */
  4502.     char        *start;          /* Start of text            */
  4503.     char        dat[MAX_PTXT_LEN+2*MAX_PTXT_HDR];/* The data itself */
  4504.     unsigned long     mbz;          /* ZERO to catch runaway strings  */
  4505.     struct ptext    *previous;        /* Previous element in list       */
  4506.     struct ptext    *next;          /* Next element in linked list    */
  4507.     int            seq;          /* Sequence Number            */
  4508. };
  4509.  
  4510. typedef struct ptext *PTEXT;
  4511. typedef struct ptext PTEXT_ST;
  4512.  
  4513. /* Request structure: maintains information about server requests */
  4514. struct preq {
  4515.     int            cid;          /* Connection ID                  */
  4516.     short        priority;      /* Connection priority            */
  4517.     int            pf_priority;      /* Priority assigned by pri_func  */
  4518.     int            recv_tot;      /* Total # of packets received    */
  4519.     int            trns_tot;      /* Total # of packets to transmit */
  4520.     struct ptext    *cpkt;          /* Current packet being filled in */
  4521.     struct ptext    *recv;          /* Received packets               */
  4522.     struct ptext    *trns;          /* Transmitted packets            */
  4523.     int            rcvd_thru;      /* Received all packets through # */
  4524.     struct preq        *previous;        /* Previous element in list       */
  4525.     struct preq        *next;          /* Next element in linked list    */
  4526.     struct sockaddr_in    fromto;       /* Sender/Destination            */
  4527. };
  4528.  
  4529. typedef struct preq *PREQ;
  4530. typedef struct preq PREQ_ST;
  4531.  
  4532.  
  4533. /* Definition of structure containing information on virtual link */
  4534.  
  4535. struct vlink {
  4536.     int            dontfree;      /* Flag: don't free this link     */
  4537.     char        *name;          /* Component of path name        */
  4538.     char        linktype;      /* L = Link, U = Union, N= Native */
  4539.     int            expanded;      /* Has a union link been expanded */
  4540.     char        *type;            /* Type of object pointed to      */
  4541.     struct vlink    *filters;      /* Filters associated with link   */
  4542.     struct vlink    *replicas;      /* Replicas (* see comment below) */
  4543.     char        *hosttype;      /* Type of hostname            */
  4544.     char        *host;          /* Files physical location        */
  4545.     char        *nametype;      /* Type of filename            */
  4546.     char        *filename;      /* System level filename        */
  4547.     long        version;      /* Version number of destination  */
  4548.     long        f_magic_no;      /* File's magic number        */
  4549.     struct acl        *acl;          /* ACL for link            */
  4550.     long        dest_exp;      /* Expiration for dest of link    */
  4551.     long        link_exp;      /* Expiration of link itself      */
  4552.     char        *args;          /* Arguments if this is a filter  */
  4553.     struct pattrib    *lattrib;      /* Attributes associated w/ link  */
  4554.     struct pfile    *f_info;      /* Info to be assoicated w/ file  */
  4555.     struct vlink    *previous;        /* Previous elt in linked list    */
  4556.     struct vlink    *next;          /* Next element in linked list    */
  4557. };
  4558.  
  4559. typedef struct vlink *VLINK;
  4560. typedef struct vlink VLINK_ST;
  4561.  
  4562. /* * Note that vlink->replicas is not really a list of replicas of the  */
  4563. /*   object.  Instead, it is a list of the objects returned during name */
  4564. /*   resolution that share the same name as the current object.  Such   */
  4565. /*   an object should only be considered a replica if it also shares    */
  4566. /*   the same non-zero magic number.                                    */
  4567.  
  4568. /* Definition of structure continiaing virtual directory information    */
  4569.  
  4570. struct vdir {
  4571.     int            version;      /* Version of local directory fmt  */
  4572.     int            inc_native;      /* Include the native directory    */
  4573.     long        magic_no;      /* Magic number of current file    */
  4574.     struct acl        *dacl;            /* Default acl for links in dir    */
  4575.     struct pfile    *f_info;      /* Directory file info             */
  4576.     struct vlink    *links;          /* The directory entries         */
  4577.     struct vlink    *lastlink;      /* Last directory entry            */
  4578.     struct vlink    *ulinks;      /* The entries for union links     */
  4579.     struct vdir        *previous;        /* Previous element in linked list */
  4580.     struct vdir        *next;          /* Next element in linked list     */
  4581. };
  4582.  
  4583. typedef struct vdir *VDIR;
  4584. typedef struct vdir VDIR_ST;
  4585.  
  4586. /* Initialize directory */
  4587. #define vdir_init(dir)  ZERO(dir)
  4588. /* XXX: was
  4589.  
  4590.   dir->version = 0;     dir->inc_native = 0; \
  4591.   dir->magic_no = 0;    dir->f_info = NULL; \
  4592.   dir->links = NULL;    dir->lastlink = NULL; \
  4593.   dir->ulinks = NULL;   dir->dacl = NULL; \
  4594.   dir->previous = NULL; dir->next = NULL;
  4595. */
  4596.  
  4597. #define vdir_copy(d1,d2) d2->version = d1->version; \
  4598.                          d2->inc_native = d1->inc_native; \
  4599.                          d2->magic_no = d1->magic_no; \
  4600.                  d2->f_info = d1->f_info; \
  4601.                          d2->links = d1->links; \
  4602.                          d2->lastlink = d1->lastlink; \
  4603.                          d2->ulinks = d1->ulinks; \
  4604.                          d2->dacl = d1->dacl; \
  4605.                          d2->previous = d1->previous; \
  4606.                          d2->next = d1->next; 
  4607.                          
  4608. /* Values of ->inc_native in vdir structure */
  4609. #define VDIN_REALONLY    -1   /* Include native files, but not . and ..       */
  4610. #define VDIN_NONATIVE     0   /* Do not include files from native directory   */
  4611. #define VDIN_INCLNATIVE     1   /* Include files from native directory          */
  4612. #define VDIN_NATIVEONLY  2   /* All entries in directory are from native dir */
  4613. #define VDIN_PSEUDO      3   /* Directory is not real                        */
  4614.  
  4615.  
  4616. /* Definition of structure containing information on a specific file */
  4617.  
  4618. union avalue {
  4619.     char        *ascii;        /* Character string                */
  4620.     struct vlink    *link;        /* A link               */
  4621. };
  4622.  
  4623.  
  4624. struct pattrib {
  4625.     char        precedence;    /* Precedence for link attribute   */
  4626.     char        *aname;        /* Name of the attribute           */
  4627.     char        *avtype;    /* Type of the attribute value     */
  4628.     union avalue    value;        /* Attribute Value                 */
  4629.     struct pattrib    *previous;      /* Previous element in linked list */
  4630.     struct pattrib    *next;        /* Next element in linked list     */
  4631. };
  4632.  
  4633. typedef struct pattrib *PATTRIB;
  4634. typedef struct pattrib PATTRIB_ST;
  4635.  
  4636. #define     ATR_PREC_OBJECT  'O'   /* Authoritative answer for object */
  4637. #define     ATR_PREC_LINK    'L'   /* Authoritative answer for link   */
  4638. #define     ATR_PREC_CACHED  'C'   /* Object info cached w/ link      */
  4639. #define     ATR_PREC_REPLACE 'R'   /* From link (replaces O)          */
  4640. #define     ATR_PREC_ADD     'A'   /* From link (additional value)    */
  4641.  
  4642. /* **** Incomplete **** */
  4643. struct pfile {
  4644.     int            version;      /* Version of local finfo format   */
  4645.     long        f_magic_no;      /* Magic number of current file    */
  4646.     long        exp;          /* Expiration date of timeout      */
  4647.     long        ttl;          /* Time to live after reference    */
  4648.     long        last_ref;      /* Time of last reference          */
  4649.     struct vlink    *forward;      /* List of forwarding pointers     */
  4650.     struct vlink    *backlinks;      /* Partial list of back links      */
  4651.     struct pattrib    *attributes;      /* List of file attributes         */
  4652.     struct pfile    *previous;        /* Previous element in linked list */
  4653.     struct pfile    *next;          /* Next element in linked list     */
  4654. };
  4655.  
  4656. typedef struct pfile *PFILE;
  4657. typedef struct pfile PFILE_ST;
  4658.  
  4659. /* Definition of structure contining an access control list entry */
  4660.  
  4661. struct acl {
  4662.     int            acetype;      /* Access Contol Entry type       */
  4663.     char        *atype;           /* Authentication type            */
  4664.     char        *rights;          /* Rights                         */
  4665.     char        *principals;      /* Authorized principals          */
  4666.     struct restrict     *restrictions;    /* Restrictions on use            */
  4667.     struct acl        *previous;        /* Previous elt in linked list    */
  4668.     struct acl        *next;          /* Next element in linked list    */
  4669. };
  4670. typedef struct acl *ACL;
  4671. typedef struct acl ACL_ST;
  4672.  
  4673. #define ACL_NONE        0         /* Nobody authorized by ths entry */
  4674. #define ACL_DEFAULT        1         /* System default                 */
  4675. #define ACL_SYSTEM        2         /* System administrator           */
  4676. #define ACL_OWNER               3         /* Directory owner                */
  4677. #define ACL_DIRECTORY           4         /* Same as directory              */
  4678. #define ACL_ANY                 5         /* Any user                       */
  4679. #define ACL_AUTHENT             6         /* Authenticated principal        */
  4680. #define ACL_LGROUP              7         /* Local group                    */
  4681. #define ACL_GROUP               8         /* External group                 */
  4682. #define ACL_ASRTHOST            10        /* Check host and asserted userid */
  4683. #define ACL_TRSTHOST            11        /* ASRTHOST from privileged port  */
  4684.  
  4685.  
  4686. /* Definition of structure contining access restrictions */
  4687. /* for future extensions                                 */
  4688. struct restrict {
  4689.     struct acl        *previous;        /* Previous elt in linked list    */
  4690.     struct acl        *next;          /* Next element in linked list    */
  4691. };
  4692.  
  4693. /* Definitions for send_to_dirsrv */
  4694. #define    CLIENT_DIRSRV_TIMEOUT        4    /* time between retries      */
  4695. #define CLIENT_DIRSRV_BACKOFF(x)  (2 * x)    /* Backoff algorithm         */
  4696. #define CLIENT_DIRSRV_RETRY        3    /* retry this many times     */
  4697.  
  4698. /* Definitions for rd_vlink and rd_vdir */
  4699. #define        SYMLINK_NESTING 10       /* Max nesting depth for sym links */
  4700.  
  4701. /* Definition fo check_acl */
  4702. #define        ACL_NESTING     10       /* Max depth for ACL group nesting */
  4703.  
  4704. /* Flags for mk_vdir */
  4705. #define         MKVD_LPRIV     1   /* Minimize privs for creator in new ACL    */
  4706.  
  4707. /* Flags for get_vdir */
  4708. #define         GVD_UNION      0    /* Do not expand union links              */
  4709. #define      GVD_EXPAND     1   /* Expand union links locally             */
  4710. #define         GVD_LREMEXP    3   /* Request remote expansion of local links   */
  4711. #define         GVD_REMEXP     7   /* Request remote expansion of all links     */
  4712. #define         GVD_VERIFY     8    /* Only verify args are for a directory      */
  4713. #define      GVD_FIND       16   /* Stop expanding when match is found        */
  4714. #define         GVD_ATTRIB    32   /* Request attributes from remote server     */
  4715. #define         GVD_NOSORT       64   /* Do not sort links when adding to dir      */
  4716.  
  4717. /* Flags for rd_vdir */
  4718. #define         RVD_UNION      GVD_UNION
  4719. #define         RVD_EXPAND     GVD_EXPAND 
  4720. #define         RVD_LREMEXP    GVD_LREMEXP
  4721. #define         RVD_REMEXP     GVD_REMEXP
  4722. #define         RVD_DFILE_ONLY GVD_VERIFY /* Only return ptr to dir file        */
  4723. #define      RVD_FIND       GVD_FIND   
  4724. #define      RVD_ATTRIB     GVD_ATTRIB
  4725. #define         RVD_NOSORT        GVD_NOSORT
  4726. #define         RVD_NOCACHE    128
  4727.  
  4728. /* Flags for add_vlink */
  4729. #define         AVL_UNION      1   /* Link is a union link                      */
  4730.  
  4731. /* Flags for vl_insert */
  4732. #define         VLI_NOCONFLICT 0   /* Do not insert links w/ conflicting names  */
  4733. #define      VLI_ALLOW_CONF 1   /* Allow links with conflicting names        */
  4734. #define         VLI_NOSORT     2   /* Allow conflicts and don't sort            */
  4735.  
  4736. /* Flags for mapname */
  4737. #define      MAP_READWRITE  0   /* Named file to be read and written         */
  4738. #define         MAP_READONLY   1   /* Named file to be read only                */
  4739.  
  4740. /* Flags for modify_acl */
  4741. #define         MACL_NOSYSTEM   0x01
  4742. #define      MACL_NOSELF     0x02
  4743. #define      MACL_DEFAULT    0x08
  4744. #define      MACL_SET        0x0C
  4745. #define      MACL_INSERT     0x14
  4746. #define      MACL_DELETE     0x10
  4747. #define      MACL_ADD        0x1C
  4748. #define      MACL_SUBTRACT   0x18
  4749. #define      MACL_LINK       0x00
  4750. #define      MACL_DIRECTORY  0x20
  4751. #define      MACL_OBJECT     0x60
  4752. #define      MACL_INCLUDE    0x40
  4753.  
  4754. #define      MACL_OP    (MACL_DEFAULT|MACL_SET|MACL_INSERT|\
  4755.              MACL_DELETE|MACL_ADD|MACL_SUBTRACT)
  4756.  
  4757. #define      MACL_OTYPE (MACL_LINK|MACL_DIRECTORY|MACL_OBJECT|MACL_INCLUDE)
  4758.  
  4759. /* Access methods returned by Pget_am */
  4760. #define P_AM_ERROR            0
  4761. #define P_AM_FTP            1
  4762. #define P_AM_AFTP            2  /* Anonymous FTP  */
  4763. #define P_AM_NFS            4
  4764. #define P_AM_KNFS            8  /* Kerberized NFS */
  4765. #define P_AM_AFS               16
  4766.  
  4767. /* Return codes */
  4768.  
  4769. #define        PSUCCESS    0
  4770. #define        PFAILURE    255
  4771.  
  4772. /* Hush up warnings.  */
  4773. void vllfree();
  4774.  
  4775. /* Procedures in libpfs.a */
  4776.  
  4777. char *pget_wdhost(), *pget_wdfile(), *pget_wd(), *pget_hdhost();
  4778. char *pget_hdfile(), *pget_hd(), *pget_rdhost(), *pget_rdfile();
  4779. char *pget_dhost(), *pget_dfile(), *pget_vsname(), *nlsindex();
  4780. char *sindex(), *strtok(), *nxtline(), *unquote(), *stcopy();
  4781. char *stcopyr(), *readheader(), *month_sname();
  4782.  
  4783. long        asntotime();
  4784. void        procquery();
  4785.  
  4786. PTEXT        ptalloc();
  4787. PTEXT        dirsend();
  4788. void        ptfree();
  4789. void        ptlfree();
  4790.  
  4791. PREQ        pralloc();
  4792. PREQ        get_next_request();
  4793.  
  4794. VLINK        rd_slink();
  4795. VLINK        rd_vlink();
  4796. VLINK        vl_delete();
  4797. VLINK        vlalloc();
  4798. VLINK        vlcopy();
  4799. void        vlfree();
  4800.  
  4801. PFILE        pfalloc();
  4802.  
  4803. PATTRIB         parse_attribute();
  4804. PATTRIB         atalloc();
  4805. PATTRIB     pget_at();
  4806. void        atfree();
  4807. void        atlfree();
  4808.  
  4809. ACL             acalloc();
  4810. ACL             get_acl();
  4811.  
  4812. void        stfree();
  4813.  
  4814. /* Miscellaneous useful definitions */
  4815. #ifndef TRUE
  4816. #define TRUE        1
  4817. #define FALSE        0
  4818. #endif
  4819.  
  4820. #define AUTHORIZED      1
  4821. #define NOT_AUTHORIZED  0
  4822. #define NEG_AUTHORIZED  -1
  4823.  
  4824. #ifndef NULL
  4825. #define NULL        0
  4826. #endif
  4827.  
  4828. #define FAILED        -1
  4829. $EOD
  4830. $!
  4831. $CREATE [.archie]pmachine.h
  4832. $DECK
  4833. /*
  4834.  * Miscellaneous system dependencies.
  4835.  *
  4836.  * I kept the name pmachine.h because it was already in all of the files...this
  4837.  * barely resembles the pmachine.h that comes with the real Prospero, tho.
  4838.  *
  4839.  * v1.2.1 - 12/13/91 (bpk) - added 3b2
  4840.  * v1.2.0 - 11/19/91 (mmt) - added MSDOS & OS2 stuff
  4841.  */
  4842.  
  4843. #ifdef u3b2
  4844. # define USG
  4845. # define NOREGEX
  4846. # define MAXPATHLEN 1024    /* There's no maxpathlen in any 3b2 .h file.  */
  4847. #endif
  4848.  
  4849. #ifdef hpux
  4850. # ifndef bcopy
  4851. #  define FUNCS            /* HP/UX 8.0 has the fns.  */
  4852. # endif
  4853. # define NOREGEX
  4854. # define NEED_STRING_H
  4855. #endif
  4856.  
  4857. #if defined(USG) || defined(SYSV)
  4858. # define FUNCS
  4859. #endif
  4860.  
  4861. #ifdef ISC
  4862. # define FUNCS
  4863. # define STRSPN
  4864. # define NOREGEX
  4865. #endif
  4866.  
  4867. #ifdef CUTCP
  4868. # define FUNCS
  4869. # define NOREGEX
  4870. # define NEED_STRING_H
  4871. # define SELECTARG int
  4872. # define MSDOS
  4873. #endif
  4874.  
  4875. #ifdef OS2
  4876. # define NOREGEX
  4877. # include <pctcp.h>
  4878. #endif
  4879. #ifdef MSDOS
  4880. # define USG
  4881. # define NOREGEX
  4882. # include <string.h>
  4883. # include <stdlib.h>
  4884. #endif
  4885.  
  4886. #ifdef _AIX
  4887. # ifdef u370
  4888. #  define FUNCS
  4889. # endif /* AIX/370 */
  4890. # define _NONSTD_TYPES
  4891. # define _BSD_INCLUDES
  4892. # define NEED_STRING_H
  4893. # define NEED_SELECT_H
  4894. # define NEED_TIME_H
  4895. #endif
  4896.  
  4897. /* ==== */
  4898. #ifdef FUNCS
  4899. # define index        strchr
  4900. /* According to mycroft. */
  4901. # ifdef _IBMR2
  4902. char *strchr();
  4903. # endif
  4904. # define rindex        strrchr
  4905. # ifndef AUX
  4906. #  define bcopy(a,b,n)    memcpy(b,a,n)
  4907. #  define bzero(a,n)    memset(a,0,n)
  4908. # ifdef _IBMR2
  4909. char *memset();
  4910. # endif
  4911. # endif
  4912. #endif
  4913.  
  4914. #if defined(_IBMR2) || defined(_BULL_SOURCE)
  4915. # define NEED_SELECT_H
  4916. #endif
  4917. #if defined(USG) || defined(UTS)
  4918. # define NEED_STRING_H
  4919. #endif
  4920. #if defined(USG) || defined(UTS) || defined(AUX)
  4921. # define NEED_TIME_H
  4922. #endif
  4923.  
  4924. #ifdef VMS
  4925. /* Get the system status stuff.  */
  4926. # include <ssdef.h>
  4927. #endif /* VMS */
  4928.  
  4929. /*
  4930.  * FD_SET: lib/pfs/dirsend.c, user/vget/ftp.c
  4931.  */
  4932. #ifndef CUTCP
  4933.  
  4934. #define SELECTARG fd_set
  4935. #if !defined(FD_SET) && !defined(VMS) && !defined(NEED_SELECT_H)
  4936. #define    FD_SETSIZE    32
  4937. #define    FD_SET(n, p)    ((p)->fds_bits[(n)/NFDBITS] |= (1 << ((n) % NFDBITS)))
  4938. #define    FD_CLR(n, p)    ((p)->fds_bits[(n)/NFDBITS] &= ~(1 << ((n) % NFDBITS)))
  4939. #define    FD_ISSET(n, p)    ((p)->fds_bits[(n)/NFDBITS] & (1 << ((n) % NFDBITS)))
  4940. #define FD_ZERO(p)    bzero((char *)(p), sizeof(*(p)))
  4941. #endif
  4942.  
  4943. #endif /* not CUTCP */
  4944. $EOD
  4945. $!
  4946. $CREATE [.archie]pprot.h
  4947. $DECK
  4948. /*
  4949.  * Copyright (c) 1989, 1990, 1991 by the University of Washington
  4950.  *
  4951.  * For copying and distribution information, please see the file
  4952.  * <copyright.h>.
  4953.  *
  4954.  * v1.2.0 - 11/19/91 (mmt) - added MSDOS & OS2 stuff
  4955.  */
  4956.  
  4957. #include <copyright.h>
  4958.  
  4959. #ifndef MAXPATHLEN
  4960. # ifdef VMS
  4961. #  define MAXPATHLEN 32
  4962. # else /* not VMS */
  4963. #  if defined(MSDOS) && !defined(OS2)
  4964. #   define MAXPATHLEN 255
  4965. #  else /* not MSDOS */
  4966. #   ifdef ISC
  4967. #    define MAXPATHLEN 512
  4968. #   else /* not Interactive..normal! (gasp) */
  4969. #    include <sys/param.h>
  4970. #   endif /* ISC */
  4971. #  endif /* MSDOS && !OS2 */
  4972. # endif /* VMS */
  4973. #endif
  4974.  
  4975. /* Protocol Definitions */
  4976.  
  4977. #define           VFPROT_VNO    1      /* Protocol Version Number           */
  4978.  
  4979. #define           DIRSRV_PORT      1525   /* Server port used if not in srvtab */
  4980. #define        PROSPERO_PORT    191    /* Officially assigned prived port   */
  4981. #define           PROS_FIRST_PRIVP 901    /* First privileged port to try      */
  4982. #define        PROS_NUM_PRIVP   20     /* Number of privileged ports to try */
  4983.  
  4984. #define           MAXPKT            1024   /* Max size of response from server  */
  4985. #define           SEQ_SIZE        32     /* Max size of sequence text in resp */ 
  4986. #define           MAX_DIR_LINESIZE 160+MAXPATHLEN /* Max linesize in directory */
  4987.  
  4988. #define           MAX_FWD_DEPTH    20     /* Max fwd pointers to follow        */
  4989.  
  4990. #define S_AD_SZ        sizeof(struct sockaddr_in)
  4991.  
  4992. /* Replacement for strtok that doesn't keep state.  Both the variable  */
  4993. /* S and the variable S_next must be defined.  To initialize, assign   */
  4994. /* the string to be stepped through to S_next, then call get_token on  */
  4995. /* S.  The first token will be in S, and S_next will point to the next */
  4996. /* token.  Like strtok, this macro does modify the string passed to it */
  4997. #define get_token(S,C) \
  4998.     S = S/**/_next; \
  4999.     if(S) { \
  5000.      while(*S == C) S++; \
  5001.      S/**/_next = index(S,C); \
  5002.      if(S/**/_next) *(S/**/_next++) = '\0'; \
  5003.      if(!*S) S = NULL; \
  5004.     }
  5005.  
  5006.  
  5007. $EOD
  5008. $!
  5009. $CREATE [.archie]procquery.c
  5010. $DECK
  5011. /*
  5012.  * procquery.c : Routines for processing results from Archie
  5013.  *
  5014.  * Originally part of the Prospero Archie client by Cliff Neuman (bcn@isi.edu).
  5015.  * Modified by Brendan Kehoe (brendan@cs.widener.edu).
  5016.  * Re-modified by George Ferguson (ferguson@cs.rochester.edu).
  5017.  *
  5018.  * Copyright (c) 1991 by the University of Washington
  5019.  *
  5020.  * For copying and distribution information, please see the file
  5021.  * <copyright.h>.
  5022.  *
  5023.  * v1.2.2 - 11/19/91 (mmt) - added MSDOS & OS2 stuff
  5024.  * v1.2.1 - 10/18/91 (bpk) - warning stuff
  5025.  * v1.2.0 - 09/20/91 (bpk) - VMS under Multinet 3.0 too
  5026.  * v1.1.1 - 08/20/91 (bpk) - took out archie_query from error msg
  5027.  */
  5028. #include <copyright.h>
  5029. #include <stdio.h>
  5030. #include <pfs.h>
  5031. #include <perrno.h>
  5032. #include <pmachine.h>
  5033. #include <archie.h>
  5034.  
  5035. #ifdef NEED_TIME_H
  5036. # include <time.h>
  5037. #else
  5038. # ifndef VMS
  5039. #  include <sys/time.h>
  5040. # endif
  5041. #endif
  5042.  
  5043. extern int client_dirsrv_timeout,client_dirsrv_retry;    /* dirsend.c */
  5044. extern char *progname;
  5045.  
  5046.  
  5047. /*
  5048.  * Functions defined here
  5049.  */
  5050. void display_link(), procquery();
  5051.  
  5052. /*
  5053.  * Data defined here
  5054.  */
  5055. extern int pwarn, perrno;
  5056. #ifdef DEBUG
  5057. int pfs_debug;
  5058. #endif
  5059. static struct tm *presenttime;
  5060. static char lastpath[MAX_VPATH] = "\001";
  5061. static char lasthost[MAX_VPATH] = "\001";
  5062.  
  5063. /*    -    -    -    -    -    -    -    -    */
  5064. /*
  5065.  * display_link : Prints the contents of the given virtual link. If
  5066.  *    listflag is 0, then this uses last{host,path} to save state
  5067.  *    between calls for a less verbose output. If listflag is non-zero
  5068.  *    then all information is printed every time.
  5069.  */
  5070. void
  5071. display_link(l,listflag)
  5072. VLINK l;
  5073. int listflag;
  5074. {
  5075.     PATTRIB     ap;
  5076.     char    linkpath[MAX_VPATH];
  5077.     int        dirflag = 0;
  5078. #ifdef MSDOS
  5079.     unsigned long size = 0L;
  5080. #else
  5081.     int        size = 0;
  5082. #endif
  5083.     char    *modes = "";
  5084.     char    archie_date[20];
  5085.     char    *gt_date = "";
  5086.     int        gt_year = 0;
  5087.     int        gt_mon = 0;
  5088.     int        gt_day = 0;
  5089.     int        gt_hour = 0;
  5090.     int        gt_min = 0;
  5091.     
  5092.     /* Initialize local buffers */
  5093.     *archie_date = '\0';
  5094.  
  5095.     /* Remember if we're looking at a directory */
  5096.     if (sindex(l->type,"DIRECTORY"))
  5097.     dirflag = 1;
  5098.     else
  5099.     dirflag = 0;
  5100.     
  5101.     /* Extract the linkpath from the filename */
  5102.     strcpy(linkpath,l->filename);
  5103.     *(linkpath + (strlen(linkpath) - strlen(l->name) - 1)) = '\0';
  5104.     
  5105.     /* Is this a new host? */
  5106.     if (strcmp(l->host,lasthost) != 0) {
  5107.     if (!listflag)
  5108.         printf("\nHost %s\n\n",l->host);
  5109.     strcpy(lasthost,l->host);
  5110.     *lastpath = '\001';
  5111.     }
  5112.     
  5113.     /* Is this a new linkpath (location)? */
  5114.     if(strcmp(linkpath,lastpath) != 0) {
  5115.     if (!listflag)
  5116.         printf("    Location: %s\n",(*linkpath ? linkpath : "/"));
  5117.     strcpy(lastpath,linkpath);
  5118.     }
  5119.     
  5120.     /* Parse the attibutes of this link */
  5121.     for (ap = l->lattrib; ap; ap = ap->next) {
  5122.     if (strcmp(ap->aname,"SIZE") == 0) {
  5123. #ifdef MSDOS
  5124.         sscanf(ap->value.ascii,"%lu",&size);
  5125. #else
  5126.         sscanf(ap->value.ascii,"%d",&size);
  5127. #endif
  5128.     } else if(strcmp(ap->aname,"UNIX-MODES") == 0) {
  5129.         modes = ap->value.ascii;
  5130.     } else if(strcmp(ap->aname,"LAST-MODIFIED") == 0) {
  5131.         gt_date = ap->value.ascii;
  5132.         sscanf(gt_date,"%4d%2d%2d%2d%2d",>_year,
  5133.            >_mon, >_day, >_hour, >_min);
  5134.         if ((12 * (presenttime->tm_year + 1900 - gt_year) + 
  5135.                     presenttime->tm_mon - gt_mon) > 6) 
  5136.         sprintf(archie_date,"%s %2d %4d",month_sname(gt_mon),
  5137.             gt_day, gt_year);
  5138.         else
  5139.         sprintf(archie_date,"%s %2d %02d:%02d",month_sname(gt_mon),
  5140.              gt_day, gt_hour, gt_min);
  5141.     }
  5142.     }
  5143.     
  5144.     /* Print this link's information */
  5145.     if (listflag)
  5146. #if defined(MSDOS)
  5147.     printf("%s %6lu %s %s%s\n",gt_date,size,l->host,l->filename,
  5148.            (dirflag ? "/" : ""));
  5149. #else
  5150.     printf("%s %6d %s %s%s\n",gt_date,size,l->host,l->filename,
  5151.            (dirflag ? "/" : ""));
  5152. #endif
  5153.     else
  5154. #ifdef MSDOS
  5155.     printf("      %9s %s %10lu  %s  %s\n",(dirflag ? "DIRECTORY" : "FILE"),
  5156.                     modes,size,archie_date,l->name);
  5157. #else
  5158.     printf("      %9s %s %10d  %s  %s\n",(dirflag ? "DIRECTORY" : "FILE"),
  5159.                     modes,size,archie_date,l->name);
  5160. #endif /* MSDOS */
  5161.  
  5162.  
  5163.     /* Free the attibutes */
  5164.     atlfree(l->lattrib);
  5165.     l->lattrib = NULL;
  5166. }
  5167.  
  5168. /*    -    -    -    -    -    -    -    -    */
  5169. /*
  5170.  * procquery : Process the given query and display the results. If
  5171.  *    sortflag is non-zero, then the results are sorted by increasing
  5172.  *    date, else by host/filename. If listflag is non-zero then each
  5173.  *    entry is printed on a separate, complete line. Note that listflag
  5174.  *    is ignored by xarchie.
  5175.  */
  5176. void
  5177. procquery(host,str,max_hits,offset,query_type,sortflag,listflag)
  5178. char *host,*str;
  5179. int max_hits,offset;
  5180. char query_type;
  5181. int sortflag,listflag;
  5182. {
  5183.     VLINK l;
  5184.     long now;
  5185.     extern int rdgram_priority;
  5186.  
  5187.     /* initialize data structures for this query */
  5188.     (void)time(&now);
  5189.     presenttime = localtime(&now);
  5190.  
  5191.     /* Do the query */
  5192.     if (sortflag == 1)
  5193.     l = archie_query(host,str,max_hits,offset,query_type,AQ_INVDATECMP,0);
  5194.     else
  5195.     l = archie_query(host,str,max_hits,offset,query_type,NULL,0);
  5196.  
  5197.     /* Error? */
  5198.     if (perrno != PSUCCESS) {
  5199.     if (p_err_text[perrno]) {
  5200.         if (*p_err_string)
  5201.         fprintf(stderr, "%s: failed: %s - %s\n", progname,
  5202.                 p_err_text[perrno], p_err_string);
  5203.         else
  5204.             fprintf(stderr, "%s failed: %s\n", progname, p_err_text[perrno]);
  5205.     } else
  5206.         fprintf(stderr, "%s failed: Undefined error %d (prospero)", perrno);
  5207.     }
  5208.  
  5209.     /* Warning? */
  5210.     if (pwarn != PNOWARN) {
  5211.     if (*p_warn_string)
  5212.         fprintf(stderr, "%s: Warning! %s - %s\n", progname,
  5213.         p_warn_text[pwarn], p_warn_string);
  5214.     else
  5215.         fprintf(stderr, "%s: Warning! %s\n", progname, p_warn_text[pwarn]);
  5216.     }
  5217.  
  5218.  
  5219.     /* Display the results */
  5220.  
  5221.     if (l == (VLINK)NULL && pwarn == PNOWARN && perrno == PSUCCESS) {
  5222.     if (! listflag) puts ("No matches.");
  5223.     exit (1);
  5224.     }
  5225.  
  5226.     *lasthost = '\001';
  5227.     *lastpath = '\001';
  5228.     while (l != NULL) {
  5229.     display_link(l,listflag);
  5230.     l = l->next;
  5231.     }
  5232. }
  5233. $EOD
  5234. $!
  5235. $CREATE [.archie]ptalloc.c
  5236. $DECK
  5237. /*
  5238.  * Copyright (c) 1989, 1990, 1991 by the University of Washington
  5239.  *
  5240.  * For copying and distribution information, please see the file
  5241.  * <copyright.h>.
  5242.  *
  5243.  * v1.2.0 - 11/19/91 (mmt) - added MSDOS & OS2 stuff
  5244.  */
  5245.  
  5246. #include <copyright.h>
  5247. #include <stdio.h>
  5248.  
  5249. #include <pfs.h>
  5250. #include <pmachine.h> /* for correct definition of ZERO */
  5251. #ifdef MSDOS
  5252. # define free _pfree   /* otherwise we get conflicts with free() */
  5253. #endif
  5254.  
  5255. static PTEXT    free = NULL;
  5256. int         ptext_count = 0;
  5257. int        ptext_max = 0;
  5258.  
  5259. /*
  5260.  * ptalloc - allocate and initialize ptext structure
  5261.  *
  5262.  *    PTALLOC returns a pointer to an initialized structure of type
  5263.  *    PTEXT.  If it is unable to allocate such a structure, it
  5264.  *    returns NULL.
  5265.  */
  5266. PTEXT
  5267. ptalloc()
  5268.     {
  5269.     PTEXT    vt;
  5270.     if(free) {
  5271.         vt = free;
  5272.         free = free->next;
  5273.     }
  5274.     else {
  5275.         vt = (PTEXT) malloc(sizeof(PTEXT_ST));
  5276.         if (!vt) return(NULL);
  5277.         ptext_max++;
  5278.     }
  5279.     ptext_count++;
  5280.  
  5281.     /* nearly all parts are 0 [or NULL] */
  5282.     ZERO(vt);
  5283.     /* The offset is to leave room for additional headers */
  5284.     vt->start = vt->dat + MAX_PTXT_HDR;
  5285.  
  5286.     return(vt);
  5287.     }
  5288.  
  5289. /*
  5290.  * ptfree - free a VTEXT structure
  5291.  *
  5292.  *    VTFREE takes a pointer to a VTEXT structure and adds it to
  5293.  *    the free list for later reuse.
  5294.  */
  5295. void
  5296. ptfree(vt)
  5297.     PTEXT    vt;
  5298.     {
  5299.     vt->next = free;
  5300.     vt->previous = NULL;
  5301.     free = vt;
  5302.     ptext_count--;
  5303.     }
  5304.  
  5305. /*
  5306.  * ptlfree - free a VTEXT structure
  5307.  *
  5308.  *    VTLFREE takes a pointer to a VTEXT structure frees it and any linked
  5309.  *    VTEXT structures.  It is used to free an entrie list of VTEXT
  5310.  *    structures.
  5311.  */
  5312. void
  5313. ptlfree(vt)
  5314.     PTEXT    vt;
  5315.     {
  5316.     PTEXT    nxt;
  5317.  
  5318.     while(vt != NULL) {
  5319.         nxt = vt->next;
  5320.         ptfree(vt);
  5321.         vt = nxt;
  5322.     }
  5323.     }
  5324.  
  5325. $EOD
  5326. $!
  5327. $CREATE [.archie]rdgram.h
  5328. $DECK
  5329. /*
  5330.  * Copyright (c) 1991 by the University of Washington
  5331.  *
  5332.  * For copying and distribution information, please see the file
  5333.  * <copyright.h>.
  5334.  */
  5335.  
  5336. #include <copyright.h>
  5337.  
  5338. /* Queuing priorities for datagrams */
  5339. #define           RDGRAM_MAX_PRI   32765  /* Maximum user proiority          */
  5340. #define           RDGRAM_MAX_SPRI  32767  /* Maximum priority for system use */
  5341. #define           RDGRAM_MIN_PRI  -32765  /* Maximum user proiority          */
  5342. #define           RDGRAM_MIN_SPRI -32768  /* Maximum priority for system use */
  5343.  
  5344. int    rdgram_priority = 0;
  5345. $EOD
  5346. $!
  5347. $CREATE [.archie]regex.c
  5348. $DECK
  5349. #include <pmachine.h>
  5350.  
  5351. #ifdef NOREGEX
  5352. /*
  5353.  * These routines are BSD regex(3)/ed(1) compatible regular-expression
  5354.  * routines written by Ozan S. Yigit, Computer Science, York University.
  5355.  * Parts of the code that are not needed by Prospero have been removed,
  5356.  * but most of the accompanying information has been left intact. 
  5357.  * This file is to be included on those operating systems that do not
  5358.  * support re_comp and re_exec.
  5359.  */
  5360.  
  5361. /*
  5362.  * regex - Regular expression pattern matching
  5363.  *         and replacement
  5364.  *
  5365.  * by:  Ozan S. Yigit (oz@nexus.yorku.ca)
  5366.  *    Dept. of Computing Services
  5367.  *      York University
  5368.  *
  5369.  * These routines are the PUBLIC DOMAIN equivalents 
  5370.  * of regex routines as found in 4.nBSD UN*X, with minor
  5371.  * extensions.
  5372.  *
  5373.  * Modification history:
  5374.  *
  5375.  * $Log:    regex.c,v $
  5376.  * Revision 1.3  89/04/01  14:18:09  oz
  5377.  * Change all references to a dfa: this is actually an nfa.
  5378.  * 
  5379.  * Revision 1.2  88/08/28  15:36:04  oz
  5380.  * Use a complement bitmap to represent NCL.
  5381.  * This removes the need to have seperate 
  5382.  * code in the pmatch case block - it is 
  5383.  * just CCL code now.
  5384.  * 
  5385.  * Use the actual CCL code in the CLO
  5386.  * section of pmatch. No need for a recursive
  5387.  * pmatch call.
  5388.  * 
  5389.  * Use a bitmap table to set char bits in an
  5390.  * 8-bit chunk.
  5391.  * 
  5392.  * Routines:
  5393.  *      re_comp:        compile a regular expression into
  5394.  *                      a NFA.
  5395.  *
  5396.  *            char *re_comp(s)
  5397.  *            char *s;
  5398.  *
  5399.  *      re_exec:        execute the NFA to match a pattern.
  5400.  *
  5401.  *            int re_exec(s)
  5402.  *            char *s;
  5403.  *
  5404.  * Regular Expressions:
  5405.  *
  5406.  *      [1]     char    matches itself, unless it is a special
  5407.  *                      character (metachar): . \ [ ] * + ^ $
  5408.  *
  5409.  *      [2]     .       matches any character.
  5410.  *
  5411.  *      [3]     \       matches the character following it, except
  5412.  *            when followed by a left or right round bracket,
  5413.  *            a digit 1 to 9 or a left or right angle bracket. 
  5414.  *            (see [7], [8] and [9])
  5415.  *            It is used as an escape character for all 
  5416.  *            other meta-characters, and itself. When used
  5417.  *            in a set ([4]), it is treated as an ordinary
  5418.  *            character.
  5419.  *
  5420.  *      [4]     [set]   matches one of the characters in the set.
  5421.  *                      If the first character in the set is "^",
  5422.  *                      it matches a character NOT in the set, i.e. 
  5423.  *            complements the set. A shorthand S-E is 
  5424.  *            used to specify a set of characters S upto 
  5425.  *            E, inclusive. The special characters "]" and 
  5426.  *            "-" have no special meaning if they appear 
  5427.  *            as the first chars in the set.
  5428.  *                      examples:        match:
  5429.  *
  5430.  *                              [a-z]    any lowercase alpha
  5431.  *
  5432.  *                              [^]-]    any char except ] and -
  5433.  *
  5434.  *                              [^A-Z]   any char except uppercase
  5435.  *                                       alpha
  5436.  *
  5437.  *                              [a-zA-Z] any alpha
  5438.  *
  5439.  *      [5]     *       any regular expression form [1] to [4], followed by
  5440.  *                      closure char (*) matches zero or more matches of
  5441.  *                      that form.
  5442.  *
  5443.  *      [6]     +       same as [5], except it matches one or more.
  5444.  *
  5445.  *      [7]             a regular expression in the form [1] to [10], enclosed
  5446.  *                      as \(form\) matches what form matches. The enclosure
  5447.  *                      creates a set of tags, used for [8] and for
  5448.  *                      pattern substution. The tagged forms are numbered
  5449.  *            starting from 1.
  5450.  *
  5451.  *      [8]             a \ followed by a digit 1 to 9 matches whatever a
  5452.  *                      previously tagged regular expression ([7]) matched.
  5453.  *
  5454.  *    [9]    \<    a regular expression starting with a \< construct
  5455.  *        \>    and/or ending with a \> construct, restricts the
  5456.  *            pattern matching to the beginning of a word, and/or
  5457.  *            the end of a word. A word is defined to be a character
  5458.  *            string beginning and/or ending with the characters
  5459.  *            A-Z a-z 0-9 and _. It must also be preceded and/or
  5460.  *            followed by any character outside those mentioned.
  5461.  *
  5462.  *      [10]            a composite regular expression xy where x and y
  5463.  *                      are in the form [1] to [10] matches the longest
  5464.  *                      match of x followed by a match for y.
  5465.  *
  5466.  *      [11]    ^    a regular expression starting with a ^ character
  5467.  *        $    and/or ending with a $ character, restricts the
  5468.  *                      pattern matching to the beginning of the line,
  5469.  *                      or the end of line. [anchors] Elsewhere in the
  5470.  *            pattern, ^ and $ are treated as ordinary characters.
  5471.  *
  5472.  *
  5473.  * Acknowledgements:
  5474.  *
  5475.  *    HCR's Hugh Redelmeier has been most helpful in various
  5476.  *    stages of development. He convinced me to include BOW
  5477.  *    and EOW constructs, originally invented by Rob Pike at
  5478.  *    the University of Toronto.
  5479.  *
  5480.  * References:
  5481.  *              Software tools            Kernighan & Plauger
  5482.  *              Software tools in Pascal        Kernighan & Plauger
  5483.  *              Grep [rsx-11 C dist]            David Conroy
  5484.  *        ed - text editor        Un*x Programmer's Manual
  5485.  *        Advanced editing on Un*x    B. W. Kernighan
  5486.  *        regexp routines            Henry Spencer
  5487.  *
  5488.  * Notes:
  5489.  *
  5490.  *    This implementation uses a bit-set representation for character
  5491.  *    classes for speed and compactness. Each character is represented 
  5492.  *    by one bit in a 128-bit block. Thus, CCL always takes a 
  5493.  *    constant 16 bytes in the internal nfa, and re_exec does a single
  5494.  *    bit comparison to locate the character in the set.
  5495.  *
  5496.  * Examples:
  5497.  *
  5498.  *    pattern:    foo*.*
  5499.  *    compile:    CHR f CHR o CLO CHR o END CLO ANY END END
  5500.  *    matches:    fo foo fooo foobar fobar foxx ...
  5501.  *
  5502.  *    pattern:    fo[ob]a[rz]    
  5503.  *    compile:    CHR f CHR o CCL bitset CHR a CCL bitset END
  5504.  *    matches:    fobar fooar fobaz fooaz
  5505.  *
  5506.  *    pattern:    foo\\+
  5507.  *    compile:    CHR f CHR o CHR o CHR \ CLO CHR \ END END
  5508.  *    matches:    foo\ foo\\ foo\\\  ...
  5509.  *
  5510.  *    pattern:    \(foo\)[1-3]\1    (same as foo[1-3]foo)
  5511.  *    compile:    BOT 1 CHR f CHR o CHR o EOT 1 CCL bitset REF 1 END
  5512.  *    matches:    foo1foo foo2foo foo3foo
  5513.  *
  5514.  *    pattern:    \(fo.*\)-\1
  5515.  *    compile:    BOT 1 CHR f CHR o CLO ANY END EOT 1 CHR - REF 1 END
  5516.  *    matches:    foo-foo fo-fo fob-fob foobar-foobar ...
  5517.  * 
  5518.  */
  5519.  
  5520. #define MAXNFA  1024
  5521. #define MAXTAG  10
  5522.  
  5523. #define OKP     1
  5524. #define NOP     0
  5525.  
  5526. #define CHR     1
  5527. #define ANY     2
  5528. #define CCL     3
  5529. #define BOL     4
  5530. #define EOL     5
  5531. #define BOT     6
  5532. #define EOT     7
  5533. #define BOW    8
  5534. #define EOW    9
  5535. #define REF     10
  5536. #define CLO     11
  5537.  
  5538. #define END     0
  5539.  
  5540. /*
  5541.  * The following defines are not meant
  5542.  * to be changeable. They are for readability
  5543.  * only.
  5544.  *
  5545.  */
  5546. #define MAXCHR    128
  5547. #define CHRBIT    8
  5548. #define BITBLK    MAXCHR/CHRBIT
  5549. #define BLKIND    0170
  5550. #define BITIND    07
  5551.  
  5552. #define ASCIIB    0177
  5553.  
  5554. typedef /*unsigned*/ char CHAR;
  5555.  
  5556. static int  tagstk[MAXTAG];             /* subpat tag stack..*/
  5557. static CHAR nfa[MAXNFA];        /* automaton..       */
  5558. static int  sta = NOP;                   /* status of lastpat */
  5559.  
  5560. static CHAR bittab[BITBLK];        /* bit table for CCL */
  5561.                     /* pre-set bits...   */
  5562. static CHAR bitarr[] = {1,2,4,8,16,32,64,128};
  5563.  
  5564. static int internal_error;
  5565.  
  5566. static void
  5567. chset(c)
  5568. register CHAR c;
  5569. {
  5570.     bittab[((c) & BLKIND) >> 3] |= bitarr[(c) & BITIND];
  5571. }
  5572.  
  5573. #define badpat(x)    return (*nfa = END, x)
  5574. #define store(x)    *mp++ = x
  5575.  
  5576. char *     
  5577. re_comp(pat)
  5578. char *pat;
  5579. {
  5580.     register char *p;               /* pattern pointer   */
  5581.     register CHAR *mp = nfa;        /* nfa pointer       */
  5582.     register CHAR *lp;              /* saved pointer..   */
  5583.     register CHAR *sp = nfa;        /* another one..     */
  5584.  
  5585.     register int tagi = 0;          /* tag stack index   */
  5586.     register int tagc = 1;          /* actual tag count  */
  5587.  
  5588.     register int n;
  5589.     register CHAR mask;        /* xor mask -CCL/NCL */
  5590.     int c1, c2;
  5591.         
  5592.     if (!pat || !*pat)
  5593.         if (sta)
  5594.             return 0;
  5595.         else
  5596.             badpat("No previous regular expression");
  5597.     sta = NOP;
  5598.  
  5599.     for (p = pat; *p; p++) {
  5600.         lp = mp;
  5601.         switch(*p) {
  5602.  
  5603.         case '.':               /* match any char..  */
  5604.             store(ANY);
  5605.             break;
  5606.  
  5607.         case '^':               /* match beginning.. */
  5608.             if (p == pat)
  5609.                 store(BOL);
  5610.             else {
  5611.                 store(CHR);
  5612.                 store(*p);
  5613.             }
  5614.             break;
  5615.  
  5616.         case '$':               /* match endofline.. */
  5617.             if (!*(p+1))
  5618.                 store(EOL);
  5619.             else {
  5620.                 store(CHR);
  5621.                 store(*p);
  5622.             }
  5623.             break;
  5624.  
  5625.         case '[':               /* match char class..*/
  5626.             store(CCL);
  5627.  
  5628.             if (*++p == '^') {
  5629.                 mask = 0377;    
  5630.                 p++;
  5631.             }
  5632.             else
  5633.                 mask = 0;
  5634.  
  5635.             if (*p == '-')        /* real dash */
  5636.                 chset(*p++);
  5637.             if (*p == ']')        /* real brac */
  5638.                 chset(*p++);
  5639.             while (*p && *p != ']') {
  5640.                 if (*p == '-' && *(p+1) && *(p+1) != ']') {
  5641.                     p++;
  5642.                     c1 = *(p-2) + 1;
  5643.                     c2 = *p++;
  5644.                     while (c1 <= c2)
  5645.                         chset(c1++);
  5646.                 }
  5647. #ifdef EXTEND
  5648.                 else if (*p == '\\' && *(p+1)) {
  5649.                     p++;
  5650.                     chset(*p++);
  5651.                 }
  5652. #endif
  5653.                 else
  5654.                     chset(*p++);
  5655.             }
  5656.             if (!*p)
  5657.                 badpat("Missing ]");
  5658.  
  5659.             for (n = 0; n < BITBLK; bittab[n++] = (char) 0)
  5660.                 store(mask ^ bittab[n]);
  5661.     
  5662.             break;
  5663.  
  5664.         case '*':               /* match 0 or more.. */
  5665.         case '+':               /* match 1 or more.. */
  5666.             if (p == pat)
  5667.                 badpat("Empty closure");
  5668.             lp = sp;        /* previous opcode */
  5669.             if (*lp == CLO)        /* equivalence..   */
  5670.                 break;
  5671.             switch(*lp) {
  5672.  
  5673.             case BOL:
  5674.             case BOT:
  5675.             case EOT:
  5676.             case BOW:
  5677.             case EOW:
  5678.             case REF:
  5679.                 badpat("Illegal closure");
  5680.             default:
  5681.                 break;
  5682.             }
  5683.  
  5684.             if (*p == '+')
  5685.                 for (sp = mp; lp < sp; lp++)
  5686.                     store(*lp);
  5687.  
  5688.             store(END);
  5689.             store(END);
  5690.             sp = mp;
  5691.             while (--mp > lp)
  5692.                 *mp = mp[-1];
  5693.             store(CLO);
  5694.             mp = sp;
  5695.             break;
  5696.  
  5697.         case '\\':              /* tags, backrefs .. */
  5698.             switch(*++p) {
  5699.  
  5700.             case '(':
  5701.                 if (tagc < MAXTAG) {
  5702.                     tagstk[++tagi] = tagc;
  5703.                     store(BOT);
  5704.                     store(tagc++);
  5705.                 }
  5706.                 else
  5707.                     badpat("Too many \\(\\) pairs");
  5708.                 break;
  5709.             case ')':
  5710.                 if (*sp == BOT)
  5711.                     badpat("Null pattern inside \\(\\)");
  5712.                 if (tagi > 0) {
  5713.                     store(EOT);
  5714.                     store(tagstk[tagi--]);
  5715.                 }
  5716.                 else
  5717.                     badpat("Unmatched \\)");
  5718.                 break;
  5719.             case '<':
  5720.                 store(BOW);
  5721.                 break;
  5722.             case '>':
  5723.                 if (*sp == BOW)
  5724.                     badpat("Null pattern inside \\<\\>");
  5725.                 store(EOW);
  5726.                 break;
  5727.             case '1':
  5728.             case '2':
  5729.             case '3':
  5730.             case '4':
  5731.             case '5':
  5732.             case '6':
  5733.             case '7':
  5734.             case '8':
  5735.             case '9':
  5736.                 n = *p-'0';
  5737.                 if (tagi > 0 && tagstk[tagi] == n)
  5738.                     badpat("Cyclical reference");
  5739.                 if (tagc > n) {
  5740.                     store(REF);
  5741.                     store(n);
  5742.                 }
  5743.                 else
  5744.                     badpat("Undetermined reference");
  5745.                 break;
  5746. #ifdef EXTEND
  5747.             case 'b':
  5748.                 store(CHR);
  5749.                 store('\b');
  5750.                 break;
  5751.             case 'n':
  5752.                 store(CHR);
  5753.                 store('\n');
  5754.                 break;
  5755.             case 'f':
  5756.                 store(CHR);
  5757.                 store('\f');
  5758.                 break;
  5759.             case 'r':
  5760.                 store(CHR);
  5761.                 store('\r');
  5762.                 break;
  5763.             case 't':
  5764.                 store(CHR);
  5765.                 store('\t');
  5766.                 break;
  5767. #endif
  5768.             default:
  5769.                 store(CHR);
  5770.                 store(*p);
  5771.             }
  5772.             break;
  5773.  
  5774.         default :               /* an ordinary char  */
  5775.             store(CHR);
  5776.             store(*p);
  5777.             break;
  5778.         }
  5779.         sp = lp;
  5780.     }
  5781.     if (tagi > 0)
  5782.         badpat("Unmatched \\(");
  5783.     store(END);
  5784.     sta = OKP;
  5785.     return 0;
  5786. }
  5787.  
  5788.  
  5789. static char *bol;
  5790. static char *bopat[MAXTAG];
  5791. static char *eopat[MAXTAG];
  5792. char *pmatch();
  5793.  
  5794. /*
  5795.  * re_exec:
  5796.  *     execute nfa to find a match.
  5797.  *
  5798.  *    special cases: (nfa[0])    
  5799.  *        BOL
  5800.  *            Match only once, starting from the
  5801.  *            beginning.
  5802.  *        CHR
  5803.  *            First locate the character without
  5804.  *            calling pmatch, and if found, call
  5805.  *            pmatch for the remaining string.
  5806.  *        END
  5807.  *            re_comp failed, poor luser did not
  5808.  *            check for it. Fail fast.
  5809.  *
  5810.  *    If a match is found, bopat[0] and eopat[0] are set
  5811.  *    to the beginning and the end of the matched fragment,
  5812.  *    respectively.
  5813.  *
  5814.  */
  5815.  
  5816. int
  5817. re_exec(lp)
  5818. register char *lp;
  5819. {
  5820.     register char c;
  5821.     register char *ep = 0;
  5822.     register CHAR *ap = nfa;
  5823.  
  5824.     bol = lp;
  5825.  
  5826.     bopat[0] = 0;
  5827.     bopat[1] = 0;
  5828.     bopat[2] = 0;
  5829.     bopat[3] = 0;
  5830.     bopat[4] = 0;
  5831.     bopat[5] = 0;
  5832.     bopat[6] = 0;
  5833.     bopat[7] = 0;
  5834.     bopat[8] = 0;
  5835.     bopat[9] = 0;
  5836.  
  5837.     switch(*ap) {
  5838.  
  5839.     case BOL:            /* anchored: match from BOL only */
  5840.         ep = pmatch(lp,ap);
  5841.         break;
  5842.     case CHR:            /* ordinary char: locate it fast */
  5843.         c = *(ap+1);
  5844.         while (*lp && *lp != c)
  5845.             lp++;
  5846.         if (!*lp)        /* if EOS, fail, else fall thru. */
  5847.             return 0;
  5848.     default:            /* regular matching all the way. */
  5849.         while (*lp) {
  5850.             if ((ep = pmatch(lp,ap)))
  5851.                 break;
  5852.             lp++;
  5853.         }
  5854.         break;
  5855.     case END:            /* munged automaton. fail always */
  5856.         return 0;
  5857.     }
  5858.     if (!ep)
  5859.         return 0;
  5860.  
  5861.     if (internal_error)
  5862.         return -1;
  5863.  
  5864.     bopat[0] = lp;
  5865.     eopat[0] = ep;
  5866.     return 1;
  5867. }
  5868.  
  5869. /* 
  5870.  * pmatch: 
  5871.  *    internal routine for the hard part
  5872.  *
  5873.  *     This code is mostly snarfed from an early
  5874.  *     grep written by David Conroy. The backref and
  5875.  *     tag stuff, and various other mods are by oZ.
  5876.  *
  5877.  *    special cases: (nfa[n], nfa[n+1])
  5878.  *        CLO ANY
  5879.  *            We KNOW ".*" will match ANYTHING
  5880.  *            upto the end of line. Thus, go to
  5881.  *            the end of line straight, without
  5882.  *            calling pmatch recursively. As in
  5883.  *            the other closure cases, the remaining
  5884.  *            pattern must be matched by moving
  5885.  *            backwards on the string recursively,
  5886.  *            to find a match for xy (x is ".*" and 
  5887.  *            y is the remaining pattern) where
  5888.  *            the match satisfies the LONGEST match
  5889.  *            for x followed by a match for y.
  5890.  *        CLO CHR
  5891.  *            We can again scan the string forward
  5892.  *            for the single char without recursion, 
  5893.  *            and at the point of failure, we execute 
  5894.  *            the remaining nfa recursively, as
  5895.  *            described above.
  5896.  *
  5897.  *    At the end of a successful match, bopat[n] and eopat[n]
  5898.  *    are set to the beginning and end of subpatterns matched
  5899.  *    by tagged expressions (n = 1 to 9).    
  5900.  *
  5901.  */
  5902.  
  5903. /*
  5904.  * character classification table for word boundary
  5905.  * operators BOW and EOW. the reason for not using 
  5906.  * ctype macros is that we can let the user add into 
  5907.  * our own table. see re_modw. This table is not in
  5908.  * the bitset form, since we may wish to extend it
  5909.  * in the future for other character classifications. 
  5910.  *
  5911.  *    TRUE for 0-9 A-Z a-z _
  5912.  */
  5913. static char chrtyp[MAXCHR] = {
  5914.     0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
  5915.     0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
  5916.     0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
  5917.     0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
  5918.     0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 
  5919.     1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 
  5920.     0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 
  5921.     1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 
  5922.     1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 
  5923.     1, 0, 0, 0, 0, 1, 0, 1, 1, 1, 
  5924.     1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 
  5925.     1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 
  5926.     1, 1, 1, 0, 0, 0, 0, 0
  5927.     };
  5928.  
  5929. #define inascii(x)    (0177&(x))
  5930. #define iswordc(x)     chrtyp[inascii(x)]
  5931. #define isinset(x,y)     ((x)[((y)&BLKIND)>>3] & bitarr[(y)&BITIND])
  5932.  
  5933. /*
  5934.  * skip values for CLO XXX to skip past the closure
  5935.  *
  5936.  */
  5937.  
  5938. #define ANYSKIP    2     /* [CLO] ANY END ...         */
  5939. #define CHRSKIP    3    /* [CLO] CHR chr END ...     */
  5940. #define CCLSKIP 18    /* [CLO] CCL 16bytes END ... */
  5941.  
  5942. static char *
  5943. pmatch(lp, ap)
  5944. register char *lp;
  5945. register CHAR *ap;
  5946. {
  5947.     register int op, c, n;
  5948.     register char *e;        /* extra pointer for CLO */
  5949.     register char *bp;        /* beginning of subpat.. */
  5950.     register char *ep;        /* ending of subpat..     */
  5951.     char *are;            /* to save the line ptr. */
  5952.  
  5953.     while ((op = *ap++) != END)
  5954.         switch(op) {
  5955.  
  5956.         case CHR:
  5957.             if (*lp++ != *ap++)
  5958.                 return 0;
  5959.             break;
  5960.         case ANY:
  5961.             if (!*lp++)
  5962.                 return 0;
  5963.             break;
  5964.         case CCL:
  5965.             c = *lp++;
  5966.             if (!isinset(ap,c))
  5967.                 return 0;
  5968.             ap += BITBLK;
  5969.             break;
  5970.         case BOL:
  5971.             if (lp != bol)
  5972.                 return 0;
  5973.             break;
  5974.         case EOL:
  5975.             if (*lp)
  5976.                 return 0;
  5977.             break;
  5978.         case BOT:
  5979.             bopat[*ap++] = lp;
  5980.             break;
  5981.         case EOT:
  5982.             eopat[*ap++] = lp;
  5983.             break;
  5984.          case BOW:
  5985.             if (lp!=bol && iswordc(lp[-1]) || !iswordc(*lp))
  5986.                 return 0;
  5987.             break;
  5988.         case EOW:
  5989.             if (lp==bol || !iswordc(lp[-1]) || iswordc(*lp))
  5990.                 return 0;
  5991.             break;
  5992.         case REF:
  5993.             n = *ap++;
  5994.             bp = bopat[n];
  5995.             ep = eopat[n];
  5996.             while (bp < ep)
  5997.                 if (*bp++ != *lp++)
  5998.                     return 0;
  5999.             break;
  6000.         case CLO:
  6001.             are = lp;
  6002.             switch(*ap) {
  6003.  
  6004.             case ANY:
  6005.                 while (*lp)
  6006.                     lp++;
  6007.                 n = ANYSKIP;
  6008.                 break;
  6009.             case CHR:
  6010.                 c = *(ap+1);
  6011.                 while (*lp && c == *lp)
  6012.                     lp++;
  6013.                 n = CHRSKIP;
  6014.                 break;
  6015.             case CCL:
  6016.                 while ((c = *lp) && isinset(ap+1,c))
  6017.                     lp++;
  6018.                 n = CCLSKIP;
  6019.                 break;
  6020.             default:
  6021.                 internal_error++;
  6022.                 return 0;
  6023.             }
  6024.  
  6025.             ap += n;
  6026.  
  6027.             while (lp >= are) {
  6028.                 if (e = pmatch(lp, ap))
  6029.                     return e;
  6030.                 --lp;
  6031.             }
  6032.             return 0;
  6033.         default:
  6034.             internal_error++;
  6035.             return 0;
  6036.         }
  6037.     return lp;
  6038. }
  6039. #endif /* Need regex libraries? Compile to nothing if not.  */
  6040. $EOD
  6041. $!
  6042. $CREATE [.archie]regex.h
  6043. $DECK
  6044. /*
  6045.  * regex.h : External defs for Ozan Yigit's regex functions, for systems
  6046.  *    that don't have them builtin. See regex.c for copyright and other
  6047.  *    details.
  6048.  *
  6049.  * Note that this file can be included even if we're linking against the
  6050.  * system routines, since the interface is (deliberately) identical.
  6051.  *
  6052.  * George Ferguson, ferguson@cs.rochester.edu, 11 Sep 1991.
  6053.  */
  6054.  
  6055. #if defined(AUX) || defined(USG)
  6056. /* Let them use ours if they wish.  */
  6057. # ifndef NOREGEX
  6058. extern char *regcmp();
  6059. extern char *regex();
  6060. #define re_comp regcmp
  6061. #define re_exec regex
  6062. # endif
  6063. #else
  6064. extern char *re_comp();
  6065. extern int re_exec();
  6066. #endif
  6067. $EOD
  6068. $!
  6069. $CREATE [.archie]stcopy.c
  6070. $DECK
  6071. /*
  6072.  * Copyright (c) 1989, 1990, 1991 by the University of Washington
  6073.  *
  6074.  * For copying and distribution information, please see the file
  6075.  * <copyright.h>.
  6076.  *
  6077.  * v1.2.1 - 11/19/91 (mmt) - added MSDOS & OS2 stuff
  6078.  * v1.2.0 - 09/17/91 (bpk) - added BULL & USG stuff, thanks to Jim Sillas
  6079.  */
  6080.  
  6081. #include <copyright.h>
  6082. #include <stdio.h>
  6083. #include <pmachine.h>
  6084.  
  6085. #ifdef NEED_STRING_H
  6086. # include <string.h>
  6087. #else
  6088. # include <strings.h>
  6089. #endif
  6090.  
  6091. #if defined(MSDOS)
  6092. # include <stdlib.h>
  6093. #endif
  6094.  
  6095. char    *stcopyr();
  6096.  
  6097. int    string_count = 0;
  6098. int    string_max = 0;
  6099.  
  6100. /*
  6101.  * stcopy - allocate space for and copy a string
  6102.  *
  6103.  *     STCOPY takes a string as an argument, allocates space for
  6104.  *     a copy of the string, copies the string to the allocated space,
  6105.  *     and returns a pointer to the copy.
  6106.  */
  6107.  
  6108. char *
  6109. stcopy(st)
  6110.     char    *st;
  6111.     {
  6112.       if (!st) return(NULL);
  6113.       if (string_max < ++string_count) string_max = string_count;
  6114.  
  6115.       return strcpy((char *)malloc(strlen(st) + 1), st);
  6116.     }
  6117.  
  6118. /*
  6119.  * stcopyr - copy a string allocating space if necessary
  6120.  *
  6121.  *     STCOPYR takes a string, S, as an argument, and a pointer to a second
  6122.  *     string, R, which is to be replaced by S.  If R is long enough to
  6123.  *     hold S, S is copied.  Otherwise, new space is allocated, and R is
  6124.  *     freed.  S is then copied to the newly allocated space.  If S is
  6125.  *     NULL, then R is freed and NULL is returned.
  6126.  *
  6127.  *     In any event, STCOPYR returns a pointer to the new copy of S,
  6128.  *     or a NULL pointer.
  6129.  */
  6130. char *
  6131. stcopyr(s,r)
  6132.     char    *s;
  6133.     char    *r;
  6134.     {
  6135.     int    sl;
  6136.  
  6137.     if(!s && r) {
  6138.         free(r);
  6139.         string_count--;
  6140.         return(NULL);
  6141.     }
  6142.     else if (!s) return(NULL);
  6143.  
  6144.     sl = strlen(s) + 1;
  6145.  
  6146.     if(r) {
  6147.         if ((strlen(r) + 1) < sl) {
  6148.         free(r);
  6149.         r = (char *) malloc(sl);
  6150.         }
  6151.     }
  6152.     else {
  6153.         r = (char *) malloc(sl);
  6154.         string_count++;
  6155.         if(string_max < string_count) string_max = string_count;
  6156.     }
  6157.         
  6158.     return strcpy(r,s);
  6159.     }
  6160.  
  6161. /*
  6162.  * stfree - free space allocated by stcopy or stalloc
  6163.  *
  6164.  *     STFREE takes a string that was returned by stcopy or stalloc 
  6165.  *     and frees the space that was allocated for the string.
  6166.  */
  6167. void
  6168. stfree(st)
  6169.     char *st;
  6170.     {
  6171.     if(st) {
  6172.         free(st);
  6173.         string_count--;
  6174.     }
  6175.     }
  6176.  
  6177.  
  6178. $EOD
  6179. $!
  6180. $CREATE [.archie]support.c
  6181. $DECK
  6182. /*
  6183.  * Copyright (c) 1989, 1990, 1991 by the University of Washington
  6184.  *
  6185.  * For copying and distribution information, please see the file
  6186.  * <copyright.h>.
  6187.  *
  6188.  * v1.2.2 - 11/19/91 (mmt) - added MSDOS & OS2 stuff
  6189.  * v1.2.1 - 09/23/91 (gf)  - made it use regex.h---much nicer
  6190.  * v1.2.0 - 09/17/91 (bpk) - added BULL & USG stuff, thanks to Jim Sillas
  6191.  * v1.1.1 - 08/30/91 (bpk) - added VMS support; cast index()
  6192.  */
  6193.  
  6194. /*
  6195.  * Miscellaneous routines pulled from ~beta/lib/pfs and ~beta/lib/filters
  6196.  */
  6197.  
  6198. #include <copyright.h>
  6199. #include <stdio.h>
  6200.  
  6201. #include <errno.h>
  6202.  
  6203. #ifdef VMS
  6204. # ifdef WOLLONGONG
  6205. #  include "twg$tcp:[netdist.include]netdb.h"
  6206. # else /* not Wollongong */
  6207. #  ifdef UCX
  6208. #   include netdb
  6209. #  else /* Multinet */
  6210. #   include "multinet_root:[multinet.include]netdb.h"
  6211. #  endif
  6212. # endif
  6213. # include <vms.h>
  6214. #else /* not VMS */
  6215. # include <sys/types.h>
  6216. # include <pmachine.h>
  6217. # ifdef NEED_STRING_H
  6218. #  include <string.h>
  6219. # else
  6220. #  include <strings.h>
  6221. # endif
  6222. # ifndef CUTCP
  6223. #  include <netdb.h>
  6224. # endif
  6225. # if !defined(MSDOS) || defined(OS2)
  6226. #  include <sys/file.h>
  6227. #  include <sys/param.h>
  6228. # endif
  6229. #endif /* VMS */
  6230.  
  6231. #include <pfs.h>
  6232. #include <pprot.h>
  6233. #include <perrno.h>
  6234. #include <pcompat.h>
  6235. #include <pauthent.h>
  6236.  
  6237. #include "regex.h"
  6238.  
  6239. int    pfs_enable = PMAP_ATSIGN;
  6240.  
  6241. #ifndef FALSE
  6242. # define TRUE     1
  6243. # define FALSE   0
  6244. #endif
  6245.  
  6246. /* 
  6247.  * wcmatch - Match string s against template containing widlcards
  6248.  *
  6249.  *         WCMATCH takes a string and a template, and returns
  6250.  *         true if the string matches the template, and 
  6251.  *         FALSE otherwise.
  6252.  *
  6253.  *    ARGS:  s        - string to be tested
  6254.  *           template - Template containing optional wildcards
  6255.  *
  6256.  * RETURNS:  TRUE (non-zero) on match.  FALSE (0) otherwise.
  6257.  *
  6258.  *    NOTE:  If template is NULL, will return TRUE.
  6259.  *
  6260.  */
  6261. int
  6262. wcmatch(s,template)
  6263.     char    *s;
  6264.     char    *template;
  6265.     {
  6266.     char    temp[200];
  6267.     char    *p = temp;
  6268.  
  6269.     if(!template) return(TRUE);
  6270.     *p++ = '^';
  6271.  
  6272.     while(*template) {
  6273.         if(*template == '*') {*(p++)='.'; *(p++) = *(template++);}
  6274.         else if(*template == '?') {*(p++)='.';template++;}
  6275.         else if(*template == '.') {*(p++)='\\';*(p++)='.';template++;}
  6276.         else if(*template == '[') {*(p++)='\\';*(p++)='[';template++;}
  6277.         else if(*template == '$') {*(p++)='\\';*(p++)='$';template++;}
  6278.         else if(*template == '^') {*(p++)='\\';*(p++)='^';template++;}
  6279.         else if(*template == '\\') {*(p++)='\\';*(p++)='\\';template++;}
  6280.         else *(p++) = *(template++);
  6281.     }
  6282.         
  6283.     *p++ = '$';
  6284.     *p++ = '\0';
  6285.  
  6286.     if(re_comp(temp)) return(FALSE);
  6287.  
  6288. #ifdef AUX
  6289.     if (re_exec(s) == (char *)NULL)
  6290.       return 0;
  6291.     return 1;
  6292. #else
  6293.     return(re_exec(s));
  6294. #endif
  6295.     }
  6296.  
  6297. /*
  6298.  * ul_insert - Insert a union link at the right location
  6299.  *
  6300.  *             UL_INSERT takes a directory and a union link to be added
  6301.  *             to a the list of union links in the directory.  It then
  6302.  *             inserts the union link in the right spot in the linked
  6303.  *             list of union links associated with that directory.
  6304.  *
  6305.  *           If an identical link already exists, then the link which
  6306.  *             would be evaluated earlier (closer to the front of the list)
  6307.  *             wins and the other one is freed.  If this happens, an error
  6308.  *             will also be returned.
  6309.  *        
  6310.  *    ARGS:    ul    - link to be inserted
  6311.  *           vd    - directory to get link
  6312.  *             p     - vl that this link will apper after
  6313.  *                     NULL - This vl will go at end of list
  6314.  *                     vd   - This vl will go at head of list
  6315.  *
  6316.  * RETURNS:    Success, or UL_INSERT_ALREADY_THERE or UL_INSERT_SUPERSEDING
  6317.  */
  6318. int
  6319. ul_insert(ul,vd,p)
  6320.     VLINK    ul;        /* Link to be inserted                   */
  6321.     VDIR    vd;        /* Directory to receive link             */
  6322.     VLINK    p;        /* Union link to appear prior to new one */
  6323.     {
  6324.     VLINK    current;
  6325.  
  6326.     /* This is the first ul in the directory */
  6327.     if(vd->ulinks == NULL) {
  6328.         vd->ulinks = ul;
  6329.         ul->previous = NULL;
  6330.         ul->next = NULL;
  6331.         return(PSUCCESS);
  6332.     }
  6333.  
  6334.     /* This ul will go at the head of the list */
  6335.     if(p == (VLINK) vd) {
  6336.         ul->next = vd->ulinks;
  6337.         ul->next->previous = ul;
  6338.         vd->ulinks = ul;
  6339.         ul->previous = NULL;
  6340.     }
  6341.     /* Otherwise, decide if it must be inserted at all  */
  6342.     /* If an identical link appears before the position */
  6343.     /* at which the new one is to be inserted, we can   */
  6344.     /* return without inserting it                 */
  6345.     else {
  6346.         current = vd->ulinks;
  6347.  
  6348.         while(current) {
  6349.         /* p == NULL means we insert after last link */
  6350.         if(!p && (current->next == NULL))
  6351.             p = current;
  6352.  
  6353.         if(vl_comp(current,ul) == 0) {
  6354.             vlfree(ul);
  6355.             return(UL_INSERT_ALREADY_THERE);
  6356.         }
  6357.  
  6358.         if(current == p) break;
  6359.         current = current->next;
  6360.         }
  6361.  
  6362.         /* If current is null, p was not found */
  6363.         if(current == NULL)
  6364.         return(UL_INSERT_POS_NOTFOUND);
  6365.  
  6366.         /* Insert ul */
  6367.         ul->next = p->next;
  6368.         p->next = ul;
  6369.         ul->previous = p;
  6370.         if(ul->next) ul->next->previous = ul;
  6371.     }
  6372.  
  6373.     /* Check for identical links after ul */
  6374.     current = ul->next;
  6375.  
  6376.     while(current) {
  6377.         if(vl_comp(current,ul) == 0) {
  6378.         current->previous->next = current->next;
  6379.         if(current->next)
  6380.             current->next->previous = current->previous;
  6381.         vlfree(current);
  6382.         return(UL_INSERT_SUPERSEDING);
  6383.         }
  6384.         current = current->next;
  6385.     }
  6386.     
  6387.     return(PSUCCESS);
  6388.     }
  6389.  
  6390. /*
  6391.  * vl_insert - Insert a directory link at the right location
  6392.  *
  6393.  *             VL_INSERT takes a directory and a link to be added to a 
  6394.  *             directory and inserts it in the linked list of links for
  6395.  *             that directory.  
  6396.  *
  6397.  *             If a link already exists with the same name, and if the
  6398.  *             information associated with the new link matches that in
  6399.  *             the existing link, an error is returned.  If the information
  6400.  *             associated with the new link is different, but the magic numbers
  6401.  *             match, then the new link will be added as a replica of the
  6402.  *             existing link.  If the magic numbers do not match, the new
  6403.  *             link will only be added to the list of "replicas" if the
  6404.  *             allow_conflict flag has been set.
  6405.  * 
  6406.  *             If the link is not added, an error is returned and the link
  6407.  *             is freed.  Ordering for the list of links is by the link name.  
  6408.  *        
  6409.  *             If vl is a union link, then VL_INSERT calls ul_insert with an
  6410.  *           added argument indicating the link is to be included at the
  6411.  *             end of the union link list.
  6412.  * 
  6413.  *    ARGS:    vl - Link to be inserted, vd - directory to get link
  6414.  *             allow_conflict - insert links with conflicting names
  6415.  *
  6416.  * RETURNS:    Success, or VL_INSERT_ALREADY_THERE
  6417.  */
  6418. int
  6419. vl_insert(vl,vd,allow_conflict)
  6420.     VLINK    vl;        /* Link to be inserted               */
  6421.     VDIR    vd;        /* Directory to receive link         */
  6422.     int        allow_conflict;    /* Allow duplicate names             */
  6423.     {
  6424.     VLINK    current;    /* To step through list             */
  6425.     VLINK    crep;        /* To step through list of replicas  */
  6426.     int    retval;        /* Temp for checking returned values */
  6427.  
  6428.     /* This can also be used to insert union links at end of list */
  6429.     if(vl->linktype == 'U') return(ul_insert(vl,vd,NULL));
  6430.  
  6431.     /* If this is the first link in the directory */
  6432.     if(vd->links == NULL) {
  6433.         vd->links = vl;
  6434.         vl->previous = NULL;
  6435.         vl->next = NULL;
  6436.         vd->lastlink = vl;
  6437.         return(PSUCCESS);
  6438.     }
  6439.  
  6440.     /* If no sorting is to be done, just insert at end of list */
  6441.     if(allow_conflict == VLI_NOSORT) {
  6442.         vd->lastlink->next = vl;
  6443.         vl->previous = vd->lastlink;
  6444.         vl->next = NULL;
  6445.         vd->lastlink = vl;
  6446.         return(PSUCCESS);
  6447.     }
  6448.  
  6449.     /* If it is to be inserted at start of list */
  6450.     if(vl_comp(vl,vd->links) < 0) {
  6451.         vl->next = vd->links;
  6452.         vl->previous = NULL;
  6453.         vl->next->previous = vl;
  6454.         vd->links = vl;
  6455.         return(PSUCCESS);
  6456.     }
  6457.  
  6458.     current = vd->links;
  6459.  
  6460.     /* Otherwise, we must find the right spot to insert it */
  6461.     while((retval = vl_comp(vl,current)) > 0) {
  6462.         if(!current->next) {
  6463.         /* insert at end */
  6464.         vl->previous = current;
  6465.         vl->next = NULL;
  6466.         current->next = vl;
  6467.         vd->lastlink = vl;
  6468.         return(PSUCCESS);
  6469.         }
  6470.         current = current->next;
  6471.     }
  6472.  
  6473.     /* If we found an equivilant entry already in list */
  6474.     if(!retval) {
  6475.         if(vl_equal(vl,current)) {
  6476.         vlfree(vl);
  6477.         return(VL_INSERT_ALREADY_THERE);
  6478.         }
  6479.         if((allow_conflict == VLI_NOCONFLICT) &&
  6480.            ((vl->f_magic_no != current->f_magic_no) ||
  6481.         (vl->f_magic_no==0)))
  6482.         return(VL_INSERT_CONFLICT);
  6483.         /* Insert the link into the list of "replicas" */
  6484.         /* If magic is 0, then create a pseudo magic number */
  6485.         if(vl->f_magic_no == 0) vl->f_magic_no = -1;
  6486.         crep = current->replicas;
  6487.         if(!crep) {
  6488.         current->replicas = vl;
  6489.         vl->next = NULL;
  6490.         vl->previous = NULL;
  6491.         }
  6492.         else {
  6493.         while(crep->next) {
  6494.             /* If magic was 0, then we need a unique magic number */
  6495.             if((crep->f_magic_no < 0) && (vl->f_magic_no < 1))
  6496.             (vl->f_magic_no)--;
  6497.             crep = crep->next;
  6498.         }
  6499.         /* If magic was 0, then we need a unique magic number */
  6500.         if((crep->f_magic_no < 0) && (vl->f_magic_no < 1))
  6501.             (vl->f_magic_no)--;
  6502.         crep->next = vl;
  6503.         vl->previous = crep;
  6504.         vl->next = NULL;
  6505.         }
  6506.         return(PSUCCESS);
  6507.     }
  6508.  
  6509.     /* We found the spot where vl is to be inserted */
  6510.     vl->next = current;
  6511.     vl->previous = current->previous;
  6512.     current->previous = vl;
  6513.     vl->previous->next = vl;
  6514.     return(PSUCCESS);
  6515.     }
  6516.  
  6517. /*
  6518.  * nlsindex - Find first instance of string 2 in string 1 following newline
  6519.  *
  6520.  *          NLSINDEX scans string 1 for the first instance of string
  6521.  *          2 that immediately follows a newline.  If found, NLSINDEX
  6522.  *          returns a pointer to the first character of that instance.
  6523.  *          If no instance is found, NLSINDEX returns NULL (0).
  6524.  *
  6525.  *    NOTE:   This function is only useful for searching strings that
  6526.  *            consist of multiple lines.  s1 is assumed to be preceeded
  6527.  *           by a newline.  Thus, if s2 is at the start of s1, it will
  6528.  *          be found.
  6529.  *    ARGS:   s1 - string to be searched
  6530.  *            s2 - string to be found
  6531.  * RETURNS:   First instance of s2 in s1, or NULL (0) if not found
  6532.  */
  6533. char *
  6534. nlsindex(s1,s2)
  6535.     char    *s1;        /* String to be searched */
  6536.     char    *s2;        /* String to be found    */
  6537.     {
  6538.     register int s2len = strlen(s2);
  6539.     char    *curline = s1;    /* Pointer to start of current line */
  6540.  
  6541.     /* In case s2 appears at start of s1 */
  6542.     if(strncmp(curline,s2,s2len) == 0)
  6543.         return(curline);
  6544.  
  6545.     /* Check remaining lines of s1 */
  6546.     while((curline = (char *) index(curline,'\n')) != NULL) {
  6547.         curline++;
  6548.         if(strncmp(curline,s2,s2len) == 0)
  6549.         return(curline);
  6550.     }
  6551.  
  6552.     /* We didn't find it */
  6553.     return(NULL);
  6554.     }
  6555.  
  6556. /*
  6557.  * month_sname - Return a month name from it's number
  6558.  *
  6559.  *               MONTH_SNAME takes a number in the range 0
  6560.  *               to 12 and returns a pointer to a string
  6561.  *               representing the three letter abbreviation
  6562.  *             for that month.  If the argument is out of 
  6563.  *         range, MONTH_SNAME returns a pointer to "Unk".
  6564.  *
  6565.  *       ARGS:   n - Number of the month
  6566.  *    RETURNS:   Abbreviation for selected month
  6567.  */
  6568. char *month_sname(n)
  6569.     int n;        /* Month number */
  6570. {
  6571.     static char *name[] = { "Unk",
  6572.         "Jan","Feb","Mar","Apr","May","Jun",
  6573.         "Jul","Aug","Sep","Oct","Nov","Dec"
  6574.     };
  6575.     return((n < 1 || n > 12) ? name[0] : name[n]);
  6576. }
  6577.  
  6578. /*
  6579.  * sindex - Find first instance of string 2 in string 1 
  6580.  *
  6581.  *          SINDEX scans string 1 for the first instance of string
  6582.  *          2.  If found, SINDEX returns a pointer to the first
  6583.  *          character of that instance.  If no instance is found, 
  6584.  *          SINDEX returns NULL (0).
  6585.  *
  6586.  *    ARGS:   s1 - string to be searched
  6587.  *            s2 - string to be found
  6588.  * RETURNS:   First instance of s2 in s1, or NULL (0) if not found
  6589.  */
  6590. char *
  6591. sindex(s1,s2)
  6592.     char    *s1;        /* String to be searched   */
  6593.     char    *s2;        /* String to be found      */
  6594.     {
  6595.     register int s2len = strlen(s2);
  6596.     char    *s = s1;    /* Temp pointer to string  */
  6597.  
  6598.     /* Check for first character of s2 */
  6599.     while((s = (char *) index(s,*s2)) != NULL) {
  6600.         if(strncmp(s,s2,s2len) == 0)
  6601.         return(s);
  6602.         s++;
  6603.     }
  6604.  
  6605.     /* We didn't find it */
  6606.     return(NULL);
  6607.     }
  6608.  
  6609. int
  6610. scan_error(erst)
  6611.     char    *erst;
  6612.     {
  6613.     *p_err_string = '\0';
  6614.  
  6615.     if(strncmp(erst,"NOT-A-DIRECTORY",15) == 0) 
  6616.         return(DIRSRV_NOT_DIRECTORY);
  6617.  
  6618.     if(strncmp(erst,"UNIMPLEMENTED",13) == 0) {
  6619.         perrno = DIRSRV_UNIMPLEMENTED;
  6620.         sscanf(erst+13,"%*[^\n \t\r]%*[ \t]%[^\n]",p_err_string);
  6621.         return(perrno);
  6622.     }
  6623.  
  6624.     if(strncmp(erst,"WARNING ",8) == 0) {
  6625.         erst += 8;
  6626.         *p_warn_string = '\0';
  6627.         sscanf(erst,"%*[^\n \t\r]%*[ \t]%[^\n]",p_warn_string);
  6628.         /* Return values for warnings are negative */
  6629.         if(strncmp(erst,"OUT-OF-DATE",11) == 0) {
  6630.         pwarn = PWARN_OUT_OF_DATE;
  6631.         return(PSUCCESS);
  6632.         }
  6633.         if(strncmp(erst,"MESSAGE",7) == 0) {
  6634.         pwarn = PWARN_MSG_FROM_SERVER;
  6635.         return(PSUCCESS);
  6636.         }
  6637.         pwarn = PWARNING;
  6638.         sscanf(erst,"%[^\n]",p_warn_string);
  6639.         return(PSUCCESS);
  6640.     }
  6641.     else if(strncmp(erst,"ERROR",5) == 0) {
  6642.         if(*(erst+5)) sscanf(erst+6,"%[^\n]",p_err_string);
  6643.         perrno = DIRSRV_ERROR;
  6644.         return(perrno);
  6645.     }
  6646.     /* The rest start with "FAILURE" */
  6647.     else if(strncmp(erst,"FAILURE",7) != 0) {
  6648.         /* Unrecognized - Give warning, but return PSUCCESS */
  6649.         if(pwarn == 0) {
  6650.         *p_warn_string = '\0';
  6651.         pwarn = PWARN_UNRECOGNIZED_RESP;
  6652.         sscanf(erst,"%[^\n]",p_warn_string);
  6653.         }
  6654.         return(PSUCCESS);
  6655.     }
  6656.  
  6657.     if(strncmp(erst,"FAILURE ",8) != 0) {
  6658.         perrno = PFAILURE;
  6659.         return(perrno);
  6660.     }    
  6661.     erst += 8;
  6662.     
  6663.     sscanf(erst,"%*[^\n \t\r]%*[ \t]%[^\n]",p_err_string);
  6664.  
  6665.     /* Still to add               */
  6666.     /* DIRSRV_AUTHENT_REQ     242 */
  6667.     /* DIRSRV_BAD_VERS        245 */
  6668.  
  6669.     if(strncmp(erst,"NOT-FOUND",9) == 0) 
  6670.         perrno = DIRSRV_NOT_FOUND;
  6671.     else if(strncmp(erst,"NOT-AUTHORIZED",13) == 0) 
  6672.         perrno = DIRSRV_NOT_AUTHORIZED;
  6673.     else if(strncmp(erst,"ALREADY-EXISTS",14) == 0) 
  6674.         perrno = DIRSRV_ALREADY_EXISTS;
  6675.     else if(strncmp(erst,"NAME-CONFLICT",13) == 0) 
  6676.         perrno = DIRSRV_NAME_CONFLICT;
  6677.     else if(strncmp(erst,"SERVER-FAILED",13) == 0) 
  6678.         perrno = DIRSRV_SERVER_FAILED;
  6679.      /* Use it whether it starts with FAILURE or not */
  6680.     else if(strncmp(erst,"NOT-A-DIRECTORY",15) == 0) 
  6681.         perrno = DIRSRV_NOT_DIRECTORY;
  6682.     else perrno = PFAILURE;
  6683.  
  6684.     return(perrno);
  6685.     }
  6686.  
  6687. PATTRIB 
  6688. parse_attribute(line)
  6689.     char    *line;
  6690.     {
  6691.     char    l_precedence[MAX_DIR_LINESIZE];
  6692.     char    l_name[MAX_DIR_LINESIZE];
  6693.     char    l_type[MAX_DIR_LINESIZE];
  6694.     char    l_value[MAX_DIR_LINESIZE];
  6695.     PATTRIB    at;
  6696.     int    tmp;
  6697.  
  6698.     tmp = sscanf(line,"OBJECT-INFO %s %s %[^\n]", l_name, l_type, l_value);
  6699.     
  6700.     if(tmp < 3) {
  6701.         tmp = sscanf(line,"LINK-INFO %s %s %s %[^\n]", l_precedence,
  6702.              l_name, l_type, l_value);
  6703.         if(tmp < 4) {
  6704.         perrno = DIRSRV_BAD_FORMAT;
  6705.         return(NULL);
  6706.         }
  6707.     }
  6708.  
  6709.     at = atalloc();
  6710.  
  6711.     if(tmp == 4) {
  6712.         if(strcmp(l_precedence,"CACHED") == 0) 
  6713.         at->precedence = ATR_PREC_CACHED;
  6714.         else if(strcmp(l_precedence,"LINK") == 0) 
  6715.         at->precedence = ATR_PREC_LINK;
  6716.         else if(strcmp(l_precedence,"REPLACEMENT") == 0) 
  6717.         at->precedence = ATR_PREC_REPLACE;
  6718.         else if(strcmp(l_precedence,"ADDITIONAL") == 0) 
  6719.         at->precedence = ATR_PREC_ADD;
  6720.     }
  6721.  
  6722.     at->aname = stcopy(l_name);
  6723.     at->avtype = stcopy(l_type);
  6724.     if(strcmp(l_type,"ASCII") == 0) 
  6725.         at->value.ascii = stcopy(l_value);
  6726.     else if(strcmp(l_type,"LINK") == 0) {
  6727.         char        ftype[MAX_DIR_LINESIZE];
  6728.         char        lname[MAX_DIR_LINESIZE];
  6729.         char        htype[MAX_DIR_LINESIZE];
  6730.         char        host[MAX_DIR_LINESIZE];
  6731.         char        ntype[MAX_DIR_LINESIZE];
  6732.         char        fname[MAX_DIR_LINESIZE];
  6733.         VLINK        al;
  6734.  
  6735.         al = vlalloc();
  6736.         at->value.link = al;
  6737.  
  6738.         tmp = sscanf(l_value,"%c %s %s %s %s %s %s %d %d",
  6739.              &(al->linktype),
  6740.              ftype,lname,htype,host,ntype,fname,
  6741.              &(al->version),
  6742.              &(al->f_magic_no));
  6743.         if(tmp == 9) {
  6744.         al->type = stcopyr(ftype,al->type);
  6745.         al->name = stcopyr(unquote(lname),al->name);
  6746.         al->hosttype = stcopyr(htype,al->hosttype);
  6747.         al->host = stcopyr(host,al->host);
  6748.         al->nametype = stcopyr(ntype,al->nametype);
  6749.         al->filename = stcopyr(fname,al->filename);
  6750.         }
  6751.         else {
  6752.         perrno = DIRSRV_BAD_FORMAT;
  6753.         return(NULL);
  6754.         }
  6755.         
  6756.     }
  6757.  
  6758.     return(at);
  6759.     }
  6760.  
  6761. /*
  6762.  * nxtline - Find the next line in the string
  6763.  *
  6764.  *          NXTLINE takes a string and returns a pointer to
  6765.  *          the character immediately following the next newline.
  6766.  *
  6767.  *    ARGS:   s - string to be searched
  6768.  *
  6769.  * RETURNS:   Next line or NULL (0) on failure
  6770.  */
  6771. char *
  6772. nxtline(s)
  6773.     char    *s;        /* String to be searched */
  6774.  {
  6775.     s = (char *) index(s,'\n');
  6776.     if(s) return(++s);
  6777.     else return(NULL);
  6778.     }
  6779.  
  6780.  
  6781. /*
  6782.  * unquote - unquote string if necessary
  6783.  *
  6784.  *          UNQUOTE takes a string and unquotes it if it has been quoted.
  6785.  *
  6786.  *    ARGS:   s - string to be unquoted
  6787.  *            
  6788.  * RETURNS:   The original string.  If the string has been quoted, then the
  6789.  *            result appears in static storage, and must be copied if 
  6790.  *            it is to last beyond the next call to quote.
  6791.  *
  6792.  */
  6793. char *
  6794. unquote(s)
  6795.     char    *s;        /* String to be quoted */
  6796.     {
  6797.     static char    unquoted[200];
  6798.     char        *c = unquoted;
  6799.  
  6800.     if(*s != '\'') return(s);
  6801.  
  6802.     s++;
  6803.  
  6804.     /* This should really treat a quote followed by other */
  6805.     /* than a quote or a null as an error                 */
  6806.     while(*s) {
  6807.         if(*s == '\'') s++;
  6808.         if(*s) *c++ = *s++;
  6809.     }
  6810.  
  6811.     *c++ = '\0';
  6812.  
  6813.     return(unquoted);
  6814.     }
  6815.  
  6816. #if defined(DEBUG) && defined(STRSPN)
  6817. /* needed for -D option parsing */
  6818. /*
  6819.  * strspn - Count initial characters from chrs in s
  6820.  *
  6821.  *          STRSPN counts the occurances of chacters from chrs
  6822.  *            in the string s preceeding the first occurance of
  6823.  *            a character not in s.
  6824.  *
  6825.  *    ARGS:   s    - string to be checked
  6826.  *            chrs - string of characters we are looking for
  6827.  *
  6828.  * RETURNS:   Count of initial characters from chrs in s
  6829.  */
  6830. strspn(s,chrs)
  6831.     char    *s;    /* String to search                         */
  6832.     char    *chrs; /* String of characters we are looking for  */
  6833.     {
  6834.     char    *cp;   /* Pointer to the current character in chrs */
  6835.     int    count; /* Count of characters seen so far          */
  6836.     
  6837.     count = 0;
  6838.  
  6839.     while(*s) {
  6840.         for(cp = chrs;*cp;cp++)
  6841.         if(*cp == *s) {
  6842.             s++;
  6843.             count++;
  6844.             goto done;
  6845.         }
  6846.         return(count);
  6847.     done:
  6848.         ;
  6849.     }
  6850.     return(count);
  6851.     }
  6852. #endif
  6853.  
  6854. #ifdef CUTCP
  6855. char
  6856. *inet_ntoa(struct in_addr in)
  6857. {
  6858.     static    char    buff[36];
  6859.  
  6860.     unsigned char    *c = (char *) &in.address;
  6861.     sprintf(buff,"%d.%d.%d.%d",*c,*(c+1),*(c+2),*(c+3));
  6862.     return(buff);
  6863. }
  6864.  
  6865. long
  6866. inet_addr(char *cp)
  6867. {
  6868.     long    value = 0;
  6869.     unsigned    v1,v2,v3,v4;
  6870.  
  6871.     v1 = v2 = v3 = v4 = 0xff;
  6872.     sscanf(cp,"%d.%d.%d.%d",&v1,&v2,&v3,&v4);
  6873.     value = (v1 << 24) | (v2 << 16) | (v3 << 8) | v4;
  6874.     return(value);
  6875. }
  6876.  
  6877. struct    hostent
  6878. *gethostbyname(char *name)
  6879. {
  6880.     struct machinfo    *mp;
  6881.     int    mnum;
  6882.     unsigned long    now;
  6883.     static    struct hostent    ht;
  6884.     extern int pfs_debug;
  6885.  
  6886.     mp = Shostlook(name);
  6887.     if(!mp || (!mp->hostip[0])) {    /* DNS lookup */
  6888. #ifdef DEBUG
  6889.         if (pfs_debug)
  6890.         fprintf(stderr, "Domain name lookup of %s\n", name);
  6891. #endif
  6892.         mnum = Sdomain(name);        /* start a DNS lookup */
  6893.         now = time(NULL) + NS_TIMEOUT;
  6894.         while(now > time(NULL)) {
  6895.             int    i, class, dat;
  6896.  
  6897.             Stask();
  6898.             i = Sgetevent(USERCLASS, &class, &dat);
  6899.             if(i == DOMOK) {    /* domain lookup ok */
  6900.                 mp = Slooknum(mnum);
  6901. #ifdef DEBUG
  6902.         if (pfs_debug)
  6903.         fprintf(stderr, "Domain name lookup of %s Completed OK\n", name);
  6904. #endif
  6905.                 break;
  6906.             }
  6907.         }
  6908.         if(!mp)    {    /* get here if timeout */
  6909. #ifdef DEBUG
  6910.         if (pfs_debug)
  6911.         fprintf(stderr, "Domain name lookup of %s Failed\n", name);
  6912. #endif
  6913.             return(NULL);
  6914.         }
  6915.     }
  6916.     ht.h_addr = *((unsigned long *) mp->hostip);
  6917.     ht.h_length = 4;
  6918.     ht.h_addrtype = AF_INET;
  6919.     return(&ht);
  6920.  
  6921. }
  6922. #endif /* CUTCP */
  6923.  
  6924. #ifdef GETENV
  6925. /*
  6926.  * Copyright (c) 1987 Regents of the University of California.
  6927.  * All rights reserved.
  6928.  *
  6929.  * Redistribution and use in source and binary forms are permitted
  6930.  * provided that: (1) source distributions retain this entire copyright
  6931.  * notice and comment, and (2) distributions including binaries display
  6932.  * the following acknowledgement:  ``This product includes software
  6933.  * developed by the University of California, Berkeley and its contributors''
  6934.  * in the documentation or other materials provided with the distribution
  6935.  * and in all advertising materials mentioning features or use of this
  6936.  * software. Neither the name of the University nor the names of its
  6937.  * contributors may be used to endorse or promote products derived
  6938.  * from this software without specific prior written permission.
  6939.  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
  6940.  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
  6941.  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  6942.  */
  6943.  
  6944. #if defined(LIBC_SCCS) && !defined(lint)
  6945. static char sccsid[] = "@(#)getenv.c    5.7 (Berkeley) 6/1/90";
  6946. #endif /* LIBC_SCCS and not lint */
  6947.  
  6948. #include <stdlib.h>
  6949. #include <stddef.h>
  6950.  
  6951. /*
  6952.  * getenv --
  6953.  *    Returns ptr to value associated with name, if any, else NULL.
  6954.  */
  6955. char *
  6956. getenv(name)
  6957.     char *name;
  6958. {
  6959.     int offset;
  6960.     char *_findenv();
  6961.  
  6962.     return(_findenv(name, &offset));
  6963. }
  6964.  
  6965. /*
  6966.  * _findenv --
  6967.  *    Returns pointer to value associated with name, if any, else NULL.
  6968.  *    Sets offset to be the offset of the name/value combination in the
  6969.  *    environmental array, for use by setenv(3) and unsetenv(3).
  6970.  *    Explicitly removes '=' in argument name.
  6971.  *
  6972.  *    This routine *should* be a static; don't use it.
  6973.  */
  6974. char *
  6975. _findenv(name, offset)
  6976.     register char *name;
  6977.     int *offset;
  6978. {
  6979.     extern char **environ;
  6980.     register int len;
  6981.     register char **P, *C;
  6982.  
  6983.     for (C = name, len = 0; *C && *C != '='; ++C, ++len);
  6984.     for (P = environ; *P; ++P)
  6985.         if (!strncmp(*P, name, len))
  6986.             if (*(C = *P + len) == '=') {
  6987.                 *offset = P - environ;
  6988.                 return(++C);
  6989.             }
  6990.     return(NULL);
  6991. }
  6992. #endif
  6993. $EOD
  6994. $!
  6995. $CREATE [.archie]copyright.h
  6996. $DECK
  6997. /* 
  6998.   Copyright (c) 1989, 1990, 1991 by the University of Washington
  6999.  
  7000.   Permission to use, copy, modify, and distribute this software and its
  7001.   documentation for non-commercial purposes and without fee is hereby
  7002.   granted, provided that the above copyright notice appear in all copies
  7003.   and that both the copyright notice and this permission notice appear in
  7004.   supporting documentation, and that the name of the University of
  7005.   Washington not be used in advertising or publicity pertaining to
  7006.   distribution of the software without specific, written prior
  7007.   permission.  The University of Washington makes no representations
  7008.   about the suitability of this software for any purpose.  It is
  7009.   provided "as is" without express or implied warranty.
  7010.  
  7011.   Prospero was written by Clifford Neuman (bcn@isi.edu).
  7012.  
  7013.   Questions concerning this software should be directed to 
  7014.   info-prospero@isi.edu.
  7015.  
  7016.   */
  7017. $EOD
  7018. $!
  7019. $CREATE [.archie]udp.c
  7020. $DECK
  7021. /*
  7022.  * udp - Check if UDP traffic is allowed on this host; we open port 1527 on
  7023.  *       a system (default of cs.widener.edu), which is expecting it; the
  7024.  *       date is output (e.g. very similar to the daytime service).  This
  7025.  *       will conclusively tell us if UDP traffic on ports > 1000 is allowed.
  7026.  *
  7027.  *    It should print out the date if UDP traffic's not blocked on your
  7028.  *    system.  If it just hangs, try these tests too:
  7029.  *      a. run it with -d  (e.g. "udp -d"); that goes to the normal UDP port
  7030.  *         to print the date.  If it works, then you can be sure that any
  7031.  *         UDP traffic > port 1000 is blocked on your system.
  7032.  *      b. if it hangs too, try "telnet 147.31.254.130 13" and see if
  7033.  *         _that_ prints the date; if it doesn't, it's another problem (your
  7034.  *         network can't get to me, e.g.).
  7035.  *
  7036.  * Compile by: cc -o udp udp.c
  7037.  *
  7038.  * Brendan Kehoe, brendan@cs.widener.edu, Oct 1991.
  7039.  */
  7040.  
  7041. #include <stdio.h>
  7042. #include <sys/types.h>
  7043. #include <sys/socket.h>
  7044. #include <netinet/in.h>
  7045. #ifndef hpux
  7046. # include <arpa/inet.h>
  7047. #endif
  7048.  
  7049. #define    SIZE    2048
  7050. #define    HOST    "147.31.254.130"    /* cs.widener.edu */
  7051. #define PORT    1527
  7052.  
  7053. main (argc, argv)
  7054.      int argc;
  7055.      char **argv;
  7056. {
  7057.   int s, len;
  7058.   struct sockaddr_in server, sa;
  7059.   char buf[SIZE];
  7060.  
  7061.   if ((s = socket (AF_INET, SOCK_DGRAM, IPPROTO_UDP)) < 0)
  7062.     {
  7063.       perror ("socket()");
  7064.       exit (1);
  7065.     }
  7066.  
  7067.   bzero ((char *) &sa, sizeof (sa));
  7068.   sa.sin_family = AF_INET;
  7069.   sa.sin_addr.s_addr = htonl (INADDR_ANY);
  7070.   sa.sin_port = htons (0);
  7071.  
  7072.   if (bind (s, (struct sockaddr *) &sa, sizeof (sa)) < 0)
  7073.     {
  7074.       perror ("bind()");
  7075.       exit (1);
  7076.     }
  7077.  
  7078.   bzero ((char *) &server, sizeof (server));
  7079.   server.sin_family = AF_INET;
  7080.   server.sin_addr.s_addr = inet_addr (HOST);
  7081.   if (argc > 1 && strcmp(*(argv + 1), "-d") == 0)
  7082.     server.sin_port = htons ((unsigned short) 13);
  7083.   else
  7084.     server.sin_port = htons ((unsigned short) PORT);
  7085.  
  7086.   /* yoo hoo, we're here .. */
  7087.   if (sendto (s, "\n", 1, 0, &server, sizeof (server)) < 0)
  7088.     {
  7089.       perror ("sendto()");
  7090.       exit (1);
  7091.     }
  7092.  
  7093.   /* slurp */
  7094.   len = sizeof (server);
  7095.   if (recvfrom (s, buf, sizeof (buf), 0, &server, &len) < 0)
  7096.     {
  7097.       perror ("recvfrom");
  7098.       exit (1);
  7099.     }
  7100.  
  7101.   printf ("%s", buf);
  7102.   close (s);
  7103. }
  7104. $EOD
  7105. $!
  7106. $CREATE [.archie]vl_comp.c
  7107. $DECK
  7108. /*
  7109.  * Copyright (c) 1989, 1990, 1991 by the University of Washington
  7110.  *
  7111.  * For copying and distribution information, please see the file
  7112.  * <copyright.h>.
  7113.  */
  7114.  
  7115. #include <copyright.h>
  7116. #include <pfs.h>
  7117.  
  7118. /*
  7119.  * vl_comp - compare the names of two virtual links
  7120.  *
  7121.  *           VL_COMP compares the names of two links.  It returns
  7122.  *           0 if they are equal, negative if vl1 < vl2, and positive if
  7123.  *           vl1 > vl2.
  7124.  *
  7125.  *    ARGS:  vl1,vl2 - Virtual links to be compared
  7126.  * 
  7127.  * RETURNS:  0 if equal, + is vl1 > vl2, - if vl1 < vl2
  7128.  *
  7129.  *   NOTES:  Order of significance is as follows.  Existence,
  7130.  *           name.  If names do not exist, then hosttype, host,
  7131.  *           native filenametype, native filename.  The only time
  7132.  *           the name will not exist if if the link is a union link.
  7133.  */
  7134. int
  7135. vl_comp(vl1,vl2)
  7136.     VLINK    vl1;
  7137.     VLINK    vl2;
  7138.     {
  7139.     int    retval;
  7140.  
  7141.     if(vl1->name && !vl2->name) return(1);
  7142.     if(!vl1->name && vl2->name) return(-1);
  7143.     if(vl1->name && vl2->name && (*(vl1->name) || *(vl2->name)))
  7144.         return(strcmp(vl1->name,vl2->name));
  7145.  
  7146.     retval = strcmp(vl1->hosttype,vl2->hosttype);
  7147.     if(!retval) retval = strcmp(vl1->host,vl2->host);
  7148.     if(!retval) retval = strcmp(vl1->nametype,vl2->nametype);
  7149.     if(!retval) retval = strcmp(vl1->filename,vl2->filename);
  7150.     return(retval);
  7151.     }
  7152.  
  7153. /*
  7154.  * vl_equal - compare the values of two virtual links
  7155.  *
  7156.  *           VL_EQUAL compares the values of two links.  It returns
  7157.  *           1 if all important fields are the same, and 0 otherwise.
  7158.  *
  7159.  *    ARGS:  vl1,vl2 - Virtual links to be compared
  7160.  * 
  7161.  * RETURNS:  1 if equal, 0 if not equal
  7162.  *
  7163.  */
  7164. int
  7165. vl_equal(vl1,vl2)
  7166.     VLINK    vl1;
  7167.     VLINK    vl2;
  7168.     {
  7169.       return strcmp(vl1->name, vl2->name) == 0         &&
  7170.          vl1->linktype == vl2->linktype            &&
  7171.          strcmp(vl1->type, vl2->type) == 0         &&
  7172.          strcmp(vl1->hosttype, vl2->hosttype) == 0 &&
  7173.          strcmp(vl1->host, vl2->host) == 0         &&
  7174.          strcmp(vl1->nametype, vl2->nametype) == 0 &&
  7175.          strcmp(vl1->filename, vl2->filename) == 0 &&
  7176.          vl1->version == vl2->version              &&
  7177.          vl1->f_magic_no == vl2->f_magic_no        ;
  7178.  
  7179.     }
  7180.  
  7181. $EOD
  7182. $!
  7183. $CREATE [.archie]vlalloc.c
  7184. $DECK
  7185. /*
  7186.  * Copyright (c) 1989, 1990, 1991 by the University of Washington
  7187.  *
  7188.  * For copying and distribution information, please see the file
  7189.  * <copyright.h>.
  7190.  */
  7191.  
  7192. #include <copyright.h>
  7193. #include <stdio.h>
  7194.  
  7195. #include <pfs.h>
  7196. #include <pmachine.h>
  7197.  
  7198. static VLINK    lfree = NULL;
  7199. int        vlink_count = 0;
  7200. int        vlink_max = 0;
  7201.  
  7202. /*
  7203.  * vlalloc - allocate and initialize vlink structure
  7204.  *
  7205.  *    VLALLOC returns a pointer to an initialized structure of type
  7206.  *    VLINK.  If it is unable to allocate such a structure, it
  7207.  *    returns NULL.
  7208.  */
  7209. VLINK
  7210. vlalloc()
  7211.     {
  7212.     VLINK    vl;
  7213.     if(lfree) {
  7214.         vl = lfree;
  7215.         lfree = lfree->next;
  7216.     }
  7217.     else {
  7218.         vl = (VLINK) malloc(sizeof(VLINK_ST));
  7219.         if (!vl) return(NULL);
  7220.         vlink_max++;
  7221.     }
  7222.  
  7223.     vlink_count++;
  7224.  
  7225.     /* Initialize and fill in default values */
  7226.     /* Since all but four are set to a zero-value,
  7227.        why not just wipe it clean?  */
  7228.     ZERO(vl);
  7229.  
  7230.     vl->linktype = 'L';
  7231.     vl->type = stcopy("FILE");
  7232.     vl->hosttype = stcopy("INTERNET-D");
  7233.     vl->nametype = stcopy("ASCII");
  7234.  
  7235.     return(vl);
  7236.     }
  7237.  
  7238. /*
  7239.  * vlfree - free a VLINK structure
  7240.  *
  7241.  *    VLFREE takes a pointer to a VLINK structure and adds it to
  7242.  *    the free list for later reuse.
  7243.  */
  7244. void
  7245. vlfree(vl)
  7246.     VLINK    vl;
  7247.     {
  7248.         extern int string_count;
  7249.  
  7250.     if(vl->dontfree) return;
  7251.     /* many of these don't need to call stfree(); since a check
  7252.        for pointer validity's already done before even calling
  7253.        it, we can just call free() here then do one big decrement
  7254.        of string_count at the end.  */
  7255.     if(vl->name) free(vl->name);
  7256.     stfree(vl->type);
  7257.     if(vl->replicas) vllfree(vl->replicas);
  7258.     stfree(vl->hosttype);
  7259.     if(vl->host) free(vl->host);
  7260.     stfree(vl->nametype);
  7261.     if(vl->filename) free(vl->filename);
  7262.     if(vl->args) free(vl->args);
  7263.     if(vl->lattrib) atlfree(vl->lattrib);
  7264.     /* No allocation routines for f_info yet */
  7265.     vl->f_info = NULL;
  7266.     vl->next = lfree;
  7267.     vl->previous = NULL;
  7268.     lfree = vl;
  7269.     vlink_count--;
  7270.     string_count -= 4; /* freed name, host, filename, and args */
  7271.     }
  7272.  
  7273. /*
  7274.  * vllfree - free a VLINK structure
  7275.  *
  7276.  *    VLLFREE takes a pointer to a VLINK structure frees it and any linked
  7277.  *    VLINK structures.  It is used to free an entrie list of VLINK
  7278.  *    structures.
  7279.  */
  7280. void
  7281. vllfree(vl)
  7282.     VLINK    vl;
  7283.     {
  7284.     VLINK    nxt;
  7285.  
  7286.     while((vl != NULL) && !vl->dontfree) {
  7287.         nxt = vl->next;
  7288.         vlfree(vl);
  7289.         vl = nxt;
  7290.     }
  7291.     }
  7292.  
  7293. $EOD
  7294. $!
  7295. $CREATE [.archie]vms.h
  7296. $DECK
  7297. #ifndef _ARCHIE_VMS
  7298. #define _ARCHIE_VMS
  7299. #include <pmachine.h>
  7300.  
  7301. #if !defined(MULTINET_30) && !defined(WOLLONGONG) && !defined(UCX)
  7302. #include "[.vms]pseudos.h"
  7303. #include "[.vms]types.h"
  7304. #include "[.vms]in.h"
  7305. #include "[.vms]signal.h"
  7306. #include "[.vms]socket.h"
  7307. #include "[.vms]time.h"
  7308.  
  7309. #else
  7310.  
  7311. /* time_t gets multiply defined <ekup> */
  7312. #ifndef __TYPES
  7313. #define __TYPES
  7314. #endif
  7315. #ifdef MULTINET_30
  7316. # include "multinet_root:[multinet.include.sys]types.h"
  7317. # include "multinet_root:[multinet.include.netinet]in.h"
  7318. # include "multinet_root:[multinet.include.sys]socket.h"
  7319. # include "multinet_root:[multinet.include.sys]time.h"
  7320. #endif /* MULTINET_30 */
  7321.  
  7322. #ifdef WOLLONGONG
  7323. /* We don't want size_t defined.  */
  7324. # ifndef __STDDEF
  7325. #  define __STDDEF
  7326. # endif
  7327. # include "twg$tcp:[netdist.include.sys]types.h"
  7328. # include "twg$tcp:[netdist.include.netinet]in.h"
  7329. # include "twg$tcp:[netdist.include.sys]socket.h"
  7330. # include "twg$tcp:[netdist.include.sys]time.h"
  7331. #endif /* WOLLONGONG */
  7332.  
  7333. #ifdef UCX
  7334. # include <types.h>
  7335. # include <in.h>
  7336. # include <socket.h>
  7337. # include <time.h>
  7338. # include "[.vms]fd.h"
  7339. #endif /* UCX */
  7340.  
  7341. #endif /* Multinet or Wallongong or UCX */
  7342.  
  7343. #endif /* _ARCHIE_VMS */
  7344. $EOD
  7345. $!
  7346. $CREATE [.archie]vms_support.c
  7347. $DECK
  7348. /* Emulation of 4.2 UNIX socket interface routines includes drivers for
  7349.    Wollongong, CMU-TEK, UCX tcp/ip interface and also emulates the SUN
  7350.    version of X.25 sockets.  The TWG will also work for MultiNet.  */
  7351.  
  7352. /* This is from unixlib, by P.Kay@massey.ac.nz; wonderful implementation.
  7353.    You can get the real thing on 130.123.1.4 as unixlib_tar.z.  */
  7354.  
  7355. #include <stdio.h>
  7356. #include <errno.h>
  7357. #include <ssdef.h>
  7358. #include <dvidef.h>
  7359. #include <signal.h>
  7360. #include <sys$library:msgdef.h>
  7361. #include <iodef.h>
  7362. #include <ctype.h>
  7363. #include <vms.h>
  7364. #include "[.vms]network.h"
  7365.  
  7366. #define QIO_FAILED (st != SS$_NORMAL || p[s].iosb[0] != SS$_NORMAL)
  7367. #define QIO_ST_FAILED (st != SS$_NORMAL)
  7368.  
  7369. /* Socket routine.  */
  7370. int
  7371. VMSsocket (domain, type, protocol)
  7372.      int domain, type, protocol;
  7373. {
  7374.   struct descriptor inetdesc, x25desc, mbxdesc;
  7375.   int i, st, s, p_initialise ();
  7376.   long ucx_sock_def;
  7377.   char *getenv ();
  7378.  
  7379.   if (!tcp_make)
  7380.     set_tcp_make ();
  7381.  
  7382.   if (p_initialised == 0)
  7383.     {
  7384.       for (i = 0; i < 32; i++)
  7385.     p_initialise (i);
  7386.  
  7387.       p_initialised = 1;
  7388.     }
  7389.  
  7390.   /* First of all, get a file descriptor and file ptr we can associate with
  7391.      the socket, allocate a buffer, and remember the socket details.  */
  7392.   s = dup (0);
  7393.   if (s > 31)
  7394.     {
  7395.       errno = EMFILE;
  7396.       close (s);
  7397.       return -1;
  7398.     }
  7399.  
  7400.   p[s].fptr = fdopen (s, "r");
  7401.   p[s].fd_buff = (unsigned char *) malloc (BUF_SIZE);
  7402.   p[s].domain = domain;
  7403.   p[s].type = type;
  7404.   p[s].protocol = protocol;
  7405.  
  7406.   /* Handle the case of INET and X.25 separately.  */
  7407.   if (domain == AF_INET)
  7408.     {
  7409.       if (tcp_make == NONE)
  7410.     {
  7411.       printf ("Trying to obtain a TCP socket when we don't have TCP!\n");
  7412.       exit (1);
  7413.     }
  7414.       if (tcp_make == CMU)
  7415.     {
  7416.       /* For CMU we need only assign a channel.  */
  7417.       inetdesc.size = 3;
  7418.       inetdesc.ptr = "IP:";
  7419.       if (sys$assign (&inetdesc, &p[s].channel, 0, 0) != SS$_NORMAL)
  7420.         return -1;
  7421.     }
  7422.       else if (tcp_make == UCX)
  7423.     {
  7424.       /* For UCX assign channel and associate a socket with it.  */
  7425.       inetdesc.size = 3;
  7426.       inetdesc.ptr = "BG:";
  7427.       if (sys$assign (&inetdesc, &p[s].channel, 0, 0) != SS$_NORMAL)
  7428.         return -1;
  7429.  
  7430.       ucx_sock_def = (domain << 24) + (type << 16) + protocol;
  7431.       st = sys$qiow (0, p[s].channel, IO$_SETMODE, p[s].iosb, 0, 0,
  7432.              &ucx_sock_def, 0, 0, 0, 0, 0);
  7433.       if (QIO_FAILED)
  7434.         return -1;
  7435.     }
  7436.       else
  7437.     {
  7438.       /* For TWG we assign the channel and associate a socket with it.  */
  7439.       inetdesc.size = 7;
  7440.       inetdesc.ptr = "_INET0:";
  7441.  
  7442.       if (sys$assign (&inetdesc, &p[s].channel, 0, 0) != SS$_NORMAL)
  7443.         return -1;
  7444.  
  7445.       st = sys$qiow (0, p[s].channel, IO$_SOCKET, p[s].iosb, 0, 0,
  7446.              domain, type, 0, 0, 0, 0);
  7447.       if (QIO_FAILED)
  7448.         return -1;
  7449.     }
  7450.     }
  7451.   else
  7452.     /* We don't handle any other domains yet.  */
  7453.     return -1;
  7454.  
  7455.   /* For each case if we are successful we return the descriptor.  */
  7456.   return s;
  7457. }
  7458.  
  7459. /* Bind routine.  */
  7460. VMSbind (s, name, namelen)
  7461.      int s;
  7462.      union socket_addr *name;
  7463.      int namelen;
  7464. {
  7465.   char infobuff[1024], lhost[32];
  7466.   int st;
  7467.  
  7468.   if (!tcp_make)
  7469.     set_tcp_make ();
  7470.  
  7471.   if (p[s].domain == AF_INET)
  7472.     {
  7473.       /* One main problem with bind is that if we're given a port number
  7474.      of 0, then we're expected to return a unique port number.  Since
  7475.      we don't KNOW, we return 1050+s and look to Lady Luck.  */
  7476.       if (tcp_make == CMU)
  7477.     {
  7478.       if (name->in.sin_port == 0 && p[s].type != SOCK_DGRAM)
  7479.         name->in.sin_port = 1050 + s;
  7480.       p[s].namelen = namelen;
  7481.       bcopy (name, &(p[s].name), namelen);
  7482.  
  7483.       if (p[s].type == SOCK_DGRAM)
  7484.         {
  7485.           /* Another problem is that CMU still needs an OPEN request
  7486.          even if it's a datagram socket.  */
  7487.           st = sys$qiow (0, p[s].channel, TCP$OPEN, p[s].iosb,
  7488.                  0, 0, 0, 0, ntohs (p[s].name.in.sin_port),
  7489.                  0, 1, 0);
  7490.           if (QIO_ST_FAILED)
  7491.         return -1;
  7492.  
  7493.           p[s].cmu_open = 1;
  7494.           sys$qiow (0, p[s].channel, TCP$INFO, p[s].iosb,
  7495.             0, 0, &infobuff, 1024, 0, 0, 0, 0);
  7496.           bcopy (infobuff + 264, &(p[s].name.in.sin_port), 2);
  7497.           p[s].name.in.sin_port = htons (p[s].name.in.sin_port);
  7498.  
  7499.           /* So get it another way.  */
  7500.           bcopy (infobuff + 136, lhost, infobuff[1]);
  7501.           lhost[infobuff[1]] = '\0';
  7502.           sys$qiow (0, p[s].channel, GTHST, p[s].iosb,
  7503.             0, 0, &infobuff, 1024, 1, lhost, 0, 0);
  7504.           bcopy (infobuff + 4, &(p[s].name.in.sin_addr), 4);
  7505.  
  7506.           /* Be prepared to receive a message.  */
  7507.           hang_a_read (s);
  7508.         }
  7509.     }
  7510.       else if (tcp_make == UCX)
  7511.     {
  7512.       /* UCX will select a prot for you.  If the port's number is 0,
  7513.          translate "name" into an item_2 list.  */
  7514.       struct itemlist lhost;
  7515.       lhost.length = namelen;
  7516.       lhost.code = 0;
  7517.       lhost.dataptr = (char *) name;
  7518.  
  7519.       st = sys$qiow (0, p[s].channel, IO$_SETMODE, p[s].iosb, 0, 0,
  7520.              0, 0, &lhost, 0, 0, 0);
  7521.       if (QIO_FAILED)
  7522.         return -1;
  7523.  
  7524.       if (p[s].type == SOCK_DGRAM)
  7525.         hang_a_read (s);
  7526.  
  7527.     }
  7528.       else
  7529.     {
  7530.       /* WG is more straightforward */
  7531.       st = sys$qiow (0, p[s].channel, IO$_BIND, p[s].iosb,
  7532.              0, 0, name, namelen, 0, 0, 0, 0);
  7533.       if (QIO_FAILED)
  7534.         return -1;
  7535.  
  7536.       /* If it's a datagram, get ready for the message.  */
  7537.       if (p[s].type == SOCK_DGRAM)
  7538.         hang_a_read (s);
  7539.     }
  7540.     }
  7541.   else
  7542.     /* We don't handle any other domain yet.  */
  7543.     return -1;
  7544.  
  7545.   return 0;
  7546. }
  7547.  
  7548. /* Connect routine.  */
  7549. VMSconnect (s, name, namelen)
  7550.      int s;
  7551.      union socket_addr *name;
  7552.      int namelen;
  7553. {
  7554.   int pr, fl, st;
  7555.   char *inet_ntoa ();
  7556.   static struct
  7557.   {
  7558.     int len;
  7559.     char name[128];
  7560.   } gethostbuf;
  7561.   extern int connect_ast ();
  7562.  
  7563.   if (!tcp_make)
  7564.     set_tcp_make ();
  7565.  
  7566.   /* For datagrams we need to remember who the name was so we can send all
  7567.      messages to that address without having to specify it all the time.  */
  7568.   if (p[s].connected)
  7569.     {
  7570.       if (p[s].connected == 1)
  7571.     errno = EISCONN;
  7572.       else
  7573.     {
  7574.       errno = ECONNREFUSED;
  7575.       p[s].connected = 0;
  7576.     }
  7577.       return -1;
  7578.     }
  7579.  
  7580.   if (p[s].connect_pending)
  7581.     {
  7582.       errno = EALREADY;
  7583.       return -1;
  7584.     }
  7585.  
  7586.   p[s].passive = 0;
  7587.   p[s].tolen = namelen;
  7588.   bcopy (name, &(p[s].to), namelen);
  7589.  
  7590.   if (p[s].domain == AF_INET)
  7591.     {
  7592.       if (tcp_make == CMU)
  7593.     {
  7594.  
  7595.       /* Get the info about the remote host  and open up a connection.  */
  7596.       st = sys$qiow (0, p[s].channel, GTHST, p[s].iosb, 0, 0, &gethostbuf,
  7597.              132, 2, name->in.sin_addr.s_addr, 0, 0);
  7598.       if (QIO_FAILED)
  7599.         {
  7600.           strcpy (gethostbuf.name, inet_ntoa (name->in.sin_addr.s_addr));
  7601.           gethostbuf.len = strlen (gethostbuf.name);
  7602.         }
  7603.       gethostbuf.name[gethostbuf.len] = 0;
  7604.  
  7605.       /* TCP */
  7606.       pr = 0;
  7607.       /* Active */
  7608.       fl = 1;
  7609.  
  7610.       /* Nothing else for datagrams.  */
  7611.       if (p[s].type == SOCK_DGRAM)
  7612.         return (0);
  7613.       st = sys$qio (s, p[s].channel, TCP$OPEN, p[s].iosb, connect_ast,
  7614.             &p[s], &(gethostbuf.name), ntohs (name->in.sin_port),
  7615.             ntohs (p[s].name.in.sin_port), fl, pr, 0);
  7616.       if (QIO_ST_FAILED)
  7617.         return -1;
  7618.     }
  7619.       else if (tcp_make == UCX)
  7620.     {
  7621.       /* Both UDP and TCP can use a connect - IO$_ACCESS */
  7622.       p[s].rhost.length = namelen;
  7623.       p[s].rhost.code = 0;
  7624.       p[s].rhost.dataptr = (char *) name;
  7625.  
  7626.       st = sys$qio (s, p[s].channel, IO$_ACCESS, p[s].iosb, connect_ast,
  7627.             &p[s], 0, 0, &p[s].rhost, 0, 0, 0);
  7628.       if (QIO_ST_FAILED)
  7629.         return -1;
  7630.     }
  7631.       else
  7632.     {
  7633.       /* TWG */
  7634.       if (p[s].type == SOCK_DGRAM)
  7635.         return (0);
  7636.       st = sys$qio (s, p[s].channel, IO$_CONNECT, p[s].iosb, connect_ast,
  7637.             &p[s], name, namelen, 0, 0, 0, 0);
  7638.       if (QIO_ST_FAILED)
  7639.         return -1;
  7640.     }
  7641.     }
  7642.   else
  7643.     /* We don't handle any other domain yet.  */
  7644.     return -1;
  7645.  
  7646.   if (p[s].non_blocking)
  7647.     {
  7648.       if (p[s].connected)
  7649.     {
  7650.       if (p[s].connected == 1)
  7651.         return 0;
  7652.       else
  7653.         {
  7654.           p[s].connected = 0;
  7655.           errno = ECONNREFUSED;
  7656.           return -1;
  7657.         }
  7658.     }
  7659.       else
  7660.     {
  7661.       p[s].connect_pending = 1;
  7662.       errno = EINPROGRESS;
  7663.       return -1;
  7664.     }
  7665.     }
  7666.   else
  7667.     {
  7668.       /* wait for the connection to occur */
  7669.       if (p[s].connected)
  7670.     {
  7671.       if (p[s].connected == 1)
  7672.         return 0;
  7673.       else
  7674.         {
  7675.           p[s].connected = 0;
  7676.           errno = ECONNREFUSED;
  7677.           return -1;
  7678.         }
  7679.     }
  7680.  
  7681.       /* Timed out? */
  7682.       if (wait_efn (s) == -1)
  7683.     return -1;
  7684.  
  7685.       if (p[s].connected != SS$_NORMAL)
  7686.     {
  7687.       errno = ECONNREFUSED;
  7688.       return -1;
  7689.     }
  7690.  
  7691.       return 0;
  7692.     }
  7693. }
  7694.  
  7695. /* Listen routine.  */
  7696. VMSlisten (s, backlog)
  7697.      int s;
  7698.      int backlog;
  7699. {
  7700.   int st;
  7701.  
  7702.   if (!tcp_make)
  7703.     set_tcp_make ();
  7704.  
  7705.   p[s].passive = 1;
  7706.   p[s].backlog = backlog;
  7707.   if (p[s].domain == AF_INET)
  7708.     {
  7709.       if (tcp_make == CMU)
  7710.     {
  7711.       /* For the CMU sockets we can't do the open call in listen;
  7712.          we have to do it in hang_an_accept, because when we close
  7713.          off the connection we have to be ready to accept another
  7714.          one.  accept() also calls hang_an_accept on the old
  7715.          descriptor.  */
  7716.  
  7717.       /* Nothing */
  7718.     }
  7719.       else if (tcp_make == UCX)
  7720.     {
  7721.  
  7722.       /* Doc Verbage sez backlog is descriptor of byte.  Doc examples
  7723.          and common sense say backlog is value.  Value doesn't work,
  7724.          so let's try descriptor of byte after all.  */
  7725.       struct descriptor bl;
  7726.       unsigned char ucx_backlog;
  7727.  
  7728.       ucx_backlog = (unsigned char) backlog;
  7729.       bl.size = sizeof (ucx_backlog);
  7730.       bl.ptr = (char *) &ucx_backlog;
  7731.  
  7732.       st = sys$qiow (0, p[s].channel, IO$_SETMODE, p[s].iosb, 0, 0,
  7733.              0, 0, 0, &bl, 0, 0);
  7734.       if (QIO_FAILED)
  7735.         return -1;
  7736.     }
  7737.       else
  7738.     {
  7739.       /* TWG */
  7740.       st = sys$qiow (0, p[s].channel, IO$_LISTEN, p[s].iosb, 0, 0,
  7741.              backlog, 0, 0, 0, 0, 0);
  7742.       if (QIO_FAILED)
  7743.         return -1;
  7744.     }
  7745.     }
  7746.   else
  7747.     /* We don't handle any other domain yet.  */
  7748.     return -1;
  7749.  
  7750.   p[s].status = LISTENING;
  7751.   hang_an_accept (s);
  7752.   return 0;
  7753. }
  7754.  
  7755. /* Accept routine.  */
  7756. int
  7757. VMSaccept (s, addr, addrlen)
  7758.      int s;
  7759.      union socket_addr *addr;
  7760.      int *addrlen;
  7761. {
  7762.   int news, st;
  7763.   struct descriptor inetdesc;
  7764.  
  7765.   if (!tcp_make)
  7766.     set_tcp_make ();
  7767.  
  7768.   if (p[s].non_blocking && !p[s].accept_pending)
  7769.     {
  7770.       errno = EWOULDBLOCK;
  7771.       return -1;
  7772.     }
  7773.  
  7774.   /* hang_an_accept set up an incoming connection request so we have first
  7775.      to hang around until one appears or we time out.  */
  7776.   if (p[s].domain == AF_INET)
  7777.     {
  7778.       if (tcp_make == CMU)
  7779.     {
  7780.       char infobuff[1024];
  7781.  
  7782.       /* Timed out?  */
  7783.       if (wait_efn (s) == -1)
  7784.         return -1;
  7785.  
  7786.       /* Ok, get a new descriptor ...  */
  7787.       news = dup (0);
  7788.       if (news > 31)
  7789.         {
  7790.           errno = EMFILE;
  7791.           close (news);
  7792.           return -1;
  7793.         }
  7794.  
  7795.       /* ... and copy all of our data across.  */
  7796.       bcopy (&p[s], &p[news], sizeof (p[0]));
  7797.  
  7798.       /* But not this field, of course! */
  7799.       p[news].s = news;
  7800.  
  7801.       sys$qiow (0, p[news].channel, TCP$INFO, p[news].iosb,
  7802.             0, 0, &infobuff, 1024, 0, 0, 0, 0);
  7803.  
  7804.       /* Copy across the connection info if necessary.  */
  7805.       if (addr != 0)
  7806.         {
  7807.           *addrlen = sizeof (struct sockaddr_in);
  7808.           bcopy (infobuff + 132, &(addr->in.sin_port), 2);
  7809.           addr->in.sin_port = htons (addr->in.sin_port);
  7810.           addr->in.sin_family = AF_INET;
  7811.           bcopy (infobuff + 272, &(addr->in.sin_addr), 4);
  7812.           p[news].fromlen = *addrlen;
  7813.           bcopy (addr, &(p[news].from), *addrlen);
  7814.         }
  7815.       p[news].status = PASSIVE_CONNECTION;
  7816.  
  7817.       /* Get a new file ptr for the socket.  */
  7818.       p[news].fptr = fdopen (news, "r");
  7819.  
  7820.       /* Reset this field.  */
  7821.       p[news].accept_pending = 0;
  7822.  
  7823.       /* Allocate a buffer.  */
  7824.       p[news].fd_buff = (unsigned char *) malloc (BUF_SIZE);
  7825.       p[news].fd_leftover = 0;
  7826.  
  7827.       /* Be prepared to get msgs.  */
  7828.       hang_a_read (news);
  7829.  
  7830.       /* Now fix up our previous socket so it's again listening
  7831.          for connections.  */
  7832.       inetdesc.size = 3;
  7833.       inetdesc.ptr = "IP:";
  7834.       if (sys$assign (&inetdesc, &p[s].channel, 0, 0) != SS$_NORMAL)
  7835.         return -1;
  7836.       p[s].status = LISTENING;
  7837.       hang_an_accept (s);
  7838.  
  7839.       /* Return the new socket descriptor.  */
  7840.       return news;
  7841.     }
  7842.       else if (tcp_make == UCX)
  7843.     {
  7844.       /* UCX does the actual accept from hang_an_accept.  The accept info
  7845.         is put into the data structure for the "listening" socket.
  7846.         These just need to be copied into a newly allocated socket for
  7847.         the connect and the listening socket re-started.  */
  7848.  
  7849.       /* Wait for event flag from accept being received inside
  7850.          of hang_an_accept().  */
  7851.  
  7852.       if (wait_efn (s) == -1)
  7853.         /* Timed out.  */
  7854.         return -1;
  7855.  
  7856.       /* Ok, get a new descriptor ...  */
  7857.       news = dup (0);
  7858.       if (news > 31)
  7859.         {
  7860.           errno = EMFILE;
  7861.           close (news);
  7862.           return -1;
  7863.         }
  7864.       /* ... and copy all of our data across.  */
  7865.       bcopy (&p[s], &p[news], sizeof (p[0]));
  7866.       p[news].s = news;    /* but not this field */
  7867.       p[news].channel = p[s].ucx_accept_chan;
  7868.  
  7869.       /* Initialize the remote host address item_list_3 struct.  */
  7870.       p[news].rhost.length = sizeof (struct sockaddr_in);
  7871.       p[news].rhost.code = 0;
  7872.       p[news].rhost.dataptr = (char *) &p[news].from;
  7873.       p[news].rhost.retlenptr = &p[news].fromdummy;
  7874.  
  7875.       if (addr != 0)
  7876.         {
  7877.           /* Return the caller's info, if requested.  */
  7878.           *addrlen = p[news].fromdummy;
  7879.           bcopy (&p[news].from, addr, p[news].fromdummy);
  7880.         }
  7881.  
  7882.       /* Finish fleshing out the new structure.  */
  7883.       p[news].status = PASSIVE_CONNECTION;
  7884.  
  7885.       /* Get a new file pointer for the socket.  */
  7886.       p[news].fptr = fdopen (news, "r");
  7887.  
  7888.       /* Reset this field.  */
  7889.       p[news].accept_pending = 0;
  7890.  
  7891.       /* Allocate a buffer.  */
  7892.       p[news].fd_buff = (unsigned char *) malloc (BUF_SIZE);
  7893.       p[news].fd_leftover = 0;
  7894.  
  7895.       /* Get it started reading.  */
  7896.       hang_a_read (news);
  7897.  
  7898.       p[s].status = LISTENING;
  7899.       hang_an_accept (s);
  7900.  
  7901.       return news;
  7902.     }
  7903.       else
  7904.     {
  7905.       /* TWG */
  7906.       struct descriptor inetdesc;
  7907.       int size;
  7908.  
  7909.       /* Time out?  */
  7910.       if (wait_efn (s) == -1)
  7911.         return -1;
  7912.  
  7913.       /* Ok, get a new descriptor ...  */
  7914.       news = dup (0);
  7915.       if (news > 31)
  7916.         {
  7917.           errno = EMFILE;
  7918.           close (news);
  7919.           return -1;
  7920.         }
  7921.  
  7922.       /* Assign a new channel.  */
  7923.       inetdesc.size = 7;
  7924.       inetdesc.ptr = "_INET0:";
  7925.       st = sys$assign (&inetdesc, &p[news].channel, 0, 0);
  7926.       if (QIO_ST_FAILED)
  7927.         {
  7928.           p[s].accept_pending = 0;
  7929.           sys$clref (s);
  7930.           return -1;
  7931.         }
  7932.  
  7933.       /* From info needs an int length field! */
  7934.       size = sizeof (p[s].from) + 4;
  7935.       st = sys$qiow (0, p[news].channel, IO$_ACCEPT, p[news].iosb, 0, 0,
  7936.              &p[s].fromdummy, size, p[s].channel, 0, 0, 0);
  7937.  
  7938.       if (QIO_ST_FAILED || p[news].iosb[0] != SS$_NORMAL)
  7939.         {
  7940.           p[s].accept_pending = 0;
  7941.           sys$clref (s);
  7942.           return -1;
  7943.         }
  7944.  
  7945.       if (addr != 0)
  7946.         {
  7947.           /* Return the caller's info if requested.  */
  7948.           *addrlen = p[s].fromdummy;
  7949.           bcopy (&p[s].from, addr, *addrlen);
  7950.         }
  7951.  
  7952.       /* Fix up our new data structure.  */
  7953.       p[news].status = PASSIVE_CONNECTION;
  7954.       p[news].domain = AF_INET;
  7955.       p[news].passive = 1;
  7956.       p[news].fptr = fdopen (news, "r");
  7957.       /* Allocate a buffer.  */
  7958.       p[news].fd_buff = (unsigned char *) malloc (BUF_SIZE);
  7959.  
  7960.       /* Be prepared to accept msgs.  */
  7961.       hang_a_read (news);
  7962.  
  7963.       /* Get the old descriptor back onto accepting.  */
  7964.       hang_an_accept (s);
  7965.       return news;
  7966.     }
  7967.     }
  7968.   else
  7969.     /* We don't handle any other domain yet.  */
  7970.     return -1;
  7971. }
  7972.  
  7973. /* Recv routine.  */
  7974. int
  7975. VMSrecv (s, buf, len, flags)
  7976.      int s;
  7977.      char *buf;
  7978.      int len, flags;
  7979. {
  7980.   return recvfrom (s, buf, len, flags, 0, 0);
  7981. }
  7982.  
  7983. /* Revfrom routine.  */
  7984. int
  7985. VMSrecvfrom (s, buf, len, flags, from, fromlen)
  7986.      int s;
  7987.      char *buf;
  7988.      int len, flags;
  7989.      union socket_addr *from;
  7990.      int *fromlen;
  7991. {
  7992.   int number;
  7993.  
  7994.   if (!tcp_make)
  7995.     set_tcp_make ();
  7996.  
  7997.   if (p[s].domain != AF_INET && p[s].domain != AF_X25)
  7998.     return -1;
  7999.  
  8000.   /* If we're not onto datagrams, then it's possible that a previous
  8001.      call to recvfrom didn't read all the data, and left some behind.
  8002.      So first of all, look in our data buffer for any leftovers that
  8003.      will satisfy this read.  */
  8004.  
  8005.   /* We couldn't satisfy the request from previous calls so we must now
  8006.      wait for a message to come through.  */
  8007.   if (wait_efn (s) == -1)
  8008.     /* Timed out.  */
  8009.     return -1;
  8010.  
  8011.   if (p[s].closed_by_remote == 1)
  8012.     {
  8013.       /* This could have happened! */
  8014.       errno = ECONNRESET;
  8015.       return -1;
  8016.     }
  8017.  
  8018.   if (from != NULL)
  8019.     {
  8020.       if (tcp_make == CMU)
  8021.     {
  8022.       if (p[s].type == SOCK_DGRAM)
  8023.         {
  8024.           /* Not documented but we get the from data from the beginning of
  8025.          the data buffer.  */
  8026.           *fromlen = sizeof (p[s].from.in);
  8027.           from->in.sin_family = AF_INET;
  8028.           bcopy (&p[s].fd_buff[8], &(from->in.sin_port), 2);
  8029.           from->in.sin_port = htons (from->in.sin_port);
  8030.           bcopy (&p[s].fd_buff[0], &(from->in.sin_addr), 4);
  8031.  
  8032.           /* Remove the address data from front of data buffer.  */
  8033.           bcopy (p[s].fd_buff + 12, p[s].fd_buff, p[s].fd_buff_size);
  8034.         }
  8035.       else
  8036.         {
  8037.           *fromlen = p[s].fromlen;
  8038.           bcopy (&p[s].from, from, p[s].fromlen);
  8039.         }
  8040.     }
  8041.       else if (tcp_make == UCX)
  8042.     {
  8043.       *fromlen = p[s].fromdummy;
  8044.       bcopy (&p[s].from, from, p[s].fromdummy);
  8045.     }
  8046.       else
  8047.     {
  8048.       *fromlen = p[s].fromlen;
  8049.       bcopy (&p[s].from, from, p[s].fromlen);
  8050.     }
  8051.     }
  8052.  
  8053.   /* We may've received too much.  */
  8054.   number = p[s].fd_buff_size;
  8055.   if (number <= len)
  8056.     {
  8057.       /* If we haven't give back all the data available.  */
  8058.       bcopy (p[s].fd_buff, buf, number);
  8059.       p[s].fd_leftover = 0;
  8060.       hang_a_read (s);
  8061.       return (number);
  8062.     }
  8063.   else
  8064.     {
  8065.       /* If we have too much data then split it up.  */
  8066.       p[s].fd_leftover = p[s].fd_buff;
  8067.       bcopy (p[s].fd_leftover, buf, len);
  8068.       /* And change the pointers.  */
  8069.       p[s].fd_leftover += len;
  8070.       p[s].fd_buff_size -= len;
  8071.       return (len);
  8072.     }
  8073. }
  8074.  
  8075. /* Send routine.  */
  8076. int
  8077. VMSsend (s, msg, len, flags)
  8078.      int s;
  8079.      char *msg;
  8080.      int len, flags;
  8081. {
  8082.   return sendto (s, msg, len, flags, 0, 0);
  8083. }
  8084.  
  8085. /* Sendto routine.  */
  8086. int
  8087. VMSsendto (s, msg, len, flags, to, tolen)
  8088.      int s;
  8089.      unsigned char *msg;
  8090.      int len, flags;
  8091.      union socket_addr *to;
  8092.      int tolen;
  8093. {
  8094.   int i, j, st, size;
  8095.   unsigned char udpbuf[BUF_SIZE + 12];
  8096.   char infobuff[1024], lhost[32];
  8097.   unsigned short int temp;
  8098.  
  8099.   if (!tcp_make)
  8100.     set_tcp_make ();
  8101.  
  8102.   /* First remember who we sent it to and set the value of size.  */
  8103.   if (to != 0)
  8104.     {
  8105.       p[s].tolen = tolen;
  8106.       bcopy (to, &(p[s].to), tolen);
  8107.       size = tolen;
  8108.     }
  8109.   else
  8110.     size = 0;
  8111.  
  8112.   if (p[s].domain == AF_INET)
  8113.     {
  8114.       /* We might never have started a read for udp (socket/sendto) so
  8115.      put one here.  */
  8116.       if (p[s].type == SOCK_DGRAM)
  8117.     hang_a_read (s);
  8118.  
  8119.       if (tcp_make == CMU)
  8120.     {
  8121.       if (p[s].type == SOCK_DGRAM)
  8122.         {
  8123.           /* We might never have opened up a udp connection yet,
  8124.          so check.  */
  8125.           if (p[s].cmu_open != 1)
  8126.         {
  8127.           st = sys$qiow (0, p[s].channel, TCP$OPEN, p[s].iosb, 0, 0,
  8128.                  0, 0, 0, 0, 1, 0);
  8129.           if (QIO_ST_FAILED)
  8130.             return -1;
  8131.  
  8132.           p[s].cmu_open = 1;
  8133.           sys$qiow (0, p[s].channel, TCP$INFO, p[s].iosb,
  8134.                 0, 0, &infobuff, 1024, 0, 0, 0, 0);
  8135.           bcopy (infobuff + 264, &(p[s].name.in.sin_port), 2);
  8136.           p[s].name.in.sin_port = htons (p[s].name.in.sin_port);
  8137.           bcopy (infobuff + 136, lhost, infobuff[1]);
  8138.           lhost[infobuff[1]] = '\0';
  8139.           sys$qiow (0, p[s].channel, GTHST, p[s].iosb,
  8140.                 0, 0, &infobuff, 1024, 1, lhost, 0, 0);
  8141.           bcopy (infobuff + 4, &(p[s].name.in.sin_addr), 4);
  8142.         }
  8143.  
  8144.           /* This isn't well documented.  To send to a UDP socket, we
  8145.          need to put the address info at the beginning of the
  8146.          buffer.  */
  8147.           bcopy (msg, udpbuf + 12, len);
  8148.           bcopy (&p[s].to.in.sin_addr, udpbuf + 4, 4);
  8149.           temp = ntohs (p[s].to.in.sin_port);
  8150.           bcopy (&temp, udpbuf + 10, 2);
  8151.           bcopy (&p[s].name.in.sin_addr, udpbuf, 4);
  8152.           temp = ntohs (p[s].name.in.sin_port);
  8153.           bcopy (&temp, udpbuf + 8, 2);
  8154.           temp = len + 12;
  8155.           st = sys$qiow (0, p[s].channel, TCP$SEND, p[s].iosb, 0, 0,
  8156.                  udpbuf, temp, 0, 0, 0, 0);
  8157.           if (QIO_FAILED)
  8158.         return -1;
  8159.         }
  8160.       else
  8161.         {
  8162.           /* TCP (! UDP)  */
  8163.           st = sys$qiow (0, p[s].channel, TCP$SEND, p[s].iosb, 0, 0,
  8164.                  msg, len, 0, 0, 0, 0);
  8165.           if (QIO_FAILED)
  8166.         return -1;
  8167.         }
  8168.       return len;
  8169.     }
  8170.       else if (tcp_make == UCX)
  8171.     {
  8172.       struct itemlist rhost;
  8173.       rhost.length = sizeof (struct sockaddr_in);
  8174.       rhost.code = 0;
  8175.       rhost.dataptr = (char *) &p[s].to;
  8176.  
  8177.       st = sys$qiow (0, p[s].channel, IO$_WRITEVBLK, p[s].iosb, 0, 0,
  8178.              msg, len, &rhost, 0, 0, 0);
  8179.       if (QIO_FAILED)
  8180.         return -1;
  8181.  
  8182.       return len;
  8183.     }
  8184.       else
  8185.     {
  8186.       /* TWG */
  8187.       st = sys$qiow (0, p[s].channel, IO$_WRITEVBLK, p[s].iosb,
  8188.              0, 0, msg, len, 0, &p[s].to, size, 0);
  8189.       if (QIO_FAILED)
  8190.         return -1;
  8191.  
  8192.       return len;
  8193.     }
  8194.     }
  8195.   else
  8196.     /* We don't handle any other domain yet.  */
  8197.     return -1;
  8198. }
  8199.  
  8200. /* Getsockname routine.  */
  8201. int
  8202. VMSgetsockname (s, name, namelen)
  8203.      int s;
  8204.      union socket_addr *name;
  8205.      int *namelen;
  8206. {
  8207.   int st;
  8208.  
  8209.   if (!tcp_make)
  8210.     set_tcp_make ();
  8211.  
  8212.   if (p[s].domain == AF_INET)
  8213.     {
  8214.       if (tcp_make == CMU)
  8215.     {
  8216.       /* For CMU we just return values held in our data structure.  */
  8217.       *namelen = p[s].namelen;
  8218.       bcopy (&(p[s].name), name, *namelen);
  8219.       return (0);
  8220.     }
  8221.       else if (tcp_make == UCX)
  8222.     {
  8223.       /* An item_list_3 descriptor.  */
  8224.       struct itemlist lhost;
  8225.  
  8226.       lhost.length = *namelen;
  8227.       lhost.code = 0;
  8228.       lhost.dataptr = (char *) name;
  8229.  
  8230.       /* Fill in namelen with actual ret len value.  */
  8231.       lhost.retlenptr = (short int *) namelen;
  8232.  
  8233.       st = sys$qiow (0, p[s].channel, IO$_SENSEMODE, p[s].iosb, 0, 0,
  8234.              0, 0, &lhost, 0, 0, 0);
  8235.       if (QIO_FAILED)
  8236.         return -1;
  8237.  
  8238.       return 0;
  8239.     }
  8240.       else
  8241.     {
  8242.       /* TWG gives us the information. */
  8243.       st = sys$qiow (0, p[s].channel, IO$_GETSOCKNAME, p[s].iosb,
  8244.              0, 0, name, namelen, 0, 0, 0, 0);
  8245.       if (QIO_FAILED)
  8246.         return -1;
  8247.  
  8248.       return 0;
  8249.     }
  8250.     }
  8251.   else
  8252.     /* We don't handle any other domain yet.  */
  8253.     return -1;
  8254. }
  8255.  
  8256. /* Select routine.  */
  8257. int
  8258. VMSselect (nfds, readfds, writefds, exceptfds, timeout)
  8259.      int nfds;
  8260.      fd_set *readfds, *writefds, *exceptfds;
  8261.      struct timeval *timeout;
  8262. {
  8263.   int timer, fd, alarm_set, total, end;
  8264.   long mask, cluster;
  8265.   struct descriptor termdesc;
  8266.   static fd_set new_readfds, new_writefds, new_exceptfds;
  8267.  
  8268.   FD_ZERO (&new_readfds);
  8269.   FD_ZERO (&new_writefds);
  8270.   FD_ZERO (&new_exceptfds);
  8271.   total = 0;
  8272.  
  8273.   /* Assign a terminal channel if we haven't already.  */
  8274.   if (terminal.chan == -1)
  8275.     {
  8276.       termdesc.size = 10;
  8277.       termdesc.ptr = "SYS$INPUT:";
  8278.       sys$assign (&termdesc, &terminal.chan, 0, 0);
  8279.     }
  8280.   alarm_set = 0;
  8281.   if (timeout != NULL)
  8282.     {
  8283.       /* If a timeout is given then set the alarm.  */
  8284.       end = timeout->tv_sec;
  8285.       if (timer != 0)
  8286.     {
  8287.       /* We need to reset the alarm if it didn't fire, but we set it.  */
  8288.       alarm_set = 1;
  8289.       si_alarm (end);
  8290.     }
  8291.     }
  8292.   else
  8293.     end = 1;
  8294.  
  8295.   do
  8296.     {
  8297.       if (exceptfds)
  8298.     {
  8299.        /* Nothing */ ;
  8300.     }
  8301.  
  8302.       if (writefds)
  8303.     {
  8304.       for (fd = 0; fd < nfds; fd++)
  8305.         if (FD_ISSET (fd, writefds))
  8306.           {
  8307.         if (p[fd].connect_pending)
  8308.            /* Nothing */ ;
  8309.         else if ((p[fd].status == ACTIVE_CONNECTION)
  8310.              || (p[fd].status == PASSIVE_CONNECTION))
  8311.           {
  8312.             FD_SET (fd, &new_writefds);
  8313.             total++;
  8314.           }
  8315.           }
  8316.     }
  8317.  
  8318.       if (readfds)
  8319.     {
  8320.       /* True if data pending or an accept.  */
  8321.       for (fd = 3; fd < nfds; fd++)
  8322.         if (FD_ISSET (fd, readfds) &&
  8323.         ((p[fd].fd_buff_size != -1) || (p[fd].accept_pending == 1)))
  8324.           {
  8325.         FD_SET (fd, &new_readfds);
  8326.         total++;
  8327.           }
  8328.     }
  8329.  
  8330.       if (total || (end == 0))
  8331.     break;
  8332.  
  8333.       /* Otherwise, wait on an event flag.  It's possible that the wait can
  8334.      be stopped by a spurious event flag being set -- i.e. one that's
  8335.      got a status not normal.  So we've got to be prepared to loop
  8336.      around the wait until a valid reason happens.  */
  8337.  
  8338.       /* Set up the wait mask.  */
  8339.       cluster = 0;
  8340.       mask = 0;
  8341.       for (fd = 3; fd < nfds; fd++)
  8342.     {
  8343.       sys$clref (fd);
  8344.       if (readfds)
  8345.         if FD_ISSET
  8346.           (fd, readfds) mask |= (1 << fd);
  8347.       if (writefds)
  8348.         if FD_ISSET
  8349.           (fd, writefds) mask |= (1 << fd);
  8350.       if (exceptfds)
  8351.         if FD_ISSET
  8352.           (fd, exceptfds) mask |= (1 << fd);
  8353.     }
  8354.  
  8355.       mask |= (1 << TIMER_EFN);
  8356.  
  8357.       /* Clear it off just in case.  */
  8358.       sys$clref (TIMER_EFN);
  8359.  
  8360.       /* Wait around.  */
  8361.       sys$wflor (cluster, mask);
  8362.  
  8363.       mask = 0;
  8364.       if (read_efn (TIMER_EFN))
  8365.     {
  8366.       errno = EINTR;
  8367.       break;
  8368.     }
  8369.   } while (1);
  8370.   /*NOTREACHED*/
  8371.  
  8372.   /* Unset the alarm if we set it.  */
  8373.   if (alarm_set == 1)
  8374.     alarm (0);
  8375.  
  8376.   if (readfds)
  8377.     *readfds = new_readfds;
  8378.  
  8379.   if (writefds)
  8380.     *writefds = new_writefds;
  8381.  
  8382.   if (exceptfds)
  8383.     *exceptfds = new_exceptfds;
  8384.  
  8385.   return total;
  8386. }
  8387.  
  8388. /* Shutdown routine.  */
  8389. VMSshutdown (s, how)
  8390.      int s, how;
  8391. {
  8392.   int st;
  8393.   int ucx_how;
  8394.  
  8395.   if (!tcp_make)
  8396.     set_tcp_make ();
  8397.  
  8398.   if (p[s].domain == AF_INET)
  8399.     {
  8400.       if (tcp_make == CMU)
  8401.     {
  8402.       /* For CMU we just close off.  */
  8403.       si_close (s);
  8404.       return 0;
  8405.     }
  8406.       else if (tcp_make == UCX)
  8407.     {
  8408.       st = sys$qiow (0, p[s].channel, IO$_DEACCESS | IO$M_SHUTDOWN,
  8409.              p[s].iosb, 0, 0, 0, 0, 0, how, 0, 0);
  8410.       if (QIO_FAILED)
  8411.         return -1;
  8412.  
  8413.       return 0;
  8414.     }
  8415.       else
  8416.     {
  8417.       /* TWG lets us do it.  */
  8418.       st = sys$qiow (0, p[s].channel, IO$_SHUTDOWN, p[s].iosb, 0, 0, how,
  8419.              0, 0, 0, 0, 0);
  8420.       if (QIO_FAILED)
  8421.         return -1;
  8422.  
  8423.       return 0;
  8424.     }
  8425.     }
  8426.   else                /* it wasn't a socket */
  8427.     return -1;
  8428. }
  8429.  
  8430. /*   */
  8431.  
  8432. /* The following routines are used by the above socket calls.  */
  8433.  
  8434. /* hang_a_read sets up a read to be finished at some later time.  */
  8435. hang_a_read (s)
  8436.      int s;
  8437. {
  8438.   extern int read_ast ();
  8439.   int size, st;
  8440.  
  8441.   /* Don't bother if we already did it.  */
  8442.   if (p[s].read_outstanding == 1)
  8443.     return;
  8444.  
  8445.   /* Have a read outstanding.  */
  8446.   p[s].read_outstanding = 1;
  8447.   size = sizeof (p[s].from) + 4;
  8448.   sys$clref (s);
  8449.  
  8450.   /* Clear off the event flag just in case, and reset the buf size.  */
  8451.   p[s].fd_buff_size = -1;
  8452.   if (p[s].domain == AF_INET)
  8453.     {
  8454.       if (tcp_make == CMU)
  8455.     {
  8456.       st = sys$qio (s, p[s].channel, TCP$RECEIVE, p[s].iosb, read_ast,
  8457.             &p[s], p[s].fd_buff, BUF_SIZE, 0, 0, 0, 0);
  8458.       if (QIO_ST_FAILED)
  8459.         return -1;
  8460.     }
  8461.       else if (tcp_make == UCX)
  8462.     {
  8463.  
  8464.       p[s].rhost.length = sizeof (struct sockaddr_in);
  8465.       p[s].rhost.code = 0;
  8466.       p[s].rhost.dataptr = (char *) &p[s].from;
  8467.       p[s].rhost.retlenptr = &p[s].fromdummy;
  8468.  
  8469.       st = sys$qio (s, p[s].channel, IO$_READVBLK, p[s].iosb, read_ast,
  8470.             &p[s], p[s].fd_buff, BUF_SIZE, &p[s].rhost, 0, 0, 0);
  8471.       if (QIO_ST_FAILED)
  8472.         return -1;
  8473.     }
  8474.       else
  8475.     {
  8476.       /* TWG */
  8477.       st = sys$qio (s, p[s].channel, IO$_READVBLK, p[s].iosb, read_ast,
  8478.             &p[s], p[s].fd_buff, BUF_SIZE, 0, &p[s].fromlen,
  8479.             size, 0);
  8480.       if (QIO_ST_FAILED)
  8481.         return -1;
  8482.     }
  8483.     }
  8484.   else
  8485.     /* We don't handle any other domain yet.  */
  8486.     return -1;
  8487. }
  8488.  
  8489. /* hang_an_accept waits for a connection request to come in.  */
  8490. hang_an_accept (s)
  8491.      int s;
  8492. {
  8493.   extern int accept_ast ();
  8494.   int st;
  8495.  
  8496.   /* Clear the event flag just in case.  */
  8497.   sys$clref (s);
  8498.  
  8499.   /* Reset our flag & buf size.  */
  8500.   p[s].accept_pending = 0;
  8501.   p[s].fd_buff_size = -1;
  8502.   if (p[s].domain == AF_INET)
  8503.     {
  8504.       if (tcp_make == CMU)
  8505.     {
  8506.       st = sys$qio (s, p[s].channel, TCP$OPEN, p[s].iosb, accept_ast,
  8507.             &p[s], 0, 0, ntohs (p[s].name.in.sin_port), 0, 0, 0);
  8508.       if (QIO_ST_FAILED)
  8509.         return -1;
  8510.     }
  8511.       else if (tcp_make == UCX)
  8512.     {
  8513.       struct descriptor inetdesc;
  8514.  
  8515.       /* Assign channel for actual connection off listener.  */
  8516.       inetdesc.size = 3;
  8517.       inetdesc.ptr = "BG:";
  8518.       if (sys$assign (&inetdesc, &p[s].ucx_accept_chan, 0,
  8519.               0) != SS$_NORMAL)
  8520.         return -1;
  8521.  
  8522.       /* UCX's accept returns remote host info and the channel for a new
  8523.          socket to perform reads/writes on, so a sys$assign isn't
  8524.          really necessary.  */
  8525.       p[s].rhost.length = sizeof (struct sockaddr_in);
  8526.       p[s].rhost.dataptr = (char *) &p[s].from;
  8527.       p[s].fromdummy = 0;
  8528.       p[s].rhost.retlenptr = &p[s].fromdummy;
  8529.  
  8530.       st = sys$qio (s, p[s].channel, IO$_ACCESS | IO$M_ACCEPT, p[s].iosb,
  8531.             accept_ast, &p[s], 0, 0, &p[s].rhost,
  8532.             &p[s].ucx_accept_chan, 0, 0);
  8533.       if (QIO_ST_FAILED)
  8534.         return -1;
  8535.     }
  8536.       else
  8537.     {
  8538.       st = sys$qio (s, p[s].channel, IO$_ACCEPT_WAIT, p[s].iosb,
  8539.             accept_ast, &p[s], 0, 0, 0, 0, 0, 0);
  8540.       if (QIO_ST_FAILED)
  8541.         return -1;
  8542.     }
  8543.     }
  8544.   else
  8545.     /* We don't handle any other domain yet.  */
  8546.     return -1;
  8547. }
  8548.  
  8549. /* wait_efn just sets up a wait on either an event or the timer.  */
  8550. wait_efn (s)
  8551.      int s;
  8552. {
  8553.   long mask, cluster;
  8554.  
  8555.   cluster = 0;
  8556.   sys$clref (TIMER_EFN);
  8557.   mask = (1 << s) | (1 << TIMER_EFN);
  8558.   sys$wflor (cluster, mask);
  8559.  
  8560.   if (read_efn (TIMER_EFN))
  8561.     {
  8562.       errno = EINTR;
  8563.       return -1;
  8564.     }
  8565.  
  8566.   return 0;
  8567. }
  8568.  
  8569. /* read_ast is called by the system whenever a read is done.  */
  8570. read_ast (p)
  8571.      struct fd_entry *p;
  8572. {
  8573.   int i, j;
  8574.   unsigned char *v, *w;
  8575.  
  8576.   /* Reset the outstanding flag.  */
  8577.   p->read_outstanding = 0;
  8578.   if (p->iosb[0] == SS$_NORMAL)
  8579.     {
  8580.       /* Check no errors.  */
  8581.       p->fd_buff_size = p->iosb[1];
  8582.       if (tcp_make == CMU)
  8583.     {
  8584.       /* fiddle for DGRMs */
  8585.       if (p->type == SOCK_DGRAM)
  8586.         p->fd_buff_size -= 12;
  8587.     }
  8588.       if (p->sig_req == 1)
  8589.     gsignal (SIGIO);
  8590.     }
  8591.   else if (p->iosb[0] == SS$_CLEARED)
  8592.     p->closed_by_remote = 1;
  8593.   else if (tcp_make == UCX)
  8594.     {
  8595.       if (p->iosb[0] == SS$_LINKDISCON)
  8596.     p->closed_by_remote = 1;
  8597.     }
  8598. }
  8599.  
  8600. /* accept_ast is called whenever an incoming call is detected.  */
  8601. accept_ast (p)
  8602.      struct fd_entry *p;
  8603. {
  8604.   if (p->iosb[0] == SS$_NORMAL)
  8605.     p->accept_pending = 1;
  8606.   else
  8607.     /* If it failed set up another listen.  */
  8608.     listen (p->s, p[p->s].backlog);
  8609. }
  8610.  
  8611. /* connect_ast is called whenever an async connect is made.  */
  8612. connect_ast (p)
  8613.      struct fd_entry *p;
  8614. {
  8615.   p->connect_pending = 0;
  8616.   if ((p->connected = p->iosb[0]) == SS$_NORMAL)
  8617.     {
  8618.       /* We made the connection.  */
  8619.       p->status = ACTIVE_CONNECTION;
  8620.  
  8621.       /* Be prepared to accept a msg.  */
  8622.       hang_a_read (p->s);
  8623.     }
  8624. }
  8625.  
  8626. /*   */
  8627. /* These routines handle stream I/O.  */
  8628.  
  8629. /* si_close -- must close off any connection in progress.  */
  8630. si_close (s)
  8631.      int s;
  8632. {
  8633.   if (!tcp_make)
  8634.     set_tcp_make ();
  8635.  
  8636.   if ((s < 0) || (s > 31))
  8637.     return -1;
  8638.  
  8639.   if (p[s].channel != 0)
  8640.     {
  8641.       /* Was it one of our descriptors? */
  8642.       if (p[s].domain == AF_INET)
  8643.     {
  8644.       if (tcp_make == CMU)
  8645.         sys$qiow (0, p[s].channel, TCP$CLOSE, p[s].iosb,
  8646.               0, 0, 0, 0, 0, 0, 0, 0);
  8647.       if (p[s].status != HANDED_OFF)
  8648.         sys$dassgn (p[s].channel);
  8649.       close (s);
  8650.       free (p[s].fd_buff);
  8651.       p_initialise (s);
  8652.     }
  8653.       return 0;
  8654.     }
  8655.   else
  8656.     {
  8657.       /* Re-initialise data structure just in case.  */
  8658.       p[s].fd_buff_size = -1;
  8659.       p[s].accept_pending = 0;
  8660.       p[s].status = INITIALISED;
  8661.       return close (s);
  8662.     }
  8663. }
  8664.  
  8665. /* si_alarm -- insert a call to our own alarm function.  */
  8666. si_alarm (i)
  8667.      int i;
  8668. {
  8669.   extern int pre_alarm ();
  8670.  
  8671.   /* Make the call to pre_alarm instead of what the user wants;
  8672.      pre_alarm will call his routine when it finishes.  */
  8673.   /* VAX needs this call each time! */
  8674.   signal (SIGALRM, pre_alarm);
  8675.   alarm (i);
  8676. }
  8677.  
  8678. /* pre_alarm -- gets called first on an alarm signal.  */
  8679. pre_alarm ()
  8680. {
  8681.   /* Come here first so we can set our timer event flag.  */
  8682.   sys$setef (TIMER_EFN);
  8683.   (*alarm_function) ();
  8684. }
  8685.  
  8686. /* p_initialise - initialise our data array.  */
  8687. p_initialise (s)
  8688.      int s;
  8689. {
  8690.   int j;
  8691.   for (j = 0; j < 4; j++)
  8692.     p[s].iosb[j] = 0;
  8693.   p[s].channel = 0;
  8694.   p[s].fd_buff_size = -1;
  8695.   p[s].accept_pending = 0;
  8696.   p[s].connect_pending = 0;
  8697.   p[s].connected = 0;
  8698.   p[s].fd_buff = NULL;
  8699.   p[s].fd_leftover = NULL;
  8700.   p[s].fptr = NULL;
  8701.   p[s].s = s;
  8702.   p[s].name.in.sin_port = 0;
  8703.   p[s].masklen = 4;
  8704.   for (j = 0; j < 16; j++)
  8705.     p[s].mask[j] = 0xff;
  8706.   p[s].need_header = 0;
  8707.   p[s].status = INITIALISED;
  8708.   p[s].read_outstanding = 0;
  8709.   p[s].cmu_open = 0;
  8710.   p[s].x25_listener = 0;
  8711.   p[s].mother = s;
  8712.   p[s].child = 0;
  8713.   p[s].no_more_accepts = 0;
  8714.   p[s].closed_by_remote = 0;
  8715.   p[s].non_blocking = 0;
  8716.   p[s].sig_req = 0;
  8717.   sys$clref (s);
  8718. }
  8719.  
  8720. /* read_efn -- see whether an event flag is set.  */
  8721. read_efn (i)
  8722.      int i;
  8723. {
  8724.   int j;
  8725.   sys$readef (i, &j);
  8726.   j &= (1 << i);
  8727.  
  8728.   return j;
  8729. }
  8730.  
  8731. static
  8732. set_tcp_make ()
  8733. {
  8734.   struct descriptor inetdesc;
  8735.   int channel;
  8736.   /* first try CMU */
  8737.   inetdesc.size = 3;
  8738.   inetdesc.ptr = "IP:";
  8739.   if (sys$assign (&inetdesc, &channel, 0, 0) == SS$_NORMAL)
  8740.     {
  8741.       sys$dassgn (channel);
  8742.       tcp_make = CMU;
  8743.       return;
  8744.     }
  8745.  
  8746.   /* next try TWG */
  8747.   inetdesc.size = 7;
  8748.   inetdesc.ptr = "_INET0:";
  8749.   if (sys$assign (&inetdesc, &channel, 0, 0) == SS$_NORMAL)
  8750.     {
  8751.       sys$dassgn (channel);
  8752.       tcp_make = WG;
  8753.       return;
  8754.     }
  8755.  
  8756.   /* next try UCX */
  8757.   inetdesc.size = 4;
  8758.   inetdesc.ptr = "BG0:";
  8759.   if (sys$assign (&inetdesc, &channel, 0, 0) == SS$_NORMAL)
  8760.     {
  8761.       sys$dassgn (channel);
  8762.       tcp_make = UCX;
  8763.       return;
  8764.     }
  8765.  
  8766.   /* nothing there oh dear!*/
  8767.   tcp_make = NONE;
  8768.   return;
  8769. }
  8770.  
  8771. static char *
  8772. getdevicename (channel)
  8773.      unsigned short int channel;
  8774. {
  8775.   int st;
  8776.   struct
  8777.   {
  8778.     struct itemlist id;
  8779.     int eol;
  8780.   } itmlst;
  8781.   static char name[64];
  8782.   short int lgth;
  8783.  
  8784.   name[0] = '\0';
  8785.   itmlst.id.code = DVI$_DEVNAM;
  8786.   itmlst.id.length = 64;
  8787.   itmlst.id.dataptr = name;
  8788.   itmlst.id.retlenptr = &lgth;
  8789.   itmlst.eol = 0;
  8790.   st = sys$getdvi (0, channel, 0, &itmlst, 0, 0, 0, 0);
  8791.   if (QIO_ST_FAILED)
  8792.     fprintf (stderr, "error getting device name %d\n", st);
  8793.  
  8794.   return (name);
  8795. }
  8796. $EOD
  8797. $!
  8798. $CREATE [.archie.vms]fd.h
  8799. $DECK
  8800. #ifndef _VMS_FD
  8801. #define _VMS_FD
  8802.  
  8803. typedef struct fd_set
  8804. {
  8805.   int fds_bits[1];
  8806. } fd_set;
  8807.  
  8808. #define FD_SETSIZE          (sizeof (fd_set) * 8)
  8809. #define FD_SET(f,s)         ((s)->fds_bits[0] |= (1 << (f)))
  8810. #define FD_CLR(f,s)         ((s)->fds_bits[0] &= ~(1 << (f)))
  8811. #define FD_ISSET(f,s)       ((s)->fds_bits[0] & (1 << (f)))
  8812. #define FD_ZERO(s)          ((s)->fds_bits[0] = 0)
  8813.  
  8814. #endif /* _VMS_FD */
  8815. $EOD
  8816. $!
  8817. $CREATE [.archie.vms]in.h
  8818. $DECK
  8819. /* netinet/in.h */
  8820. struct in_addr
  8821. {
  8822.   union
  8823.   {
  8824.     struct
  8825.     {
  8826.       unsigned char s_b1, s_b2, s_b3, s_b4;
  8827.     } S_un_b;
  8828.     struct
  8829.     {
  8830.       unsigned short s_w1, s_w2;
  8831.     } S_un_w;
  8832.     unsigned long S_addr;
  8833.   } S_un;
  8834. #define   s_addr S_un.S_addr
  8835. #define   s_host S_un.S_un_b.s_b2
  8836. #define   s_net  S_un.S_un_b.s_b1
  8837. #define   s_imp  S_un.S_un_w.s_w2
  8838. #define   s_impno S_un.S_un_b.s_b4
  8839. #define   s_lh   S_un.S_un_b.s_b3
  8840. };
  8841.  
  8842. #define INADDR_ANY 0x00000000
  8843. #define INADDR_BROADCAST 0xffffffff
  8844. #define INADDR_LOOPBACK 0x7f000001
  8845.  
  8846. struct sockaddr_in
  8847. {
  8848.   short sin_family;
  8849.   unsigned short sin_port;
  8850.   struct in_addr sin_addr;
  8851.   char sin_zero[8];
  8852. };
  8853.  
  8854. #define ntohl(x) (( (((unsigned long) x) >> 24)& 0x000000ff ) |\
  8855.                   ( (((unsigned long) x) >> 8) & 0x0000ff00 ) |\
  8856.                   ( (((unsigned long) x) << 8) & 0x00ff0000 ) |\
  8857.                   ( (((unsigned long) x) << 24)& 0xff000000 ))
  8858. #define ntohs(x) (( (((unsigned short) x) >> 8) |\
  8859.                   ( (((unsigned short) x) << 8)) & 0xffff ))
  8860. #define htonl(x) (( (((unsigned long) x) >> 24)& 0x000000ff ) |\
  8861.                   ( (((unsigned long) x) >> 8) & 0x0000ff00 ) |\
  8862.                   ( (((unsigned long) x) << 8) & 0x00ff0000 ) |\
  8863.                   ( (((unsigned long) x) << 24)& 0xff000000 ))
  8864. #define htons(x) (( (((unsigned short) x) >> 8) |\
  8865.                   ( (((unsigned short) x) << 8)) & 0xffff ))
  8866.  
  8867. #define IPPORT_RESERVED 1024
  8868. $EOD
  8869. $!
  8870. $CREATE [.archie.vms]pseudos.h
  8871. $DECK
  8872. /* These are so we don't end up using the MultiNet versions.  */
  8873. #define socket    VMSsocket
  8874. #define bind    VMSbind
  8875. #define connect    VMSconnect
  8876. #define listen    VMSlisten
  8877. #define accept    VMSaccept
  8878. #define select    VMSselect
  8879. #define recv    VMSrecv
  8880. #define recvfrom    VMSrecvfrom
  8881. #define send    VMSsend
  8882. #define sendto    VMSsendto
  8883. #define getsockname    VMSgetsockname
  8884. #define shutdown    VMSshutdown
  8885. #define getsockopt    VMSgetsockopt
  8886. #define setsockopt    VMSsetsockopt
  8887. $EOD
  8888. $!
  8889. $CREATE [.archie.vms]signal.h
  8890. $DECK
  8891. /* signal.h */
  8892. #define SIGURG  16
  8893. #define SIGTSTP 18
  8894. #define SIGCHLD 20
  8895. #define SIGIO   23
  8896. #define sigmask(m) (1 << ((m)-1))
  8897.  
  8898. #ifndef __GNUC__
  8899. # include <sys$library:signal.h>
  8900. #else /* Gnu C */
  8901. # include <gnu_cc_include:[000000]signal.h>
  8902. #endif /* not Gnu C */
  8903. $EOD
  8904. $!
  8905. $CREATE [.archie.vms]socket.h
  8906. $DECK
  8907. /* sys/socket.h */
  8908. #define SOCK_STREAM     1
  8909. #define SOCK_DGRAM      2
  8910.  
  8911. #define SO_DEBUG        0x01
  8912. #define SO_ACCEPTCONN   0x02
  8913. #define SO_REUSEADDR    0x04
  8914. #define SO_KEEPALIVE    0x08
  8915. #define SO_LINGER       0x80
  8916. #define SO_DONTLINGER   (~SO_LINGER)
  8917.  
  8918. #define AF_UNSPEC       0
  8919. #define AF_ERROR        0
  8920. #define AF_INET         2
  8921. #define AF_CCITT        10
  8922. #define AF_X25          10
  8923.  
  8924. struct sockaddr
  8925. {
  8926.   unsigned short sa_family;
  8927.   char sa_data[14];
  8928. };
  8929.  
  8930. #define SOL_SOCKET      0xffff
  8931.  
  8932. #define MSG_OOB 1
  8933. #define MSG_PEEK 2
  8934. $EOD
  8935. $!
  8936. $CREATE [.archie.vms]time.h
  8937. $DECK
  8938. #ifndef __PKTIME
  8939. #define __PKTIME
  8940.  
  8941. struct timeval
  8942. {
  8943.   long tv_sec;
  8944.   long tv_usec;
  8945. };
  8946.  
  8947. struct timezone
  8948. {
  8949.   int tz_minuteswest;
  8950.   int tz_dsttime;
  8951. };
  8952.  
  8953. struct itimerval
  8954. {
  8955.   struct timeval it_interval;
  8956.   struct timeval it_value;
  8957. };
  8958.  
  8959. #define ITIMER_REAL 0
  8960. #define timerclear(x) (x)->tv_sec = (x)->tv_usec = 0
  8961.  
  8962. #ifndef __GNUC__
  8963. # include <sys$library:time.h>
  8964. #else /* not Gnu C */
  8965. # include <gnu_cc_include:[000000]time.h>
  8966. #endif /* Gnu C */
  8967.  
  8968. #endif /* __PKTIME */
  8969. $EOD
  8970. $!
  8971. $CREATE [.archie.vms]types.h
  8972. $DECK
  8973. /* sys/types.h */
  8974. #ifndef _types_
  8975. #define _types_
  8976.  
  8977. #ifndef __GNUC__
  8978. # include <sys$library:stddef.h>
  8979. #endif /* not Gnu C */
  8980.  
  8981. typedef unsigned char u_char;
  8982. typedef unsigned short u_short;
  8983. typedef unsigned int u_int;
  8984. typedef unsigned long u_long;
  8985.  
  8986. typedef long daddr_t;
  8987. typedef char *caddr_t;
  8988.  
  8989. #include <sys$library:types.h>
  8990.  
  8991. typedef unsigned short ino_t;
  8992. typedef char *dev_t;
  8993. typedef unsigned int off_t;
  8994. typedef long key_t;
  8995.  
  8996. #include "[.vms]fd.h"
  8997.  
  8998. #endif /* _types */
  8999. $EOD
  9000. $!
  9001. $CREATE [.archie.vms]network.h
  9002. $DECK
  9003. /* Miscellaneous things for the networking library.  */
  9004.  
  9005. /* Actually an itemlist_3, but can be used for itemlist_2's.  */
  9006. struct itemlist
  9007. {
  9008.   short length;
  9009.   short code;
  9010.   char *dataptr;
  9011.   short *retlenptr;
  9012. };
  9013.  
  9014. union socket_addr
  9015. {
  9016.   struct sockaddr_in in;
  9017. };
  9018.  
  9019. #define   TCP$SEND        (IO$_WRITEVBLK)
  9020. #define   TCP$RECEIVE     (IO$_READVBLK)
  9021. #define   TCP$OPEN        (IO$_CREATE)
  9022. #define   TCP$CLOSE       (IO$_DELETE)
  9023. #define   TCP$ABORT       (IO$_DEACCESS)
  9024. #define   TCP$STATUS      (IO$_ACPCONTROL)
  9025. #define   TCP$INFO        (IO$_MODIFY)
  9026. #define   GTHST           (IO$_SKIPFILE)
  9027.  
  9028. #define   IO$_SEND        (IO$_WRITEVBLK)
  9029. #define   IO$_RECEIVE     (IO$_READVBLK)
  9030. #ifndef IO$S_FCODE
  9031. #define IO$S_FCODE 0x0006
  9032. #endif
  9033. #define   IO$_SOCKET      (IO$_ACCESS | (0 << IO$S_FCODE))
  9034. #define   IO$_BIND        (IO$_ACCESS | (1 << IO$S_FCODE))
  9035. #define   IO$_LISTEN      (IO$_ACCESS | (2 << IO$S_FCODE))
  9036. #define   IO$_ACCEPT      (IO$_ACCESS | (3 << IO$S_FCODE))
  9037. #define   IO$_CONNECT     (IO$_ACCESS | (4 << IO$S_FCODE))
  9038. #define   IO$_SETSOCKOPT  (IO$_ACCESS | (5 << IO$S_FCODE))
  9039. #define   IO$_GETSOCKOPT  (IO$_ACCESS | (6 << IO$S_FCODE))
  9040. #define   IO$_IOCTL       (IO$_ACCESS | (8 << IO$S_FCODE))
  9041. #define   IO$_ACCEPT_WAIT (IO$_ACCESS | (10 << IO$S_FCODE))
  9042. #define   IO$_NETWORK_PTY (IO$_ACCESS | (11 << IO$S_FCODE))
  9043. #define   IO$_SHUTDOWN    (IO$_ACCESS | (12 << IO$S_FCODE))
  9044. #define   IO$_GETSOCKNAME (IO$_ACCESS | (13 << IO$S_FCODE))
  9045. #define      SETCHAR_HANDOFF (1<<2)
  9046.  
  9047. #define   NFB$C_DECLNAME   0x15
  9048.  
  9049. #define TIMER_EFN 1
  9050. #define TERM_EFN  2
  9051. #define BUF_SIZE 2000
  9052.  
  9053. #define INITIALISED 0
  9054. #define ACTIVE_CONNECTION 1
  9055. #define PASSIVE_CONNECTION 2
  9056. #define LISTENING 3
  9057. #define HANDED_OFF 4
  9058.  
  9059. static struct fd_entry
  9060. {
  9061.   unsigned short int channel;    /* vms channel assigned to this socket */
  9062.   unsigned short int iosb[4];    /* returned status block */
  9063.   int fd_buff_size;        /* number of chrs in buffer still to be read */
  9064.   int accept_pending;        /* a call is waiting to be accepted */
  9065.   int connect_pending;        /* a connect is outstanding*/
  9066.   int connected;        /* this descriptor is connected */
  9067.   unsigned char *fd_buff;    /* pointer to buffer dyn assigned */
  9068.   unsigned char *fd_leftover;    /* pointer to any chrs still to be read */
  9069.   FILE *fptr;            /* we need to assgn a file ptr for stream io */
  9070.   int s;            /* socket number - needed in the ast's */
  9071.   int namelen;            /* our socket address name */
  9072.   union socket_addr name;
  9073.   short int fromdummy;        /* wg - accept wants an int - recvfrom wants a short!!*/
  9074.   short int fromlen;        /* the from socket address name */
  9075.   union socket_addr from;
  9076.   int tolen;            /* wg - sendto wants an int*/
  9077.   union socket_addr to;        /* the to socket address name */
  9078.   int passive;            /* still needed because of x25 close ambig */
  9079.   int backlog;            /* backlog - not handled well! */
  9080.   int domain;            /* domain of socket AF_INET or AF_X25 */
  9081.   int type;            /* type of socket stream or datagram */
  9082.   int protocol;            /* protocol of socket - ignored */
  9083.   int mbx_channel;        /* mailbox channel - needed for x25 */
  9084.   unsigned char mbx_buff[255];    /* mailbox buffer */
  9085.   unsigned short int miosb[4];    /* mailbox status block */
  9086.   int ncb_size;            /* x25 connection information */
  9087.   unsigned char ncb[128];
  9088.   unsigned char masklen;    /* x25 user data mask */
  9089.   unsigned char mask[16];
  9090.   int need_header;        /* x25 header field gives data status if req*/
  9091.   int send_type;        /* x25 data packet type eg more bit set etc */
  9092.   int status;            /* status of socket */
  9093.   int closed_by_remote;        /* flag for remote dropouts */
  9094.   int read_outstanding;        /* flag so we don't hang two reads */
  9095.   int cmu_open;            /* flag to say whether a cmu open was hung */
  9096.   int x25_listener;        /* flag to say we are an x25 listener */
  9097.   int oob_type;            /* handles interrupt messages */
  9098.   int mother;            /* mother socket for X25 accepts */
  9099.   int child;            /* child socket for X25 accepts */
  9100.   int no_more_accepts;        /* don't accept anymore calls */
  9101.   char int_data;        /* interrupt data - only 1 char supported */
  9102.   int non_blocking;        /* don't block on a read if no data */
  9103.   int sig_req;            /* generate SIGIO on data ready */
  9104.   struct itemlist rhost;    /* descriptor pointing to "p[].from" info for UCX */
  9105.   unsigned short ucx_accept_chan;    /* Channel returned by a UCX accept via hang_an_accept */
  9106. } p[32];
  9107.  
  9108. /* So we can handle select on terminal input.  */
  9109. static struct term_entry
  9110. {
  9111.   int chan;
  9112.   short int iosb[4];
  9113.   short int char_available;
  9114.   short int read_outstanding;
  9115.   char c[1];
  9116. } terminal =
  9117.  
  9118. {
  9119.   -1, 0, 0, 0, 0, 0, 0
  9120. };
  9121.  
  9122. #define CMU 1
  9123. #define WG  2
  9124. #define NONE 3
  9125. #define TGV 4
  9126. #define UCX 5
  9127. static int tcp_make = 0;
  9128.  
  9129. struct descriptor
  9130. {
  9131.   int size;
  9132.   char *ptr;
  9133. };
  9134.  
  9135. /* Initialize certain things 1st time thru.  */
  9136. static int p_initialised = 0;
  9137.  
  9138. /* A routine to point SIGALRM and SIGURG at.  */
  9139. static int 
  9140. si_dummy ()
  9141. {
  9142. }
  9143. static int (*alarm_function) () = si_dummy;
  9144. static int (*sigurg_function) () = si_dummy;
  9145.  
  9146. FILE *fdopen ();
  9147. static set_tcp_make ();
  9148. static char *getdevicename ();
  9149. $EOD
  9150. $!
  9151. $CREATE [.archie.vms]multi.opt
  9152. $DECK
  9153. sys$library:vaxcrtl.exe/share
  9154. multinet:multinet_socket_library.exe/share
  9155. $EOD
  9156. $!
  9157. $CREATE [.archie.vms]ucx.opt
  9158. $DECK
  9159. sys$library:vaxcrtl.exe/share
  9160. sys$library:ucx$ipc/lib
  9161. $EOD
  9162. $!
  9163. $CREATE [.archie.vms]woll.opt
  9164. $DECK
  9165. sys$library:vaxcrtl.exe/share
  9166. twg$tcp:[netdist.lib]twglib.olb/lib
  9167. $EOD
  9168. $ write sys$output "Ok, now enter the ARCHIE directory, look at MAKE.COM, then type @MAKE ."
  9169.