Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Controlling Access To Temporary File

Controlling Access To Temporary File

Scheduled Pinned Locked Moved C / C++ / MFC
questionsecurity
5 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    Poul Haahr Klemmensen
    wrote on last edited by
    #1

    My questions are these; How can I ensure that a program which creates a file is the only one allowed to access that file? And furthermore how can I make windows clean up my temporary files (in case the program crashes or something)? Taking into consideration that the program which created the file has some sort of security lock on the file. Something clever should be said, but I don't have the time

    B N 2 Replies Last reply
    0
    • P Poul Haahr Klemmensen

      My questions are these; How can I ensure that a program which creates a file is the only one allowed to access that file? And furthermore how can I make windows clean up my temporary files (in case the program crashes or something)? Taking into consideration that the program which created the file has some sort of security lock on the file. Something clever should be said, but I don't have the time

      B Offline
      B Offline
      BhaskarBora
      wrote on last edited by
      #2

      1. you can't do it directly in Windows. Windows does not support file locking or access validity of any form. Only access level rights of a file are checked while accessing a file, which comes from the current user's access rights and privileges. Probable solution: You need to put some sort of file encryption algo so that only authorize process/program can open it to read/write data from/into the file. but one draw back there in this. anyone can corrupt the file and data will be lost beyound recovery. 2. A tmp files can be deleted by a countom made software that looks for special file name patters and if found can take appropriate action of deletion.. this SW can be put to start during Windows startup so that by teh time PC is ready to be used all tmp files are deleted. 2. B also tmp file names can be logged in one common file with complete path. this file can be opened by a SW during Windows startup and all entries in that file can be deleted one by one. tmp file paths will be added to this log file by various processes/programs that require peroidic/auto deletion of log files. techi !!

      N 1 Reply Last reply
      0
      • B BhaskarBora

        1. you can't do it directly in Windows. Windows does not support file locking or access validity of any form. Only access level rights of a file are checked while accessing a file, which comes from the current user's access rights and privileges. Probable solution: You need to put some sort of file encryption algo so that only authorize process/program can open it to read/write data from/into the file. but one draw back there in this. anyone can corrupt the file and data will be lost beyound recovery. 2. A tmp files can be deleted by a countom made software that looks for special file name patters and if found can take appropriate action of deletion.. this SW can be put to start during Windows startup so that by teh time PC is ready to be used all tmp files are deleted. 2. B also tmp file names can be logged in one common file with complete path. this file can be opened by a SW during Windows startup and all entries in that file can be deleted one by one. tmp file paths will be added to this log file by various processes/programs that require peroidic/auto deletion of log files. techi !!

        N Offline
        N Offline
        Neville Franks
        wrote on last edited by
        #3

        BhaskarBora wrote: 1. you can't do it directly in Windows. Windows does not support file locking or access validity of any form. Only access level rights of a file are checked while accessing a file, which comes from the current user's access rights and privileges. What rubbish. See the dwShareMode param of CreateFile(). http://msdn.microsoft.com/library/default.asp?url=/library/en-us/fileio/base/createfile.asp[^] 2. This is trying to clean up after the fact. Far better to prevent the problem in the first place. Neville Franks, Author of ED for Windows. Free Trial at www.getsoft.com

        B 1 Reply Last reply
        0
        • P Poul Haahr Klemmensen

          My questions are these; How can I ensure that a program which creates a file is the only one allowed to access that file? And furthermore how can I make windows clean up my temporary files (in case the program crashes or something)? Taking into consideration that the program which created the file has some sort of security lock on the file. Something clever should be said, but I don't have the time

          N Offline
          N Offline
          Neville Franks
          wrote on last edited by
          #4

          Raggamuffin wrote: How can I ensure that a program which creates a file is the only one allowed to access that file? See the dwShareMode param of CreateFile(). Sharemode can be also spec'd in some other functions that wrap CreateFile(). See: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/fileio/base/createfile.asp[^] Raggamuffin wrote: And furthermore how can I make windows clean up my temporary files (in case the program crashes or something)? 1) Use C++ and/or Structured Exception Handling (SEH). There are several good articles here on CP about Exception Handling. 2) Use RAII to manage the file handle and simply rely on destructors to cleanup for you. Boost scoped_ptr will do this for you very nicely. See: http://www.boost.org/libs/smart_ptr/scoped_ptr.htm[^] Neville Franks, Author of ED for Windows. Free Trial at www.getsoft.com

          1 Reply Last reply
          0
          • N Neville Franks

            BhaskarBora wrote: 1. you can't do it directly in Windows. Windows does not support file locking or access validity of any form. Only access level rights of a file are checked while accessing a file, which comes from the current user's access rights and privileges. What rubbish. See the dwShareMode param of CreateFile(). http://msdn.microsoft.com/library/default.asp?url=/library/en-us/fileio/base/createfile.asp[^] 2. This is trying to clean up after the fact. Far better to prevent the problem in the first place. Neville Franks, Author of ED for Windows. Free Trial at www.getsoft.com

            B Offline
            B Offline
            BhaskarBora
            wrote on last edited by
            #5

            "What rubbish. See the dwShareMode param of CreateFile(). " CreateFile will work till you have opened the file and after u close it any process can open it and read the contents. requirement is that no other process should be able to even open or read the file, which was originally created by some other process. this can be done by encrypting the file whose descryption is known to only the creator of the file. _________________________________________________________________ "Think big, think fast, think ahead. Ideas are no one's monopoly"

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups