[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: How to suspend x86 via apm as non-root user?



-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On Tue, 24 Aug 2004, Ivo Marino wrote:

> Hello folks,
>
> Each time I try to suspend my x86 `sid` workstation as a non-root user
> via the command apm -s I receive this error message:
>
> 	apm: Operation not permitted
> Any suggestions on how to fix this?

Use sudo, combined with a script that runs apm -s.

> Maybe chmod +s /usr/bin/apm? Seems to be an eventual `workaround`.

No!

Okay, here's an example. On my laptop, I want to let ordinary users shut
the machine down. Of course, /sbin/shutdown is root only, as it should be
(ugh, setuid is bad).

In /etc/sudoers, I have:
User_Alias      USERS = {my user list}
Cmnd_Alias      SHUTDOWN = /usr/local/sbin/shutdown.sh
Cmnd_Alias      NTPDATE = /etc/init.d/ntpdate
USERS   ALL = NOPASSWD: SHUTDOWN, NTPDATE

That allows users to run shutdown.sh and ntpdate (but only from the init.d
script, not ntpdate by itself, which means that they can't change the
server that ntpdate uses).

shutdown.sh looks like this:
#! /bin/sh
#
# Meant to be used as a target for sudo to allow users to gracefully
# shutdown the laptop.

case "$1" in
  restart)
	/sbin/shutdown -r now
	;;
  shutdown)
	/sbin/shutdown -h now
	;;
  *)
	echo "Usage: shutdown.sh {restart|shutdown}" >&2
	exit 1
	;;
esac

exit 0

This prevents users from using any other modifiers to shutdown. You could
easily add a section like this to the script:
  suspend)
	apm -s
	;;
I don't bother because my laptop suspends automatically when it's closed,
so users don't need root access anyway :)

So in my other scripts (I have some that call Xdialog to confirm shutdown
or restart), I use sudo /usr/local/sbin/shutdown.sh shutdown or
sudo /usr/local/sbin/shutdown.sh restart to allow users to shutdown or
restart.

You could even setup aliases in /etc/skel/.bashrc & /etc/skel/.tcshrc for
these sudo calls, if you're too lazy to write a scripted frontend.
- -- 
GnuPG public key available from
http://ca.geocities.com/redvision.geo/gnupg_key.html
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.5 (GNU/Linux)

iD8DBQFBK2GkMqUhaD+LmFcRAgNrAJwPedgDjxib2+YhQZcLPJCw4MWckgCfW+Ey
WXuGxXZJtbSunv3UEkqWGBo=
=QHGy
-----END PGP SIGNATURE-----



Reply to: