home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #16 / NN_1992_16.iso / spool / comp / unix / internal / 1637 < prev    next >
Encoding:
Text File  |  1992-07-31  |  2.3 KB  |  68 lines

  1. Path: sparky!uunet!dtix!darwin.sura.net!zaphod.mps.ohio-state.edu!mips!think.com!barmar
  2. From: barmar@think.com (Barry Margolin)
  3. Newsgroups: comp.unix.internals
  4. Subject: Re: Problems with fsync(2) in SunOS
  5. Keywords: fsync EACCES
  6. Message-ID: <15bpnkINNhim@early-bird.think.com>
  7. Date: 31 Jul 92 16:28:36 GMT
  8. References: <1089@krabat.marco.de>
  9. Organization: Thinking Machines Corporation, Cambridge MA, USA
  10. Lines: 55
  11. NNTP-Posting-Host: telecaster.think.com
  12.  
  13. In article <1089@krabat.marco.de> leo@krabat.marco.de (Matthias Pfaller) writes:
  14. >main(argc, argv)
  15. >int argc; char **argv;
  16. >{
  17. >    int fd;
  18. >    char b[80];
  19. >
  20. >    if ((fd = open(argv[1], O_WRONLY|O_CREAT, 0666)) < 0) {
  21. >        perror("open");
  22. >        exit(1);
  23. >    }
  24. >
  25. >    if (fchmod(fd, 0444))
  26. >        perror("fchmod");
  27. >
  28. >    sprintf(b, "su root -c '/etc/chown bin %s'", argv[1]);
  29. >    system(b);
  30. >
  31. >    if (write(fd, "hallo\n", 6) != 6)
  32. >        perror("write");
  33. >    if (fsync(fd))
  34. >        perror("fsync");
  35. >    if (close(fd))
  36. >        perror("close");
  37. >    exit(0);
  38. >}
  39.  
  40. The error actually occurred because of the write(2).  But since writes are
  41. buffered up in the kernel, you don't find out about the error until you
  42. call fsync(2) or close(2).
  43.  
  44. This problem is due to the statelessness of NFS.  For UFS, access is only
  45. checked when you open a file, and the allowable access modes are stored in
  46. the process's file table; after that, you can change the file modes, change
  47. the owner, even delete the file, and still write to the file.
  48.  
  49. The NFS protocol doesn't have the concept of an "open file"; each read or
  50. write to the object is independent.  Therefore, the server checks access on
  51. each operation.  In this case, when it received the WRITE request, it sees
  52. that you don't have write access, and returns an error.
  53.  
  54. You may be wondering why the chown is necessary to demontrate this problem.
  55. Well, there's a kludge that exists mainly because of programs that do a
  56. fchmod(3) after they open a file.  If the write request comes from the
  57. file's owner, the NFS server always permits it.  This isn't really a
  58. security violation, since the owner has the ability to change the
  59. permission if he wants to.  It generally doesn't cause problems because
  60. most clients also do access checking when they open a file, so they'll
  61. return an error from open(2) if you ask for write access when you don't
  62. have it.
  63. -- 
  64. Barry Margolin
  65. System Manager, Thinking Machines Corp.
  66.  
  67. barmar@think.com          {uunet,harvard}!think!barmar
  68.