I would like to know any solutions people came up with restricting a user from changing a system wide configuration of xscreensaver. Part of my job is managing systems which have a requirement that the desktop locks in about 10 minutes and can only be unlocked with a password. I want to use one screensaver and considering xscreensaver is very secure with a mature code base it is a logical choice.
I created appropriate settings in /etc/X11/app-defaults/XScreenSaver*, however the problem is a user can still change their personal preferences by running xscreensaver-demo or editing ~/.xscreensaver.
I understand there is a bit of a hackish way to do this, removing the executable permissions from /usr/bin/xscreensaver-demo and changing the ownership of ~/.xscreensaver to root.
If that is the only practical way of doing this, how would I go about creating ~/.xscreensaver with root ownership upon initial login of the user (in redhat and debian/ubuntu)?
If your users' home directories are on a local disk, or they are hosted on a Linux NFS server which you have sudo/root privileges on, then you can set each ~/.xscreensaver file as "immutable".
This will prevent users from modifying it, and from deleting/moving/renaming it.
Reference: http://sattia.blogspot.com/2015/01/how-to-make-file-immutable-on-linux.html
It looks like this is not really possible. I did end up slightly modifying the source of xscreensaver in order to force certain settings. I tried to use the least invasive way of accomplishing this with minimal modification of the source. This will still allow the user to configure many parts of the screensaver, just not the ones regarding screenlocking and the timeout.
In the source tree find the file driver/prefs.c and in there look for the function write_init_file. In that function find these lines:
And change to something like the below source sample. What this will do is prevent these settings from being saved to the .xscreensaver file in the user's home directory. And then as long as the system wide default is set to whatever you prefer xscreensaver will keep using these settings in lieu of what would be configured in the .xscreensaver file.
The find the function called load_init_file and change the line:
to:
Now find the aptly named function stop_the_insanity which sets some values of preferences back to sane values, such as a timeout > 15 seconds will be forced to 15 seconds. This is a good spot to make sure that when a user hand edits the .xscreensaver file instead of using xscreensaver-demo the values will not be used by xscreensaver, but our "sane" values will be used instead.
In function stop_the_insanity add something like this, using your own values if you want. Note that values for time are seconds*1000. In the case user sets mode to "off" we already force it back to blank above.
With regards to creating .xscreensaver with root ownership upon initial login, I think that is not really possible or advisable. You can create a script in /etc/profile.d which will create an empty .xscreensaver upon user login. But the above mentioned change makes that unnecessary.