home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / unix / volume22 / auth / part01 / dir.doc < prev    next >
Text File  |  1990-04-29  |  4KB  |  68 lines

  1. The authentication directory, AUTHDIR/tcp, contains several different
  2. types of files.
  3.  
  4. It is assumed that long ints representing Internet addresses take at
  5. most ten digits, short ints representing TCP port numbers take at most
  6. five digits, and ints representing process ids take at most five digits.
  7.  
  8. Files of the form I.L.R, where I, L, and R are integers, are username
  9. files. There is one username file per auth connection to/from this host,
  10. two for a local connection. I is the Internet address of the host on the
  11. other end of a TCP connection, expressed as a single long int; L and R
  12. are the connection's local and remote TCP ports respectively. The file
  13. contains just the name of the user, up to eight characters long.
  14.  
  15. Files of the form ps.C.P, where C and P are integers, are attachport
  16. process files. There is one process file for each connection served by
  17. an attachport on this host. C and P are the process ids of the child
  18. (server for a particular connection) and parent (attachport) processes
  19. respectively. The file contains the name of a username file; in effect,
  20. it points to the username file, so that the attachport can easily keep
  21. track of each of its children.
  22.  
  23. Files of the form lock.L, where L is an integer, are lock files. L is
  24. a local TCP port number. At any time there will be at most one auth
  25. program handling connections to/from port L. When authtcp or attachport
  26. starts, it opens the lock file with O_EXCL and writes its pid into it.
  27. If that fails, it reads the lock file, checks that the process exists,
  28. and gives an appropriate error. When it exits, it removes the lock file.
  29.  
  30. Lock files are also used to prevent race conditions during critical
  31. moments between connecting or accepting a connection and creating the
  32. appropriate username file. For attachport this is no big deal: it
  33. selects for reading before accepting a connection, and from before the
  34. accept() until the authentication entry is in place, it places an
  35. exclusive flock() on the lock file. (This WILL NOT WORK if selecting
  36. for reading performs an implicit accept. The race condition resulting
  37. from such a bug could be extremely hard to detect; but don't say I
  38. didn't warn you.) For authtcp, however, this is much more difficult:
  39. an outgoing connect() may take practically forever, and there's no way
  40. to precisely control the moment of connection as a select-accept can.
  41. On the other hand, authtcp has all the local authentication information
  42. it needs, before even beginning the connection. So it writes a colon,
  43. the I.R remote information, a newline, and the username into the lock
  44. file after its pid; it doesn't use a flock() except while updating the
  45. lock file. authd will look in this file only if it fails to find a
  46. username file; authentication requests rarely happen so quickly.
  47. attachport also places extra information into the lock file, namely a
  48. hyphen and the user name.
  49.  
  50. Observe that the duplicate authtcp information in the lock file gives
  51. away the user name on the local side of a connection that has not yet
  52. succeeded. Technically, this is not a violation of RFC 931, but it might
  53. offend purists. Then again, it's symmetric with how the user name is
  54. available for a moment after the connection is closed.
  55.  
  56. Latest addition to the lock file: If the first character is a ! then
  57. attachport (or, in a later version, perhaps authtcp) has been killed by
  58. the user during a critical moment. If you want a detailed explanation of
  59. how and why this is used, ask auth's author.
  60.  
  61. If the auth package gets much more complicated, it may be worth imposing
  62. a bit more structure on the authentication directory; hopefully all this
  63. authentication information will be available from the kernel long before
  64. that happens. The lock file system would have to be changed immediately
  65. if auth were to support REUSEADDR; however, ftp seems to be the only
  66. program that needs REUSEADDR, and PUFF is a much better file transfer
  67. system.
  68.