Where to store system wide settings?

Started by
9 comments, last by Bregma 14 years, 5 months ago
I'd like my application to have two kinds of settings: settings per user, and system wide settings. The settings per user, I store in "~/.config/appname/settings.xml". For the system-wide settings, I need a folder where any user can read and write to, and that exists in all normal linux distributions. I thought it'd be /etc/, but it turns out that (at least on ubuntu), /etc/ isn't writable to by non-root users! I need a dir where ANYONE can write. I need something that has the same functionality as the folder "CSIDL_COMMON_APPDATA" has in Windows. Does there exist any such folder in typical linux distro's that is destined for that? Or is it impossible to share settings between multiple users in linux without ever having root access?
Advertisement
Not impossible, but nontraditional.

I suppose you could make a sub-directory in your program's /etc, say /etc/myprogram/userconfig. Make that directory world readable/writable/executable and set the sticky bit so that it's like /tmp, to keep users from messing with each others files.

Personally (not knowing more about what you're trying to achieve), I'd probably just leave the per-user configuration in the users' home directories. Most users have world readable/executable home directories, so scanning these directories from your program executed by any user shouldn't be too hard.
Hmm actually I just made a class called "Persist" which stores named settings in an xml file, with a Win32 and a Linux implementation, and I gave it a flag "global" for system-wide settings. I thought the difference between system-wide and user settings was so common that in unix systems too there'd be a dedicated directory for that. But there isn't so I can't really use the "global" flag and better remove it from the interface of my Persist class since it's not multiplatform.
Quote:Original post by Lode
I thought the difference between system-wide and user settings was so common that in unix systems too there'd be a dedicated directory for that.
There are few settings in Linux that are be *both* system-wide and user-local by default. Those that are both have often been artificially created - look at your .bash_profile: it only inherits system-wide definitions if it manually loads the system-wide .bashrc.

In addition, unix in general takes the position that no unpriviledged user should ever be able to change the system-wide settings. You are free to support system-wide settings, but they can only be set by the super-user/sudoers.

Tristam MacDonald. Ex-BigTech Software Engineer. Future farmer. [https://trist.am]

Uhm, had a look at http://doc.trolltech.com/4.5/qsettings.html#setPath
And it says /etc/xdg. And yes, I have write access to this. Didn't know it before. Good to know.

Since it's Qt's saying it is probably true?!

regards
Quote:Original post by hydroo
Uhm, had a look at http://doc.trolltech.com/4.5/qsettings.html#setPath
And it says /etc/xdg. And yes, I have write access to this. Didn't know it before. Good to know.

Since it's Qt's saying it is probably true?!

regards

Keep in mind this is only defined by freedesktop.org's Base Directory Specification. Presumably you'd need a compliant X desktop installed first. For example, my headless Debian machine doesn't have a /etc/xdg.
@mattd: That's because XDG is part of the free desktop specifications. Your headless machine is not a desktop machine :-) If you install Gnome, KDE or any other XDG compliant desktop environment (I think LXDE does it as well) then /etc/xdg should be created.

@Lode: The proper solution is that a normal user should not be able to change system-wide settings. Take for example the network settings or printer settings under Gnome or KDE. A normal user can see them but not change them. They first have to click "Unlock" which makes them root. And root can change the settings. That's what you should add to your application as well.

<hr />
Sander Marechal<small>[Lone Wolves][Hearts for GNOME][E-mail][Forum FAQ]</small>

thanks for the input. But, nevertheless this might be what Lode could use.
Quote:Original post by Sander
@mattd: That's because XDG is part of the free desktop specifications. Your headless machine is not a desktop machine :-) If you install Gnome, KDE or any other XDG compliant desktop environment (I think LXDE does it as well) then /etc/xdg should be created.

Yeah, I'm aware :) I'm just saying that relying on that directory existing wouldn't be good for users in my situation.
Normal practice for doing this is to have a master config file, generally under /etc, that's not updated by users, and local config files under the user's home directory that override it. For a commercial game that does this, look at UT2004. Really if it's a system wide setting only the admin should be touching it. For a game especially though, it should be possible to install entirely under the ~/ directory for that user and never touch the system itself.

If you still want to though, I guess if you really wanted to share a system wide setting, editable by users, I'd create a folder under /usr/local/share and either create a group for it or give permissions to it to the users group. Highly frowned upon and not a good idea, but still very do-able.

About xdg also, it's locked down on many distro's to not be writable by users due to security concerns

This topic is closed to new replies.

Advertisement