Running as Administrator on Windows 9.3 vs. 9.4

From: Thomas Kellerer <spam_eater(at)gmx(dot)net>
To: pgsql-admin(at)postgresql(dot)org
Subject: Running as Administrator on Windows 9.3 vs. 9.4
Date: 2015-01-27 10:42:25
Message-ID: ma7q2h$2vt$1@ger.gmane.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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

Browse pgsql-admin by date

  From Date Subject
Next Message Chuck Roberts 2015-01-27 14:12:29 What monitoring tools to watch Pgsql 8.4?
Previous Message Thomas Kellerer 2015-01-27 07:36:28 Re: PITR compatible backup with exclusion