0

I would like to write a Software and this Software have to save files in /usr/share/xy/. The Software would write and read this data with fprintf() and fscanf(). The owner of the directory /xy/ is root and the group too. Now i start the Software with sudo in the .desktop file.

Now my question is it possible to start them without an password. How big Software do this to save data in the background?

Thank you Bye Nick

d a i s y
  • 5,511

2 Answers2

2

Your program shouldn't use /usr/share/xy/ to save files by default. Instead it should use $XDG_DATA_HOME/xy (with $XDG_DATA_HOME as specified in XDG Base Directory Specification).

This avoids your permission problems and problems in multi-user environments.

1

The concept of writing to a root owned folder as a standard user is just a bad idea from a security point-of-view.

Applications should never write to /usr/share/xy.

Standard apps should write to a user folder - something like ~/.config/xy or ~/.cache/xy

Stackoverflow has a Q&A for finding the home-folder - you just need to strcat either .config or .cache, test if the sub-folder xy is there and if not create that folder before writing to the folder.

fossfreedom
  • 172,746