Opened 17 years ago

Closed 14 years ago

Last modified 14 years ago

#7077 closed (fixed)

Provide a fallback for pwd

Reported by: damien_szczyt Owned by: nobody
Component: Contrib apps Version: dev
Severity: Keywords:
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: yes
Easy pickings: no UI/UX: no

Description

I've created a UNIX user in a mysql database, but my settings doesn't allow the user to know its username via getpwuid.
This is a small patch to set the default username as 'admin' if getpwuid fails.

Attachments (1)

set_default_user_as_admin_if_getpwuid_fails.patch (571 bytes ) - added by damien_szczyt 17 years ago.

Download all attachments as: .zip

Change History (5)

comment:1 by Marc Fargas, 17 years ago

Summary: Creating user when syncdb doesn't work if getpwuid is not availableProvide a fallback for pwd

Altought I don't see why would one prevent getpwuid to work, why don't you first try to read the $USER variable?
That would be a better fallback, even:

default_username = os.environ.get('USER', 'admin')

would do the job.

Anyway, this has been deprecated, you should patch django/contrib/auth/management/commands/createsuperuser.py now.

comment:2 by Malcolm Tredinnick, 16 years ago

Patch needs improvement: set
Triage Stage: UnreviewedAccepted

Regarding this patch:

  1. Bare excepts are bad. We should catch the right exception type explicitly.
  2. If retrieving the default user doesn't work, it should be set to the empty string, just like if the pwd module cannot be imported. No reason to introduce any other default.
  3. As telenieko mentioned, when the patch is updated to accommodate these changes, the relevant code is now in django/contrib/auth/management/commands/createsuperuser.py

comment:3 by Jannis Leidel, 14 years ago

Resolution: fixed
Status: newclosed

(In [14607]) Fixed #7077 and #7431 -- Use getpass.getuser instead of pwd.getpwuid to determine the current system user's username in the createsuperuser management command to enable the feature on Windows. getpass.getuser automatically falls back to the previous method.

comment:4 by Jannis Leidel, 14 years ago

(In [14608]) [1.2.X] Fixed #7077 and #7431 -- Use getpass.getuser instead of pwd.getpwuid to determine the current system user's username in the createsuperuser management command to enable the feature on Windows. getpass.getuser automatically falls back to the previous method.

Backport from trunk (r14607).

Note: See TracTickets for help on using tickets.
Back to Top