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 08-25-2011, 07:49 PM   #1
BrianK
Senior Member
 
Registered: Mar 2002
Location: Los Angeles, CA
Distribution: Debian, Ubuntu
Posts: 1,334

Rep: Reputation: 51
Python: rather than permission denied, can you get an OS specific password challenge?


In my python script, I need to copy files from one place to another. I know that the majority of the time, the destination will require the user to sudo or be the owner of the destination dir. Rather than get a simple "permission denied" message, is there a way to get a password challenge dialog to display (assuming running X or OSX, etc) so that the user can sudo/elevate so the file(s) can be copied w/o changing permissions on the dest?
 
Old 08-28-2011, 03:48 PM   #2
ta0kira
Senior Member
 
Registered: Sep 2004
Distribution: FreeBSD 9.1, Kubuntu 12.10
Posts: 3,078

Rep: Reputation: Disabled
First off, I have to tell you I don't know python; however, you might be able to translate this from bash to python because I think the general concept applies:
Code:
source=( 'some' 'list' 'of' 'files' )
dest='/home/you/some-dir'

[ -d "$dest" ] || exit 1

if [ ! -w "$dest" ]; then
  sudo -u "$( stat -c%U "$dest" )" cp -v "${source[@]}" -t "$dest"
else
  cp -v "${source[@]}" -t "$dest"
fi
Kevin Barry
 
Old 08-29-2011, 02:16 PM   #3
BrianK
Senior Member
 
Registered: Mar 2002
Location: Los Angeles, CA
Distribution: Debian, Ubuntu
Posts: 1,334

Original Poster
Rep: Reputation: 51
Thanks Kevin, but what I'm after is getting an OS-specific dialog asking for a password to pop-up. For example, when I open Synaptic on Debian/Ubuntu, I get asked for a password. The same thing often happens for update manager or something of the sort. If, in OSX, I try to copy a file (with the finder) from my homedir to, say, /Applications, it brings up a password dialog. I know those are already X applications, but I was hoping for some sort of way to spawn that from a python script... maybe using an os.system("cp --elevate_privileges /foo /bar") or something like that.

At the end of the day, I'm writing in some functionality into an existing wxPython application that will copy files from one place on a computer to another & would like to be able to do more than tell the user they don't have write permissions to the area they are trying to copy to.

Last edited by BrianK; 08-29-2011 at 02:18 PM.
 
Old 08-29-2011, 05:21 PM   #4
Tinkster
Moderator
 
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928
In terms of portability the problem for Python developers would
be that they need to cater for a whole host WM/DEs, with a variety
of possible choices to get the dialog you desire. There's no generic
built in X11 way to do that, they'll be usinge kdesu, kdesudo, the
gnome equivalents, or even use something as simple as x11-ssh-askpass.


Cheers,
Tink
 
Old 08-29-2011, 05:25 PM   #5
BrianK
Senior Member
 
Registered: Mar 2002
Location: Los Angeles, CA
Distribution: Debian, Ubuntu
Posts: 1,334

Original Poster
Rep: Reputation: 51
I figured that might be the case.

Thanks for the replies/suggestions.
 
Old 08-29-2011, 09:29 PM   #6
ta0kira
Senior Member
 
Registered: Sep 2004
Distribution: FreeBSD 9.1, Kubuntu 12.10
Posts: 3,078

Rep: Reputation: Disabled
Quote:
Originally Posted by Tinkster View Post
In terms of portability the problem for Python developers would
be that they need to cater for a whole host WM/DEs, with a variety
of possible choices to get the dialog you desire. There's no generic
built in X11 way to do that, they'll be usinge kdesu, kdesudo, the
gnome equivalents, or even use something as simple as x11-ssh-askpass.


Cheers,
Tink
And if none of those GUI options are available, you can always fake it with an xterm:
Code:
xterm -e 'sudo -u user cp src dest'
Kevin Barry

PS I think this is the first Programming thread I've seen with > 3,000 views that wasn't over 5 years old. It must make a good search result.

Last edited by ta0kira; 08-29-2011 at 09:36 PM.
 
Old 08-29-2011, 10:22 PM   #7
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,007

Rep: Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192
Just for 2 cents of dissent, you would also need to test / know if something like sudo is actually available too
 
Old 09-23-2011, 01:37 PM   #8
Ian John Locke II
Member
 
Registered: Mar 2008
Location: /dev/null
Distribution: Slackware, Android, Slackware64
Posts: 130

Rep: Reputation: 17
I'm disappointed that no one suggested just running the python script with Audi in the first place... Unless of course you're programming a GUI (for some god awful reason) in which case either os or sys should have the equivalent to C's setuid. It's dangerous, but it works.
 
Old 10-03-2011, 10:39 AM   #9
BrianK
Senior Member
 
Registered: Mar 2002
Location: Los Angeles, CA
Distribution: Debian, Ubuntu
Posts: 1,334

Original Poster
Rep: Reputation: 51
Ian John Locke II, mind sharing some info on "Audi"? Google searching for "Audi Authentication" or "Python Audi" doesn't bring back much in the way of info that isn't related to Audi Automobiles. Do you have a link?
 
Old 10-04-2011, 01:33 PM   #10
Ian John Locke II
Member
 
Registered: Mar 2008
Location: /dev/null
Distribution: Slackware, Android, Slackware64
Posts: 130

Rep: Reputation: 17
Quote:
Originally Posted by BrianK View Post
Ian John Locke II, mind sharing some info on "Audi"? Google searching for "Audi Authentication" or "Python Audi" doesn't bring back much in the way of info that isn't related to Audi Automobiles. Do you have a link?
Har, phone auto "correction". I meant simply running the script with sudo. If you were concerned about doing it across multiple machines fabric (fabfile.org iirc) and paramiko are a must. (I think paramiko relies on pycrypto so that's three things you'd need to download & install)

Sorry about the confusion.
 
  


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
ssh -- Permission denied (publickey,password,keyboard-interactive). davidkline Linux - Networking 11 08-20-2014 02:19 PM
Getting permission denied when reading in password for use with Net::SSH::Perl exceed1 Programming 0 01-30-2009 04:25 PM
Permission denied (publickey,password,keyboard-interactive) cccc Linux - General 3 05-31-2007 05:32 PM
Permission denied (publickey,password,keyboard-interactive). rockymaxsource Linux - Networking 3 04-27-2007 08:32 PM
Python CGI script can't write files, permission denied The_Nerd Programming 4 03-17-2005 12:19 PM

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

All times are GMT -5. The time now is 06:35 PM.

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