Edgewall Software
Modify

Opened 19 years ago

Closed 15 years ago

#2448 closed defect (fixed)

[patch] Trac does not allow spaces in postgres database passwords

Reported by: jacob@… Owned by: John Hampton
Priority: normal Milestone: 0.12
Component: general Version: devel
Severity: normal Keywords:
Cc: pacopablo@… Branch:
Release Notes:
API Changes:
Internal Changes:

Description

Trac currently doesn't allow spaces in postgres database passwords; the following patch (against r2616) fixes it:

Index: trac/db/postgres_backend.py
===================================================================
--- trac/db/postgres_backend.py (revision 2616)
+++ trac/db/postgres_backend.py (working copy)
@@ -91,7 +91,7 @@
             if user:
                 dsn.append('user=' + user)
             if password:
-                dsn.append('password=' + password)
+                dsn.append("password='%s'" % password)
             if host:
                 dsn.append('host=' + host)
             if port:

Attachments (0)

Change History (10)

comment:1 by sid, 18 years ago

Keywords: review added

patch attached, needs to be reviewed

comment:2 by pacopablo, 18 years ago

Cc: pacopablo@… added

comment:3 by Matthew Good, 18 years ago

Owner: changed from Jonas Borgström to Matthew Good

Jacob or John can you test this patch which quotes all parameters to the DSN:

  • trac/db/postgres_backend.py

     
    119119        if 'host' in params:
    120120            host = params['host']
    121121        if psycopg:
    122             dsn = []
    123             if path:
    124                 dsn.append('dbname=' + path)
    125             if user:
    126                 dsn.append('user=' + user)
    127             if password:
    128                 dsn.append('password=' + password)
    129             if host:
    130                 dsn.append('host=' + host)
    131             if port:
    132                 dsn.append('port=' + str(port))
    133             cnx = psycopg.connect(' '.join(dsn))
     122            dsn = {'dbname': path, 'user': user, 'password': password,
     123                   'host': host, 'port': port}
     124            cnx = psycopg.connect(' '.join([("%s='%s'" % k,v) for k,v
     125                                            in dsn.iteritems() if v]))
    134126            cnx.set_client_encoding('UNICODE')
    135127        else:
    136128            # Don't use chatty, inefficient server-side cursors.

comment:4 by Matthew Good, 18 years ago

Milestone: 0.11

comment:5 by Remy Blank, 15 years ago

Keywords: bitesized added

comment:6 by John Hampton, 15 years ago

Keywords: review bitesized removed
Milestone: next-minor-0.12.x0.12
Owner: changed from Matthew Good to John Hampton
Status: newassigned

OK, so patch is mostly correct. The bigger issue is that enabling spaces also screws up the db uri parser. I'll start working on a patch for that.

comment:7 by John Hampton, 15 years ago

Fixed in [9225]

comment:8 by John Hampton, 15 years ago

Resolution: fixed
Status: assignedclosed

comment:9 by Christian Boos, 15 years ago

Resolution: fixed
Status: closedreopened

Meep.

Python 2.4.4 (#71, Oct 18 2006, 08:34:43) [MSC v.1310 32 bit (Intel)] on win32
>>> from itertools import combinations
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
ImportError: cannot import name combinations

ActivePython 2.5.4.4 (ActiveState Software Inc.) based on
Python 2.5.4 (r254:67916, Apr 27 2009, 15:41:14) [MSC v.1310 32 bit (Intel)] on win32

>>> from itertools import combinations
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: cannot import name combinations

Plus note that itertools is riddled with memory issues, try to avoid it (ok, for the tests it's fine).

comment:10 by John Hampton, 15 years ago

Resolution: fixed
Status: reopenedclosed

See what I get for writing tests? :)

Test fixed in [9229]

Modify Ticket

Change Properties
Set your email in Preferences
Action
as closed The owner will remain John Hampton.
The resolution will be deleted. Next status will be 'reopened'.
to The owner will be changed from John Hampton to the specified user.

Add Comment


E-mail address and name can be saved in the Preferences .
 
Note: See TracTickets for help on using tickets.