home *** CD-ROM | disk | FTP | other *** search
/ Hackers Toolkit 2.0 / Hackers_Toolkit_v2.0.iso / HTML / archive / Unix / c-src / atap.c / README < prev    next >
Encoding:
Text File  |  1999-11-04  |  15.0 KB  |  338 lines

  1. #       @(#)README    1.28 1/30/95
  2. #
  3. ############################################################################
  4. #   This is the STREAMS tap module/driver pseudo-device. aka WATER-WORKS
  5. ############################################################################
  6. #
  7. # runs on:
  8. #        sun3/50 4.1.1
  9. #        sun4/75 4.1.2
  10. #        sun4/670 4.1.2 (multi-processor)
  11. #
  12.  
  13. COPYRIGHT:
  14.         - you want COPYRIGHT ? i will give you COPYRIGHT.
  15.           Copyright (c) 1992 Simon Ney -- All Rights Reserved
  16.  
  17.  
  18.                                 ---------------
  19.  
  20.  
  21. DESCRIPTION:
  22.         - the device is a monitor/manipulator for other STREAMS-devices
  23.           such as standard UNIX control-terminals.
  24.  
  25.         - this driver is a kernel-loadable-module. (==>no reboot required)
  26.  
  27.         - it is a combination of a STREAMS-module and a STREAMS-driver.
  28.  
  29.                 tap     - is the name of the pushable/poppable STREAMS-modules.
  30.                 tapc*   - are the names of the STREAMS-driver nodes (special
  31.                           files)..
  32.  
  33.         - the tap-modules must first manually pushed/popped on each stream
  34.           to be monitored or manipulated, independ if the tapc-driver is
  35.           open or not. see also ioctl(fd,I_PUSH|I_POP,"tap").
  36.  
  37.         - the first module pushed become the id 0, the second 1, and so on...
  38.           if any of these modules are popped the next pushed will become
  39.           the old id of the previous popped module. the module ids are
  40.           always unique, and are assigned first fit.
  41.           the maximal number of tap-modules pushed is NTAP (see tap.h).
  42.  
  43.         - a pushed-tap-module act as NULL-streams-MODULE (pass data from below
  44.           to above and data from above to below) unless it is connected with
  45.           the tapc-driver.
  46.  
  47.         - now if a minor device of the tapc-driver is opened the minor
  48.           device-number is used to check if such tap-module is pushed
  49.           (minor number = tap-id). if no such module id is present a
  50.           ENETUNREACH (Network is unreachable) error is returned by open().
  51.           if the module id (minor device number) can be found, a connection
  52.           to the pushed-tap-module is established.
  53.  
  54.         - all minor-device-nodes can only open by one user at a time,
  55.           the second open() on the same minor device returns a EBUSY (Device
  56.           busy) error.
  57.  
  58.         - if the open() has the O_NDELAY flag set a TAP_REVERSE flag
  59.           is internal set in the driver. the TAP_REVERSE flag can only
  60.           set by the super-user, a non-superuser open() returns a EACCES
  61.           (Permission denied) error.
  62.  
  63.         - now data can be received/send from/to the pushed-tap-module
  64.           with read() and write().
  65.  
  66.         - if the TAP_REVERSE flag is not set, data received by the tap-module
  67.           from the above modules/streamshead (upper-stream) is duplicated
  68.           and send to the read-side of the tapc-driver, and can be read by
  69.           the user process that opened the tapc-driver.
  70.           data written with write() by the process that opened the tapc-driver
  71.           are send to modules/streamshead above the tap-module (upper-stream).
  72.  
  73.         - if the TAP_REVERSE flag is set, data received by the tap-module
  74.           from the module/driver below the tap-module (lower-stream) is
  75.           duplicated and send to the read-side of the tapc-driver, and can
  76.           be read by the user process that opened the tapc-driver.
  77.           data written with write() by the process that opened the tapc-driver
  78.           are send to the modules/driver below the tap-module (lower-stream).
  79.  
  80.         - if the tapc-driver is closed the messages are not dupclicated as
  81.           long as the tapc-driver is re-open. (the tap-modules remains
  82.           pushed)
  83.  
  84.         - if data is written by the tapc-driver and the connected module
  85.           was popped a ENETCONNRESET (Connection reset by peer) error is
  86.           return to the write().
  87.  
  88.         - if the stream that has the tap-module pushed is closed, all modules
  89.           on this stream are popped by the system. but there is a configuration
  90.           option in sunos to autopush any modules on open() (that's different
  91.           in a SYSV environment).
  92.  
  93.  
  94.                                 ---------------
  95.  
  96.  
  97. FIGURES:
  98.        (USER PROCESS)           (BIG BROTHER)
  99.          (csh,vi)           (tapmon)    (tapmon -r)  (tip/cu/uucico)
  100.          /dev/ttya         /dev/tapc0   /dev/tapc1      /dev/cua1
  101. --------------------------------------------------------------------------------
  102.         |ttya HEAD |       |tapc HEAD|  |tapc HEAD|   |cua1 HEAD |
  103.         +----------+       +---------+  +---------+   +----------+
  104.              | ^              | ^          | ^             | ^
  105.              | |              | |          | |             | |
  106.              | |           ...........  ...........        | |
  107.              | |           . MORE    .  . MORE    .        | |
  108.              | |           . MODULES .  . MODULES .        | |
  109.              | |           ...........  ...........        | |
  110.              | |              | |          | |             | |
  111.              v |              v |          v |             | |
  112.         ............       +---------+  +---------+   ............
  113.         . MORE  (2).       |TAPC 0   |  |TAPC 1   |   . MORE (2) .
  114.         . MODULES  .       |DRIVER   |  |DRIVER(1)|   . MODULES  .
  115.         ............       +---------+  +---------+   ............
  116.           (3)| ^(4)           | ^          | ^             | |         UPPER
  117.              v |              | |          | |             v |         STREAMS
  118.         +----------+          | |          | |        +----------+
  119.         |    \ \   |          | |          | |        | TAP 1    |
  120.         |     \ \--|<---------/ |          | \--------|\  MODULE |
  121.         | TAP 0\---|------------/          \--------->| \  PUSHED|
  122.         | MODULE   |                                  |\ \REVERSE|
  123.         | PUSHED   |                                  | \ \ OPEN |
  124.         |          |  <--- NORMAL       REVERSE--->   |  \ \     |
  125.         +----------+                                  +----------+
  126.              | ^                                       (4)| ^(3)        LOWER
  127.              v |                                          v |           STREAMS
  128.         ............                                  ............
  129.         . MORE  (2).                                  . MORE     .
  130.         . MODULES  .                                  . MODULES  .
  131.         ............                                  ............
  132.              | ^                                          | ^
  133.              v |                                          v |
  134.         +----------+                                  +----------+
  135.         | zs DRIVER|                                  | zs DRIVER|
  136. --------------------------------------------------------------------------------
  137.     physical STREAMS device                      physical STREAMS device
  138.          (terminal)                                    (modem)
  139.          (intruder)                                (other systems)
  140.  
  141.                                         ----------
  142.                                         (1) - opened by O_NDELAY from root
  143.                                         (2) - e.g. ttcompat,ldterm,kb,ms,
  144.                                                    slip,ax25,pf,nbuf
  145.                                         (3) - duplicated streams
  146.                                         (4) - multiplexed streams
  147.  
  148.  
  149. NOTE: the ,,physical STREAMS device'' above shown can be any streams device
  150.       e.g.:      /dev/{tty*,console,nit,tcp,loop,mux,mti,kbd,mouse,*CLONE*}
  151.                 (nit and tcp is a clone device !)
  152.       slip cant monitored because itself pops all modules pushed.
  153.       the only way is to modify sliplogin.c to push the tap module below
  154.       the slip module.
  155.  
  156.  
  157.                                 ---------------
  158.  
  159.  
  160.  
  161. INSTALLATION:
  162.         the current version has been tested under sunos 4.1.1 on a sun3/50
  163.         and sunos 4.1.2 on a sun4/75. but i hope the version will run on any 
  164.     sun with the loadable-driver /dev/vd,otherwise read the INSTALL file 
  165.     and your STREAMS programming manual (the load of the pushable
  166.     streams-module is done by hand on suns). if the modload(8) 
  167.     fails or the use of the driver crashes the kernel let me know ...
  168.  
  169.         to make the kernel-loadable module and automatic load into the kernel
  170.         type (as root);
  171.  
  172.                 # make
  173.  
  174.         the tapmon(1)+streams(1) user-commands are created.(the streams(1)
  175.         command can be used to push/pop other non-tap streams modules,the
  176.         tapmon(1) is a TAP-driver application).
  177.         a possible old tap-module is automatically unloaded if a new is loaded
  178.         (after multiple make commands).  the device nodes (/dev/tapc*) are
  179.         created as expected.
  180.  
  181.  
  182.  
  183.                                 ---------------
  184.  
  185.  
  186.  
  187. SOME EXAMPLES:
  188.         now login from ttya before continue (or pick a already opened
  189.         pseudo-tty from the window-system (NOT the one you will enter
  190.         the following commands))
  191.  
  192.                 # streams -u tap < /dev/ttya
  193.                 # tapmon 0
  194.  
  195.         this push a tap-module on the already open /dev/ttya serial-tty and
  196.         then start the monitor/manipulator. all data send to /dev/ttya are
  197.         now duplicated to your standard output,and all data send by you are
  198.         send as input to the process on ttya, thats the same as you are sit
  199.         in front of ttya.
  200.         type CTRL-_ to leave the tapmon.
  201.         NOTE: after leaving tapmon the tap-streams-modules remains pushed.
  202.  
  203.         here an example output from ,,pstat -S'' while one tapmon is running:
  204.  
  205.                    LOC     WRQ       VNODE     DEVICE   PGRP SIGIO  FLAGS
  206.                  f05461e    f05583c   f0cdb94  59,  0      0     0  R
  207.                   Write side:
  208.                     NAME      COUNT FLG    MINPS  MAXPS  HIWAT  LOWAT
  209.                     strwhead      0            0      0      0      0
  210.                     tapc          0  R         0    INF      0      0
  211.                   Read side:
  212.                     tapc          0  R         0    INF      0      0
  213.                     strrhead      0  R         0    INF   5120   1024
  214.  
  215.  
  216.                    LOC     WRQ       VNODE     DEVICE   PGRP SIGIO  FLAGS
  217.                  f0543e0    f0550ec   f0cc9f4  12,  1    905     0
  218.                   Write side:
  219.                     NAME      COUNT FLG    MINPS  MAXPS  HIWAT  LOWAT
  220.                     strwhead      0            0      0      0      0
  221.                     tap           0  R         0    INF      0      0
  222.                     ttcompat      0  R         0    INF    300    200
  223.                     ldterm        0  R         0    INF      1      0
  224.                     zs            0  R         0    INF   2048    128
  225.                   Read side:
  226.                     zs            0  R         0    INF   2048    128
  227.                     ldterm        0  R         0    128    500    200
  228.                     ttcompat      0  R         0    INF   2048    128
  229.                     tap           0  R         0    INF      0      0
  230.                     strrhead      0            0    INF    300    200
  231.  
  232.  
  233.         the kernel-loadable-module can only unloaded by ./unload or by
  234.         modunload(1) if all tap-modules are popped and the /dev/tapc* devices
  235.         are closed (if you are not sure look in ,,pstat -S'' for the
  236.         string "tap" ).
  237.  
  238.                 # streams -o tap < /dev/ttya
  239.                 # ./unload
  240.  
  241.         this pops the previous pushed module and unloads the
  242.         kernel-loadable-module from the kernel...
  243.  
  244.         NOTE: always use ./unload instead of modunload(8) because the Makefile
  245.               keep track of the loaded kernel-modules !
  246.  
  247.         another example is (if you not already done the ./unload operation
  248.         above,otherwise you must reload the tapc/tap driver with another
  249.         ,,make''):
  250.  
  251.                 # streams -o ttcompat -o ldterm \
  252.                         -u tap -u ldterm -u ttcompat < /dev/ttya
  253.                 # tapmon 0
  254.  
  255.         now you can monitor direct above the physical device and below
  256.         the ldterm module and can see the line-editing functions of
  257.         the ldterm and ttcompat modules.
  258.         also signals send by you, such as CTRL-C are processes by the
  259.         ldterm and ttcompat modules and send as signal to the process
  260.         as expected (in the former example not, a CTRL-C was send as
  261.         input byte 0x03 to the user-process)
  262.  
  263.         here how to undo the last modules transaction:
  264.  
  265.                 # streams -o ttcompat -o ldterm -o tap -u ldterm \
  266.                         -u ttcompat < /dev/ttya
  267.  
  268.         NOTE: the order of ther streams(1) command is important (stack order).
  269.  
  270.  
  271.  
  272.                                 ---------------
  273.  
  274.  
  275. KERNEL CONFIG:
  276.         if you want to link the tapc/tap device-driver permanently to /vmunix
  277.         be sure not to define TAPVD (see Makefile) and to ignore tap.h
  278.         (see tap.h). follow the steps in the ,,INSTALL'' file.
  279.  
  280.  
  281.                                 ---------------
  282.  
  283.  
  284. KNOWN BUGS:
  285.         - CLONE open are currently disabled because it may crash the kernel,
  286.           after 7 modules are pushed and 7 tapmons (using clone open) started
  287.           in backgroup then close the stream that has the 7 modules pushed,
  288.           and then reconnected to the tapmons with csh ,fg'' command, the 7th
  289.           ,,fg'' crash the sun3sunos4.1.1 kernel with the following message:
  290.                                         ****
  291.          ,,assertion failed: vp->v_stream, file: ../../os/str_io.c, line 3823''
  292.          ,,panic: assertion failed''
  293.                                         ****
  294.           the kernel-backtrace shows than it was called from some kernel
  295.           select(), thats the first function tapmon calls after the CLONE open.
  296.  
  297.          - if the BUG is fixed CLONE opens connects to the first unconnected
  298.            module, and not the last pushed module!
  299.  
  300.  
  301.                                 ---------------
  302.  
  303.  
  304. SECURITY NOTES:
  305.         - the paranoid sysadmin must decide what permission he want to give to
  306.           the /dev/tapc* devices (e.g. chmod 600 /dev/tapc*).
  307.           the TAP_REVERSE mode can only be used by the super-user because
  308.           it can be used to read clear text passwords during login-time and
  309.           to get control of external devices such as modems and communication
  310.           devices.
  311.  
  312.         - a typical LUSER can start ,,pstat -S'' to see if BIG BROTHER is
  313.           watching...
  314.  
  315.  
  316.                                 ---------------
  317.  
  318.  
  319. COMMENTS:
  320.         - you can use TAP for education proposes if you push multiple
  321.           tap-modules on a single stream or you can create BIG BROTHER trees,
  322.           and make a UNIX alliance so that multiple users use the same
  323.           shell,editor.... and can correct each other....or to help UNIX
  324.           beginners....isnt it a some kind of human-neural-nets ?
  325.  
  326.         - the only problem is the possible wrong terminal-emulation *sigh*.
  327.           but there is a universal-terminal-emulation under X, and the screen
  328.           command from Oliver Laumann.
  329.  
  330.         - a MAN page is included in the next release.
  331.  
  332.         - i hope my english is funny...
  333.  
  334.         UNIX - is a registed bell of AT&T trademark laboratories.
  335.  
  336. --
  337. Simon Ney -- simon@bbisdn.isdn.cs.tu-berlin.de -- neural@cs.tu-berlin.de
  338.