LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
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 12-22-2017, 05:25 AM   #1
Nitinkumar Ambekar
LQ Newbie
 
Registered: Jul 2017
Posts: 1

Rep: Reputation: Disabled
Question How to implement unlock button to authenticate and get root privileges?


I want to implement an unlock button in a GUI application, when clicked, it will ask for root password and then the application will have root privileges . These type of button is provided in Ubuntu's "Users" dialog box in settings.

For now, I use "pkexec" to authenticate root when user starts the application, I am looking similar solution for providing root privileges to already running application.

Thanks in advance!
 
Old 12-22-2017, 09:49 AM   #2
rtmistler
Moderator
 
Registered: Mar 2011
Location: Sutton, MA. USA
Distribution: MINT Debian, Angstrom, SUSE, Ubuntu
Posts: 6,147
Blog Entries: 12

Rep: Reputation: 2103Reputation: 2103Reputation: 2103Reputation: 2103Reputation: 2103Reputation: 2103Reputation: 2103Reputation: 2103Reputation: 2103Reputation: 2103Reputation: 2103
What GUI development tools are you using for your application? Is it a GUI application?

Can you implement "a button" now? As in a button to cause a result? If not that's a first step to learn about.

Or is your problem "what to do" with the GUI button to allow root privs?
 
Old 12-22-2017, 11:21 AM   #3
keefaz
LQ Guru
 
Registered: Mar 2004
Distribution: Slackware
Posts: 5,640

Rep: Reputation: 498Reputation: 498Reputation: 498Reputation: 498Reputation: 498
Quote:
Originally Posted by Nitinkumar Ambekar View Post
These type of button is provided in Ubuntu's "Users" dialog box in settings.
Check in source code for Ubuntu Users dialog box then!
 
Old 12-22-2017, 11:48 AM   #4
hazel
Senior Member
 
Registered: Mar 2016
Location: Harrow, UK
Distribution: Debian, Crux, LFS, AntiX, NuTyX
Posts: 1,585
Blog Entries: 3

Rep: Reputation: 681Reputation: 681Reputation: 681Reputation: 681Reputation: 681Reputation: 681
I don't know if that is possible. A process already has an owner when it is launched; that user can't be changed. The only solution that I could see would be for the program to fork, and the child to execute sudo with the program as the argument and the user's password, while the parent exited.
 
Old 12-22-2017, 11:58 AM   #5
pan64
LQ Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 10,079

Rep: Reputation: 2981Reputation: 2981Reputation: 2981Reputation: 2981Reputation: 2981Reputation: 2981Reputation: 2981Reputation: 2981Reputation: 2981Reputation: 2981Reputation: 2981
The other solution is to use setuid apps, like su or sudo, which will start as root, but will not allow anything without password (or proper configuration) - and force setuid back to user in case of missing/incorrect authentication.
But I don't know if it was really a good idea for a graphical application.

also you can try to restart app with root privileges - if password was provided.

Last edited by pan64; 12-22-2017 at 12:00 PM.
 
Old 12-22-2017, 12:27 PM   #6
dugan
LQ Guru
 
Registered: Nov 2003
Location: Canada
Distribution: Slackware
Posts: 7,790

Rep: Reputation: 3036Reputation: 3036Reputation: 3036Reputation: 3036Reputation: 3036Reputation: 3036Reputation: 3036Reputation: 3036Reputation: 3036Reputation: 3036Reputation: 3036
Quote:
Originally Posted by Nitinkumar Ambekar View Post
I am looking similar solution for providing root privileges to already running application.
Can't do that.
 
Old 12-22-2017, 12:36 PM   #7
keefaz
LQ Guru
 
Registered: Mar 2004
Distribution: Slackware
Posts: 5,640

Rep: Reputation: 498Reputation: 498Reputation: 498Reputation: 498Reputation: 498
Other solution involves using a running authoritative service like polkit
https://www.freedesktop.org/software.../polkit.8.html
 
3 members found this post helpful.
Old 12-22-2017, 03:00 PM   #8
rtmistler
Moderator
 
Registered: Mar 2011
Location: Sutton, MA. USA
Distribution: MINT Debian, Angstrom, SUSE, Ubuntu
Posts: 6,147
Blog Entries: 12

Rep: Reputation: 2103Reputation: 2103Reputation: 2103Reputation: 2103Reputation: 2103Reputation: 2103Reputation: 2103Reputation: 2103Reputation: 2103Reputation: 2103Reputation: 2103
What hazel is talking about is what I've done. I have had either a script or application running and called or forked a child but used sudo in the argument list. Further, I've set it up so that sudo would not require a password for the user and command that was being used in the script. However this still goes back to whether or not you have the background and existing environment to develop a GUI with buttons and events or actions invoked from those buttons.
 
Old 12-26-2017, 07:41 PM   #9
goingbackwards
LQ Newbie
 
Registered: Jul 2015
Posts: 15

Rep: Reputation: Disabled
Thanks, a topic I've wondered about too.

Some Best Practice notes:
https://www.freedesktop.org/software...lkit-apps.html

An example project:
https://github.com/herzi/polkit-dbus-example
 
1 members found this post helpful.
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Unlock another user by non-root account CookieMan1337 Linux - Security 2 11-22-2017 10:32 AM
Configure the Directory server in a way to authenticate and unlock a user account arunplanet Linux - Newbie 7 10-04-2012 07:54 AM
How to unlock root nandu neerukonda Linux - Newbie 6 11-12-2011 06:18 AM
can I unlock the root account? newbiesforever Ubuntu 24 09-28-2009 01:27 PM
unlock a root folder? Twister512 Slackware 1 01-11-2009 06:15 PM

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

All times are GMT -5. The time now is 07:02 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration