You are not logged in.

#1 2013-03-30 12:40:37

The.Jackal
Member
Registered: 2013-03-30
Posts: 5

Write a desktop application that has sudo privlages?

Hi,
I'm writing a GUI frontend to Netcfg in C++ and am nearing 1.0 version. The problem is that since netcfg needs root privlages, right now it's nessesery to run it using sudo. I'd like the user to be able to run it without sudo, for example in startup scripts. I know it's possible, networkmanger wicd archassistant and every other program of simular nature does it. Can someone point me in the right direction? I searched in google but did not find a good solution.

Offline

#2 2013-03-30 12:46:11

parazyd
Member
From: Amsterdam
Registered: 2012-10-14
Posts: 259
Website

Re: Write a desktop application that has sudo privlages?

The sudoers file can be edited to allow specific applications run without asking for a password.

Offline

#3 2013-03-30 12:48:34

The.Jackal
Member
Registered: 2013-03-30
Posts: 5

Re: Write a desktop application that has sudo privlages?

Yea I know, but how come all other programs do this automaticly? I don't want to ask users to start editing files.

Offline

#4 2013-03-30 12:50:16

parazyd
Member
From: Amsterdam
Registered: 2012-10-14
Posts: 259
Website

Re: Write a desktop application that has sudo privlages?

Which ones do escalate privileges by themselves?

Offline

#5 2013-03-30 12:53:39

The.Jackal
Member
Registered: 2013-03-30
Posts: 5

Re: Write a desktop application that has sudo privlages?

wicd and networkmanager for example start without asking the user for the password. They somehow remember it.

Offline

#6 2013-03-30 12:56:27

Xyne
Administrator/PM
Registered: 2008-08-03
Posts: 6,963
Website

Re: Write a desktop application that has sudo privlages?

If the frontend is a binary executable (as it must be in this case if you are writing it in C++) then you can use the setuid flag:
https://en.wikipedia.org/wiki/Setuid
http://www.techrepublic.com/blog/securi … urity/2857

For reference, if it is a script (Bash, Python, Lua, etc.) then setuid will not work because it is not the script but rather the interpreter that is executed.

This may also be of interest:
https://wiki.archlinux.org/index.php/Us … _Of_Setuid



Incidentally, I believe that netcfg will soon be replaced by netctl so you may wish to redirect your efforts now to avoid wasting them.


My Arch Linux StuffForum EtiquetteCommunity Ethos - Arch is not for everyone

Offline

#7 2013-03-30 12:56:30

parazyd
Member
From: Amsterdam
Registered: 2012-10-14
Posts: 259
Website

Re: Write a desktop application that has sudo privlages?

They're both open-source tools, why don't you check the source code.

Sorry, but, applications can't "remember" your passwords unless you type them in.

Offline

#8 2013-03-30 12:59:00

The.Jackal
Member
Registered: 2013-03-30
Posts: 5

Re: Write a desktop application that has sudo privlages?

Xyne wrote:

If the frontend is a binary executable (as it must be in this case if you are writing it in C++) then you can use the setuid flag:
https://en.wikipedia.org/wiki/Setuid
http://www.techrepublic.com/blog/securi … urity/2857

For reference, if it is a script (Bash, Python, Lua, etc.) then setuid will not work because it is not the script but rather the interpreter that is executed.

This may also be of interest:
https://wiki.archlinux.org/index.php/Us … _Of_Setuid



Incidentally, I believe that netcfg will soon be replaced by netctl so you may wish to redirect your efforts now to avoid wasting them.

Xyne that is most helpfull, thank you. And don't worry, I'm mainly doing it to learn C++ and Gtkmm. Worst case scenerio I change the system calls to netcfg and convery my project (-:

Offline

#9 2013-03-30 13:01:26

progandy
Member
Registered: 2012-05-17
Posts: 5,184

Re: Write a desktop application that has sudo privlages?

networkmanager uses a client application that communicates via dbus (using polkit permissions) with a system service.


| alias CUTF='LANG=en_XX.UTF-8@POSIX ' |

Offline

#10 2013-03-30 16:36:21

ewaller
Administrator
From: Pasadena, CA
Registered: 2009-07-13
Posts: 19,744

Re: Write a desktop application that has sudo privlages?

The.Jackal wrote:

[...And don't worry, I'm mainly doing it to learn C++ and Gtkmm. .

Having been bitten (twice) by this, I want to emphasize to anyone reads this, that the setuid *WILL NOT* work with scripts -- by design.

Last edited by ewaller (2013-03-30 16:36:40)


Nothing is too wonderful to be true, if it be consistent with the laws of nature -- Michael Faraday
Sometimes it is the people no one can imagine anything of who do the things no one can imagine. -- Alan Turing
---
How to Ask Questions the Smart Way

Online

Board footer

Powered by FluxBB