disable shutdown/suspend if there is other user logged in via ssh

I remember that in versions of ubuntu around 9.04 was possible to disable user to shutdown ( and maybe suspend too ) system if there was other user logged in.Something like policykit or similar.

Is it possible to do in 11.04 ?

Thanks

edit:

if someone needs ( for own risk ), little change in /usr/lib/pm-utils/bin/pm-action will allow user to suspend machine if he is only user logged in or when user will run sudo pm-suspend. Probably not best piece of code, but for now works.

diff -r 805887c5c0f6 pm-action
--- a/pm-action Wed Jun 29 23:32:01 2011 +0200
+++ b/pm-action Wed Jun 29 23:37:23 2011 +0200
@@ -47,6 +47,14 @@
    exit 1
 fi

+if [ "$(id -u )" == 0 -o `w -h | cut -f 1 -d " " | sort | uniq | wc -l` -eq 1 ]; then
+                echo "either youre root or root isnt here and youre only user, continuing" 1>&2
+                else
+                echo "Not suspending, root is here or there is more users" 1>&2
+                exit 2
+                fi
+
+
 remove_suspend_lock()
 {
    release_lock "${STASHNAME}.lock"

Question still stands, is it possible to forbid shutdown or suspend when there is more than one user logged in ( without rewriting pm-suspend or halt ( or other hack ) )?


Solution 1:

Update (thanks to enzotib):

The files I listed in the original answer should not be edited, as a package update can overwrite your changes.

PolicyKit should instead be configured using configuration files placed in /var/lib/polkit-1/localauthority/, as detailed in the pklocalauthority manual page.

Original answer:

With the deprecation of HAL, this is now controlled in /usr/share/polkit-1/actions/org.freedesktop.consolekit.policy

Set allow_active in the two action sections shown below to no (they are set to auth_admin_keep by default):

  <action id="org.freedesktop.consolekit.system.stop-multiple-users">
    <description>Stop the system when multiple users are logged in</description>
    <message>System policy prevents stopping the system when other users are logged in</message>
    <defaults>
      <allow_inactive>no</allow_inactive>
      <allow_active>no</allow_active>
    </defaults>
  </action>

...

  <action id="org.freedesktop.consolekit.system.restart-multiple-users">
    <description>Restart the system when multiple users are logged in</description>
    <message>System policy prevents restarting the system when other users are logged in</message>
    <defaults>
      <allow_inactive>no</allow_inactive>
      <allow_active>no</allow_active>
    </defaults>
  </action>