[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.python

Setting up a new user and environment from within a python script

Henry Hollenberg

2/7/2008 6:16:00 PM

Hello,

I have written a script that uses environment variables set during
a particular users login in ".bash_profile" and ".profile".

I have changed to that users uid and gid in my python script using:

import os
os.setegid
os.setgid
os.seteuid
os.setuid

but I still am not picking up the needed environment. When I run:
os.environ I can see that I still have the environment of the user
that owns the python script.

I would like to maintain the original script owner but somehow pick up
the
correct environment for the targeted user. Several options looked to
create
an environment in a sub-process which I don't think is the correct
solution.

I could of course cut and paste the values from ".bash_profile" &
".profile"
but figured there is probably a better, cleaner way to do the same.

Searched this forum with no luck and checked several python
references.

What is the best practice to achieve this goal?

Thanks, Henry Hollenberg
8 Answers

ericbrunson

2/7/2008 9:31:00 PM

0

On Feb 7, 11:15 am, Henry Hollenberg <h...@rcwm.com> wrote:
> Hello,
>
> I have written a script that uses environment variables set during
> a particular users login in ".bash_profile" and ".profile".
>
> I have changed to that users uid and gid in my python script using:
>
> import os
> os.setegid
> os.setgid
> os.seteuid
> os.setuid
>
> but I still am not picking up the needed environment. When I run:
> os.environ I can see that I still have the environment of the user
> that owns the python script.
>
> I would like to maintain the original script owner but somehow pick up
> the
> correct environment for the targeted user. Several options looked to
> create
> an environment in a sub-process which I don't think is the correct
> solution.
>
> I could of course cut and paste the values from ".bash_profile" &
> ".profile"
> but figured there is probably a better, cleaner way to do the same.
>
> Searched this forum with no luck and checked several python
> references.
>
> What is the best practice to achieve this goal?
>
> Thanks, Henry Hollenberg

Since you're running the python script as root (the only we seteuid
would work) you could call the script using "su" and rely on it to set
the user's environment:

su - otherusername /path/to/your/script

Other than that, the alternatives are to parse the user's dot files
and set the appropriate env variables from within your script, but
that approach is fraught with problems.

Hope that helps a little.

e.

Henry Hollenberg

2/7/2008 9:48:00 PM

0

On Feb 7, 3:30 pm, ericbrun...@gmail.com wrote:
> On Feb 7, 11:15 am, Henry Hollenberg <h...@rcwm.com> wrote:
>
>
>
> > Hello,
>
> > I have written a script that uses environment variables set during
> > a particular users login in ".bash_profile" and ".profile".
>
> > I have changed to that users uid and gid in my python script using:
>
> > import os
> > os.setegid
> > os.setgid
> > os.seteuid
> > os.setuid
>
> > but I still am not picking up the needed environment. When I run:
> > os.environ I can see that I still have the environment of the user
> > that owns the python script.
>
> > I would like to maintain the original script owner but somehow pick up
> > the
> > correct environment for the targeted user. Several options looked to
> > create
> > an environment in a sub-process which I don't think is the correct
> > solution.
>
> > I could of course cut and paste the values from ".bash_profile" &
> > ".profile"
> > but figured there is probably a better, cleaner way to do the same.
>
> > Searched this forum with no luck and checked several python
> > references.
>
> > What is the best practice to achieve this goal?
>
> > Thanks, Henry Hollenberg
>
> Since you're running the python script as root (the only we seteuid
> would work) you could call the script using "su" and rely on it to set
> the user's environment:
>
> su - otherusername /path/to/your/script
>
> Other than that, the alternatives are to parse the user's dot files
> and set the appropriate env variables from within your script, but
> that approach is fraught with problems.
>
> Hope that helps a little.
>
> e.

Right you are. Running it as a cron job. I'll try that trick in
our cron.daily script. Just figured since you can change to another
user from inside python their would be a way to change to another
user's environment as well....ie something comparable to:
source .profile in bash

Thanks hgh.

Dennis Lee Bieber

2/8/2008 7:24:00 AM

0

On Thu, 7 Feb 2008 10:15:53 -0800 (PST), Henry Hollenberg <hgh@rcwm.com>
declaimed the following in comp.lang.python:

>
> but I still am not picking up the needed environment. When I run:
> os.environ I can see that I still have the environment of the user
> that owns the python script.
>
Aren't most of those environment settings /run/ as part of the login
process? Changing group/user IDs doesn't, by itself, run the
configuration shell scripts...

