grp.struct_group bug ?

G

Guest

Is this a bug ?

Running the following script with Python 2.3.5:
.................
#!/usr/bin/python

import grp

# groups = grp.getgrall()

agroup = grp.getgrnam('wheel')
print agroup
print type(agroup)

print agroup.__contains__('john')
print agroup.__contains__('x')
.................


This is the output I get:
.................
('wheel', 'x', 199, ['marcel', 'john', 'ben'])
<type 'grp.struct_group'>
False
True
.................


I expected __contains__ to tell me if a given user is part of a group, but
it seems that it's checking the password field ??

Thanks.

Yves.
 
A

attn.steven.kuo

Is this a bug ?

Running the following script with Python 2.3.5:
................
#!/usr/bin/python

import grp

# groups = grp.getgrall()

agroup = grp.getgrnam('wheel')
print agroup
print type(agroup)

print agroup.__contains__('john')
print agroup.__contains__('x')
................

This is the output I get:
................
('wheel', 'x', 199, ['marcel', 'john', 'ben'])
<type 'grp.struct_group'>
False
True
................

I expected __contains__ to tell me if a given user is part of a group, but
it seems that it's checking the password field ??



The tuple returned by getgrnam contains four fields:
the group id (gr_gid), a list of group members (gr_grmem),
the group name (gr_name), and the group password (gr_passwd).

If you want to see if user 'john' is in the list of group members,
use:

if 'john' in agroup.gr_mem:
print "Found john in group wheel"

If you want to see if a password was set:

if agroup.gr_passwd == "":
print "No group password was set for group wheel"

and so on.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,431
Messages
2,571,677
Members
48,796
Latest member
Greg L.

Latest Threads

Top