LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware
User Name
Password
Slackware This Forum is for the discussion of Slackware Linux.

Notices


Reply
  Search this Thread
Old 06-14-2014, 02:35 AM   #1
Woodsman
Senior Member
 
Registered: Oct 2005
Distribution: Slackware 14.1
Posts: 3,482

Rep: Reputation: 546Reputation: 546Reputation: 546Reputation: 546Reputation: 546Reputation: 546
whoami


I am writing a zenity script that is run through gksu/tdesu/kdesu/whateversu. After the user enters the password, from that point on the script sees `whoami` as root. Is there a way to determine the original non-root user who launched the script?

In a terminal I can run 'ps aux | $PPID' to pull the user name. Doesn't work when the script is run through whateversu. That is, unlike the terminal, $PPID is owned by root and not the non-root user.

Thanks.
 
Old 06-14-2014, 02:50 AM   #2
TommyC7
Member
 
Registered: Mar 2012
Distribution: Slackware, Alma, OpenBSD, FreeBSD
Posts: 550

Rep: Reputation: Disabled
I don't know too much about zenity, but you say you're using it in a script so I'm assuming you're using zenity with (ba)sh, in which case you can just export a variable with the output of "whoami" BEFORE the su occurs..

That is, before the {gk,tde,kde,whatever}su is launched, use something like:

Code:
export user="$(whoami)"

gksu ...

Last edited by TommyC7; 06-14-2014 at 03:34 AM.
 
Old 06-14-2014, 03:40 AM   #3
kooru
Senior Member
 
Registered: Sep 2012
Posts: 1,385

Rep: Reputation: 275Reputation: 275Reputation: 275
I don't know zenity and maybe my solution is not what you want.
Have you tried with "who am i" command?
 
Old 06-14-2014, 04:32 AM   #4
Didier Spaier
LQ Addict
 
Registered: Nov 2008
Location: Paris, France
Distribution: Slint64-15.0
Posts: 11,257

Rep: Reputation: Disabled
This would have been nice:
Code:
ps -C su -o user=
Unfortunately the "su" command doesn't start a process... (And if several users would have typed su you would have needed to select the good process).

But if you know that the "su" command is typed from a directory owned by the user, just do this:
Code:
stat -c %U .
Or just that:
Code:
whoami>/tmp/whoami
su
cat /tmp/whoami

Last edited by Didier Spaier; 06-14-2014 at 04:49 AM.
 
1 members found this post helpful.
Old 06-14-2014, 01:10 PM   #5
Diantre
Member
 
Registered: Jun 2011
Distribution: Slackware
Posts: 515

Rep: Reputation: 234Reputation: 234Reputation: 234
Environment variables might be what you're looking for. kdesu sets $KDESU_USER with the username calling it, after authenticating. I don't know about gksu and the others, but they probably do as well.
 
1 members found this post helpful.
Old 06-14-2014, 01:32 PM   #6
Woodsman
Senior Member
 
Registered: Oct 2005
Distribution: Slackware 14.1
Posts: 3,482

Original Poster
Rep: Reputation: 546Reputation: 546Reputation: 546Reputation: 546Reputation: 546Reputation: 546
I just noticed I referenced whateversu and that actually would be whateversudo. No difference to the core of the thread, which is to know the actual user launching the script.

My main challenge is the script is run directly with whateversudo. I posted and quit last night discouraged. The moment my head hit the pillow I decided I would use two scripts. The first script would be a front-end to the main script and would pass $USER as a parameter to the main script. If no parameter was passed the main script would display an error dialog and quit.

That said, today I find Didier's post with the stat command. I am shaking my head because that command seems to resolve the problem. I looked at the stat man page and I see the connection with the %U parameter, but I do not pretend to understand all of the magic.

Regardless, thank you!

I need to perform more testing with the script but hopefully in a few days I tag the thread as solved.
 
Old 06-14-2014, 01:55 PM   #7
Woodsman
Senior Member
 
Registered: Oct 2005
Distribution: Slackware 14.1
Posts: 3,482

Original Poster
Rep: Reputation: 546Reputation: 546Reputation: 546Reputation: 546Reputation: 546Reputation: 546
Quote:
Environment variables might be what you're looking for.
That sounds like an idea. With some trial and error I finally got some variables I could use: $SUDO_USER and $SUDO_UID. The strange part is I can't simply pull the variable directly. To extract the variables I have to pipe the env command through grep and sed. Nonetheless, between this method and Didier's I can pull all information to fully confirm the user's identity.

Thank you!
 
Old 06-14-2014, 02:15 PM   #8
j_v
Member
 
Registered: Oct 2011
Distribution: Slackware64
Posts: 364

Rep: Reputation: 67
what about the printenv command?

Code:
printenv SUDO_USER
printenv SUDO_UID
or

Code:
printenv SUDO_USER SUDO_UID
 
1 members found this post helpful.
Old 06-14-2014, 02:46 PM   #9
Woodsman
Senior Member
 
Registered: Oct 2005
Distribution: Slackware 14.1
Posts: 3,482

Original Poster
Rep: Reputation: 546Reputation: 546Reputation: 546Reputation: 546Reputation: 546Reputation: 546
Quote:
what about the printenv command?
Well, gollygeewillikers Mr. Wilson! Yes, that works!
 
Old 06-14-2014, 03:37 PM   #10
j_v
Member
 
Registered: Oct 2011
Distribution: Slackware64
Posts: 364

Rep: Reputation: 67
I think the printenv command is nice for scripting situations like you describe. You can check the output, which can be assigned to a variable. But you can also check the return value of the command to check success, as well. Gives you a nice choice of handling.
 
  


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
whoami klsw LinuxQuestions.org Member Intro 2 06-03-2011 02:59 PM
c++ retrieve output of whoami Endarur Programming 3 03-08-2011 09:38 AM
whoami Permission Denied Curtor Linux - Newbie 16 03-13-2008 10:16 AM
whoami jovo jovo LinuxQuestions.org Member Intro 2 07-31-2003 06:15 PM
whoami question rose_bud4201 Linux - General 8 01-10-2003 04:03 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware

All times are GMT -5. The time now is 04:56 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