FAQ
Hello,
I was trying to find out whose the program launcher, but os.environ['USER']
returns the user whom owns the desktop environment, regardless the program
is called by root.
I'd like to know it, so the program will run with the right privileges.

Is there any standard function on python, that will do it?
--
goto /dev/null

Search Discussions

  • Nitin Pawar at Jun 7, 2011 at 2:52 pm
    import getpass

    user = getpass.getuser()
    On Tue, Jun 7, 2011 at 7:54 PM, TheSaint wrote:

    Hello,
    I was trying to find out whose the program launcher, but os.environ['USER']
    returns the user whom owns the desktop environment, regardless the program
    is called by root.
    I'd like to know it, so the program will run with the right privileges.

    Is there any standard function on python, that will do it?
    --
    goto /dev/null
    --
    http://mail.python.org/mailman/listinfo/python-list


    --
    Nitin Pawar
    -------------- next part --------------
    An HTML attachment was scrubbed...
    URL: <http://mail.python.org/pipermail/python-list/attachments/20110607/8edea043/attachment.html>
  • Cameron Simpson at Jun 9, 2011 at 4:28 am

    On 07Jun2011 20:22, Nitin Pawar wrote:
    import getpass
    user = getpass.getuser()
    On Tue, Jun 7, 2011 at 7:54 PM, TheSaint wrote:
    I was trying to find out whose the program launcher, but os.environ['USER']
    returns the user whom owns the desktop environment, regardless the program
    is called by root.
    I'd like to know it, so the program will run with the right privileges.
    [...]

    From the getuser() doco:

    Get the username from the environment or password database.
    First try various environment variables, then the password database

    So, no, wrong suggestion.

    Cheers,
    --
    Cameron Simpson <cs at zip.com.au> DoD#743
    http://www.cskk.ezoshosting.com/cs/

    Dangerous stuff, science. Lots of us not fit for it.
    - H.C. Bailey, _The Long Dinner_
  • Kushal Kumaran at Jun 7, 2011 at 2:59 pm

    On Tue, Jun 7, 2011 at 7:54 PM, TheSaint wrote:
    Hello,
    I was trying to find out whose the program launcher, but os.environ['USER']
    returns the user whom owns the desktop environment, regardless the program
    is called by root.
    I'd like to know it, so the program will run with the right privileges.

    Is there any standard function on python, that will do it?
    os.geteuid

    You should consider using the access control mechanisms provided by
    your OS to do this, though. If your program is readable by
    unauthorized users, they can simply make a copy, and change as
    desired.

    --
    regards,
    kushal
  • TheSaint at Jun 8, 2011 at 1:58 pm

    Kushal Kumaran wrote:

    os.geteuid
    This return 0 for *root* . I don't know if it's a standard for all distro.
    Mine is Archlinux.
    I'd just like to avoid error caused by wrong access by user

    --
    goto /dev/null
  • Christopher Head at Jun 8, 2011 at 8:08 pm

    On Wed, 08 Jun 2011 21:58:17 +0800 TheSaint wrote:

    Kushal Kumaran wrote:
    os.geteuid
    This return 0 for *root* . I don't know if it's a standard for all
    distro. Mine is Archlinux.
    I'd just like to avoid error caused by wrong access by user
    It is. Until Linux capabilities, EUID==0 used to be special-cased in the
    kernel as being the test for binding to network ports <1024, bypassing
    filesystem access control, changing the system time, and so on. Since
    Linux caps, it's theoretically possible to use a different UID, but for
    compatibility and convenience, as well as because PID 1 (/sbin/init) is
    still invoked by the kernel as UID 0, everyone still does that.

    Chris
  • TheSaint at Jun 9, 2011 at 11:34 am

    Christopher Head wrote:

    It is. Until Linux capabilities, EUID==0 used to be special-cased in the
    kernel
    Thank you all, I got a good learning *and* something to rememeber.
    --
    goto /dev/null
  • Nobody at Jun 9, 2011 at 2:38 am

    On Wed, 08 Jun 2011 21:58:17 +0800, TheSaint wrote:

    os.geteuid
    This return 0 for *root* . I don't know if it's a standard for all distro.
    UID 0 is the "superuser". The name "root" is conventional, but it's the
    EUID (effective UID) which is used in permission checks; the kernel
    doesn't care about names.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouppython-list @
categoriespython
postedJun 7, '11 at 2:24p
activeJun 9, '11 at 11:34a
posts8
users6
websitepython.org

People

Translate

site design / logo © 2023 Grokbase