Slackware This Forum is for the discussion of Slackware Linux.
|
Notices |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
|
06-14-2014, 02:35 AM
|
#1
|
Senior Member
Registered: Oct 2005
Distribution: Slackware 14.1
Posts: 3,482
|
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.
|
|
|
06-14-2014, 02:50 AM
|
#2
|
Member
Registered: Mar 2012
Distribution: Slackware, Alma, OpenBSD, FreeBSD
Posts: 550
Rep:
|
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.
|
|
|
06-14-2014, 03:40 AM
|
#3
|
Senior Member
Registered: Sep 2012
Posts: 1,385
|
I don't know zenity and maybe my solution is not what you want.
Have you tried with "who am i" command?
|
|
|
06-14-2014, 04:32 AM
|
#4
|
LQ Addict
Registered: Nov 2008
Location: Paris, France
Distribution: Slint64-15.0
Posts: 11,257
Rep:
|
This would have been nice: 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: 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.
|
06-14-2014, 01:10 PM
|
#5
|
Member
Registered: Jun 2011
Distribution: Slackware
Posts: 515
|
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.
|
06-14-2014, 01:32 PM
|
#6
|
Senior Member
Registered: Oct 2005
Distribution: Slackware 14.1
Posts: 3,482
Original Poster
|
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.
|
|
|
06-14-2014, 01:55 PM
|
#7
|
Senior Member
Registered: Oct 2005
Distribution: Slackware 14.1
Posts: 3,482
Original Poster
|
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!
|
|
|
06-14-2014, 02:15 PM
|
#8
|
Member
Registered: Oct 2011
Distribution: Slackware64
Posts: 364
Rep:
|
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.
|
06-14-2014, 02:46 PM
|
#9
|
Senior Member
Registered: Oct 2005
Distribution: Slackware 14.1
Posts: 3,482
Original Poster
|
Quote:
what about the printenv command?
|
Well, gollygeewillikers Mr. Wilson! Yes, that works!
|
|
|
06-14-2014, 03:37 PM
|
#10
|
Member
Registered: Oct 2011
Distribution: Slackware64
Posts: 364
Rep:
|
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.
|
|
|
All times are GMT -5. The time now is 04:56 PM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|