pwd behaviour when new users are added
Jeff Epler
jepler at inetnebr.com
Tue Mar 20 22:38:28 EST 2001
On Mon, 19 Mar 2001 12:31:23 -0800, Timothy Grant
<tjg at exceptionalminds.com> wrote:
>I just ran into an interesting feature of the pwd module
>
>say I have users fred, ethel, ricky and lucy on my system and I
>issue a 'pwd.pwgetall()' this returns a tuple with user
>information. Now, while my programme is running I issue a
>'useradd gilligan'
>
>if my programme now issues another 'pwd.pwgetall()' or a
>'pwd.pwgetnam()' or 'pwd.pwgetuid()' the new user name is not
>available.
>
>if I 'reload(pwd)' it still doesn't work if I 'del pwd' and
>then 'import pwd' it doesn't work.
>
>What am I doing wrong?
Calls to the underlying C library functions don't appear to re-open
the password file.
Take a look at the following session with 'strace -e open':
>>> pwd.getpwnam("jepler")
open("/etc/nsswitch.conf", O_RDONLY) = 3
open("/etc/ld.so.cache", O_RDONLY) = 3
open("/lib/libnss_files.so.2", O_RDONLY) = 3
open("/etc/passwd", O_RDONLY) = 3
('jepler', 'x', 405, 405, 'Jeff Epler', '/home/jepler', '/bin/zsh')
>>> pwd.getpwnam("jepler")
open("/etc/passwd", O_RDONLY) = 3
('jepler', 'x', 405, 405, 'Jeff Epler', '/home/jepler', '/bin/zsh')
Adding a call which would endpwent() may help (this doesn't exist in
the pwd module yet), because the next getpw* call will have to reopen
/etc/passwd
Jeff
More information about the Python-list
mailing list