diff options
| author | Olivier Dony <odo@openerp.com> | 2013-03-13 16:20:20 +0100 |
|---|---|---|
| committer | Olivier Dony <odo@openerp.com> | 2013-03-13 16:20:20 +0100 |
| commit | ab76b7a67f9042c90abc292f9f3bb00eae33e066 (patch) | |
| tree | 8f3263901397f0cf2b3ddcf453c01d8071402442 | |
| parent | 52e47a660a1996dac6d1f9d729fef3bd35eac959 (diff) | |
[FIX] web_services: fix db dump/restore when authentication requires a password on non-win32 systems
The various pg_* utilities require the password
via a special environment variable or a special
`pgpass` file in the user home, even on Unix,
namely when the PostgreSQL connection is done
via TCP and not via a unix socket.
Setting the environment variable is relatively
safe if it is removed from the environment
immediately after the operation, and saves user
the trouble of managing the pgpass file themselves.
This had been fixed at revision 3992 but was
incorrectly removed for non win32 platforms
at revision 4424 (rev-id stw@openerp.com-20120912114651-8hcliparft1ep9tc)
lp bug: https://launchpad.net/bugs/790164 fixed
lp bug: https://launchpad.net/bugs/919100 fixed
bzr revid: odo@openerp.com-20130313152020-suo2pyrabae0ecg4
| -rw-r--r-- | openerp/service/web_services.py | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/openerp/service/web_services.py b/openerp/service/web_services.py index 49bbf474020..0aabe62b1d7 100644 --- a/openerp/service/web_services.py +++ b/openerp/service/web_services.py @@ -234,14 +234,22 @@ class db(netsvc.ExportService): @contextlib.contextmanager def _set_pg_password_in_environment(self): - """ On Win32, pg_dump (and pg_restore) require that - :envvar:`PGPASSWORD` be set + """ On systems where pg_restore/pg_dump require an explicit + password (i.e. when not connecting via unix sockets, and most + importantly on Windows), it is necessary to pass the PG user + password in the environment or in a special .pgpass file. This context management method handles setting - :envvar:`PGPASSWORD` iif win32 and the envvar is not already + :envvar:`PGPASSWORD` if it is not already set, and removing it afterwards. + + See also http://www.postgresql.org/docs/8.4/static/libpq-envars.html + + .. note:: This is not thread-safe, and should never be enabled for + SaaS (giving SaaS users the super-admin password is not a good idea + anyway) """ - if os.name != 'nt' or os.environ.get('PGPASSWORD'): + if os.environ.get('PGPASSWORD'): yield else: os.environ['PGPASSWORD'] = tools.config['db_password'] |
