home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #18 / NN_1992_18.iso / spool / comp / sys / sun / admin / 5455 < prev    next >
Encoding:
Text File  |  1992-08-12  |  5.2 KB  |  157 lines

  1. Newsgroups: comp.sys.sun.admin
  2. Path: sparky!uunet!mcsun!sunic!sics.se!eua.ericsson.se!erix.ericsson.se!per
  3. From: per@erix.ericsson.se (Per Hedeland)
  4. Subject: Re: SUMMARY: Login box for openwin
  5. Message-ID: <1992Aug12.140542.28436@eua.ericsson.se>
  6. Sender: news@eua.ericsson.se
  7. Nntp-Posting-Host: aalborg.eua.ericsson.se
  8. Organization: Ellemtel Telecom Systems Labs, Stockholm, Sweden
  9. References:  <1992Aug11.013417.15041@ccu.umanitoba.ca>
  10. Date: Wed, 12 Aug 1992 14:05:42 GMT
  11. Lines: 144
  12.  
  13. In article <1992Aug11.013417.15041@ccu.umanitoba.ca>, mills@ccu.umanitoba.ca (Gary Mills) writes:
  14. |> >  There should still be a way to get to the
  15. |> >console vt100 emulator in case the user wanted to run something else,
  16. |> >like sunview.  A button or a magic login name might do it.  Can this be
  17. |> >done with X11R5?
  18. |> 
  19. |> Thanks to all that replied.  What I would like seems to be impossible
  20. |> with the tools available.
  21.  
  22. Well, not impossible - at least we're doing it, but it's perhaps a bit
  23. awkward... The ideal solution would be to have something like a "shell
  24. escape", that let the user get a login shell on the console, and then
  25. when he logged out fired up the X server again - and *that* is not
  26. possible without hacking xdm, as far as I know.
  27.  
  28. But there are other ways - xdm has the abort-display() action, which can
  29. be bound to a e.g. a function key and will cause it to just kill the X
  30. server and stop managing the display in question. Next, the login
  31. shell: I've found that leaving the console getty enabled doesn't
  32. conflict with xdm/server in any way, and as soon as the server is
  33. killed, the getty is ready for a normal login (i.e. the user should call
  34. abort-display() *before* logging in under xdm).
  35.  
  36. Finally, getting xdm to fire up the X server again is done by logging in
  37. as a dummy user, which may or may not have a password and has the
  38. program below as "login shell" (you get to decide whether it (now:-)
  39. meets your definition of "tools available"). The security note might not
  40. apply if you have installed recent SunOS patches - but I won't make any
  41. guarantees in either case...
  42.  
  43. All this under X11R{4,5}, of course, I haven't tried it with OpenWindows
  44. (users will have to go through the contortions above if they want to run
  45. it:-) - but I can't see any reason why it wouldn't work, provided you
  46. can overcome the apparent difficulties with getting it to run *at all*
  47. under xdm.
  48.  
  49. Hope this helps...
  50. --Per Hedeland
  51. per@erix.ericsson.se  or
  52. per%erix.ericsson.se@sunic.sunet.se  or
  53. ...uunet!erix.ericsson.se!per
  54.  
  55. xdmrestart.c-------------------------------------------------------------
  56. /*
  57.    Little program to "restart" xdm, making it remanage aborted displays.
  58.    We require it to be started from the console (code stolen from xdmshell),
  59.    and that argv[0] starts with a dash - the idea is to install it setuid
  60.    to root and use as login shell for some dummy user (e.g. 'x').
  61.  
  62.    NOTE: It is important that the dummy user has a harmless userid (e.g.
  63.    that of 'nobody') and this program is setuid, rather than the dummy
  64.    user having userid 0, otherwise this can be exploited as a security
  65.    hole (by playing tricks with LD_LIBRARY_PATH and running login -p).
  66.    Static linking might be a good idea, too.
  67. */
  68.  
  69. #include <stdio.h>
  70. #include <sys/file.h>
  71. #include <sys/ioctl.h>
  72. #include <signal.h>
  73.  
  74. /* Shouldn't hardwire this here but it's too hard to do right... */
  75. #define PIDFILE "/etc/xdm/xdm-pid"
  76.  
  77. main (argc, argv)
  78.     int argc;
  79.     char *argv[];
  80. {
  81.     int ttyfd, consfd;
  82.     int ttypgrp, conspgrp, pid;
  83.     char *ttyName;
  84.     FILE *pidfile;
  85.     extern char *ttyname();
  86.  
  87.     if (*argv[0] != '-') {
  88.     fprintf (stderr, "%s:  must be run as login \"shell\".\r\n",
  89.          argv[0]);
  90.     exit (1);
  91.     }
  92.  
  93.     if (argc > 1) {
  94.     fprintf (stderr, "usage:  %s\r\n", argv[0]);
  95.     exit (1);
  96.     }
  97.  
  98.     ttyfd = open ("/dev/tty", O_RDWR, 0);
  99.     if (ttyfd < 3) {            /* stdin = 0, stdout = 1, stderr = 2 */
  100.     fprintf (stderr, 
  101.          "%s:  must be run directly from the console.\r\n",
  102.          argv[0]);
  103.     exit (1);
  104.     }
  105.     if (ioctl (ttyfd, TIOCGPGRP, (char *)&ttypgrp) != 0) {
  106.     fprintf (stderr, "%s:  unable to get process group of /dev/tty\r\n",
  107.          argv[0]);
  108.     (void) close (ttyfd);
  109.     exit (1);
  110.     }
  111.     (void) close (ttyfd);
  112.     
  113.     ttyName = ttyname (0);
  114.     if (!ttyName || strcmp (ttyName, "/dev/console") != 0) {
  115.     fprintf (stderr, "%s:  must login on /dev/console instead of %s\r\n",
  116.          argv[0], ttyName ? ttyName : "non-terminal device");
  117.     exit (1);
  118.     }
  119.  
  120.     consfd = open ("/dev/console", O_RDWR, 0);
  121.     if (consfd < 3) {            /* stdin = 0, stdout = 1, stderr = 2 */
  122.     fprintf (stderr, "%s:  unable to open /dev/console\r\n",
  123.          argv[0]);
  124.     exit (1);
  125.     }
  126.  
  127.     if (ioctl (consfd, TIOCGPGRP, (char *)&conspgrp) != 0) {
  128.     fprintf (stderr,
  129.          "%s:  unable to get process group of /dev/console\r\n",
  130.          argv[0]);
  131.     (void) close (consfd);
  132.     exit (1);
  133.     }
  134.     (void) close (consfd);
  135.  
  136.     if (ttypgrp != conspgrp) {
  137.     fprintf (stderr, "%s:  must be run from /dev/console\r\n", 
  138.          argv[0]);
  139.     exit (1);
  140.     }
  141.  
  142.     if ((pidfile = fopen(PIDFILE, "r")) == NULL ||
  143.     fscanf(pidfile, "%d", &pid) != 1 || pid < 3) {
  144.     fprintf (stderr, "%s:  unable to get PID of xdm from %s.\r\n",
  145.          argv[0], PIDFILE);
  146.     exit (1);
  147.     }
  148.  
  149.     if (kill(pid, SIGHUP) != 0) {
  150.     fprintf (stderr, "%s:  unable to restart xdm (PID %d).\r\n",
  151.          argv[0], pid);
  152.     exit (1);
  153.     }
  154.     
  155.     exit(0);
  156. }
  157.