in reply to Non-Duplicate File Names, Security, and Self Cleaning

  1. I would use $$ somewhere in the filename.
    BTW: Do users log in? You could give each of them her own subdir so no one will see or destroy other's ZIPs. Given that you can easily use the same file name over and over again, just erasing the old one or even adding pictures to it.
  2. If you use a cgi for download add an unlink $filname.
    I wouldn't do it. I would give the user the oportunity to delete it at will. At least if you go the delete-after-10-minutes-way.
  3. After creating the ZIP you could fork another process which does a sleep 10*60 at first and then unlinks the file.

Replies are listed 'Best First'.
Re: Re: Non-Duplicate File Names, Security, and Self Cleaning
by Petras (Friar) on Jun 06, 2003 at 06:29 UTC
    Users don't log in. Really only one person is wanting some img files. Just my brain started spinning and thought I could do it this way to learn something in the process. If I wind up making something usefull that I or other people would want to use again later, great! I was wanting to make unique names, though, just because that would mean learning how to do something, and because someday if the code is good it might be used in a more trafficed scenario.

    I thought letting users delete the file themselves could make for some big security holes, and there are also lazy users out there. I just didn't know that I could make the script delete the file, but it seemed like something I should be able to do (yep, I'm still quite the newbie!)

    Thanks,
    Petras
    Don't worry about people stealing your ideas. If your ideas are any good, you'll have to ram them down people's throats.

    -Howard Aiken
      > Users don't log in. [...] I could do it this way to learn
      So this is another option for you to learn. ;-)

      > I thought letting users delete the file themselves could make for some big security holes
      It depends on how you do it. Each user should be able to delete just her own files. So if you make up some rally good random name this shouldn't be a problem. Just remember that your script should not allow any character in filenames to delete other than those characters you use in your generated filenames. Espacially no "/"!

      > and there are also lazy users out there
      That's why I said you should do it if you take the 10-minute-than-delete-way. So user can be gentle and delete the file after they used it.
      While I write it: Why don't you simply store the indices of the selected pictures in a cookie? If you don't have to many pictures this shouldn't be a problem. You could even save some space if you use a vec-tor to store which pics are choosen. When the user clicks on "download" the ZIP will be generated "on the fly" and will never appear in any direcory on the server.
      Just some more opportunities for you to learn from ;-)

        > > Users don't log in. ... I could do it this way to learn
        > So this is another option for you to learn. ;-)


        The difference is, with a check-box form my friend might look at it and say, "Hey, this is kinda cool." But if I make her log in she might say, "You geek! Why do I need to log in to something you set up for me to download images for a single presentation?" ;)

        Okay, so maybe I'm not that into learning right now. It's the Petras lazyness/ingenuity cycle. I should write an algorhythm about it someday....

        Where I've taken this idea/learning-experience is posted here if you are interested.
        Cheers!
        -P
        Don't worry about people stealing your ideas. If your ideas are any good, you'll have to ram them down people's throats.

        -Howard Aiken
Re: Re: Non-Duplicate File Names, Security, and Self Cleaning
by bm (Hermit) on Jun 06, 2003 at 12:04 UTC
    Im not sure if $$ is either new or unique...

    but localtime() is.

      $$ is uniqe as long as the system is not rebooted and as long as there is no overflow in the machines process counter. It might happen, but it's not very probable. I also didn't say that it's guaranteed to give you a unique filename. I just said, I would use it in the name. Not that I would use it as a name.

      But regarding localtime: it's almost sure that you will get the same result quite often. At least there is a delay of 1 second you will have to have before the script might be started again.

        I also didn't say that it's guaranteed to give you a unique filename.

        Nope, but the OP asked for that.

        $$ is uniqe as long as the system is not rebooted and as long as there is no overflow in the machines process counter. It might happen, but it's not very probable

        pids are assigned sequentially until a certain point (most probably 32767) is reached. Then they wrap around to 0. Rebooting also resets the count to 0. The chances of either reaching 32767 or a reboot are just about 100%, which is more probable than two instances of the same script calling localtime within the same second.Incidently, on AIX pids maybe reused within seconds.

        But regarding localtime: it's almost sure that you will get the same result quite often

        I'm not sure how? Do you mean by two instances of the same script both calling localtime at the same second?