473,399 Members | 4,177 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

grp.struct_group bug ?

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.
----
Yves Dorfsman yv**@zioup.com
http://www.SollerS.ca

Jan 31 '07 #1
2 1110
On Jan 30, 5:42 pm, spam <x...@x.comwrote:
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.

--
Hope this helps,
Steven
Jan 31 '07 #2
at*************@gmail.com wrote:
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"
Thanks !

Yves.
----
Yves Dorfsman yv**@zioup.com
Jan 31 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.