How to solve the problem? Sorry... I can visualize /why/ it doesn't
work, but not how to work around it...
--
Wulfraed Dennis Lee Bieber KD6MOG
wlfraed@ix.netcom.com wulfraed@bestiaria.com
HTTP://wlfraed.home.netcom.com/
(Bestiaria Support Staff: web-asst@bestiaria.com)
HTTP://www.bestiaria.com/

Jeanne Douglas

10/4/2013 11:13:00 PM

0

In article <pan.2013.10.04.11.55.32.66092@nowhere.invalid>,
MarkA <nobody@nowhere.invalid> wrote:

> On Thu, 03 Oct 2013 16:06:18 -0300, John Manning wrote:
>
> >
> >
> > CARTOON: http://www.bartcop.com/weekend-at-...
>
> I'm not good with facial recognition. Is that Boehner they're holding up?

You can tell from the orange skin.

--

JD

"Osama Bin Laden is dead and GM is alive."--VP Joseph Biden

NEMO

10/4/2013 11:36:00 PM

0

On 10/4/2013 4:12 PM, Jeanne Douglas wrote:
> In article <pan.2013.10.04.11.55.32.66092@nowhere.invalid>,
> MarkA <nobody@nowhere.invalid> wrote:
>
>> On Thu, 03 Oct 2013 16:06:18 -0300, John Manning wrote:
>>
>>>
>>>
>>> CARTOON: http://www.bartcop.com/weekend-at-...
>>
>> I'm not good with facial recognition. Is that Boehner they're holding up?
>
> You can tell from the orange skin.

So he's got a tan...what colour's YOUR skin, cunt? Grey?

SkyEyes

10/5/2013 7:26:00 AM

0

MarkA <nobody@nowhere.invalid> wrote in
news:pan.2013.10.04.11.55.32.66092@nowhere.invalid:

> On Thu, 03 Oct 2013 16:06:18 -0300, John Manning wrote:
>
>>
>>
>> CARTOON: http://www.bartcop.com/weekend-at-...
>
> I'm not good with facial recognition. Is that Boehner they're holding
> up?

Yup. You can tell by the color of his skin.

--
Brenda Nelson, A.A.#34 and A+ atheist
BAAWA Knight of the Golden Litterbox
EAC Professor of Feline Thermometrics and Cat-Herding
skyeyes nine at cox dot net OR
skyeyes nine at yahoo dot com



SkyEyes

10/5/2013 7:27:00 AM

0

John Manning <jrobertm@terra.com.br> wrote in
news:JeWdnV8dmPCXQtPPnZ2dnUVZ_smdnZ2d@giganews.com:

> On 10/4/2013 8:55 AM, MarkA wrote:
>> On Thu, 03 Oct 2013 16:06:18 -0300, John Manning wrote:
>>
>>>
>>>
>>> CARTOON: http://www.bartcop.com/weekend-at-...
>>
>> I'm not good with facial recognition. Is that Boehner they're
>> holding up?
>>
>
>
> Yes. That's the orange man himself being pictured well pickled as per
> his reputation.

Well-pickled? In the cartoon he's *dead*. It's a send-up based on the
_Weekend at Bernie's_ movie, where the two stars spend a whole weekend
trying to disguise the fact that their friend Bernie is, um, deceased.

--
Brenda Nelson, A.A.#34 and A+ atheist
BAAWA Knight of the Golden Litterbox
EAC Professor of Feline Thermometrics and Cat-Herding
skyeyes nine at cox dot net OR
skyeyes nine at yahoo dot com



John Manning

10/5/2013 3:36:00 PM

0

On 10/5/2013 4:27 AM, SkyEyes wrote:
> John Manning <jrobertm@terra.com.br> wrote in
> news:JeWdnV8dmPCXQtPPnZ2dnUVZ_smdnZ2d@giganews.com:
>
>> On 10/4/2013 8:55 AM, MarkA wrote:
>>> On Thu, 03 Oct 2013 16:06:18 -0300, John Manning wrote:
>>>
>>>>
>>>>
>>>> CARTOON: http://www.bartcop.com/weekend-at-...
>>>
>>> I'm not good with facial recognition. Is that Boehner they're
>>> holding up?
>>>
>>
>>
>> Yes. That's the orange man himself being pictured well pickled as per
>> his reputation.
>
> Well-pickled? In the cartoon he's *dead*. It's a send-up based on the
> _Weekend at Bernie's_ movie, where the two stars spend a whole weekend
> trying to disguise the fact that their friend Bernie is, um, deceased.
>


In Boehner's case it's a metaphorical equivalency.