102: NIS backend breaks if users don't have names

plu***@gmai***** (Google Code) (Is this you? Claim this profile.)
June 8, 2007
If the user in an NIS system doesn't have a name set (none of ours do...
don't ask me, I don't run it!) the NIS backend blows up on line 26:

  first_name, last_name = passwd[4].split(' ', 1)

Since the split returns an array of length 1.
Index: accounts/backends.py
===================================================================
--- accounts/backends.py	(revision 679)
+++ accounts/backends.py	(working copy)
@@ -26,7 +26,12 @@
             try:
                 if not passwd:
                     passwd = nis.match(username, 'passwd').split(':')
-                first_name, last_name = passwd[4].split(' ', 1)
+		names = passwd[4].split(' ', 1)
+		first_name = names[0]
+		if len( names ) > 1:
+		  last_name = names[1]
+		else:
+		  last_name = ''
                 email = '%s@%s' % (username, settings.NIS_EMAIL_DOMAIN)
 
                 user = User(username=username,
david
#1 david
Committed to svn, thanks!
  • +Fixed