home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1992 March / Source_Code_CD-ROM_Walnut_Creek_March_1992.iso / usenet / altsrcs / 3 / 3437 < prev    next >
Encoding:
Internet Message Format  |  1991-06-04  |  4.4 KB

  1. From: jfh@rpp386.cactus.org (John F Haugh II)
  2. Newsgroups: alt.security,alt.sources
  3. Subject: Re: Sun security problem with floppies.
  4. Message-ID: <19353@rpp386.cactus.org>
  5. Date: 2 Jun 91 19:34:12 GMT
  6.  
  7. In article <1991Jun2.014516.29451@nntp.hut.fi> jkp@cs.HUT.FI (Jyrki Kuoppala) writes:
  8. >I'd suppose that floppies on a Sun are used mostly to transfer data to
  9. >some other kinds of computers, writing some personal files with tar,
  10. >using MS-LOSS tools or something like that, not mounting them.  Making
  11. >the floppy device unreadable would make it useless for this purpose.
  12. >
  13. >Suggested fix: don't mount the floppy in the first place.
  14.  
  15. Better Suggested Fix:
  16.  
  17. Write a little utility which will change the ownership of the floppy
  18. disk from some standard UID that you make up to own the device to the
  19. real UID of the invoker.  Something like this -
  20. --
  21. #if    0
  22. cc -o checkin -DHAVE_FUSER checkinout.c
  23. touch /etc/checkinout
  24. cp checkin /usr/local/bin
  25. ln /usr/local/bin/checkin /usr/local/bin/checkout
  26. chown root /usr/local/bin/checkin
  27. chmod 400 /etc/checkinout
  28. chmod 4711 /usr/local/bin/checkin
  29. exit 0
  30. #endif
  31.  
  32. /*
  33.  * checkinout.c - manage a sharable device
  34.  *
  35.  *    You must define the HAVE_FCHOWN macro on the compile command
  36.  *    line if you have the fchown() system call.
  37.  *    Otherwise don't bother using this thing because it can let
  38.  *    anyone change the ownership of any file (more or less ...)
  39.  *    It is only safe without HAVE_FCHOWN if you have no writable
  40.  *    directories on the root partition (which should be the only
  41.  *    place with files owned by UNUSED_NAME) and if your system
  42.  *    does not have symbolic links.
  43.  *
  44.  *    You should define the HAVE_FUSER macro if you have the fuser
  45.  *    command.  It will be used to clean the device before giving
  46.  *    it to you.
  47.  *
  48.  *    To compile and install this source code, feed to /bin/sh
  49.  *    as root.
  50.  */
  51.  
  52. #include <sys/types.h>
  53. #include <sys/stat.h>
  54. #include <pwd.h>
  55. #include <stdio.h>
  56.  
  57. #define    UNUSED_NAME    "share"
  58. #define    SHARE_FILES    "/etc/checkinout"
  59.  
  60. usage ()
  61. {
  62.     fprintf (stderr, "usage:\tcheckin <device>\n\tcheckout <device>\n");
  63.     exit (1);
  64. }
  65.  
  66. main (argc, argv)
  67. int    argc;
  68. char    **argv;
  69. {
  70.     struct    passwd    *pwd;
  71.     uid_t    unused_uid;
  72.     struct    stat    sb;
  73.     enum    { in, out, unknown } in_out;
  74.     char    *cp;
  75.     char    *Prog;
  76.     int    fd;
  77.     char    buf[BUFSIZ];
  78.     FILE    *valid;
  79.     char    *strchr();
  80.  
  81.     if (argc != 2)
  82.         usage ();
  83.  
  84.     if (Prog = strchr (argv[0], '/'))
  85.         Prog++;
  86.     else
  87.         Prog = argv[0];
  88.  
  89.     if (strcmp ("checkin", Prog) == 0)
  90.         in_out = in;
  91.     else if (strcmp ("checkout", Prog) == 0)
  92.         in_out = out;
  93.     else
  94.         usage ();
  95.  
  96.     if (! (valid = fopen (SHARE_FILES, "r"))) {
  97.         fprintf (stderr,
  98.             "no list of shared devices in %s\n", SHARE_FILES);
  99.         exit (1);
  100.     }
  101.     while (fgets (buf, sizeof buf, valid)) {
  102.         if (cp = strchr (buf, '\n'))
  103.             *cp = '\0';
  104.  
  105.         if (strcmp (argv[1], buf) == 0)
  106.             break;
  107.     }
  108.     if (feof (valid)) {
  109.         fprintf (stderr, "unknown device: %s\n", argv[1]);
  110.         exit (1);
  111.     }
  112.     if ((pwd = getpwnam (UNUSED_NAME)) == 0) {
  113.         fprintf (stderr, "no sharable device owner\n");
  114.         exit (1);
  115.     }
  116. #ifdef    HAVE_FCHOWN
  117.     if ((fd = open (argv[1], O_RDONLY|O_NDELAY)) < 0) {
  118.         perror (argv[1]);
  119.         exit (1);
  120.     }
  121.     if (fstat (fd, &sb)) {
  122.         perror (argv[1]);
  123.         exit (1);
  124.     }
  125.     if (in_out == in && sb.st_uid != getuid () && getuid () != 0) {
  126.         fprintf (stderr, "device not owned by invoker\n");
  127.         exit (1);
  128.     }
  129.     if (in_out == out && sb.st_uid != pwd->pw_uid && getuid () != 0) {
  130.         fprintf (stderr, "device not owned by %s\n", UNUSED_NAME);
  131.         exit (1);
  132.     }
  133.     if (fchown (fd, in_out == in ? pwd->pw_uid:getuid(), sb.st_gid)) {
  134.         perror (argv[1]);
  135.         exit (1);
  136.     }
  137.     if (fchown (fd, 0)) {
  138.         perror (argv[1]);
  139.         exit (1);
  140.     }
  141.     close (fd);
  142. #else
  143.     if (stat (argv[1], &sb)) {
  144.         perror (argv[1]);
  145.         exit (1);
  146.     }
  147.     if (in_out == in && sb.st_uid != getuid () && getuid () != 0) {
  148.         fprintf (stderr, "device not owned by invoker\n");
  149.         exit (1);
  150.     }
  151.     if (in_out == out && sb.st_uid != pwd->pw_uid && getuid () != 0) {
  152.         fprintf (stderr, "device not owned by %s\n", UNUSED_NAME);
  153.         exit (1);
  154.     }
  155.     if (chown (argv[1], in_out == in ? pwd->pw_uid:getuid(), sb.st_gid)) {
  156.         perror (argv[1]);
  157.         exit (1);
  158.     }
  159.     if (chmod (argv[1], 0)) {
  160.         perror (argv[1]);
  161.         exit (1);
  162.     }
  163. #endif
  164. #ifdef    HAVE_FUSER
  165.     sprintf (buf, "fuser -k %s >> /dev/null", argv[1]);
  166.     (void) system (buf);
  167. #endif
  168.     exit (0);
  169. }
  170. -- 
  171. John F. Haugh II        | Distribution to  | UUCP: ...!cs.utexas.edu!rpp386!jfh
  172. Ma Bell: (512) 255-8251 | GEnie PROHIBITED :-) |  Domain: jfh@rpp386.cactus.org
  173. "If liberals interpreted the 2nd Amendment the same way they interpret the
  174.  rest of the Constitution, gun ownership would be mandatory."
  175.