home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / answers / unix-faq / faq / part4 < prev    next >
Encoding:
Text File  |  1993-12-26  |  26.0 KB  |  643 lines

  1. Path: senator-bedfellow.mit.edu!bloom-beacon.mit.edu!pad-thai.aktis.com!pad-thai.aktis.com!not-for-mail
  2. From: tmatimar@empress.com (Ted M A Timar)
  3. Newsgroups: comp.unix.questions,comp.unix.shell,news.answers,comp.answers
  4. Subject: Unix - Frequently Asked Questions (4/7) Digest [Frequent posting]
  5. Supersedes: <unix-faq/faq/part4_755758811@GZA.COM>
  6. Followup-To: comp.unix.questions
  7. Date: 27 Dec 1993 00:00:31 -0500
  8. Organization: Empress Software
  9. Lines: 623
  10. Sender: faqserv@security.ov.com
  11. Approved: news-answers-request@MIT.Edu
  12. Distribution: world
  13. Expires: 24 Jan 1994 05:00:09 GMT
  14. Message-ID: <unix-faq/faq/part4_756968409@GZA.COM>
  15. References: <unix-faq/faq/contents_756968409@GZA.COM>
  16. NNTP-Posting-Host: pad-thai.aktis.com
  17. X-Last-Updated: 1993/09/02
  18. Xref: senator-bedfellow.mit.edu comp.unix.questions:66496 comp.unix.shell:14269 news.answers:16185 comp.answers:3157
  19.  
  20. Archive-name: unix-faq/faq/part4
  21. Version: $Id: part4,v 2.3 1993/09/01 23:28:52 tmatimar Exp $
  22.  
  23. These seven articles contain the answers to some Frequently Asked
  24. Questions often seen in comp.unix.questions and comp.unix.shell.
  25. Please don't ask these questions again, they've been answered plenty
  26. of times already - and please don't flame someone just because they may
  27. not have read this particular posting.  Thank you.
  28.  
  29. Many FAQs, including this one, are available on the archive site
  30. rtfm.mit.edu in the directory pub/usenet/news.answers.
  31. The name under which a FAQ is archived appears in the "Archive-Name:"
  32. line at the top of the article.  This FAQ is archived as
  33. "unix-faq/faq/part[1-7]".
  34.  
  35. These articles are divided approximately as follows:
  36.  
  37.       1.*) General questions.
  38.       2.*) Relatively basic questions, likely to be asked by beginners.
  39.       3.*) Intermediate questions.
  40.       4.*) Advanced questions, likely to be asked by people who thought
  41.        they already knew all of the answers.
  42.       5.*) Questions pertaining to the various shells, and the differences.
  43.       6.*) An overview of Unix variants.
  44.       7.*) An comparison of configuration management systems (RCS, SCCS).
  45.  
  46. This article includes answers to:
  47.  
  48.       4.1)  How do I read characters from a terminal without requiring the user
  49.               to hit RETURN?
  50.       4.2)  How do I check to see if there are characters to be read without
  51.               actually reading?
  52.       4.3)  How do I find the name of an open file?
  53.       4.4)  How can an executing program determine its own pathname?
  54.       4.5)  How do I use popen() to open a process for reading AND writing?
  55.       4.6)  How do I sleep() in a C program for less than one second?
  56.       4.7)  How can I get setuid shell scripts to work?
  57.       4.8)  How can I find out which user or process has a file open or is using
  58.             a particular file system (so that I can unmount it?)
  59.       4.9)  How do I keep track of people who are fingering me?
  60.       4.10) Is it possible to reconnect a process to a terminal after it has
  61.             been disconnected, e.g. after starting a program in the background
  62.             and logging out?
  63.       4.11) Is it possible to "spy" on a terminal, displaying the output
  64.             that's appearing on it on another terminal?
  65.  
  66. If you're looking for the answer to, say, question 4.5, and want to skip
  67. everything else, you can search ahead for the regular expression "^4.5)".
  68.  
  69. While these are all legitimate questions, they seem to crop up in
  70. comp.unix.questions or comp.unix.shell on an annual basis, usually
  71. followed by plenty of replies (only some of which are correct) and then
  72. a period of griping about how the same questions keep coming up.  You
  73. may also like to read the monthly article "Answers to Frequently Asked
  74. Questions" in the newsgroup "news.announce.newusers", which will tell
  75. you what "UNIX" stands for.
  76.  
  77. With the variety of Unix systems in the world, it's hard to guarantee
  78. that these answers will work everywhere.  Read your local manual pages
  79. before trying anything suggested here.  If you have suggestions or
  80. corrections for any of these answers, please send them to to
  81. tmatimar@empress.com.
  82.  
  83. ----------------------------------------------------------------------
  84.  
  85. Subject: How do I read characters ... without requiring the user to hit RETURN?
  86. Date: Thu Mar 18 17:16:55 EST 1993
  87.  
  88. 4.1)  How do I read characters from a terminal without requiring the user
  89.       to hit RETURN?
  90.  
  91.       Check out cbreak mode in BSD, ~ICANON mode in SysV.
  92.  
  93.       If you don't want to tackle setting the terminal parameters
  94.       yourself (using the "ioctl(2)" system call) you can let the stty
  95.       program do the work - but this is slow and inefficient, and you
  96.       should change the code to do it right some time:
  97.  
  98.       #include <stdio.h>
  99.       main()
  100.       {
  101.         int c;
  102.  
  103.         printf("Hit any character to continue\n");
  104.         /*
  105.          * ioctl() would be better here; only lazy
  106.          * programmers do it this way:
  107.          */
  108.         system("/bin/stty cbreak");        /* or "stty raw" */
  109.         c = getchar();
  110.         system("/bin/stty -cbreak");
  111.         printf("Thank you for typing %c.\n", c);
  112.  
  113.         exit(0);
  114.       }
  115.  
  116.       Several people have sent me various more correct solutions to
  117.       this problem.  I'm sorry that I'm not including any of them here,
  118.       because they really are beyond the scope of this list.
  119.  
  120.       You might like to check out the documentation for the "curses"
  121.       library of portable screen functions.  Often if you're interested
  122.       in single-character I/O like this, you're also interested in
  123.       doing some sort of screen display control, and the curses library
  124.       provides various portable routines for both functions.
  125.  
  126. ------------------------------
  127.  
  128. Subject: How do I check to see if there are characters to be read ... ?
  129. Date: Thu Mar 18 17:16:55 EST 1993
  130.  
  131. 4.2)  How do I check to see if there are characters to be read without
  132.       actually reading?
  133.  
  134.       Certain versions of UNIX provide ways to check whether characters
  135.       are currently available to be read from a file descriptor.  In
  136.       BSD, you can use select(2).  You can also use the FIONREAD ioctl
  137.       (see tty(4)), which returns the number of characters waiting to
  138.       be read, but only works on terminals, pipes and sockets.  In
  139.       System V Release 3, you can use poll(2), but that only works on
  140.       streams.  In Xenix - and therefore Unix SysV r3.2 and later - the
  141.       rdchk() system call reports whether a read() call on a given file
  142.       descriptor will block.
  143.  
  144.       There is no way to check whether characters are available to be
  145.       read from a FILE pointer.  (You could poke around inside stdio
  146.       data structures to see if the input buffer is nonempty, but that
  147.       wouldn't work since you'd have no way of knowing what will happen
  148.       the next time you try to fill the buffer.)
  149.  
  150.       Sometimes people ask this question with the intention of writing
  151.         if (characters available from fd)
  152.             read(fd, buf, sizeof buf);
  153.       in order to get the effect of a nonblocking read.  This is not
  154.       the best way to do this, because it is possible that characters
  155.       will be available when you test for availability, but will no
  156.       longer be available when you call read.  Instead, set the
  157.       O_NDELAY flag (which is also called FNDELAY under BSD) using the
  158.       F_SETFL option of fcntl(2).  Older systems (Version 7, 4.1 BSD)
  159.       don't have O_NDELAY; on these systems the closest you can get to
  160.       a nonblocking read is to use alarm(2) to time out the read.
  161.  
  162. ------------------------------
  163.  
  164. Subject: How do I find the name of an open file?
  165. Date: Thu Mar 18 17:16:55 EST 1993
  166.  
  167. 4.3)  How do I find the name of an open file?
  168.  
  169.       In general, this is too difficult.  The file descriptor may
  170.       be attached to a pipe or pty, in which case it has no name.
  171.       It may be attached to a file that has been removed.  It may
  172.       have multiple names, due to either hard or symbolic links.
  173.  
  174.       If you really need to do this, and be sure you think long
  175.       and hard about it and have decided that you have no choice,
  176.       you can use find with the -inum and possibly -xdev option,
  177.       or you can use ncheck, or you can recreate the functionality
  178.       of one of these within your program.  Just realize that
  179.       searching a 600 megabyte filesystem for a file that may not
  180.       even exist is going to take some time.
  181.  
  182. ------------------------------
  183.  
  184. Subject: How can an executing program determine its own pathname?
  185. Date: Thu Mar 18 17:16:55 EST 1993
  186.  
  187. 4.4)  How can an executing program determine its own pathname?
  188.  
  189.       Your program can look at argv[0]; if it begins with a "/", it is
  190.       probably the absolute pathname to your program, otherwise your
  191.       program can look at every directory named in the environment
  192.       variable PATH and try to find the first one that contains an
  193.       executable file whose name matches your program's argv[0] (which
  194.       by convention is the name of the file being executed).  By
  195.       concatenating that directory and the value of argv[0] you'd
  196.       probably have the right name.
  197.  
  198.       You can't really be sure though, since it is quite legal for one
  199.       program to exec() another with any value of argv[0] it desires.
  200.       It is merely a convention that new programs are exec'd with the
  201.       executable file name in argv[0].
  202.  
  203.       For instance, purely a hypothetical example:
  204.     
  205.     #include <stdio.h>
  206.     main()
  207.     {
  208.         execl("/usr/games/rogue", "vi Thesis", (char *)NULL);
  209.     }
  210.  
  211.       The executed program thinks its name (its argv[0] value) is
  212.       "vi Thesis".   (Certain other programs might also think that
  213.       the name of the program you're currently running is "vi Thesis",
  214.       but of course this is just a hypothetical example, don't
  215.       try it yourself :-)
  216.  
  217. ------------------------------
  218.  
  219. Subject: How do I use popen() to open a process for reading AND writing?
  220. Date: Thu Mar 18 17:16:55 EST 1993
  221.  
  222. 4.5)  How do I use popen() to open a process for reading AND writing?
  223.  
  224.       The problem with trying to pipe both input and output to an
  225.       arbitrary slave process is that deadlock can occur, if both
  226.       processes are waiting for not-yet-generated input at the same
  227.       time.  Deadlock can be avoided only by having BOTH sides follow a
  228.       strict deadlock-free protocol, but since that requires
  229.       cooperation from the processes it is inappropriate for a
  230.       popen()-like library function.
  231.  
  232.       The 'expect' distribution includes a library of functions that a
  233.       C programmer can call directly.  One of the functions does the
  234.       equivalent of a popen for both reading and writing.  It uses ptys
  235.       rather than pipes, and has no deadlock problem.  It's portable to
  236.       both BSD and SV.  See the next answer for more about 'expect'.
  237.  
  238. ------------------------------
  239.  
  240. Subject: How do I sleep() in a C program for less than one second?
  241. Date: Thu Mar 18 17:16:55 EST 1993
  242.  
  243. 4.6)  How do I sleep() in a C program for less than one second?
  244.  
  245.       The first thing you need to be aware of is that all you can
  246.       specify is a MINIMUM amount of delay; the actual delay will
  247.       depend on scheduling issues such as system load, and could be
  248.       arbitrarily large if you're unlucky.
  249.  
  250.       There is no standard library function that you can count on in
  251.       all environments for "napping" (the usual name for short
  252.       sleeps).  Some environments supply a "usleep(n)" function which
  253.       suspends execution for n microseconds.  If your environment
  254.       doesn't support usleep(), here are a couple of implementations
  255.       for BSD and System V environments.
  256.  
  257.       The following code is adapted from Doug Gwyn's System V emulation
  258.       support for 4BSD and exploits the 4BSD select() system call.
  259.       Doug originally called it 'nap()'; you probably want to call it
  260.       "usleep()";
  261.  
  262.       /*
  263.         usleep -- support routine for 4.2BSD system call emulations
  264.         last edit:    29-Oct-1984    D A Gwyn
  265.       */
  266.  
  267.       extern int    select();
  268.  
  269.       int
  270.       usleep( usec )                /* returns 0 if ok, else -1 */
  271.         long        usec;        /* delay in microseconds */
  272.         {
  273.         static struct            /* `timeval' */
  274.             {
  275.             long    tv_sec;        /* seconds */
  276.             long    tv_usec;    /* microsecs */
  277.             }    delay;        /* _select() timeout */
  278.  
  279.         delay.tv_sec = usec / 1000000L;
  280.         delay.tv_usec = usec % 1000000L;
  281.  
  282.         return select( 0, (long *)0, (long *)0, (long *)0, &delay );
  283.         }
  284.  
  285.       On System V you might do it this way:
  286.  
  287.       /*
  288.       subseconds sleeps for System V - or anything that has poll()
  289.       Don Libes, 4/1/1991
  290.  
  291.       The BSD analog to this function is defined in terms of
  292.       microseconds while poll() is defined in terms of milliseconds.
  293.       For compatibility, this function provides accuracy "over the long
  294.       run" by truncating actual requests to milliseconds and
  295.       accumulating microseconds across calls with the idea that you are
  296.       probably calling it in a tight loop, and that over the long run,
  297.       the error will even out.
  298.  
  299.       If you aren't calling it in a tight loop, then you almost
  300.       certainly aren't making microsecond-resolution requests anyway,
  301.       in which case you don't care about microseconds.  And if you did,
  302.       you wouldn't be using UNIX anyway because random system
  303.       indigestion (i.e., scheduling) can make mincemeat out of any
  304.       timing code.
  305.  
  306.       Returns 0 if successful timeout, -1 if unsuccessful.
  307.  
  308.       */
  309.  
  310.       #include <poll.h>
  311.  
  312.       int
  313.       usleep(usec)
  314.       unsigned int usec;        /* microseconds */
  315.       {
  316.         static subtotal = 0;    /* microseconds */
  317.         int msec;            /* milliseconds */
  318.  
  319.         /* 'foo' is only here because some versions of 5.3 have
  320.          * a bug where the first argument to poll() is checked
  321.          * for a valid memory address even if the second argument is 0.
  322.          */
  323.         struct pollfd foo;
  324.  
  325.         subtotal += usec;
  326.         /* if less then 1 msec request, do nothing but remember it */
  327.         if (subtotal < 1000) return(0);
  328.         msec = subtotal/1000;
  329.         subtotal = subtotal%1000;
  330.         return poll(&foo,(unsigned long)0,msec);
  331.       }
  332.  
  333.       Another possibility for nap()ing on System V, and probably other
  334.       non-BSD Unices is Jon Zeeff's s5nap package, posted to
  335.       comp.sources.misc, volume 4.  It does require a installing a
  336.       device driver, but works flawlessly once installed.  (Its
  337.       resolution is limited to the kernel HZ value, since it uses the
  338.       kernel delay() routine.)
  339.  
  340. ------------------------------
  341.  
  342. Subject: How can I get setuid shell scripts to work?
  343. Date: Thu Mar 18 17:16:55 EST 1993
  344.  
  345. 4.7)  How can I get setuid shell scripts to work?
  346.  
  347.       [ This is a long answer, but it's a complicated and frequently-asked
  348.         question.  Thanks to Maarten Litmaath for this answer, and
  349.         for the "indir" program mentioned below. ]
  350.  
  351.       Let us first assume you are on a UNIX variant (e.g. 4.3BSD or
  352.       SunOS) that knows about so-called `executable shell scripts'.
  353.       Such a script must start with a line like:
  354.  
  355.     #!/bin/sh
  356.  
  357.       The script is called `executable' because just like a real (binary)
  358.       executable it starts with a so-called `magic number' indicating
  359.       the type of the executable.  In our case this number is `#!' and
  360.       the OS takes the rest of the first line as the interpreter for
  361.       the script, possibly followed by 1 initial option like:
  362.  
  363.     #!/bin/sed -f
  364.  
  365.       Suppose this script is called `foo' and is found in /bin,
  366.       then if you type:
  367.  
  368.     foo arg1 arg2 arg3
  369.  
  370.       the OS will rearrange things as though you had typed:
  371.  
  372.     /bin/sed -f /bin/foo arg1 arg2 arg3
  373.  
  374.       There is one difference though: if the setuid permission bit for
  375.       `foo' is set, it will be honored in the first form of the
  376.       command; if you really type the second form, the OS will honor
  377.       the permission bits of /bin/sed, which is not setuid, of course.
  378.  
  379.       ----------
  380.  
  381.       OK, but what if my shell script does NOT start with such a `#!'
  382.       line or my OS does not know about it?
  383.  
  384.       Well, if the shell (or anybody else) tries to execute it, the OS
  385.       will return an error indication, as the file does not start with
  386.       a valid magic number.  Upon receiving this indication the shell
  387.       ASSUMES the file to be a shell script and gives it another try:
  388.  
  389.     /bin/sh shell_script arguments
  390.  
  391.       But we have already seen that a setuid bit on `shell_script' will
  392.       NOT be honored in this case!
  393.  
  394.       ----------
  395.  
  396.       Right, but what about the security risks of setuid shell scripts?
  397.  
  398.       Well, suppose the script is called `/etc/setuid_script', starting
  399.       with:
  400.  
  401.     #!/bin/sh
  402.     
  403.       Now let us see what happens if we issue the following commands:
  404.  
  405.     $ cd /tmp
  406.     $ ln /etc/setuid_script -i
  407.     $ PATH=.
  408.     $ -i
  409.  
  410.       We know the last command will be rearranged to:
  411.  
  412.     /bin/sh -i
  413.  
  414.       But this command will give us an interactive shell, setuid to the
  415.       owner of the script!
  416.       Fortunately this security hole can easily be closed by making the
  417.       first line:
  418.  
  419.     #!/bin/sh -
  420.  
  421.       The `-' signals the end of the option list: the next argument `-i'
  422.       will be taken as the name of the file to read commands from, just
  423.       like it should!
  424.  
  425.       ---------
  426.  
  427.       There are more serious problems though:
  428.  
  429.     $ cd /tmp
  430.     $ ln /etc/setuid_script temp
  431.     $ nice -20 temp &
  432.     $ mv my_script temp
  433.  
  434.       The third command will be rearranged to:
  435.  
  436.     nice -20 /bin/sh - temp
  437.  
  438.       As this command runs so slowly, the fourth command might be able
  439.       to replace the original `temp' with `my_script' BEFORE `temp' is
  440.       opened by the shell!  There are 4 ways to fix this security hole:
  441.  
  442.     1)  let the OS start setuid scripts in a different, secure way
  443.         - System V R4 and 4.4BSD use the /dev/fd driver to pass the
  444.         interpreter a file descriptor for the script
  445.  
  446.     2)  let the script be interpreted indirectly, through a frontend
  447.         that makes sure everything is all right before starting the
  448.         real interpreter - if you use the `indir' program from
  449.         comp.sources.unix the setuid script will look like this:
  450.  
  451.         #!/bin/indir -u
  452.         #?/bin/sh /etc/setuid_script
  453.  
  454.     3)  make a `binary wrapper': a real executable that is setuid and
  455.         whose only task is to execute the interpreter with the name of
  456.         the script as an argument
  457.  
  458.     4)  make a general `setuid script server' that tries to locate the
  459.         requested `service' in a database of valid scripts and upon
  460.         success will start the right interpreter with the right
  461.         arguments.
  462.  
  463.       ---------
  464.  
  465.       Now that we have made sure the right file gets interpreted, are
  466.       there any risks left?
  467.  
  468.       Certainly!  For shell scripts you must not forget to set the PATH
  469.       variable to a safe path explicitly.  Can you figure out why?
  470.       Also there is the IFS variable that might cause trouble if not
  471.       set properly.  Other environment variables might turn out to
  472.       compromise security as well, e.g. SHELL...  Furthermore you must
  473.       make sure the commands in the script do not allow interactive
  474.       shell escapes!  Then there is the umask which may have been set
  475.       to something strange...
  476.  
  477.       Etcetera.  You should realise that a setuid script `inherits' all
  478.       the bugs and security risks of the commands that it calls!
  479.  
  480.       All in all we get the impression setuid shell scripts are quite a
  481.       risky business!  You may be better off writing a C program instead!
  482.  
  483. ------------------------------
  484.  
  485. Subject: How can I find out which user or process has a file open ... ?
  486. Date: Thu Mar 18 17:16:55 EST 1993
  487.  
  488. 4.8)  How can I find out which user or process has a file open or is using
  489.       a particular file system (so that I can unmount it?)
  490.  
  491.       Use fuser (system V), fstat (BSD), ofiles (public domain) or
  492.       pff (public domain).  These programs will tell you various things
  493.       about processes using particular files.
  494.  
  495.       A port of the 4.3 BSD fstat to Dynix, SunOS and Ultrix
  496.       can be found in archives of comp.sources.unix, volume 18.
  497.  
  498.       pff is part of the kstuff package, and works on quite a few systems.
  499.       Instructions for obtaining kstuff are provided in question 3.10.
  500.  
  501. ------------------------------
  502.  
  503. Subject: How do I keep track of people who are fingering me?
  504. >From: jik@pit-manager.MIT.EDU (Jonathan I. Kamens)
  505. >From: malenovi@plains.NoDak.edu (Nikola Malenovic)
  506. Date: Mon, 23 Nov 1992 16:01:45 -0600
  507.  
  508. 4.9)  How do I keep track of people who are fingering me?
  509.  
  510.       Generally, you can't find out the userid of someone who is
  511.       fingering you from a remote machine.  You may be able to
  512.       find out which machine the remote request is coming from.
  513.       One possibility, if your system supports it and assuming
  514.       the finger daemon doesn't object, is to make your .plan file a
  515.       "named pipe" instead of a plain file.  (Use 'mknod' to do this.)
  516.  
  517.       You can then start up a program that will open your .plan file
  518.       for writing; the open will block until some other process (namely
  519.       fingerd) opens the .plan for reading.  Now you can whatever you
  520.       want through this pipe, which lets you show different .plan
  521.       information every time someone fingers you.
  522.  
  523.       Of course, this may not work at all if your system doesn't
  524.       support named pipes or if your local fingerd insists
  525.       on having plain .plan files.
  526.  
  527.       Your program can also take the opportunity to look at the output
  528.       of "netstat" and spot where an incoming finger connection is
  529.       coming from, but this won't get you the remote user.
  530.  
  531.       Getting the remote userid would require that the remote site be
  532.       running an identity service such as RFC 931.  There are now three
  533.       RFC 931 implementations for popular BSD machines, and several
  534.       applications (such as the wuarchive ftpd) supporting the server.
  535.       For more information join the rfc931-users mailing list,
  536.       rfc931-users-request@kramden.acf.nyu.edu.
  537.  
  538.       There are three caveats relating to this answer.  The first is
  539.       that many NFS systems won't recognize the named pipe correctly.
  540.       This means that trying to read the pipe on another machine will
  541.       either block until it times out, or see it as a zero-length file,
  542.       and never print it.
  543.  
  544.       The second problem is that on many systems, fingerd checks that
  545.       the .plan file contains data (and is readable) before trying to
  546.       read it.  This will cause remote fingers to miss your .plan file
  547.       entirely.
  548.  
  549.       The third problem is that a system that supports named pipes
  550.       usually has a fixed number of named pipes available on the
  551.       system at any given time - check the kernel config file and
  552.       FIFOCNT option.  If the number of pipes on the system exceeds the
  553.       FIFOCNT value, the system blocks new pipes until somebody frees
  554.       the resources.  The reason for this is that buffers are allocated
  555.       in a non-paged memory.
  556.  
  557. ------------------------------
  558.  
  559. Subject: Is it possible to reconnect a process to a terminal ... ?
  560. Date: Thu Mar 18 17:16:55 EST 1993
  561.  
  562. 4.10) Is it possible to reconnect a process to a terminal after it has
  563.       been disconnected, e.g. after starting a program in the background
  564.       and logging out?
  565.  
  566.       Most variants of Unix do not support "detaching" and "attaching"
  567.       processes, as operating systems such as VMS and Multics support.
  568.       However, there are two freely redistributable packages which can
  569.       be used to start processes in such a way that they can be later
  570.       reattached to a terminal.
  571.  
  572.       The first is "screen," which is described in the
  573.       comp.sources.unix archives as "Screen, multiple windows on a CRT"
  574.       (see the "screen-3.2" package in comp.sources.misc, volume 28.)
  575.       This package will run on at least BSD, System V r3.2 and SCO UNIX.
  576.  
  577.       The second is "pty," which is described in the comp.sources.unix
  578.       archives as a package to "Run a program under a pty session" (see
  579.       "pty" in volume 23).  pty is designed for use under BSD-like
  580.       system only.
  581.  
  582.       Neither of these packages is retroactive, i.e. you must have
  583.       started a process under screen or pty in order to be able to
  584.       detach and reattach it.
  585.  
  586. ------------------------------
  587.  
  588. Subject: Is it possible to "spy" on a terminal ... ?
  589. Date: Thu Mar 18 17:16:55 EST 1993
  590.  
  591. 4.11) Is it possible to "spy" on a terminal, displaying the output
  592.       that's appearing on it on another terminal?
  593.  
  594.       There are a few different ways you can do this, although none
  595.       of them is perfect:
  596.  
  597.       * kibitz allows two (or more) people to interact with a shell
  598.         (or any arbitary program).  Uses include:
  599.  
  600.     - watching or aiding another person's terminal session;
  601.     - recording a conversation while retaining the ability to
  602.       scroll backwards, save the conversation, or even edit it
  603.       while in progress;
  604.     - teaming up on games, document editing, or other cooperative
  605.       tasks where each person has strengths and weakness that
  606.       complement one another.
  607.  
  608.         kibitz comes as part of the expect distribution.  See question 3.9.
  609.  
  610.         kibitz requires permission from the person to be spyed upon.  To
  611.         spy without permission requires less pleasant approaches:
  612.  
  613.       * You can write a program that grovels through Kernel structures
  614.         and watches the output buffer for the terminal in question,
  615.         displaying characters as they are output.  This, obviously, is
  616.         not something that should be attempted by anyone who does not
  617.         have experience working with the Unix kernel.  Furthermore,
  618.         whatever method you come up with will probably be quite
  619.         non-portable.
  620.  
  621.       * If you want to do this to a particular hard-wired terminal all
  622.         the time (e.g. if you want operators to be able to check the
  623.         console terminal of a machine from other machines), you can
  624.         actually splice a monitor into the cable for the terminal.  For
  625.         example, plug the monitor output into another machine's serial
  626.         port, and run a program on that port that stores its input
  627.         somewhere and then transmits it out *another* port, this one
  628.         really going to the physical terminal.  If you do this, you have
  629.         to make sure that any output from the terminal is transmitted
  630.         back over the wire, although if you splice only into the
  631.         computer->terminal wires, this isn't much of a problem.  This is
  632.         not something that should be attempted by anyone who is not very
  633.         familiar with terminal wiring and such.
  634.  
  635. ------------------------------
  636.  
  637. End of unix/faq Digest part 4 of 7
  638. **********************************
  639.  
  640. -- 
  641. Ted Timar - tmatimar@empress.com
  642. Empress Software, 3100 Steeles Ave E, Markham, Ont., Canada L3R 8T3
  643.