Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Internal directory
QtWS25 Last Chance

Internal directory

Scheduled Pinned Locked Moved General and Desktop
19 Posts 7 Posters 6.7k Views
  • 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.
  • R Offline
    R Offline
    ruiluis
    wrote on last edited by
    #1

    Hi.
    I am doing a windows/linux application using qt. I need to load some files from the disk. However i do not want for other applications or users to see or use such files. Is there any way to do a kind of "private" directory where only my application can save and read files?

    @QString myPrivateDirectory (QDesktopServices::storageLocation (QDesktopServices::DataLocation));@

    gives a more obscure directory.. but not safe..

    [edit : added @ code tags, Eddy]

    1 Reply Last reply
    0
    • K Offline
      K Offline
      koahnig
      wrote on last edited by
      #2

      Welcome to devnet

      If you are reading from those files only, you could use the "resource system":http://developer.qt.nokia.com/doc/qt-4.7/resources.html
      The file information will be stored in your application. So it is probably not the best solution for larger files.

      Vote the answer(s) that helped you to solve your issue(s)

      1 Reply Last reply
      0
      • T Offline
        T Offline
        tobias.hunger
        wrote on last edited by
        #3

        All applications run under the id of the user that started them. So if you want your application to read data, then the user can also read it. So, no, there is no safe directory on linux.

        If you have static data you can build it into your exectuable using the Qt resource system.

        1 Reply Last reply
        0
        • R Offline
          R Offline
          ruiluis
          wrote on last edited by
          #4

          Thanks for both your answers.
          Its kind of what i was expecting..

          Is there any way to emulate a memory file system in qt?
          what i want to do is download a file from internet and store it just the time that it takes to process it. The problem is that i am using 3rd party libs and the only way to use it is by passing a char* with the filename location..

          1 Reply Last reply
          0
          • K Offline
            K Offline
            koahnig
            wrote on last edited by
            #5

            The only solution coming to my mind immediately would be a temporary file during the executation of your application. In case of a crash it may remain somewhere and is accessible to the user.

            Vote the answer(s) that helped you to solve your issue(s)

            1 Reply Last reply
            0
            • R Offline
              R Offline
              ruiluis
              wrote on last edited by
              #6

              thanks..
              but it also leaves the problem of being accessed by external users..
              going to try this:
              http://labs.qt.nokia.com/2007/10/15/file-mapping/

              1 Reply Last reply
              0
              • A Offline
                A Offline
                andre
                wrote on last edited by
                #7

                Well, yes, there is actually, though the needed API is marked deprecated and will not be in Qt 5.

                What you could do, is create a [[doc:QAbstractFileEngine]] subclass. That would enable you to create an in-memory implementation of a file system, and use it using all the normal Qt classes.

                On Linux, another approach is that you can create a file, open it, and immediately delete it again. That way, as long your application keeps the file open, it is accessible only to your application. I don't think windows supports this trick though.

                1 Reply Last reply
                0
                • F Offline
                  F Offline
                  fluca1978
                  wrote on last edited by
                  #8

                  [quote author="ruiluis" date="1323685668"]
                  what i want to do is download a file from internet and store it just the time that it takes to process it. The problem is that i am using 3rd party libs and the only way to use it is by passing a char* with the filename location..[/quote]

                  It seems to me you are overestimating the problem. I suspect the file will be of a few bytes to a few kilobytes, so it will not take so much longer to parse/analyze it. If this is the case, your application could store the file with a strange name and delete it on exiting (or as soon as you want). In the case of an application crash the file could still be present somewhere, and this depends on the operating system (e.g., if the temporary file is on memory it will deleted as soon as memory is required). By the way, going with an in-memory file will not solve all your problems, since a memory dump could still occur...but as I said, I guess this is a little overestimated. Depending on the third party library you could also try to use a named pipe to pass the content of the file without having to store it locally, but again depends on the operating system and on the implementation of the library.

                  1 Reply Last reply
                  0
                  • G Offline
                    G Offline
                    goetz
                    wrote on last edited by
                    #9

                    @Andre
                    the QAFE subclass would not solve the problem, as it only works with Qt classes, but not with the external library that takes the const char pointer - that is not aware of the RAM disk.

                    The problem in its current presentation is unsolvable. As long as your library behaves kind of "external" to Qt, you will have to pass it a const char pointer. That points to a file that must be readable by the user running the process. So any other process run by the same user can access the file too.

                    And I agree with fluca1978, you either over estimate the problem or - if security is of such a big concern - saving it somewhere is the error in the first place.

                    Don't waste your time in the file mapping approach. It maps existing files into memory. You will have to save to the file beforehand.

                    http://www.catb.org/~esr/faqs/smart-questions.html

                    1 Reply Last reply
                    0
                    • A Offline
                      A Offline
                      andre
                      wrote on last edited by
                      #10

                      [quote author="Volker" date="1323695271"]@Andre
                      the QAFE subclass would not solve the problem, as it only works with Qt classes, but not with the external library that takes the const char pointer - that is not aware of the RAM disk.
                      [/quote]
                      Right, I missed that comment. In that case, the suggestion I gave for Linux is also not going to work. You will need to solve this as the OS level, if possible, but I am not aware of process-private ram-disc implementations.

                      I agree with Fluca1978: why is it so important for you that you cannot use temporary files on the normal file system that are potentialy visible to the user (and other users) of the system?

                      1 Reply Last reply
                      0
                      • R Offline
                        R Offline
                        ruiluis
                        wrote on last edited by
                        #11

                        using the temporary files i have always the problem of being accessed by the user.. if its protected content is a bit bad.. i will try to change the 3rd party library.. if not.. temporary files...

                        Thanks for your help.

                        1 Reply Last reply
                        0
                        • F Offline
                          F Offline
                          fluca1978
                          wrote on last edited by
                          #12

                          I believe that the real problem is about leaving this files around the system for a while, so I will search for another solution like making the file hidden, place it into random destinations (to avoid the user to understand where the file is going to be saved), and so on.
                          By the way, the best solution is to have the library to work with a stream, if possible.

                          1 Reply Last reply
                          0
                          • A Offline
                            A Offline
                            andre
                            wrote on last edited by
                            #13

                            I would not just save the file in random places. A determined user will find them anyway (the OS can tell you what files are used by what process). More and more platforms will constrict applications' writing permissions to certain designated directories. It is a good idea to make your application well-behaved, and prevent spreading temporary files all over the system. Who cleans them up if your application (or the system as a whole) crashes?

                            I agree that the library accepting streams instead of files is best. Otherwise, you might considder encrypting the file before storing it (and having the lib able to decrypt again).

                            1 Reply Last reply
                            0
                            • F Offline
                              F Offline
                              fluca1978
                              wrote on last edited by
                              #14

                              [quote author="Andre" date="1323702149"]I would not just save the file in random places. A determined user will find them anyway (the OS can tell you what files are used by what process). [/quote]

                              Right. I was thinking about a directory tree, let say localstorage populated with random directories which contain random named files, so that it is quite difficult for a user that does not know how to use lsof (or similar) to understand where the file is. Of course, to get a possibility to clean up everything, there must be a common ancestor. But this is a kind of desperate-poor-developer solution!

                              1 Reply Last reply
                              0
                              • G Offline
                                G Offline
                                goetz
                                wrote on last edited by
                                #15

                                Poorly obfuscating things is usually not worth putting too much effort in it.

                                http://www.catb.org/~esr/faqs/smart-questions.html

                                1 Reply Last reply
                                0
                                • sierdzioS Offline
                                  sierdzioS Offline
                                  sierdzio
                                  Moderators
                                  wrote on last edited by
                                  #16

                                  Qt5 will have QTemporaryDir - maybe you should look into that area? I think the code is already in the repository.

                                  (Z(:^

                                  1 Reply Last reply
                                  0
                                  • R Offline
                                    R Offline
                                    ruiluis
                                    wrote on last edited by
                                    #17

                                    Thanks.
                                    QTemporaryDir will create a directory that will be placed in the system temp path or the current work path.
                                    that is my current used/tested solution.

                                    1 Reply Last reply
                                    0
                                    • A Offline
                                      A Offline
                                      andre
                                      wrote on last edited by
                                      #18

                                      Well, as you only need a single file (or just a few files, right?), you can probably just use [[doc:QTemporaryFile]].

                                      1 Reply Last reply
                                      0
                                      • G Offline
                                        G Offline
                                        goetz
                                        wrote on last edited by
                                        #19

                                        [quote author="Andre" date="1323721023"]Well, as you only need a single file (or just a few files, right?), you can probably just use [[doc:QTemporaryFile]].[/quote]

                                        Unfortunately, QTemporaryFile has a valid path name only as long as it's open. As soon as you close it, the path name is reset/invalid. I had problems using that together with an external library that takes const char pointers for file paths too (GraphicsMagick in that case).

                                        http://www.catb.org/~esr/faqs/smart-questions.html

                                        1 Reply Last reply
                                        0

                                        • Login

                                        • Login or register to search.
                                        • First post
                                          Last post
                                        0
                                        • Categories
                                        • Recent
                                        • Tags
                                        • Popular
                                        • Users
                                        • Groups
                                        • Search
                                        • Get Qt Extensions
                                        • Unsolved