Is there a standard module library function to access /etc/passwd or /etc/group

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Robin Cull

    Is there a standard module library function to access /etc/passwd or /etc/group

    Hi all,

    I'm writing a script that needs to do lookups on the UNIX passwd and
    groups file on textual usernames/group names and return numeric
    UID/GID. Something that gives access to the C standard libarary
    functions get[pw|group]ent(), for example. I've Googled around on
    various logical search terms and looked through pydoc and the module
    reference but haven't found anything up to this point. I'd have
    thought that the os module would provide this sort of access. I did
    find something called UserDBM but this appears not to be a standard
    module.

    Before I go away and write a couple of functions to do this myself,
    can anyone tell me if there is a module that provides this sort of
    interface? I'd really like it to be a standard module as the script
    will have to run at a lot of different sites and I'm hoping there are
    no external dependencies past an RPM installation of Python. If not,
    I'll do my own local functions in the script.

    Thanks all.

    Cheers,

    Robin
  • Heather Coppersmith

    #2
    Re: Is there a standard module library function to access /etc/passwd or /etc/group

    On 30 Jul 2003 05:16:43 -0700,
    robin.cull@pace .co.uk (Robin Cull) wrote:
    [color=blue]
    > ... Something that gives access to the C standard libarary
    > functions get[pw|group]ent(), for example ...[/color]

    Right out of the table of contents of Python's Library Reference:

    8.2 pwd -- The password database
    8.3 grp -- The group database

    When all else fails, read the manual.... ;-)

    Regards,
    Heather

    --
    Heather Coppersmith
    That's not right; that's not even wrong. -- Wolfgang Pauli

    Comment

    • Gerhard Häring

      #3
      Re: Is there a standard module library function to access /etc/passwdor /etc/group

      Robin Cull wrote:[color=blue]
      > Hi all,
      >
      > I'm writing a script that needs to do lookups on the UNIX passwd and
      > groups file [...][/color]

      import pwd, grp

      Next question? :)

      -- Gerhard

      Comment

      • Robin Cull

        #4
        Re: Is there a standard module library function to access /etc/passwd or /etc/group

        Heather Coppersmith <me@privacy.net > wrote in message news:<m2vftkw5u m.fsf@host200-null.null.bells outh.net>...[color=blue]
        > On 30 Jul 2003 05:16:43 -0700,
        > robin.cull@pace .co.uk (Robin Cull) wrote:
        >[color=green]
        > > ... Something that gives access to the C standard libarary
        > > functions get[pw|group]ent(), for example ...[/color]
        >
        > Right out of the table of contents of Python's Library Reference:
        >
        > 8.2 pwd -- The password database
        > 8.3 grp -- The group database[/color]

        Those'll be the ones! :)
        [color=blue]
        >
        > When all else fails, read the manual.... ;-)[/color]

        I assure you I did, in fact it baffles me that I missed "pwd" in the
        global module index when I was scanning for "passwd". Then I went off
        on a complete tangent and started looking through "os" and "posix" for
        some reason. A case of "can't see the wood for the trees" I think!

        I'll look harder next time ;)

        Cheers,

        Robin

        Comment

        • Steven Taschuk

          #5
          Re: Is there a standard module library function to access /etc/passwd or /etc/group

          Quoth Andrew Dalke:
          [...][color=blue]
          > When you're stuck because you don't know which module something
          > might be in (eg, I was just looking for XMLRPC server code in
          > xmlrpclib - wrong place!), try the full index at
          > http://python.org/doc/current/lib/genindex.html[/color]

          And don't forget the full-text searching capabilities at pydoc.org.

          --
          Steven Taschuk "The world will end if you get this wrong."
          staschuk@telusp lanet.net -- "Typesettin g Mathematics -- User's Guide",
          Brian Kernighan and Lorrinda Cherry

          Comment

          • Andrew Dalke

            #6
            Re: Is there a standard module library function to access /etc/passwd or /etc/group

            Steven Taschuk:[color=blue]
            > And don't forget the full-text searching capabilities at pydoc.org.[/color]

            Can't forgot something I didn't know about ;)

            Hmmm, my search for "xmlrpc server" fails but "xml-rpc server" is
            successful.

            Any idea when it'll be updated for 2.3?

            Andrew
            dalke@dalkescie ntific.com


            Comment

            Working...