Skip to content

Instantly share code, notes, and snippets.

@ivan

ivan/polkit.nix Secret

Created January 7, 2019 08:50
Show Gist options
  • Save ivan/d2dab6df26a67bf6d8b0938065ed6e8e to your computer and use it in GitHub Desktop.
Save ivan/d2dab6df26a67bf6d8b0938065ed6e8e to your computer and use it in GitHub Desktop.
# Prevent non-root users from restarting or shutting down the system using the GUI.
# This is mostly to prevent accidental restarts; the "Log Out" and "Restart" buttons
# are right next to each other and "Restart" does not require confirmation.
#
# http://askubuntu.com/questions/453479/how-to-disable-shutdown-reboot-from-lightdm-in-14-04/454230#454230
# no longer works because pklocalauthority was removed.
#
# https://www.centos.org/forums/viewtopic.php?t=50936 works, but it does not disable
# the buttons in xfce 4.13; it just causes the session to crash when you click them:
#
# kernel: traps: xfsm-shutdown-h[23684] general protection ip:75b0741f2311 sp:7fff0e2a0e50 error:0 in libc-2.27.so[75b074171000+1aa000]
# xfconfd[22895]: Name org.xfce.Xfconf lost on the message dbus, exiting.
# xfce4-notifyd[23087]: xfce4-notifyd: Fatal IO error 11 (Resource temporarily unavailable) on X server :0.
environment.etc."polkit-1/rules.d/00-stop-reboot.rules".text = ''
polkit.addRule(function(action, subject) {
if (action.id.indexOf("org.freedesktop.login1.hibernate") == 0) {
return polkit.Result.AUTH_ADMIN;
}
});
polkit.addRule(function(action, subject) {
if (action.id.indexOf("org.freedesktop.login1.power-off") == 0) {
return polkit.Result.AUTH_ADMIN;
}
});
polkit.addRule(function(action, subject) {
if (action.id.indexOf("org.freedesktop.login1.reboot") == 0) {
return polkit.Result.AUTH_ADMIN;
}
});
polkit.addRule(function(action, subject) {
if (action.id.indexOf("org.freedesktop.login1.suspend") == 0) {
return polkit.Result.AUTH_ADMIN;
}
});
'';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment