kahrlzero has asked for the wisdom of the Perl Monks concerning the following question:

I'm running nms wwwboard in my pair.com account and it's chowning the actual HTML document to 'nobody' so I can't edit it outside the admin script. Can someone show me a simple script to chown the file back to myself, even temporarily, so that I can fix it? I'm a complete perl outsider at this point and don't know where to start. Thanks a ton! -Allin

Replies are listed 'Best First'.
Re: nms wwwboard ownership silliness
by graff (Chancellor) on Sep 20, 2005 at 01:42 UTC
    If the web server is a unix-like box, "chown" is a place you cannot go -- that's something only root (superuser) can do.

    What's happening is that the file is being created by the web server account (which happens to be called "nobody" on your server).

    If the file had existed previously, and had been owned by some other account (eg you), then the logical approach would be that the web server simply truncates and rewrites the content of the file, without deleting it completely -- this would mean that you would retain ownership. But for this to work, you need to grant write permission to "nobody" for the file you own, so the web server account can modify it.

    Then again, maybe this service doesn't take that approach, and somehow manages to always create a new file, which must therefore be owned by "nobody". In that case, the process that creates the file must also do a "chgrp" to associate it with a user group that you are also a member of, and then set group write permission on the new file.

    (If the directory has the appropriate group ownership, and its "set-group-id" mode flag is set, the group ownership of the file will be set automatically, and the file creation process only needs to set group write access.)

      maybe this service doesn't take that approach, and somehow manages to always create a new file
      It's fairly common to create a new file, then rename it to the original name, since that guarantees there is never a partially written file served up.
      (If the directory has the appropriate group ownership, and its "set-group-id" mode flag is set, the group ownership of the file will be set automatically, and the file creation process only needs to set group write access.)
      Setting an appropriate umask may also accomplish this, depending on the code.

      This is a really clever solution; I didn't realize that the setgid bit would let the Web server user create a file owned by a group it wasn't a member of, but a small test confirms this. I can think of tons of places to use this. Thanks!

      If the web server is a unix-like box, "chown" is a place you cannot go -- that's something only root (superuser) can do.
      That's not necessarely true. One some Unix systems, only root may chown files to a different user. But other Unix systems allow a user to chown their own files to a different user.
Re: nms wwwboard ownership silliness
by sauoq (Abbot) on Sep 20, 2005 at 01:54 UTC

    If it is currently owned by nobody, you've got to change the permissions on it so that you can write to it. At that point, you can decide to 1) keep it as is or 2) copy it, move your copy back on top of it, and then change perms to allow nobody to write to it later.

    To get nobody to change the perms for you, put something like this in a file called fixperms.cgi (or whatever you need to do to get it to run as a CGI in your environment.)

    #!/bin/sh /bin/chmod 777 /full/path/to/hosed/file.html /usr/bin/echo "Content-type: text\plain" /usr/bin/echo /usr/bin/echo "Hopefully that worked."
    Make sure it is executable and then point your browser at it. After you are done with it, get rid of it.

    You may have to double check the full paths to chmod and echo but the above should be right on most sane systems.

    -sauoq
    "My two cents aren't worth a dime.";
    
Re: nms wwwboard ownership silliness
by davorg (Chancellor) on Sep 20, 2005 at 10:31 UTC

    Did you try asking the nms team (nms-cgi-support@lists.sourceforge.net) for support? Sounds like a sensible thing for the program to do, but it might need to set slightly different permissions - in which case telling the nms developers is the best way to get it fixed.

    --
    <http://dave.org.uk>

    "The first rule of Perl club is you do not talk about Perl club."
    -- Chip Salzenberg

Re: nms wwwboard ownership silliness
by parv (Parson) on Sep 20, 2005 at 01:40 UTC
    Have you tried running the board under your own userid via cgiwarp (which comes w/ its own caveats)?