LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 07-01-2005, 06:23 AM   #1
•Vaan•
LQ Newbie
 
Registered: Jul 2005
Posts: 6

Rep: Reputation: 0
Reboot system


Hello, I need some help. how to reboot linux in C/C++ ?
i have try :

1. system ("shutdown -r"); ==> but my adm didn't give acces

2. reboot(0x123456) ==> use Linux/reboot.h, but it need Root acces


did any one can give me the solution
 
Old 07-01-2005, 06:30 AM   #2
keefaz
LQ Guru
 
Registered: Mar 2004
Distribution: Slackware
Posts: 6,552

Rep: Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872
the 2. should be reboot(0x1234567)

From the man 2 reboot page :
Quote:
Only the super-user may use this function.
It is as this, if you haven't the proper rights to do it,
you can't do it, the programming language has nothing to
do with that

[edit]
sorry I misread the man page,
the 2. should be : reboot(LINUX_REBOOT_CMD_RESTART);

Last edited by keefaz; 07-01-2005 at 06:39 AM.
 
Old 07-01-2005, 07:11 AM   #3
64bitprocessor
LQ Newbie
 
Registered: Jul 2005
Location: Bangalore
Distribution: Debian
Posts: 15

Rep: Reputation: 0
HI,
I don't think that you can reboot the machine with out proper privileges. Do not use the system() call in your code. It will create serious security problems.
 
Old 07-02-2005, 01:21 AM   #4
•Vaan•
LQ Newbie
 
Registered: Jul 2005
Posts: 6

Original Poster
Rep: Reputation: 0
Quote:
Originally posted by 64bitprocessor
HI,
I don't think that you can reboot the machine with out proper privileges. Do not use the system() call in your code. It will create serious security problems.
why it will create serious security ? i don't undestand.
is there any posible to reboot without root acces ??

Last edited by •Vaan•; 07-02-2005 at 01:27 AM.
 
Old 07-02-2005, 01:37 PM   #5
vladmihaisima
Member
 
Registered: Oct 2002
Location: Delft, Netherlands
Distribution: Gentoo
Posts: 196

Rep: Reputation: 33
For question 2:

Linux is a multi user environment. This means it should allow multiple users to use a machine without the possibility of one user to affect other users. (unless badly configured of course). I assume you wouldn't want someone to reboot you machine while you are reading this. . So unless you have root access you can't reboot it.

If you do have root access and want to reboot it as a normal user (perhaps because you are the only user of the machine), you can configure it in someway but I'm sure it depends on the distribution. For my distribution it works ro run reboot, but I don't remember if it's a configuration that I have made, or it is the default.
 
Old 07-03-2005, 10:06 AM   #6
thandermax
Member
 
Registered: Jun 2005
Distribution: OpenSUSE 10.3 , 11.2 , Solaris 10, Ubuntu 9.10
Posts: 84

Rep: Reputation: 16
When I restart programatically using an my GUI then it get started automatically next time when I start the pc . What to do with this ? I don't want my prog to start automatically next time .
 
Old 07-03-2005, 09:23 PM   #7
•Vaan•
LQ Newbie
 
Registered: Jul 2005
Posts: 6

Original Poster
Rep: Reputation: 0
actualy i want to make auto timer shutdown for linux, but i didn't have root acces. The target just local mechine.
is there any way to do it ?
 
Old 07-03-2005, 10:02 PM   #8
perfect_circle
Senior Member
 
Registered: Oct 2004
Location: Athens, Greece
Distribution: Slackware, arch
Posts: 1,783

Rep: Reputation: 53
Unless root gives you permission to reboot, lets say by adding something like this:
Code:
<your username>  localhost=NOPASSWD:/sbin/shutdown -r now
in the /etc/sudoers file, you cannot reboot the machine.
 
Old 07-03-2005, 10:03 PM   #9
freegianghu
Member
 
Registered: Oct 2004
Location: somewhere in the street
Distribution: Window$
Posts: 192

Rep: Reputation: 30
Quote:
Originally posted by •Vaan•
actualy i want to make auto timer shutdown for linux, but i didn't have root acces. The target just local mechine.
is there any way to do it ?
Running a cron service with root permission
 
Old 07-03-2005, 11:55 PM   #10
64bitprocessor
LQ Newbie
 
Registered: Jul 2005
Location: Bangalore
Distribution: Debian
Posts: 15

Rep: Reputation: 0
HI all,
Create a C code with reboot(0x123456) to reboot the machine. Compile the program. Make the owner of the program as root and give suid permission to it. Now using this executable an ordinary user can reboot the machine.
 
Old 07-04-2005, 05:47 AM   #11
•Vaan•
LQ Newbie
 
Registered: Jul 2005
Posts: 6

Original Poster
Rep: Reputation: 0
is there any X Windows library or QT library to do it ?
so i can use it, becuse so far i have try in c, and newbie in QT.
 
Old 07-04-2005, 06:27 AM   #12
64bitprocessor
LQ Newbie
 
Registered: Jul 2005
Location: Bangalore
Distribution: Debian
Posts: 15

Rep: Reputation: 0
Hi,
All the libraries are using the int reboot(int magic, int magic2, int flag, void *arg) system call for rebooting the system. See man 2 reboot for more details. This system call needs super user permission. Normally in Linux systems users are not allowed to reboot or turn off the systems because it is a multi-user system. So I don't think that there will be any other functions to reboot the machine with out privileged permission.
You can use the ordinary reboot(int) in Qt. There is no problem in that. But do not make large GUI programs SUID. It will create serious problems. SUID programs are so dangerous.

Last edited by 64bitprocessor; 07-04-2005 at 06:37 AM.
 
Old 07-04-2005, 11:50 PM   #13
•Vaan•
LQ Newbie
 
Registered: Jul 2005
Posts: 6

Original Poster
Rep: Reputation: 0
How about using asm to shut down the mechine ?
can it be shut down normaly or it can be make serious problem ?
 
Old 07-05-2005, 12:03 AM   #14
64bitprocessor
LQ Newbie
 
Registered: Jul 2005
Location: Bangalore
Distribution: Debian
Posts: 15

Rep: Reputation: 0
You can use ASM, C, C++ anything you want. But the user issuing the reboot command should be privileged. To understand the "serious problems” with system() call and SUID programs I have a sample code for you. Just try this.

main()
{
system("/bin/bash");
}


Compile this code as root. Change the permission of the executable to 711. Make the executable SUID and copy it to /bin.
Now login as an ordinary user and execute this program. You will get a shell with root's privilages!

Last edited by 64bitprocessor; 07-05-2005 at 12:18 AM.
 
Old 07-05-2005, 12:32 AM   #15
•Vaan•
LQ Newbie
 
Registered: Jul 2005
Posts: 6

Original Poster
Rep: Reputation: 0
thx, i have try it and it work so far in my mechine, because i did it by root acces.
but the problem if i haven't root acces to did it.
I haven't idea to reboot it with my less acces.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Why does my system reboot every time i try.... Hdstdlxe Linux - Newbie 9 10-22-2005 04:31 AM
system will not reboot php4u Fedora 1 09-06-2005 07:49 AM
System doesn't reboot mlalkm Fedora 5 01-05-2005 06:28 PM
system will not reboot mhr Linux - General 3 10-27-2004 12:23 PM
Can't reboot system nistelrooy Mandriva 4 10-11-2003 06:07 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 11:01 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration