rfc: auto_user_id implicit bug

John Arbash Meinel john at arbash-meinel.com
Tue Jan 30 15:21:00 GMT 2007


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Alexander Belchenko wrote:
> Fixing auto_user_id I found implicit bug in current realization.
> Here excerpt from bzrlib/config.py
> 
> def _auto_user_id():
>     ...
>     try:
>         import pwd
> 	...
>     except ImportError:
>         import getpass
>         try:
>             realname = username = getpass.getuser().decode(bzrlib.user_encoding)
>         except UnicodeDecodeError:
> 		...
> 
> This code contains implicit bug inside.
> Standard pwd module is exist *only* on Unix platform.
> So when import of pwd fails bzr falling down to import getpass.
> But function getpass.getuser *also* try to import pwd!
> Here the actual code:
> 
> def getuser():
>     import os
>     for name in ('LOGNAME', 'USER', 'LNAME', 'USERNAME'):
>         user = os.environ.get(name)
>         if user:
>             return user
> 
>     # If this fails, the exception will "explain" why
>     import pwd
>     return pwd.getpwuid(os.getuid())[0]
> 
> I think that right way to fix this implicit bug in bzr is
> just copy-paste from getuser() iteration over env variables.
> 
> Anyway I fix auto_user_id for windows (especially win98)
> in different way,
> so I just want to notice about this issue because it may
> affects Mac users.
> 
> Alexander

pwd also exists on Mac. At least OS-X, and we've never claimed support
for Mac OS 9.

The thing that you are noticing is that none of:
LOGNAME, USER, LNAME, USERNAME are set.
And pwd isn't available, so none of those functions are available either.

Is there another way to find a username of Windows? Because if
getpass.getuser() is failing, that means there is no user name to be found.

And I'm guessing win98 may not have any concept of a username (since
IIRC you don't ever have to "login" to a win98 machine).

My feeling is that if everything fails we just error out with:

bzr could not determine a valid user name for you. Please set one with
"bzr whoami".

That message isn't quite right, but it would be close.

John
=:->
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.3 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFFv2JcJdeBCYSNAAMRAuWtAKCDqNT0xH2gzZXwzR7qhbgwr+m4xwCcCmb3
EzuWGP5gHtlbzaWvLAU4EVQ=
=Q1ce
-----END PGP SIGNATURE-----



More information about the bazaar mailing list