Page 1 of 2 12 LastLast
Results 1 to 10 of 11

Thread: Repost Non-root Shutdown Code

  1. #1
    Senior Member
    Join Date
    May 2001
    Posts
    411

    Repost Non-root Shutdown Code

    Can someone repost the code for enabling non-root users to shutdown or reboot without becoming su? The thread seems to have been dropped because it was created back in July. Thanks.

  2. #2
    Moderator
    Good Guru
    Schotty's Avatar
    Join Date
    Jul 2001
    Location
    Milwaukee, WI
    Posts
    5,760

    Re: Repost Non-root Shutdown Code

    Isnt it just changing the permissions on init or whatever reboot or shutdown symlink to? I am not on my linux box now (or near one -- at a remote location for work), but thats where I would start. I know RedHat 7.2 has the reboot and shutdown commands, which stock are set to be accessable to everyone. I changed them, but dont remember how at this moment (hangover, early for me.....)

  3. #3

    Re: Repost Non-root Shutdown Code

    hmm you can power down with ctrl-alt-del if this is in /etc/inittab

    Code:
    ca::ctrlaltdel:/sbin/shutdown -a -t5 -rf now
    the -a switch looks if the user who performs ctrl-alt-del has an entry in /etc/shutdown.allow if the name is there he is able to shutdown the system ..

    its not the best solution but just something i found in the man pages ..

  4. #4

    Re: Repost Non-root Shutdown Code

    I'm sure this is a terribly way of doing it, but couldn't you just set the "halt" program (or whatever you use to shut down) as setuid? It's probably not the greatest idea because instead of having users be able to shut down, you'd end up giving (slightly restricted) root access to users who want to shut down...

  5. #5
    Moderator
    Advisor
    redhead's Avatar
    Join Date
    Jun 2001
    Location
    Copenhagen, Denmark
    Posts
    811

    Re: Repost Non-root Shutdown Code

    hmm On RH 7.0 it worked, if you created a file /etc/sysconfig/console/shutdown whcih contained a list of users able to shutdown ie:
    USER=root,user1,user2....

    But dont know if it will work on any other dist.

  6. #6
    Senior Member
    Join Date
    May 2001
    Posts
    411

    Re: Repost Non-root Shutdown Code

    I found a copy that I had saved before:

    #include <unistd.h>
    main() {
    setuid(0);
    execl("/sbin/halt", "halt", 0);
    }

    You have to compile this code like so (assuming the file is called shutdown.c):

    gcc -o shutdown shutdown.c

    then

    chown root shutdown; chmod u+x shutdown

    then

    move it to non-root's path (e.g., /usr/local/bin).

  7. #7
    Moderator
    Advisor
    redhead's Avatar
    Join Date
    Jun 2001
    Location
    Copenhagen, Denmark
    Posts
    811

    Re: Repost Non-root Shutdown Code


    I found a copy that I had saved before:

    #include <unistd.h>
    main() {
    setuid(0);
    execl("/sbin/halt", "halt", 0);
    }

    You have to compile this code like so (assuming the file is called shutdown.c):

    gcc -o shutdown shutdown.c

    then

    chown root shutdown; chmod u+x shutdown

    then

    move it to non-root's path (e.g., /usr/local/bin).
    You would still need to set the SUID bit on that program, It would be the same as Festaa suggested, to SUID halt or shutdown itself.

  8. #8
    Senior Member
    Join Date
    May 2001
    Posts
    411

    Re: Repost Non-root Shutdown Code




    You would still need to set the SUID bit on that program, It would be the same as Festaa suggested, to SUID halt or shutdown itself.
    I'm no expert in C programming, but I believe the line

    setuid(0)

    takes care of that worry.

  9. #9
    Moderator
    Advisor
    redhead's Avatar
    Join Date
    Jun 2001
    Location
    Copenhagen, Denmark
    Posts
    811

    Re: Repost Non-root Shutdown Code

    ahhh I was reading it as chuid(0);... my bad..

  10. #10
    Guest

    Re: Repost Non-root Shutdown Code

    You could also use sudo to prevent unauthorized users from shutting down your box.

Similar Threads

  1. XP won't shutdown
    By Waka-Gashira in forum Windows - General Topics
    Replies: 8
    Last Post: 02-04-2005, 04:45 PM
  2. Shutdown Linux
    By ripleyscat in forum Linux - General Topics
    Replies: 23
    Last Post: 02-02-2005, 01:12 PM
  3. what files shutdown RH
    By Blaqb0x in forum Linux - General Topics
    Replies: 1
    Last Post: 03-11-2003, 08:12 PM
  4. Linux shutdown.
    By jmajor2000 in forum Linux - Hardware, Networking & Security
    Replies: 6
    Last Post: 09-26-2002, 11:42 AM
  5. Unusual problem at shutdown
    By papanohair in forum Linux - General Topics
    Replies: 2
    Last Post: 03-13-2002, 09:30 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •