Running as Administrator on Windows 9.3 vs. 9.4 - Mailing list pgsql-admin

From Thomas Kellerer
Subject Running as Administrator on Windows 9.3 vs. 9.4
Date
Msg-id ma7q2h$2vt$1@ger.gmane.org
Whole thread Raw
List pgsql-admin
Hi all,

I stumbled over a little thing, that I thought might make sense to share - maybe only for having this in the archvies.

I have a little batch file to quickly create a new Postgres cluster for testing purposes, something like this:

--- snip
  set pgdir=%~dp0
  set datadir=%pgdir%datadir
  set bindir=%pgdir%pgsql\bin
  set pwfile=%pgdir%password_for_postgres_db_user.txt
  echo secret> %pwfile%

  %bindir%\initdb -D "%datadir%" --lc-messages=English -U postgres --pwfile="%pwfile%"  -E UTF8 -A md5

--- snip

It assumes the ZIP distribution (provided by EnterpriseDB) is unzipped into the same directory.

This works without any problems, even when the current user is a local Administrator
because initdb, just like pg_ctl, drops the admin privileges.

Now for some reason the following small change crept into my batch file:

  "%bindir%"\initdb -D "%datadir%" --lc-messages=English -U postgres --pwfile="%pwfile%"  -E UTF8 -A md5

The difference is "%bindir%"\initdb vs. %bindir%\initdb

In this case 9.4 initdb fails with the message:

  Execution of PostgreSQL by a user with administrative permissions is not permitted.

Apparently the code that tries to lose the admin privileges stumbles over the quotes around the path but not the .exe

The error message in 9.3 was a bit "better" - at least it gave a better hint on where the problem might be:

  initdb: could not re-execute with restricted token: error code 3
  Execution of PostgreSQL by a user with administrative permissions is not permitted.

I don't really consider this a problem, but I was thinking if it makes sense to enhance the error message in 9.4.
(I also don't know if there are other ways to make re-executing the binary fail)

But then again, maybe the use-case is so uncommon that it doesn't warrant a change at all.

Regards
Thomas


pgsql-admin by date:

Previous
From: Thomas Kellerer
Date:
Subject: Re: PITR compatible backup with exclusion
Next
From: Chuck Roberts
Date:
Subject: What monitoring tools to watch Pgsql 8.4?