sulfericacid,
Your problem is not with your code, but your understanding of *nix file systems. You really need to spend some time understanding how these work. Here is some helpful advice:

  • man chmod
  • man chgrp
  • /etc/passwd
  • /etc/group

    Each line in /etc/passwd is a 7 field record using : delimiter

  • First field is the login name
  • Second field is for the password (typically stored in another file)
  • Third field is the user id
  • Fourth field is the group id

    Each file on the system has an owner and a group. This combined with the permissions determine who can do what to that file. You will be amazed to find that the permission to delete a file is not controlled by the permission on the file, but rather by the permission of the directory the file is in. Why is this? Because the inode that tells the OS where that file is stored in the directory.

    When setting permissions, you are typically only concerned with the last 3 octal settings:

  • 1 = execute
  • 2 = write
  • 3 = write + execute
  • 4 = read
  • 5 = read + execute
  • 6 = write + read
  • 7 = execute + write + read
  • octal position 1 is for special bits (typically not used)
  • octal position 2 is for owner of file
  • octal position 3 is for group of file
  • octal position 4 is for world (everyone)

    A typical use would be chmod 640 file
    If you decide you want to use the special bits:

  • 1 = sticky bit
  • 2 = set group id bit
  • 4 = set user id bit

    I will leave it up to you why you might want to use one of these, but Coplan has already shed some light on the matter.

    Depending on the system, you will not be able to give your files away (chown) unless you are the superuser. You can't change the group (chgrp) on a file to a group you don't belong (/etc/group). You can not delete a non-empty directory.

  • So finally to your question: How can you delete all the files and directories created by your CGI script.

    One idea would be to make sure you and the apache daemon's account (typically nobody) are both in the same group. Then just make sure that anything you create (directory or file) is writeable by group.

    Another bad idea would be to give everything 777 permissions. Please do not consider this an option - security.

    The best idea would be for you to absorb this information and come up with what is the best solution for you in your environment.

    Cheers - L~R


    In reply to Re: File ownership by Limbic~Region
    in thread File ownership by sulfericacid

    Title:
    Use:  <p> text here (a paragraph) </p>
    and:  <code> code here </code>
    to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.