How can we set restriction to .ini file?



  • I did not want that general user can edit the contents of ini file



  • -You must make your key a subkey.-

    EDIT
    Sorry, I completely misread your post. Must have been caused by too less coffee at that time ;-)


  • Moderators

    [quote author="pratik041" date="1322917622"]I did not want that general user can edit the contents of ini file [/quote]

    You could use QFile::setPermissions and set the file attribute to read only. But that would require admin rights. If your user has admin rights, he will be able to change the settings anyhow. So it idoes not make sense. In windows, you may write to the registry, which is less likely to be modified by an unexperienced user.



  • [quote author="koahnig" date="1322933279"][quote author="pratik041" date="1322917622"]I did not want that general user can edit the contents of ini file [/quote]

    You could use QFile::setPermissions and set the file attribute to read only. But that would require admin rights. If your user has admin rights, he will be able to change the settings anyhow. So it idoes not make sense. In windows, you may write to the registry, which is less likely to be modified by an unexperienced user.

    [/quote]

    setPermissions will work only during run time. So when the program is not running does that permissions will persist.



  • There is simply no solution.
    The configuration file is a plain text file so it can be edited, modified, moved, deleted, and so on, and the only one that can avoid it is the operating system. If you are running on Unix one (including Apple) you can set an immutable flag to the file, so that nobody except the administrator will be able to alter the file. Something similar can be achieved on linux, but I don't know about windows. However this is not a recommended setup for your application (since you have to do on each installation). It would be better to avoid using a config file and use a binary one (that cannot be easily edited) or an encrypted one.



  • Well you can use simple encryption :)
    Once i use encrypted keys and encrypted fields.;)



  • Please note that you could be using the wrong tool for the wrong purpose. Configuration files are what they mean: configurations! You should store there widget layouts, preferences, and other stuff that is not critical for proper application work. Stuff that is critical, such as database password and/or stuff like that should be stored in a private way.



  • [quote author="fluca1978" date="1323071673"]There is simply no solution.
    The configuration file is a plain text file so it can be edited, modified, moved, deleted, and so on, and the only one that can avoid it is the operating system. If you are running on Unix one (including Apple) you can set an immutable flag to the file, so that nobody except the administrator will be able to alter the file. Something similar can be achieved on linux, but I don't know about windows. However this is not a recommended setup for your application (since you have to do on each installation). It would be better to avoid using a config file and use a binary one (that cannot be easily edited) or an encrypted one. [/quote]

    For binary file creation which class i should use and how i can read its contents




  • Moderators

    [quote author="pratik041" date="1323059347"]
    setPermissions will work only during run time. So when the program is not running does that permissions will persist.
    [/quote]

    There is a static version of setPermissions. So I assume it simply change the file attributes and they should be persistent. However, I have not tried. Nevertheless, in my opinion I would not do it. It is a bit of hazzle. You need to change prior to access and also before program stops.
    I agree with fluca1978 QSettings is not really meant for your purpose.

    Is it secrecy or you just do not want the user to mess around?
    For the latter case you may simply use non-descriptive key names and the values may be output as a string contaning hex values. Nevertheless, I would prefer to use a completely separate file then.



  • [quote author="koahnig" date="1323078084"]
    [quote author="pratik041" date="1323059347"]
    setPermissions will work only during run time. So when the program is not running does that permissions will persist.
    [/quote]

    There is a static version of setPermissions. So I assume it simply change the file attributes and they should be persistent. However, I have not tried. Nevertheless, in my opinion I would not do it. It is a bit of hazzle. You need to change prior to access and also before program stops.
    I agree with fluca1978 QSettings is not really meant for your purpose.

    Is it secrecy or you just do not want the user to mess around?
    For the latter case you may simply use non-descriptive key names and the values may be output as a string contaning hex values. Nevertheless, I would prefer to use a completely separate file then. [/quote]
    can you say what is the static version of set permission?



  • Sorry, this becomes to be a bit annoying. You are able to type "setPermission" into Qt Assistant or any other Qt help browser yourself, aren't you? For the time beeing: http://doc.qt.nokia.com/4.7/qfile.html#setPermissions-2

    Do you intend to write to that file from your application or is it created at build time and should be delivered read-only to your users?



  • [quote author="Volker" date="1323089335"]Sorry, this becomes to be a bit annoying. You are able to type "setPermission" into Qt Assistant or any other Qt help browser yourself, aren't you? For the time beeing: http://doc.qt.nokia.com/4.7/qfile.html#setPermissions-2

    Do you intend to write to that file from your application or is it created at build time and should be delivered read-only to your users?

    [/quote]
    It will be delivered read-only to users



  • In that case I would go with a [[Doc:QResource]]. Either compiled into the binary the usual way or loading/unloading it with registerResource/unregisterResource.

    If you really want that ini-File, make your installer change the properties of the file to read-only.



  • [quote author="Volker" date="1323092949"]In that case I would go with a [[Doc:QResource]]. Either compiled into the binary the usual way or loading/unloading it with registerResource/unregisterResource.

    If you really want that ini-File, make your installer change the properties of the file to read-only.[/quote]
    can we store general text information using QResource and it can be compiled into binary.Can you give some example of that?



  • [quote author="pratik041" date="1323146684"]

    can we store general text information using QResource and it can be compiled into binary.Can you give some example of that?
    [/quote]

    Just put the text file into the resource system as you would do for an icon. Then from the application access the file (e.g., using QFile) using the resource path. It does not change your code having the file in the resource system instead of the filesystem, it only changes the path you use to access it.



  • [quote author="fluca1978" date="1323154095"]
    [quote author="pratik041" date="1323146684"]

    can we store general text information using QResource and it can be compiled into binary.Can you give some example of that?
    [/quote]

    Just put the text file into the resource system as you would do for an icon. Then from the application access the file (e.g., using QFile) using the resource path. It does not change your code having the file in the resource system instead of the filesystem, it only changes the path you use to access it.

    [/quote]

    Thank you



  • [quote author="pratik041" date="1323146684"]
    can we store general text information using QResource and it can be compiled into binary.Can you give some example of that?
    [/quote]

    Qt resources are just a storage container for regular files. You can put into that whatever you want. For examples, see the documentation.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.