On 10/9/06, Jon Rosebaugh <[EMAIL PROTECTED]> wrote:
>
> On 10/9/06, skip <[EMAIL PROTECTED]> wrote:
> >
> > hi all,
> >
> > I am making a control panel application that will do things like let
> > people change their unix password and view a list of their files.
> >
> > Is there some technique/method/something I can google for which will
> > enable me to effectively set the unix user running the script to the
> > user logged in?
>
> If your script is initially running as root, you can use os.seteuid.
> That's the only thing I can think of.

Yep, you'll need to be running as root to start with.  Hopefully,
you'll find this chunk of code useful:

-jj

"""This module contains the ``seteids`` function."""

__docformat__ = "restructuredtext"

import os


def seteids(user, group):
    """Change the ``euid`` and ``egid`` if run as root.

    user, group
      The user and group to change to.

    This function is self contained so that subclasses can easily drop this
    behavior.  I won't, however, bother to catch exceptions because this is
    something you need to think about.

    """
    import pwd
    import grp
    UID = GID = 2
    if not os.geteuid():
        os.setegid(grp.getgrnam(group)[GID])    # This must come first.
        os.seteuid(pwd.getpwnam(user)[UID])

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"pylons-discuss" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/pylons-discuss
-~----------~----~----~----~------~----~------~--~---

Reply via email to